[win32] integrate mainline, plus a few small win32 enhancements
authorGurusamy Sarathy <gsar@cpan.org>
Sat, 7 Feb 1998 23:45:22 +0000 (23:45 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Sat, 7 Feb 1998 23:45:22 +0000 (23:45 +0000)
 - 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

1  2 
win32/makedef.pl
win32/win32.c
win32/win32iop.h

@@@ -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
  #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 -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 <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(&times->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);
      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
--
--
--
--
--
--
--
--
@@@ -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__
  #define times                 win32_times
  #define alarm                 win32_alarm
  #define ioctl                 win32_ioctl
++#define utime                 win32_utime
  #define wait                  win32_wait
  
  #ifdef HAVE_DES_FCRYPT