diff src/fileio.c @ 4834:b3ea9c582280

Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
author Ben Wing <ben@xemacs.org>
date Tue, 12 Jan 2010 01:38:04 -0600
parents 780bb5441c14
children a03421eb562b
line wrap: on
line diff
--- a/src/fileio.c	Sun Jan 10 01:06:15 2010 -0600
+++ b/src/fileio.c	Tue Jan 12 01:38:04 2010 -0600
@@ -1,6 +1,6 @@
 /* File IO for XEmacs.
    Copyright (C) 1985-1988, 1992-1995 Free Software Foundation, Inc.
-   Copyright (C) 1996, 2001, 2002, 2003, 2004 Ben Wing.
+   Copyright (C) 1996, 2001, 2002, 2003, 2004, 2010 Ben Wing.
 
 This file is part of XEmacs.
 
@@ -1388,7 +1388,7 @@
        detect that c:/windows == /windows for example. */
     if (! (IS_DIRECTORY_SEP (path[0]) && IS_DIRECTORY_SEP (path[1])))
       {
-	LOCAL_TO_WIN32_FILE_FORMAT (path, p);
+	LOCAL_FILE_FORMAT_TO_INTERNAL_MSWIN (path, p);
 	path = p;
       }
 #endif
@@ -2271,7 +2271,7 @@
      encapsulated. */
 
   LISP_STRING_TO_EXTERNAL (path, path_ext, Qfile_name);
-  LISP_STRING_TO_EXTERNAL (login, login_ext, Qnative);
+  LISP_STRING_TO_EXTERNAL (login, login_ext, Quser_name_encoding);
 
   netresult = netunam (path_ext, login_ext);
 
