some win32 tweaks
This commit is contained in:
parent
1e34abbb35
commit
201b475133
@ -956,24 +956,41 @@ static void log_write (moo_t* moo, moo_bitmask_t mask, const moo_ooch_t* msg, mo
|
|||||||
* do classification based on mask. */
|
* do classification based on mask. */
|
||||||
if (!(mask & (MOO_LOG_STDOUT | MOO_LOG_STDERR)))
|
if (!(mask & (MOO_LOG_STDOUT | MOO_LOG_STDERR)))
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
TIME_ZONE_INFORMATION tzi;
|
||||||
|
SYSTEMTIME now;
|
||||||
|
#else
|
||||||
time_t now;
|
time_t now;
|
||||||
|
struct tm tm, *tmp;
|
||||||
|
#endif
|
||||||
#if defined(MOO_OOCH_IS_UCH)
|
#if defined(MOO_OOCH_IS_UCH)
|
||||||
char ts[32 * MOO_BCSIZE_MAX];
|
char ts[32 * MOO_BCSIZE_MAX];
|
||||||
#else
|
#else
|
||||||
char ts[32];
|
char ts[32];
|
||||||
#endif
|
#endif
|
||||||
moo_oow_t tslen;
|
moo_oow_t tslen;
|
||||||
struct tm tm, *tmp;
|
|
||||||
|
|
||||||
now = time(MOO_NULL);
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
tmp = localtime(&now);
|
/* %z for strftime() in win32 seems to produce a long non-numeric timezone name.
|
||||||
tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp);
|
* i don't use strftime() for time formatting. */
|
||||||
if (tslen == 0)
|
GetLocalTime (&now);
|
||||||
|
if (GetTimeZoneInformation(&tzi) != TIME_ZONE_ID_INVALID)
|
||||||
{
|
{
|
||||||
tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
|
tzi.Bias = -tzi.Bias;
|
||||||
|
tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d %+02.2d%02.2d ",
|
||||||
|
(int)now.wYear, (int)now.wMonth, (int)now.wDay,
|
||||||
|
(int)now.wHour, (int)now.wMinute, (int)now.wSecond,
|
||||||
|
(int)(tzi.Bias / 60), (int)(tzi.Bias % 60));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ",
|
||||||
|
(int)now.wYear, (int)now.wMonth, (int)now.wDay,
|
||||||
|
(int)now.wHour, (int)now.wMinute, (int)now.wSecond);
|
||||||
}
|
}
|
||||||
#elif defined(__OS2__)
|
#elif defined(__OS2__)
|
||||||
|
now = time(MOO_NULL);
|
||||||
|
|
||||||
#if defined(__WATCOMC__)
|
#if defined(__WATCOMC__)
|
||||||
tmp = _localtime(&now, &tm);
|
tmp = _localtime(&now, &tm);
|
||||||
#else
|
#else
|
||||||
@ -992,10 +1009,12 @@ static void log_write (moo_t* moo, moo_bitmask_t mask, const moo_ooch_t* msg, mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(__DOS__)
|
#elif defined(__DOS__)
|
||||||
|
now = time(MOO_NULL);
|
||||||
tmp = localtime(&now);
|
tmp = localtime(&now);
|
||||||
/* since i know that %z/%Z is not available in strftime, i switch to sprintf immediately */
|
/* since i know that %z/%Z is not available in strftime, i switch to sprintf immediately */
|
||||||
tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
|
tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
|
||||||
#else
|
#else
|
||||||
|
now = time(MOO_NULL);
|
||||||
#if defined(HAVE_LOCALTIME_R)
|
#if defined(HAVE_LOCALTIME_R)
|
||||||
tmp = localtime_r(&now, &tm);
|
tmp = localtime_r(&now, &tm);
|
||||||
#else
|
#else
|
||||||
|
@ -91,6 +91,7 @@ static moo_pfrc_t pf_open_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
|||||||
goto oops;
|
goto oops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(O_NONBLOCK) && defined(O_CLOEXEC)
|
||||||
fl = fcntl(fd, F_GETFL, 0);
|
fl = fcntl(fd, F_GETFL, 0);
|
||||||
if (fl == -1)
|
if (fl == -1)
|
||||||
{
|
{
|
||||||
@ -102,6 +103,7 @@ static moo_pfrc_t pf_open_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
|||||||
fl |= O_NONBLOCK | O_CLOEXEC;
|
fl |= O_NONBLOCK | O_CLOEXEC;
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFL, fl) == -1) goto fcntl_failure;
|
if (fcntl(fd, F_SETFL, fl) == -1) goto fcntl_failure;
|
||||||
|
#endif
|
||||||
|
|
||||||
io->handle = MOO_SMOOI_TO_OOP(fd);
|
io->handle = MOO_SMOOI_TO_OOP(fd);
|
||||||
MOO_STACK_SETRETTORCV (moo, nargs);
|
MOO_STACK_SETRETTORCV (moo, nargs);
|
||||||
@ -146,6 +148,10 @@ oops:
|
|||||||
|
|
||||||
static moo_pfrc_t pf_chmod_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
static moo_pfrc_t pf_chmod_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
moo_seterrnum (moo, MOO_ENOIMPL);
|
||||||
|
return MOO_PF_FAILURE;
|
||||||
|
#else
|
||||||
moo_oop_t tmp;
|
moo_oop_t tmp;
|
||||||
int fd;
|
int fd;
|
||||||
moo_oow_t mode;
|
moo_oow_t mode;
|
||||||
@ -163,11 +169,16 @@ static moo_pfrc_t pf_chmod_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
|||||||
|
|
||||||
SETRET_WITH_SYSCALL (moo, nargs, fchmod(fd, mode));
|
SETRET_WITH_SYSCALL (moo, nargs, fchmod(fd, mode));
|
||||||
return MOO_PF_SUCCESS;
|
return MOO_PF_SUCCESS;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static moo_pfrc_t pf_chown_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
static moo_pfrc_t pf_chown_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
moo_seterrnum (moo, MOO_ENOIMPL);
|
||||||
|
return MOO_PF_FAILURE;
|
||||||
|
#else
|
||||||
moo_oop_t tmp;
|
moo_oop_t tmp;
|
||||||
int fd;
|
int fd;
|
||||||
moo_ooi_t uid, gid;
|
moo_ooi_t uid, gid;
|
||||||
@ -196,10 +207,15 @@ static moo_pfrc_t pf_chown_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
|||||||
|
|
||||||
SETRET_WITH_SYSCALL (moo, nargs, fchown(fd, uid, gid));
|
SETRET_WITH_SYSCALL (moo, nargs, fchown(fd, uid, gid));
|
||||||
return MOO_PF_SUCCESS;
|
return MOO_PF_SUCCESS;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static moo_pfrc_t pf_lock_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
static moo_pfrc_t pf_lock_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||||
{
|
{
|
||||||
|
#if defined(_WIN32)
|
||||||
|
moo_seterrnum (moo, MOO_ENOIMPL);
|
||||||
|
return MOO_PF_FAILURE;
|
||||||
|
#else
|
||||||
moo_oop_t tmp;
|
moo_oop_t tmp;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
@ -214,6 +230,7 @@ static moo_pfrc_t pf_lock_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
|||||||
|
|
||||||
SETRET_WITH_SYSCALL (moo, nargs, flock(fd, MOO_OOP_TO_SMOOI(tmp)));
|
SETRET_WITH_SYSCALL (moo, nargs, flock(fd, MOO_OOP_TO_SMOOI(tmp)));
|
||||||
return MOO_PF_SUCCESS;
|
return MOO_PF_SUCCESS;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static moo_pfrc_t pf_seek_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
static moo_pfrc_t pf_seek_file (moo_t* moo, moo_mod_t* mod, moo_ooi_t nargs)
|
||||||
@ -293,6 +310,14 @@ static moo_pfinfo_t pfinfos[] =
|
|||||||
{ I, "truncate:", { pf_truncate_file, 1, 1 } }
|
{ I, "truncate:", { pf_truncate_file, 1, 1 } }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
# define LOCK_EX 0
|
||||||
|
# define LOCK_NB 0
|
||||||
|
# define LOCK_SH 0
|
||||||
|
# define LOCK_UN 0
|
||||||
|
# define O_NOFOLLOW 0
|
||||||
|
# define O_NONBLOCK 0
|
||||||
|
#endif
|
||||||
static moo_pvinfo_t pvinfos[] =
|
static moo_pvinfo_t pvinfos[] =
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user