diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1998-02-07 23:45:22 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-02-07 23:45:22 +0000 |
commit | ad0751ec707865dddd3f2c245757f2ef3ccf0dd8 (patch) | |
tree | 78a32b98f8534e35321a391fbb43da325d98dddd /win32 | |
parent | 7e3be867c805de9df8b4e2ab54f88f956419821c (diff) | |
parent | 4c2eb2563685e652246970f0aedca9ee496d53d5 (diff) | |
download | perl-ad0751ec707865dddd3f2c245757f2ef3ccf0dd8.tar.gz |
[win32] integrate mainline, plus a few small win32 enhancements
- remove Win32::GetCurrentDirectory()
- add Win32::Sleep() for compat
- add smarter utime() from Jan Dubois, and export it as win32_utime()
p4raw-id: //depot/win32/perl@486
Diffstat (limited to 'win32')
-rw-r--r-- | win32/makedef.pl | 1 | ||||
-rw-r--r-- | win32/win32.c | 91 | ||||
-rw-r--r-- | win32/win32iop.h | 3 |
3 files changed, 84 insertions, 11 deletions
diff --git a/win32/makedef.pl b/win32/makedef.pl index e0312e2494..46e4374838 100644 --- a/win32/makedef.pl +++ b/win32/makedef.pl @@ -509,6 +509,7 @@ win32_alarm win32_open_osfhandle win32_get_osfhandle win32_ioctl +win32_utime win32_wait win32_str_os_error Perl_win32_init diff --git a/win32/win32.c b/win32/win32.c index 9ae2a7d70f..83ba873334 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -35,6 +35,12 @@ #include <string.h> #include <stdarg.h> #include <float.h> +#include <time.h> +#ifdef _MSC_VER +#include <sys/utime.h> +#else +#include <utime.h> +#endif #ifdef __GNUC__ /* Mingw32 defaults to globing command line @@ -53,6 +59,7 @@ static long tokenize(char *str, char **dest, char ***destv); static int do_spawn2(char *cmd, int exectype); static BOOL has_redirection(char *ptr); static long filetime_to_clock(PFILETIME ft); +static BOOL filetime_from_time(PFILETIME ft, time_t t); char * w32_perlshell_tokens = Nullch; char ** w32_perlshell_vec; @@ -800,6 +807,68 @@ win32_times(struct tms *timebuf) return 0; } +/* fix utime() so it works on directories in NT + * thanks to Jan Dubois <jan.dubois@ibm.net> + */ +static BOOL +filetime_from_time(PFILETIME pFileTime, time_t Time) +{ + struct tm *pTM = gmtime(&Time); + SYSTEMTIME SystemTime; + + if (pTM == NULL) + return FALSE; + + SystemTime.wYear = pTM->tm_year + 1900; + SystemTime.wMonth = pTM->tm_mon + 1; + SystemTime.wDay = pTM->tm_mday; + SystemTime.wHour = pTM->tm_hour; + SystemTime.wMinute = pTM->tm_min; + SystemTime.wSecond = pTM->tm_sec; + SystemTime.wMilliseconds = 0; + + return SystemTimeToFileTime(&SystemTime, pFileTime); +} + +DllExport int +win32_utime(const char *filename, const struct utimbuf *times) +{ + HANDLE handle; + FILETIME ftCreate; + FILETIME ftAccess; + FILETIME ftWrite; + struct utimbuf TimeBuffer; + + int rc = utime(filename,times); + /* EACCES: path specifies directory or readonly file */ + if (rc == 0 || errno != EACCES /* || !IsWinNT() */) + return rc; + + if (times == NULL) { + times = &TimeBuffer; + time(×->actime); + times->modtime = times->actime; + } + + /* This will (and should) still fail on readonly files */ + handle = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, + OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (handle == INVALID_HANDLE_VALUE) + return rc; + + if (GetFileTime(handle, &ftCreate, &ftAccess, &ftWrite) && + filetime_from_time(&ftAccess, times->actime) && + filetime_from_time(&ftWrite, times->modtime) && + SetFileTime(handle, &ftCreate, &ftAccess, &ftWrite)) + { + rc = 0; + } + + CloseHandle(handle); + return rc; +} + DllExport int win32_wait(int *status) { @@ -1885,15 +1954,22 @@ XS(w32_GetShortPathName) XSRETURN(1); } +static +XS(w32_Sleep) +{ + dXSARGS; + if (items != 1) + croak("usage: Win32::Sleep($milliseconds)"); + Sleep(SvIV(ST(0))); + XSRETURN_YES; +} + void Perl_init_os_extras() { char *file = __FILE__; dXSUB_SYS; - /* XXX should be removed after checking with Nick */ - newXS("Win32::GetCurrentDirectory", w32_GetCwd, file); - /* these names are Activeware compatible */ newXS("Win32::GetCwd", w32_GetCwd, file); newXS("Win32::SetCwd", w32_SetCwd, file); @@ -1910,6 +1986,7 @@ Perl_init_os_extras() newXS("Win32::Spawn", w32_Spawn, file); newXS("Win32::GetTickCount", w32_GetTickCount, file); newXS("Win32::GetShortPathName", w32_GetShortPathName, file); + newXS("Win32::Sleep", w32_Sleep, file); /* XXX Bloat Alert! The following Activeware preloads really * ought to be part of Win32::Sys::*, so they're not included @@ -1962,11 +2039,3 @@ win32_strip_return(SV *sv) } #endif - - - - - - - - diff --git a/win32/win32iop.h b/win32/win32iop.h index e71bf3865e..d12e882b9b 100644 --- a/win32/win32iop.h +++ b/win32/win32iop.h @@ -114,6 +114,7 @@ DllExport int win32_times(struct tms *timebuf); DllExport unsigned win32_alarm(unsigned int sec); DllExport int win32_stat(const char *path, struct stat *buf); DllExport int win32_ioctl(int i, unsigned int u, char *data); +DllExport int win32_utime(const char *f, const struct utimbuf *t); DllExport int win32_wait(int *status); #ifdef HAVE_DES_FCRYPT @@ -140,6 +141,7 @@ END_EXTERN_C #undef times #undef alarm #undef ioctl +#undef utime #undef wait #ifdef __BORLANDC__ @@ -240,6 +242,7 @@ END_EXTERN_C #define times win32_times #define alarm win32_alarm #define ioctl win32_ioctl +#define utime win32_utime #define wait win32_wait #ifdef HAVE_DES_FCRYPT |