glib/gstdio.h glib/gstdio.c Wrap also access() and chmod(). (#169623)
authorTor Lillqvist <tml@novell.com>
Fri, 8 Apr 2005 12:11:41 +0000 (12:11 +0000)
committerTor Lillqvist <tml@src.gnome.org>
Fri, 8 Apr 2005 12:11:41 +0000 (12:11 +0000)
2005-04-08  Tor Lillqvist  <tml@novell.com>

* glib/gstdio.h
* glib/gstdio.c
* glib/glib.symbols (g_access, g_chmod): Wrap also access() and
chmod(). (#169623)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-8
glib/glib.symbols
glib/gstdio.c
glib/gstdio.h

index 6432d59..b820035 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2005-04-08  Tor Lillqvist  <tml@novell.com>
 
+       * glib/gstdio.h
+       * glib/gstdio.c
+       * glib/glib.symbols (g_access, g_chmod): Wrap also access() and
+       chmod(). (#169623)
+
+2005-04-08  Tor Lillqvist  <tml@novell.com>
+
        Improve g_get_system_data_dirs() on Windows. A library that calls
        g_get_system_data_dirs() might be installed in a different
        top-level prefix than GLib or the application being run.
index 6432d59..b820035 100644 (file)
@@ -1,5 +1,12 @@
 2005-04-08  Tor Lillqvist  <tml@novell.com>
 
+       * glib/gstdio.h
+       * glib/gstdio.c
+       * glib/glib.symbols (g_access, g_chmod): Wrap also access() and
+       chmod(). (#169623)
+
+2005-04-08  Tor Lillqvist  <tml@novell.com>
+
        Improve g_get_system_data_dirs() on Windows. A library that calls
        g_get_system_data_dirs() might be installed in a different
        top-level prefix than GLib or the application being run.
index 6432d59..b820035 100644 (file)
@@ -1,5 +1,12 @@
 2005-04-08  Tor Lillqvist  <tml@novell.com>
 
+       * glib/gstdio.h
+       * glib/gstdio.c
+       * glib/glib.symbols (g_access, g_chmod): Wrap also access() and
+       chmod(). (#169623)
+
+2005-04-08  Tor Lillqvist  <tml@novell.com>
+
        Improve g_get_system_data_dirs() on Windows. A library that calls
        g_get_system_data_dirs() might be installed in a different
        top-level prefix than GLib or the application being run.
index 6432d59..b820035 100644 (file)
@@ -1,5 +1,12 @@
 2005-04-08  Tor Lillqvist  <tml@novell.com>
 
+       * glib/gstdio.h
+       * glib/gstdio.c
+       * glib/glib.symbols (g_access, g_chmod): Wrap also access() and
+       chmod(). (#169623)
+
+2005-04-08  Tor Lillqvist  <tml@novell.com>
+
        Improve g_get_system_data_dirs() on Windows. A library that calls
        g_get_system_data_dirs() might be installed in a different
        top-level prefix than GLib or the application being run.
index 492b238..28c23e7 100644 (file)
@@ -849,6 +849,8 @@ g_spawn_sync
 #if IN_FILE(__G_STDIO_C__)
 #if !defined(G_OS_UNIX) || defined(G_STDIO_NO_WRAP_ON_UNIX)
 /* gstdio wrappers */
+g_access
+g_chmod
 g_open
 g_rename
 g_mkdir
index 8389dcd..2edd990 100644 (file)
 
 
 /**
+ * g_access:
+ * @filename: a pathname in the GLib file name encoding
+ * @mode: as in access()
+ *
+ * A wrapper for the POSIX access() function. This function is used to
+ * test a pathname for one or several of read, write or execute
+ * permissions, or just existence. On Windows, the underlying access()
+ * function in the C library only checks the READONLY attribute, and
+ * does not look at the ACL at all. Software that needs to handle file
+ * permisssions on Windows more exactly should use the Win32 API.
+ *
+ * See the C library manual for more details about access().
+ *
+ * Returns: zero if the pathname refers to an existing file system
+ * object that has all the tested permissions, or -1 otherwise or on
+ * error.
+ * 
+ * Since: 2.7
+ */
+int
+g_access (const gchar *filename,
+         int          mode)
+{
+#ifdef G_OS_WIN32
+  if (G_WIN32_HAVE_WIDECHAR_API ())
+    {
+      wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
+      int retval;
+      int save_errno;
+      
+      if (wfilename == NULL)
+       {
+         errno = EINVAL;
+         return -1;
+       }
+
+      retval = _waccess (wfilename, mode);
+      save_errno = errno;
+
+      g_free (wfilename);
+
+      errno = save_errno;
+      return retval;
+    }
+  else
+    {    
+      gchar *cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
+      int retval;
+      int save_errno;
+
+      if (cp_filename == NULL)
+       {
+         errno = EINVAL;
+         return -1;
+       }
+
+      retval = access (cp_filename, mode);
+      save_errno = errno;
+
+      g_free (cp_filename);
+
+      errno = save_errno;
+      return retval;
+    }
+#else
+  return access (filename, mode);
+#endif
+}
+
+/**
+ * g_chmod:
+ * @filename: a pathname in the GLib file name encoding
+ * @mode: as in chmod()
+ *
+ * A wrapper for the POSIX chmod() function. The chmod() function is
+ * used to set the permissions of a file system object. Note that on
+ * Windows the file protection mechanism is not at all POSIX-like, and
+ * the underlying chmod() function in the C library just sets or
+ * clears the READONLY attribute. It does not touch any ACL. Software
+ * that needs to manage file permisssions on Windows exactly should
+ * use the Win32 API.
+ *
+ * See the C library manual for more details about chmod().
+ *
+ * Returns: zero if the operation succeedd, -1 on error.
+ * 
+ * Since: 2.7
+ */
+int
+g_chmod (const gchar *filename,
+        int          mode)
+{
+#ifdef G_OS_WIN32
+  if (G_WIN32_HAVE_WIDECHAR_API ())
+    {
+      wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
+      int retval;
+      int save_errno;
+      
+      if (wfilename == NULL)
+       {
+         errno = EINVAL;
+         return -1;
+       }
+
+      retval = _wchmod (wfilename, mode);
+      save_errno = errno;
+
+      g_free (wfilename);
+
+      errno = save_errno;
+      return retval;
+    }
+  else
+    {    
+      gchar *cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL);
+      int retval;
+      int save_errno;
+
+      if (cp_filename == NULL)
+       {
+         errno = EINVAL;
+         return -1;
+       }
+
+      retval = chmod (cp_filename, mode);
+      save_errno = errno;
+
+      g_free (cp_filename);
+
+      errno = save_errno;
+      return retval;
+    }
+#else
+  return chmod (filename, mode);
+#endif
+}
+
+/**
  * g_open:
  * @filename: a pathname in the GLib file name encoding
  * @flags: as in open()
index 534a61e..1189a41 100644 (file)
@@ -31,6 +31,8 @@
  * format mismatches, especially with large file interfaces.
  */
 
+#define g_access  access
+#define g_chmod   chmod
 #define g_open    open
 #define g_rename  rename
 #define g_mkdir   mkdir
  * API.
  */
 
+int g_access    (const gchar *filename,
+                int          mode);
+
+int g_chmod     (const gchar *filename,
+                int          mode);
+
 int g_open      (const gchar *filename,
                  int          flags,
                  int          mode);