#include "libbb.h" unsigned int _CRT_fmode = _O_BINARY; unsigned int sleep (unsigned int seconds) { Sleep(seconds*1000); return 0; } int mkstemp(char *template) { char *filename = mktemp(template); if (filename == NULL) return -1; return open(filename, O_RDWR | O_CREAT, 0600); } /* * This is like mktime, but without normalization of tm_wday and tm_yday. */ static time_t tm_to_time_t(const struct tm *tm) { static const int mdays[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; int year = tm->tm_year - 70; int month = tm->tm_mon; int day = tm->tm_mday; if (year < 0 || year > 129) /* algo only works for 1970-2099 */ return -1; if (month < 0 || month > 11) /* array bounds */ return -1; if (month < 2 || (year + 2) % 4) day--; return (year * 365 + (year + 1) / 4 + mdays[month] + day) * 24*60*60UL + tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; } int gettimeofday(struct timeval *tv, void *tz) { SYSTEMTIME st; struct tm tm; GetSystemTime(&st); tm.tm_year = st.wYear-1900; tm.tm_mon = st.wMonth-1; tm.tm_mday = st.wDay; tm.tm_hour = st.wHour; tm.tm_min = st.wMinute; tm.tm_sec = st.wSecond; tv->tv_sec = tm_to_time_t(&tm); if (tv->tv_sec < 0) return -1; tv->tv_usec = st.wMilliseconds*1000; return 0; } int pipe(int filedes[2]) { if (_pipe(filedes, PIPE_BUF, 0) < 0) return -1; return 0; } struct tm *gmtime_r(const time_t *timep, struct tm *result) { /* gmtime() in MSVCRT.DLL is thread-safe, but not reentrant */ memcpy(result, gmtime(timep), sizeof(struct tm)); return result; } struct tm *localtime_r(const time_t *timep, struct tm *result) { /* localtime() in MSVCRT.DLL is thread-safe, but not reentrant */ memcpy(result, localtime(timep), sizeof(struct tm)); return result; } struct passwd *getpwuid(int uid) { static char user_name[100]; static struct passwd p; DWORD len = sizeof(user_name); if (!GetUserName(user_name, &len)) return NULL; p.pw_name = user_name; p.pw_gecos = "unknown"; p.pw_dir = NULL; return &p; }