apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jay Freeman \(saurik\)" <sau...@saurik.com>
Subject [PATCH] file_io\win32\filestat.c : implement apr_file_attrs_set()
Date Sun, 10 Feb 2002 10:14:34 GMT
I was trying to get the latest build of Subversion to work on Windows
today, and finally traced the problem to trying to use
apr_file_attrs_set(), which apparently isn't written for Windows yet.
In the hope of moving this along, I went ahead and wrote an
implementation for FILE_ATTRIBUTES_READONLY (there isn't really a good
corollary for EXECUTABLE...).

Latest Subversion still isn't working, but at least this puts things a
step closer...

Sincerely,
Jay Freeman (saurik)
saurik@saurik.com


Index: file_io/win32/filestat.c
===================================================================
RCS file: /home/cvspublic/apr/file_io/win32/filestat.c,v
retrieving revision 1.63
diff -u -r1.63 filestat.c
--- file_io/win32/filestat.c    7 Feb 2002 00:57:21 -0000       1.63
+++ file_io/win32/filestat.c    10 Feb 2002 10:08:44 -0000
@@ -622,5 +622,51 @@
                                              apr_fileattrs_t
attributes,
                                              apr_pool_t *cont)
 {
-   return APR_ENOTIMPL;
-}
+    DWORD flags;
+    apr_status_t rv;
+#if APR_HAS_UNICODE_FS
+    apr_wchar_t wfname[APR_PATH_MAX];
+#endif
+
+#if APR_HAS_UNICODE_FS
+    IF_WIN_OS_IS_UNICODE
+    {
+        if (rv = utf8_to_unicode_path(wfname, sizeof(wfname)
+                                            / sizeof(apr_wchar_t),
fname))
+            return rv;
+        flags = GetFileAttributesW(wfname);
+    }
+#endif
+#if APR_HAS_ANSI_FS
+    ELSE_WIN_OS_IS_ANSI
+    {
+        flags = GetFileAttributesA(fname);
+    }
+#endif
+
+    if (flags == -1)
+        return apr_get_os_error();
+
+    if (attributes & APR_FILE_ATTR_READONLY)
+        flags |= FILE_ATTRIBUTE_READONLY;
+    else
+        flags &= !FILE_ATTRIBUTE_READONLY;
+
+#if APR_HAS_UNICODE_FS
+    IF_WIN_OS_IS_UNICODE
+    {
+        rv = SetFileAttributesW(wfname, flags);
+    }
+#endif
+#if APR_HAS_ANSI_FS
+    ELSE_WIN_OS_IS_ANSI
+    {
+        rv = SetFileAttributesA(fname, flags);
+    }
+#endif
+
+    if (rv == 0)
+        return apr_get_os_error();
+
+    return APR_SUCCESS;
+}


Mime
View raw message