From: Gurusamy Sarathy Date: Sat, 7 Feb 1998 23:45:22 +0000 (+0000) Subject: [win32] integrate mainline, plus a few small win32 enhancements X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ad0751ec707865dddd3f2c245757f2ef3ccf0dd8;p=p5sagit%2Fp5-mst-13.2.git [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 --- ad0751ec707865dddd3f2c245757f2ef3ccf0dd8 diff --cc win32/makedef.pl index e0312e2,e0312e2..46e4374 --- a/win32/makedef.pl +++ b/win32/makedef.pl @@@ -509,6 -509,6 +509,7 @@@ win32_alar win32_open_osfhandle win32_get_osfhandle win32_ioctl ++win32_utime win32_wait win32_str_os_error Perl_win32_init diff --cc win32/win32.c index 9ae2a7d,9ae2a7d..83ba873 --- a/win32/win32.c +++ b/win32/win32.c @@@ -35,6 -35,6 +35,12 @@@ #include #include #include ++#include ++#ifdef _MSC_VER ++#include ++#else ++#include ++#endif #ifdef __GNUC__ /* Mingw32 defaults to globing command line @@@ -53,6 -53,6 +59,7 @@@ static long tokenize(char *str, char * 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 -800,6 +807,68 @@@ win32_times(struct tms *timebuf return 0; } ++/* fix utime() so it works on directories in NT ++ * thanks to Jan Dubois ++ */ ++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 -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 -1910,6 +1986,7 @@@ 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 -1962,11 +2039,3 @@@ win32_strip_return(SV *sv } #endif -- -- -- -- -- -- -- -- diff --cc win32/win32iop.h index e71bf38,e71bf38..d12e882 --- a/win32/win32iop.h +++ b/win32/win32iop.h @@@ -114,6 -114,6 +114,7 @@@ DllExport int win32_times(struct tms 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 -140,6 +141,7 @@@ END_EXTERN_ #undef times #undef alarm #undef ioctl ++#undef utime #undef wait #ifdef __BORLANDC__ @@@ -240,6 -240,6 +242,7 @@@ #define times win32_times #define alarm win32_alarm #define ioctl win32_ioctl ++#define utime win32_utime #define wait win32_wait #ifdef HAVE_DES_FCRYPT