Revert "Add a statically-initialized implementation of _dbus_lock() on glibc systems"
[platform/upstream/dbus.git] / dbus / dbus-file-win.c
index d1a81e2..06a8ea1 100644 (file)
@@ -68,8 +68,6 @@ _dbus_file_read (HANDLE            hnd,
 
   data = _dbus_string_get_data_len (buffer, start, count);
 
- again:
-
   result = ReadFile (hnd, data, count, &bytes_read, NULL);
   if (result == 0)
     {
@@ -114,7 +112,7 @@ _dbus_file_get_contents (DBusString       *str,
   DWORD fsize;
   DWORD fsize_hi;
   int orig_len;
-  int total;
+  unsigned int total;
   const char *filename_c;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
@@ -133,7 +131,7 @@ _dbus_file_get_contents (DBusString       *str,
       return FALSE;
     }
 
-  _dbus_verbose ("file %s fd 0x%x opened\n", filename_c, hnd);
+  _dbus_verbose ("file %s hnd %p opened\n", filename_c, hnd);
   
   fsize = GetFileSize (hnd, &fsize_hi);
   if (fsize == 0xFFFFFFFF && GetLastError() != NO_ERROR)
@@ -206,12 +204,14 @@ _dbus_file_get_contents (DBusString       *str,
  *
  * @param str the string to write out
  * @param filename the file to save string to
+ * @param world_readable if true, ensure file is world readable
  * @param error error to be filled in on failure
  * @returns #FALSE on failure
  */
 dbus_bool_t
 _dbus_string_save_to_file (const DBusString *str,
                            const DBusString *filename,
+                           dbus_bool_t       world_readable,
                            DBusError        *error)
 {
   HANDLE hnd;
@@ -261,6 +261,7 @@ _dbus_string_save_to_file (const DBusString *str,
   filename_c = _dbus_string_get_const_data (filename);
   tmp_filename_c = _dbus_string_get_const_data (&tmp_filename);
 
+  /* TODO - support world-readable in an atomic fashion */
   hnd = CreateFileA (tmp_filename_c, GENERIC_WRITE,
                      FILE_SHARE_READ | FILE_SHARE_WRITE,
                      NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
@@ -273,8 +274,13 @@ _dbus_string_save_to_file (const DBusString *str,
       _dbus_win_free_error_string (emsg);
       goto out;
     }
+  if (world_readable)
+    {
+      if (! _dbus_make_file_world_readable (&tmp_filename, error))
+        goto out;
+    }
 
-  _dbus_verbose ("tmp file %s fd 0x%x opened\n", tmp_filename_c, hnd);
+  _dbus_verbose ("tmp file %s hnd %p opened\n", tmp_filename_c, hnd);
 
   need_unlink = TRUE;
 
@@ -383,7 +389,7 @@ _dbus_create_file_exclusively (const DBusString *filename,
       return FALSE;
     }
 
-  _dbus_verbose ("exclusive file %s fd 0x%x opened\n", filename_c, hnd);
+  _dbus_verbose ("exclusive file %s hnd %p opened\n", filename_c, hnd);
 
   if (CloseHandle (hnd) == 0)
     {