@@ -2324,82 +2324,73 @@
 static int
 check_writable (const Ibyte *filename)
 {
-#if defined(WIN32_NATIVE) || defined(CYGWIN)
-#ifdef CYGWIN
-    Extbyte filename_buffer[PATH_MAX];
-#endif
-	// Since this has to work for a directory, we can't just call 'CreateFile'
-	PSECURITY_DESCRIPTOR pDesc; /* Must be freed with LocalFree */
-	/* these need not be freed, they point into pDesc */
-	PSID psidOwner;
-	PSID psidGroup;
-	PACL pDacl;
-	PACL pSacl;
-	/* end of insides of descriptor */
-	DWORD error;
-	DWORD attributes;
-	HANDLE tokenHandle;
-	GENERIC_MAPPING genericMapping;
-	DWORD accessMask;
-	PRIVILEGE_SET PrivilegeSet;
-    DWORD dwPrivSetSize = sizeof( PRIVILEGE_SET );
-    BOOL fAccessGranted = FALSE;
-    DWORD dwAccessAllowed;
-    Extbyte *fnameext;
-
-    C_STRING_TO_TSTR(filename, fnameext);
-
-#ifdef CYGWIN
-    cygwin_conv_to_full_win32_path(fnameext, filename_buffer);
-    fnameext = filename_buffer;
-#endif
-
-    // First check for a normal file with the old-style readonly bit
+#ifdef WIN32_ANY
+  // Since this has to work for a directory, we can't just call 'CreateFile'
+  PSECURITY_DESCRIPTOR pDesc; /* Must be freed with LocalFree */
+  /* these need not be freed, they point into pDesc */
+  PSID psidOwner;
+  PSID psidGroup;
+  PACL pDacl;
+  PACL pSacl;
+  /* end of insides of descriptor */
+  DWORD error;
+  DWORD attributes;
+  HANDLE tokenHandle;
+  GENERIC_MAPPING genericMapping;
+  DWORD accessMask;
+  PRIVILEGE_SET PrivilegeSet;
+  DWORD dwPrivSetSize = sizeof( PRIVILEGE_SET );
+  BOOL fAccessGranted = FALSE;
+  DWORD dwAccessAllowed;
+  Extbyte *fnameext;
+
+  LOCAL_FILE_FORMAT_TO_TSTR (filename, fnameext);
+
+  // First check for a normal file with the old-style readonly bit
+  attributes = qxeGetFileAttributes(fnameext);
+  if (FILE_ATTRIBUTE_READONLY == (attributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_READONLY)))
+    return 0;
+
+  /* Win32 prototype lacks const. */
+  error = qxeGetNamedSecurityInfo(fnameext, SE_FILE_OBJECT, 
+				  DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION,
+				  &psidOwner, &psidGroup, &pDacl, &pSacl, &pDesc);
+  if(error != ERROR_SUCCESS) { // FAT?
     attributes = qxeGetFileAttributes(fnameext);
-    if (FILE_ATTRIBUTE_READONLY == (attributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_READONLY)))
+    return (attributes & FILE_ATTRIBUTE_DIRECTORY) || (0 == (attributes & FILE_ATTRIBUTE_READONLY));
+  }
+
+  genericMapping.GenericRead = FILE_GENERIC_READ;
+  genericMapping.GenericWrite = FILE_GENERIC_WRITE;
+  genericMapping.GenericExecute = FILE_GENERIC_EXECUTE;
+  genericMapping.GenericAll = FILE_ALL_ACCESS;
+
+  if(!ImpersonateSelf(SecurityDelegation)) {
+    return 0;
+  }
+  if(!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &tokenHandle)) {
+    return 0;
+  }
+
+  accessMask = GENERIC_WRITE;
+  MapGenericMask(&accessMask, &genericMapping);
+
+  if(!AccessCheck(pDesc, tokenHandle, accessMask, &genericMapping,
+		  &PrivilegeSet,       // receives privileges used in check
+		  &dwPrivSetSize,      // size of PrivilegeSet buffer
+		  &dwAccessAllowed,    // receives mask of allowed access rights
+		  &fAccessGranted)) 
+    {
+      CloseHandle(tokenHandle);
+      RevertToSelf();
+      LocalFree(pDesc);
       return 0;
-
-	/* Win32 prototype lacks const. */
-	error = qxeGetNamedSecurityInfo(fnameext, SE_FILE_OBJECT, 
-                                    DACL_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|OWNER_SECURITY_INFORMATION,
-                                    &psidOwner, &psidGroup, &pDacl, &pSacl, &pDesc);
-	if(error != ERROR_SUCCESS) { // FAT?
-		attributes = qxeGetFileAttributes(fnameext);
-		return (attributes & FILE_ATTRIBUTE_DIRECTORY) || (0 == (attributes & FILE_ATTRIBUTE_READONLY));
-	}
-
-	genericMapping.GenericRead = FILE_GENERIC_READ;
-    genericMapping.GenericWrite = FILE_GENERIC_WRITE;
-    genericMapping.GenericExecute = FILE_GENERIC_EXECUTE;
-    genericMapping.GenericAll = FILE_ALL_ACCESS;
-
-	if(!ImpersonateSelf(SecurityDelegation)) {
-		return 0;
-	}
-	if(!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, TRUE, &tokenHandle)) {
-		return 0;
-	}
-
-	accessMask = GENERIC_WRITE;
-	MapGenericMask(&accessMask, &genericMapping);
-
-	if(!AccessCheck(pDesc, tokenHandle, accessMask, &genericMapping,
-					&PrivilegeSet,       // receives privileges used in check
-					&dwPrivSetSize,      // size of PrivilegeSet buffer
-					&dwAccessAllowed,    // receives mask of allowed access rights
-					&fAccessGranted)) 
-	{
-		CloseHandle(tokenHandle);
-		RevertToSelf();
-		LocalFree(pDesc);
-		return 0;
-	}
-	CloseHandle(tokenHandle);
-	RevertToSelf();
-	LocalFree(pDesc);
-	return fAccessGranted == TRUE;
-#else
-#ifdef HAVE_EACCESS
+    }
+  CloseHandle(tokenHandle);
+  RevertToSelf();
+  LocalFree(pDesc);
+  return fAccessGranted == TRUE;
+#elif defined (HAVE_EACCESS)
   return (qxe_eaccess (filename, W_OK) >= 0);
 #else
   /* Access isn't quite right because it uses the real uid
@@ -2408,8 +2399,7 @@
      Opening with O_WRONLY could work for an ordinary file,
      but would lose for directories.  */
   return (qxe_access (filename, W_OK) >= 0);
-#endif
-#endif
+#endif /* (not) defined (HAVE_EACCESS) */
 }
 
 DEFUN ("file-exists-p", Ffile_exists_p, 1, 1, 0, /*