Skip to content

Commit

Permalink
shared
Browse files Browse the repository at this point in the history
  • Loading branch information
medoc92 committed Jun 27, 2024
1 parent 3d6facb commit a84b27f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
6 changes: 6 additions & 0 deletions src/inc/smallut.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ bool wchartoutf8(const wchar_t *in, std::string& out, int len = 0);
std::string wchartoutf8(const wchar_t *in, int len = 0);
bool utf8towchar(const std::string& in, wchar_t *out, int obytescap);
std::unique_ptr<wchar_t[]> utf8towchar(const std::string& in);
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define localtime_r(a,b) localtime_s(b,a)
#define strtok_r strtok_s
#endif // _WIN32

/** Note for all templated functions:
Expand Down Expand Up @@ -286,6 +290,8 @@ extern std::string pc_decode(const std::string&);
/// start meaning count from the end).
bool parseHTTPRanges(const std::string& ranges, std::vector<std::pair<int64_t, int64_t>>& oranges);

void millisleep(int millis);


} // End namespace MedocUtils

Expand Down
39 changes: 32 additions & 7 deletions src/utils/smallut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#ifdef BUILDING_RECOLL
#include "autoconfig.h"
#else
#include "config.h"
#endif

#include "smallut.h"

#include <algorithm>
Expand Down Expand Up @@ -46,11 +52,6 @@


#ifdef _WIN32
#ifdef _MSC_VER
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#define localtime_r(a,b) localtime_s(b,a)
#endif // _MSC_VER

#define WIN32_LEAN_AND_MEAN
#define NOGDI
Expand Down Expand Up @@ -946,8 +947,12 @@ static void unsetenv(const char* name)
{
_putenv_s(name, "");
}
#endif

#ifdef _MSC_VER
time_t portable_timegm(struct tm *tm)
{
return _mkgmtime(tm);
}
#else
time_t portable_timegm(struct tm *tm)
{
time_t ret;
Expand All @@ -965,6 +970,14 @@ time_t portable_timegm(struct tm *tm)
tzset();
return ret;
}
#endif // End Windows not msvc
#else // -> !Windows
time_t portable_timegm(struct tm *tm)
{
return timegm(tm);
}
#endif


std::string hexprint(const std::string& in, char separ)
{
Expand Down Expand Up @@ -1263,6 +1276,18 @@ bool parseHTTPRanges(const std::string& ranges, std::vector<std::pair<int64_t, i
return true;
}

void millisleep(int millis)
{
#ifdef _WIN32
Sleep(millis);
#else
struct timespec spec;
spec.tv_sec = millis / 1000;
spec.tv_nsec = (millis % 1000) * 1000000;
nanosleep(&spec, nullptr);
#endif
}

// Initialization for static stuff to be called from main thread before going
// multiple
void smallut_init_mt()
Expand Down

0 comments on commit a84b27f

Please sign in to comment.