Skip to content

Commit

Permalink
Bug Fixes and Performance Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nixrajput committed Jul 23, 2024
1 parent 6dc21ad commit 8471fdd
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/utils.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
#ifndef UTILS_H
#define UTILS_H

#include <iostream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <limits>
#include <ctime>
#include <stddef.h>
#include <sstream>

using namespace std;

// #if defined(_WIN32) || defined(_WIN64)
// #include <windows.h>
// #else
// #include <unistd.h>
// #endif

void printHeading(string header)
{
cout << "\n\n\n\n";
Expand All @@ -36,9 +42,22 @@ string getCurrentDate()
{
time_t t = time(NULL);
struct tm tStruct;

#if defined(_WIN32) || defined(_WIN64)
// Windows: Use localtime_s
localtime_s(&tStruct, &t);
#else
// POSIX-compliant systems (Linux and macOS): Use localtime_r
localtime_r(&t, &tStruct);
#endif

// Use stringstream for efficient string construction
ostringstream oss;
oss << tStruct.tm_mday << "-"
<< (tStruct.tm_mon + 1) << "-"
<< (tStruct.tm_year + 1900);

return to_string(tStruct.tm_mday) + "-" + to_string(tStruct.tm_mon + 1) + "-" + to_string(tStruct.tm_year + 1900);
return oss.str();
}

size_t strlcpy(char *dst, const char *src, size_t dstsize = numeric_limits<size_t>::max())
Expand Down

0 comments on commit 8471fdd

Please sign in to comment.