2007-12-01 23:24:59 +03:00
|
|
|
#include "../git-compat-util.h"
|
|
|
|
|
|
|
|
unsigned int _CRT_fmode = _O_BINARY;
|
|
|
|
|
2007-11-16 00:22:47 +03:00
|
|
|
#undef open
|
|
|
|
int mingw_open (const char *filename, int oflags, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
unsigned mode;
|
|
|
|
va_start(args, oflags);
|
|
|
|
mode = va_arg(args, int);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
if (!strcmp(filename, "/dev/null"))
|
|
|
|
filename = "nul";
|
|
|
|
int fd = open(filename, oflags, mode);
|
|
|
|
if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) {
|
|
|
|
DWORD attrs = GetFileAttributes(filename);
|
|
|
|
if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
|
errno = EISDIR;
|
|
|
|
}
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2007-12-01 23:24:59 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
int gettimeofday(struct timeval *tv, void *tz)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int poll(struct pollfd *ufds, unsigned int nfds, int timeout)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-03-05 23:51:27 +03:00
|
|
|
#undef getcwd
|
|
|
|
char *mingw_getcwd(char *pointer, int len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *ret = getcwd(pointer, len);
|
|
|
|
if (!ret)
|
|
|
|
return ret;
|
|
|
|
for (i = 0; pointer[i]; i++)
|
|
|
|
if (pointer[i] == '\\')
|
|
|
|
pointer[i] = '/';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-12-01 23:24:59 +03:00
|
|
|
struct passwd *getpwuid(int uid)
|
|
|
|
{
|
2007-12-02 00:09:17 +03:00
|
|
|
static char user_name[100];
|
2007-12-01 23:24:59 +03:00
|
|
|
static struct passwd p;
|
2007-12-02 00:09:17 +03:00
|
|
|
|
|
|
|
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;
|
2007-12-01 23:24:59 +03:00
|
|
|
return &p;
|
|
|
|
}
|
|
|
|
|
|
|
|
int setitimer(int type, struct itimerval *in, struct itimerval *out)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int sigaction(int sig, struct sigaction *in, struct sigaction *out)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|