Windows: Implement a wrapper of the open() function.
[git/git-svn.git] / compat / mingw.c
blobf869999a5d6ac7b2a7a78781c0c6e16d3446e98f
1 #include "../git-compat-util.h"
3 unsigned int _CRT_fmode = _O_BINARY;
5 #undef open
6 int mingw_open (const char *filename, int oflags, ...)
8 va_list args;
9 unsigned mode;
10 va_start(args, oflags);
11 mode = va_arg(args, int);
12 va_end(args);
14 if (!strcmp(filename, "/dev/null"))
15 filename = "nul";
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))
20 errno = EISDIR;
22 return fd;
25 unsigned int sleep (unsigned int seconds)
27 Sleep(seconds*1000);
28 return 0;
31 int mkstemp(char *template)
33 char *filename = mktemp(template);
34 if (filename == NULL)
35 return -1;
36 return open(filename, O_RDWR | O_CREAT, 0600);
39 int gettimeofday(struct timeval *tv, void *tz)
41 return -1;
44 int poll(struct pollfd *ufds, unsigned int nfds, int timeout)
46 return -1;
49 struct tm *gmtime_r(const time_t *timep, struct tm *result)
51 /* gmtime() in MSVCRT.DLL is thread-safe, but not reentrant */
52 memcpy(result, gmtime(timep), sizeof(struct tm));
53 return result;
56 struct tm *localtime_r(const time_t *timep, struct tm *result)
58 /* localtime() in MSVCRT.DLL is thread-safe, but not reentrant */
59 memcpy(result, localtime(timep), sizeof(struct tm));
60 return result;
63 #undef getcwd
64 char *mingw_getcwd(char *pointer, int len)
66 int i;
67 char *ret = getcwd(pointer, len);
68 if (!ret)
69 return ret;
70 for (i = 0; pointer[i]; i++)
71 if (pointer[i] == '\\')
72 pointer[i] = '/';
73 return ret;
76 struct passwd *getpwuid(int uid)
78 static struct passwd p;
79 return &p;
82 int setitimer(int type, struct itimerval *in, struct itimerval *out)
84 return -1;
87 int sigaction(int sig, struct sigaction *in, struct sigaction *out)
89 return -1;