platform/windows.c
changeset 874 ad804f24633f
parent 864 ce0fcbbba8a3
child 875 6a5f06dbd423
equal deleted inserted replaced
873:8105cafcb456 874:ad804f24633f
   576     __PHYSFS_smallFree(wpath);
   576     __PHYSFS_smallFree(wpath);
   577     return(retval);
   577     return(retval);
   578 } /* __PHYSFS_platformExists */
   578 } /* __PHYSFS_platformExists */
   579 
   579 
   580 
   580 
       
   581 static int isSymlinkAttrs(DWORD attr, DWORD tag)
       
   582 {
       
   583     return ( (attr & FILE_ATTRIBUTE_REPARSE_POINT) &&
       
   584              ((tag & IO_REPARSE_TAG_SYMLINK) == IO_REPARSE_TAG_SYMLINK) );
       
   585 } /* isSymlinkAttrs */
       
   586 
       
   587 
   581 int __PHYSFS_platformIsSymLink(const char *fname)
   588 int __PHYSFS_platformIsSymLink(const char *fname)
   582 {
   589 {
   583     /* !!! FIXME: Vista has symlinks. Recheck this. */
   590     /* !!! FIXME:
   584     return(0);  /* no symlinks on win32. */
   591      * Windows Vista can have NTFS symlinks. Can older Windows releases have
       
   592      *  them when talking to a network file server? What happens when you
       
   593      *  mount a NTFS partition on XP that was plugged into a Vista install
       
   594      *  that made a symlink?
       
   595      */
       
   596 
       
   597     int retval = 0;
       
   598     LPWSTR wpath;
       
   599     HANDLE dir;
       
   600     WIN32_FIND_DATAW entw;
       
   601 
       
   602     /* no unicode entry points? Probably no symlinks. */
       
   603     BAIL_IF_MACRO(pFindFirstFileW == NULL, NULL, 0);
       
   604 
       
   605     UTF8_TO_UNICODE_STACK_MACRO(wpath, fname);
       
   606     BAIL_IF_MACRO(wpath == NULL, ERR_OUT_OF_MEMORY, 0);
       
   607 
       
   608     /* !!! FIXME: filter wildcard chars? */
       
   609     dir = pFindFirstFileW(wpath, &entw);
       
   610     if (dir != INVALID_HANDLE_VALUE)
       
   611     {
       
   612         retval = isSymlinkAttrs(entw.dwFileAttributes, entw.dwReserved0);
       
   613         FindClose(dir);
       
   614     } /* if */
       
   615 
       
   616     __PHYSFS_smallFree(wpath);
       
   617     return(retval);
   585 } /* __PHYSFS_platformIsSymlink */
   618 } /* __PHYSFS_platformIsSymlink */
   586 
   619 
   587 
   620 
   588 int __PHYSFS_platformIsDirectory(const char *fname)
   621 int __PHYSFS_platformIsDirectory(const char *fname)
   589 {
   622 {
   684 
   717 
   685     if (unicode)
   718     if (unicode)
   686     {
   719     {
   687         do
   720         do
   688         {
   721         {
       
   722             const DWORD attrs = entw.dwFileAttributes;
       
   723             const DWORD tag = entw.dwReserved0;
   689             const WCHAR *fn = entw.cFileName;
   724             const WCHAR *fn = entw.cFileName;
   690             if ((fn[0] == '.') && (fn[1] == '\0'))
   725             if ((fn[0] == '.') && (fn[1] == '\0'))
   691                 continue;
   726                 continue;
   692             if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
   727             if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
   693                 continue;
   728                 continue;
   694 
   729             if ((omitSymLinks) && (isSymlinkAttrs(attr, tag)))
   695             utf8 = unicodeToUtf8Heap(entw.cFileName);
   730                 continue;
       
   731 
       
   732             utf8 = unicodeToUtf8Heap(fn);
   696             if (utf8 != NULL)
   733             if (utf8 != NULL)
   697             {
   734             {
   698                 callback(callbackdata, origdir, utf8);
   735                 callback(callbackdata, origdir, utf8);
   699                 allocator.Free(utf8);
   736                 allocator.Free(utf8);
   700             } /* if */
   737             } /* if */
   703 
   740 
   704     else  /* ANSI fallback. */
   741     else  /* ANSI fallback. */
   705     {
   742     {
   706         do
   743         do
   707         {
   744         {
       
   745             const DWORD attrs = ent.dwFileAttributes;
       
   746             const DWORD tag = ent.dwReserved0;
   708             const char *fn = ent.cFileName;
   747             const char *fn = ent.cFileName;
   709             if ((fn[0] == '.') && (fn[1] == '\0'))
   748             if ((fn[0] == '.') && (fn[1] == '\0'))
   710                 continue;
   749                 continue;
   711             if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
   750             if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0'))
   712                 continue;
   751                 continue;
   713 
   752             if ((omitSymLinks) && (isSymlinkAttrs(attr, tag)))
   714             utf8 = codepageToUtf8Heap(ent.cFileName);
   753                 continue;
       
   754 
       
   755             utf8 = codepageToUtf8Heap(fn);
   715             if (utf8 != NULL)
   756             if (utf8 != NULL)
   716             {
   757             {
   717                 callback(callbackdata, origdir, utf8);
   758                 callback(callbackdata, origdir, utf8);
   718                 allocator.Free(utf8);
   759                 allocator.Free(utf8);
   719             } /* if */
   760             } /* if */