Archive-Unzip-Burst

 view release on metacpan or  search on metacpan

unzip-6.0/win32-experimental/unz60d10_w32wide-Unicode_patch.txt  view on Meta::CPAN

+#if defined(UNICODE_SUPPORT) && defined(WIN32_WIDE)
+static int FStampIsLocTimeW(__GPRO__ const wchar_t *pathw)
+{
+    return (NTQueryVolInfoW(__G__ pathw) ? G.lastVolLocTim : FALSE);
+}
+#endif
+
+
 
 #ifndef NO_W32TIMES_IZFIX
@@ -991,4 +1050,63 @@
 
 
+#if defined(UNICODE_SUPPORT) && defined(WIN32_WIDE)
+  static int getNTfiletimeW(__G__ pModFT, pAccFT, pCreFT)
+      __GDEF
+      FILETIME *pModFT;
+      FILETIME *pAccFT;
+      FILETIME *pCreFT;
+  {
+# ifdef USE_EF_UT_TIME
+      unsigned eb_izux_flg;
+      iztimes z_utime;   /* struct for Unix-style actime & modtime, + creatime */
+# endif
+      int fs_uses_loctime = FStampIsLocTimeW(__G__ G.unipath_widefilename);
+
+      /* Copy and/or convert time and date variables, if necessary;
+       * return a flag indicating which time stamps are available. */
+# ifdef USE_EF_UT_TIME
+      if (G.extra_field &&
+#  ifdef IZ_CHECK_TZ
+          G.tz_is_valid &&
+#  endif
+          ((eb_izux_flg = ef_scan_for_izux(G.extra_field,
+            G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime,
+            &z_utime, NULL)) & EB_UT_FL_MTIME))
+      {
+          TTrace((stderr, "getNTfiletime:  Unix e.f. modif. time = %lu\n",
+            z_utime.mtime));
+          UTIME_2_IZFILETIME(z_utime.mtime, pModFT)
+          if (eb_izux_flg & EB_UT_FL_ATIME) {
+              UTIME_2_IZFILETIME(z_utime.atime, pAccFT)
+          }
+          if (eb_izux_flg & EB_UT_FL_CTIME) {
+              UTIME_2_IZFILETIME(z_utime.ctime, pCreFT)
+          }
+          return (int)eb_izux_flg;
+      }
+# endif /* USE_EF_UT_TIME */
+# ifndef NO_W32TIMES_IZFIX
+      if (!fs_uses_loctime) {
+          time_t ux_modtime;
+
+          ux_modtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
+          utime2NtfsFileTime(ux_modtime, pModFT);
+      } else
+#endif /* NO_W32TIMES_IZFIX */
+      {
+          FILETIME lft;
+
+          DosDateTimeToFileTime((WORD)(G.lrec.last_mod_dos_datetime >> 16),
+                                (WORD)(G.lrec.last_mod_dos_datetime & 0xFFFFL),
+                                &lft);
+          LocalFileTimeToFileTime(&lft, pModFT);
+      }
+      *pAccFT = *pModFT;
+      return (EB_UT_FL_MTIME | EB_UT_FL_ATIME);
+
+  } /* end function getNTfiletime() */
+#endif /* (UNICODE_SUPPORT && WIN32_WIDE) */
+
+
 
 
@@ -1059,66 +1177,72 @@
     unsigned ebSDlen;
 #endif
+
+#if defined(UNICODE_SUPPORT) && defined(WIN32_WIDE)
+    if (!G.has_win32_wide) {
+#endif
 #ifdef __RSXNT__        /* RSXNT/EMX C rtl uses OEM charset */
-    char *ansi_name = (char *)alloca(strlen(G.filename) + 1);
+      char *ansi_name = (char *)alloca(strlen(G.filename) + 1);
 
-    INTERN_TO_ISO(G.filename, ansi_name);
-#   define Ansi_Fname  ansi_name
+      INTERN_TO_ISO(G.filename, ansi_name);
+#     define Ansi_Fname  ansi_name
 #else
-#   define Ansi_Fname  G.filename
+#     define Ansi_Fname  G.filename
 #endif
 
 #ifndef __RSXNT__
-    if (IsWinNT()) {
+# if !(defined(UNICODE_SUPPORT) && defined(WIN32_WIDE))
+      if (IsWinNT()) {
         /* Truncate the file to the current position.
          * This is needed to remove excess allocation in case the
          * extraction has failed or stopped prematurely. */
         SetEndOfFile((HANDLE)_get_osfhandle(fileno(G.outfile)));
-    }
+      }
+# endif /* !(defined(UNICODE_SUPPORT) && defined(WIN32_WIDE)) */
 #endif
 
-    /* Close the file and then re-open it using the Win32
-     * CreateFile call, so that the file can be created
-     * with GENERIC_WRITE access, otherwise the SetFileTime
-     * call will fail. */
-    fclose(G.outfile);
-
-    /* don't set the time stamp and attributes on standard output */
-    if (uO.cflag)
-        return;
-
-    /* skip restoring time stamps on user's request */
-    if (uO.D_flag <= 1) {
-        gotTime = getNTfiletime(__G__ &Modft, &Accft, &Creft);
-

unzip-6.0/win32-experimental/unz60d10_w32wide-Unicode_patch.txt  view on Meta::CPAN

+              char *rootpath = wchar_to_local_string(G.rootpathw, G.unicode_escape_all);
+              Trace((stderr, "rootpath now = [%s]\n", FnFilter1(rootpath)));
+              free(rootpath);
+            }
         }
         return MPN_OK;
