27 #include "dbus-protocol.h"    28 #include "dbus-errors.h"    29 #include "dbus-file.h"    30 #include "dbus-internals.h"    31 #include "dbus-sysdeps.h"    32 #include "dbus-sysdeps-unix.h"    63   const char *filename_c;
    65   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
    67   filename_c = _dbus_string_get_const_data (filename);
    70   fd = open (filename_c, O_RDONLY | O_BINARY);
    74                       "Failed to open \"%s\": %s",
    76                       _dbus_strerror (errno));
    80   _dbus_verbose (
"file fd %d opened\n", fd);
    82   if (fstat (fd, &sb) < 0)
    85                       "Failed to stat \"%s\": %s",
    87                       _dbus_strerror (errno));
    89       _dbus_verbose (
"fstat() failed: %s",
    90                      _dbus_strerror (errno));
    97   if (sb.st_size > _DBUS_ONE_MEGABYTE)
   100                       "File size %lu of \"%s\" is too large.",
   101                       (
unsigned long) sb.st_size, filename_c);
   107   orig_len = _dbus_string_get_length (str);
   108   if (sb.st_size > 0 && S_ISREG (sb.st_mode))
   112       while (total < (
int) sb.st_size)
   119                               "Error reading \"%s\": %s",
   121                               _dbus_strerror (errno));
   123               _dbus_verbose (
"read() failed: %s",
   124                              _dbus_strerror (errno));
   137   else if (sb.st_size != 0)
   139       _dbus_verbose (
"Can only open regular files at the moment.\n");
   141                       "\"%s\" is not a regular file",
   171   const char *filename_c;
   173   const char *tmp_filename_c;
   178   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   204 #define N_TMP_FILENAME_RANDOM_BYTES 8   212   filename_c = _dbus_string_get_const_data (filename);
   213   tmp_filename_c = _dbus_string_get_const_data (&tmp_filename);
   215   fd = open (tmp_filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT,
   216              world_readable ? 0644 : 0600);
   220                       "Could not create %s: %s", tmp_filename_c,
   221                       _dbus_strerror (errno));
   230       if (fchmod (fd, 0644) < 0)
   233                           "Could not chmod %s: %s", tmp_filename_c,
   234                           _dbus_strerror (errno));
   239   _dbus_verbose (
"tmp file fd %d opened\n", fd);
   244   bytes_to_write = _dbus_string_get_length (str);
   246   while (total < bytes_to_write)
   251                                    bytes_to_write - total);
   253       if (bytes_written <= 0)
   256                           "Could not write to %s: %s", tmp_filename_c,
   257                           _dbus_strerror (errno));
   262       total += bytes_written;
   268                       "Could not synchronize file %s: %s",
   269                       tmp_filename_c, _dbus_strerror (errno));
   277                       "Could not close file %s: %s",
   278                       tmp_filename_c, _dbus_strerror (errno));
   285   if (rename (tmp_filename_c, filename_c) < 0)
   288                       "Could not rename %s to %s: %s",
   289                       tmp_filename_c, filename_c,
   290                       _dbus_strerror (errno));
   307   if (need_unlink && unlink (tmp_filename_c) < 0)
   308     _dbus_verbose (
"Failed to unlink temp file %s: %s\n",
   309                    tmp_filename_c, _dbus_strerror (errno));
   314     _DBUS_ASSERT_ERROR_IS_SET (error);
   329   const char *filename_c;
   331   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   333   filename_c = _dbus_string_get_const_data (filename);
   334   if (chmod (filename_c, 0644) == -1)
   338                       "Could not change permissions of file %s: %s\n",
   340                       _dbus_strerror (errno));
   357   const char *filename_c;
   359   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   361   filename_c = _dbus_string_get_const_data (filename);
   363   fd = open (filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT,
   369                       "Could not create file %s: %s\n",
   371                       _dbus_strerror (errno));
   375   _dbus_verbose (
"exclusive file fd %d opened\n", fd);
   381                       "Could not close file %s: %s\n",
   383                       _dbus_strerror (errno));
   402   const char *filename_c;
   404   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
   406   filename_c = _dbus_string_get_const_data (filename);
   408   if (unlink (filename_c) < 0)
   411                       "Failed to delete file %s: %s\n",
   412                       filename_c, _dbus_strerror (errno));
 dbus_bool_t _dbus_string_append(DBusString *str, const char *buffer)
Appends a nul-terminated C-style string to a DBusString. 
#define NULL
A null pointer, defined appropriately for C or C++. 
dbus_bool_t _dbus_create_file_exclusively(const DBusString *filename, DBusError *error)
Creates the given file, failing if the file already exists. 
dbus_bool_t _dbus_string_save_to_file(const DBusString *str, const DBusString *filename, dbus_bool_t world_readable, DBusError *error)
Writes a string out to a file. 
int _dbus_write(int fd, const DBusString *buffer, int start, int len)
Thin wrapper around the write() system call that writes a part of a DBusString and handles EINTR for ...
dbus_bool_t _dbus_file_get_contents(DBusString *str, const DBusString *filename, DBusError *error)
Appends the contents of the given file to the string, returning error code. 
dbus_bool_t _dbus_string_init(DBusString *str)
Initializes a string. 
dbus_bool_t _dbus_string_copy(const DBusString *source, int start, DBusString *dest, int insert_at)
Like _dbus_string_move(), but does not delete the section of the source string that's copied to the d...
dbus_bool_t _dbus_delete_file(const DBusString *filename, DBusError *error)
Deletes the given file. 
const char * _dbus_error_from_errno(int error_number)
Converts a UNIX errno, or Windows errno or WinSock error value into a DBusError name. 
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE. 
dbus_bool_t _dbus_generate_random_ascii(DBusString *str, int n_bytes, DBusError *error)
Generates the given number of random bytes, where the bytes are chosen from the alphanumeric ASCII su...
dbus_bool_t _dbus_make_file_world_readable(const DBusString *filename, DBusError *error)
Makes the file readable by every user in the system. 
int _dbus_read(int fd, DBusString *buffer, int count)
Thin wrapper around the read() system call that appends the data it reads to the DBusString buffer...
Object representing an exception. 
void dbus_set_error(DBusError *error, const char *name, const char *format,...)
Assigns an error name and message to a DBusError. 
void _dbus_string_free(DBusString *str)
Frees a string created by _dbus_string_init(). 
#define TRUE
Expands to "1". 
#define DBUS_ERROR_FAILED
A generic error; "something went wrong" - see the error message for more. 
#define DBUS_ERROR_NO_MEMORY
There was not enough memory to complete an operation. 
dbus_bool_t _dbus_close(int fd, DBusError *error)
Closes a file descriptor. 
#define FALSE
Expands to "0". 
dbus_bool_t _dbus_string_set_length(DBusString *str, int length)
Sets the length of a string.