1 #include "../git-compat-util.h"
3 unsigned int _CRT_fmode = _O_BINARY;
6 int mingw_open (const char *filename, int oflags, ...)
10 va_start(args, oflags);
11 mode = va_arg(args, int);
14 if (!strcmp(filename, "/dev/null"))
16 int fd = open(filename, oflags, mode);
17 if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) {
18 DWORD attrs = GetFileAttributes(filename);
19 if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
25 unsigned int sleep (unsigned int seconds)
31 int mkstemp(char *template)
33 char *filename = mktemp(template);
36 return open(filename, O_RDWR | O_CREAT, 0600);
39 int gettimeofday(struct timeval *tv, void *tz)
44 tm.tm_year = st.wYear-1900;
45 tm.tm_mon = st.wMonth-1;
47 tm.tm_hour = st.wHour;
48 tm.tm_min = st.wMinute;
49 tm.tm_sec = st.wSecond;
50 tv->tv_sec = tm_to_time_t(&tm);
53 tv->tv_usec = st.wMilliseconds*1000;
57 int poll(struct pollfd *ufds, unsigned int nfds, int timeout)
62 struct tm *gmtime_r(const time_t *timep, struct tm *result)
64 /* gmtime() in MSVCRT.DLL is thread-safe, but not reentrant */
65 memcpy(result, gmtime(timep), sizeof(struct tm));
69 struct tm *localtime_r(const time_t *timep, struct tm *result)
71 /* localtime() in MSVCRT.DLL is thread-safe, but not reentrant */
72 memcpy(result, localtime(timep), sizeof(struct tm));
77 char *mingw_getcwd(char *pointer, int len)
80 char *ret = getcwd(pointer, len);
83 for (i = 0; pointer[i]; i++)
84 if (pointer[i] == '\\')
90 int mingw_rename(const char *pold, const char *pnew)
93 * Try native rename() first to get errno right.
94 * It is based on MoveFile(), which cannot overwrite existing files.
96 if (!rename(pold, pnew))
100 if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING))
102 /* TODO: translate more errors */
103 if (GetLastError() == ERROR_ACCESS_DENIED) {
104 DWORD attrs = GetFileAttributes(pnew);
105 if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) {
114 struct passwd *getpwuid(int uid)
116 static char user_name[100];
117 static struct passwd p;
119 DWORD len = sizeof(user_name);
120 if (!GetUserName(user_name, &len))
122 p.pw_name = user_name;
123 p.pw_gecos = "unknown";
128 int setitimer(int type, struct itimerval *in, struct itimerval *out)
133 int sigaction(int sig, struct sigaction *in, struct sigaction *out)