@@ -2467,5 +3747,5 @@
         Trace((stderr, "freeing rootpath\n"));
         if (G.rootlen > 0) {
-            free(G.rootpath);
+            free(G.rootpathw);
             G.rootlen = 0;
         }
@@ -2475,6 +3755,7 @@
     return MPN_INVALID; /* should never reach */
 
-} /* end function checkdir() */
+} /* end function checkdirw() */
 
+#endif /* defined(UNICODE_SUPPORT) && defined(WIN32_WIDE) */
 
 
@@ -2809,4 +4090,99 @@
 }
 
+
+
+#if defined(UNICODE_SUPPORT) && defined(WIN32_WIDE)
+
+int zstat_win32w(__W32STAT_GLOBALS__ const wchar_t *pathw, z_stat *buf)
+{
+    if (!zstatw(pathw, buf))
+    {
+        char *path = wchar_to_local_string((wchar_t *)pathw, G.unicode_escape_all);
+        /* stat was successful, now redo the time-stamp fetches */
+#ifndef NO_W32TIMES_IZFIX
+        int fs_uses_loctime = FStampIsLocTimeW(__G__ pathw);
+#endif
+        HANDLE h;
+        FILETIME Modft, Accft, Creft;
+
+        TTrace((stdout, "stat(%s) finds modtime %08lx\n", path, buf->st_mtime));
+        h = CreateFileW(pathw, GENERIC_READ,
+                        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
+                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+        if (h != INVALID_HANDLE_VALUE) {
+            BOOL ftOK = GetFileTime(h, &Creft, &Accft, &Modft);
+            CloseHandle(h);
+
+            if (ftOK) {
+                FTTrace((stdout, "GetFileTime returned Modft", 0, &Modft));
+                FTTrace((stdout, "GetFileTime returned Creft", 0, &Creft));
+#ifndef NO_W32TIMES_IZFIX
+                if (!fs_uses_loctime) {
+                    /*  On a filesystem that stores UTC timestamps, we refill
+                     *  the time fields of the struct stat buffer by directly
+                     *  using the UTC values as returned by the Win32
+                     *  GetFileTime() API call.
+                     */
+                    NtfsFileTime2utime(&Modft, &(buf->st_mtime));
+                    if (Accft.dwLowDateTime != 0 || Accft.dwHighDateTime != 0)
+                        NtfsFileTime2utime(&Accft, &(buf->st_atime));
+                    else
+                        buf->st_atime = buf->st_mtime;
+                    if (Creft.dwLowDateTime != 0 || Creft.dwHighDateTime != 0)
+                        NtfsFileTime2utime(&Creft, &(buf->st_ctime));
+                    else
+                        buf->st_ctime = buf->st_mtime;
+                    TTrace((stdout,"NTFS, recalculated modtime %08lx\n",
+                            buf->st_mtime));
+                } else
+#endif /* NO_W32TIMES_IZFIX */
+                {
+                    /*  On VFAT and FAT-like filesystems, the FILETIME values
+                     *  are converted back to the stable local time before
+                     *  converting them to UTC unix time-stamps.
+                     */
+                    VFatFileTime2utime(&Modft, &(buf->st_mtime));
+                    if (Accft.dwLowDateTime != 0 || Accft.dwHighDateTime != 0)
+                        VFatFileTime2utime(&Accft, &(buf->st_atime));
+                    else
+                        buf->st_atime = buf->st_mtime;
+                    if (Creft.dwLowDateTime != 0 || Creft.dwHighDateTime != 0)
+                        VFatFileTime2utime(&Creft, &(buf->st_ctime));
+                    else
+                        buf->st_ctime = buf->st_mtime;
+                    TTrace((stdout, "VFAT, recalculated modtime %08lx\n",
+                            buf->st_mtime));
+                }
+            }
+        }
+        free(path);
+
+        return 0;
+    }
+#ifdef W32_STATROOT_FIX
+    else
+    {
+        DWORD flags;
+
+        flags = GetFileAttributesW(pathw);
+        if (flags != 0xFFFFFFFF && flags & FILE_ATTRIBUTE_DIRECTORY) {
+            char *path = wchar_to_local_string((wchar_t *)pathw, G.unicode_escape_all);
+            Trace((stderr, "\nstat(\"%s\",...) failed on existing directory\n",
+                   FnFilter1(path)));
+            free(path);
+            memset(buf, 0, sizeof(z_stat));
+            buf->st_atime = buf->st_ctime = buf->st_mtime =
+              dos_to_unix_time(DOSTIME_MINIMUM);        /* 1-1-80 */
+            buf->st_mode = S_IFDIR | S_IREAD |
+                           ((flags & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWRITE);
+            return 0;
+        } /* assumes: stat() won't fail on non-dirs without good reason */
+    }
+#endif /* W32_STATROOT_FIX */
+    return -1;
+}
+
+#endif /* defined(UNICODE_SUPPORT) && defined(WIN32_WIDE) */
+
 #endif /* W32_STAT_BANDAID */
 
@@ -2939,6 +4315,5 @@
 
 
-#if 0
-#ifdef UNICODE_SUPPORT
+#if defined(UNICODE_SUPPORT) && defined(WIN32_WIDE)
 wchar_t *utf8_to_wchar_string(utf8_string)
   char *utf8_string;       /* path to get utf-8 name for */
@@ -3030,22 +4405,40 @@
   return qw;
 }
-#endif /* UNICODE_SUPPORT */
-#endif /* 0 */
 
+int has_win32_wide()
+{
+  int is_win32_wide;
 
+  /* test if we have wide function support */
 
-/* --------------------------------------------------- */



( run in 1.583 second using v1.01-cache-2.11-cpan-140bd7fdf52 )