summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-sysdeps.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-02-01 04:58:16 +0000
committerHavoc Pennington <hp@redhat.com>2003-02-01 04:58:16 +0000
commite0ffb6eb1472e6766d79346e1fae418c129ef536 (patch)
tree4fddaa6743cfcae6ef5ccac4105d4242d2408773 /dbus/dbus-sysdeps.c
parentd8f9c46bf873fe03dbb1db100f3c6d02b2d6c847 (diff)
2003-02-01 Havoc Pennington <hp@pobox.com>
* dbus/dbus-break-loader.c (main): new program to find messages that break the loader. * dbus/dbus-sysdeps.c (_dbus_string_append_uint): new function * dbus/dbus-sysdeps.c (_dbus_string_save_to_file): new function * dbus/dbus-string.c (_dbus_string_set_byte): new
Diffstat (limited to 'dbus/dbus-sysdeps.c')
-rw-r--r--dbus/dbus-sysdeps.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index bcb81f7d..17445a8f 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -618,6 +618,44 @@ _dbus_string_append_int (DBusString *str,
}
/**
+ * Appends an unsigned integer to a DBusString.
+ *
+ * @param str the string
+ * @param value the integer value
+ * @returns #FALSE if not enough memory or other failure.
+ */
+dbus_bool_t
+_dbus_string_append_uint (DBusString *str,
+ unsigned long value)
+{
+ /* this is wrong, but definitely on the high side. */
+#define MAX_ULONG_LEN (MAX_LONG_LEN * 2)
+ int orig_len;
+ int i;
+ char *buf;
+
+ orig_len = _dbus_string_get_length (str);
+
+ if (!_dbus_string_lengthen (str, MAX_ULONG_LEN))
+ return FALSE;
+
+ _dbus_string_get_data_len (str, &buf, orig_len, MAX_ULONG_LEN);
+
+ snprintf (buf, MAX_ULONG_LEN, "%lu", value);
+
+ i = 0;
+ while (*buf)
+ {
+ ++buf;
+ ++i;
+ }
+
+ _dbus_string_shorten (str, MAX_ULONG_LEN - i);
+
+ return TRUE;
+}
+
+/**
* Appends a double to a DBusString.
*
* @param str the string
@@ -1103,6 +1141,59 @@ _dbus_file_get_contents (DBusString *str,
}
/**
+ * Writes a string out to a file.
+ *
+ * @param str the string to write out
+ * @param filename the file to save string to
+ * @returns result code
+ */
+DBusResultCode
+_dbus_string_save_to_file (const DBusString *str,
+ const DBusString *filename)
+{
+ int fd;
+ int bytes_to_write;
+ const char *filename_c;
+ int total;
+
+ _dbus_string_get_const_data (filename, &filename_c);
+
+ fd = open (filename_c, O_WRONLY | O_BINARY | O_EXCL | O_CREAT,
+ 0700);
+ if (fd < 0)
+ return _dbus_result_from_errno (errno);
+
+ total = 0;
+ bytes_to_write = _dbus_string_get_length (str);
+
+ while (total < bytes_to_write)
+ {
+ int bytes_written;
+
+ bytes_written = _dbus_write (fd, str, total,
+ bytes_to_write - total);
+
+ if (bytes_written <= 0)
+ {
+ DBusResultCode result;
+
+ result = _dbus_result_from_errno (errno); /* prior to close() */
+
+ _dbus_verbose ("write() failed: %s",
+ _dbus_strerror (errno));
+
+ close (fd);
+ return result;
+ }
+
+ total += bytes_written;
+ }
+
+ close (fd);
+ return DBUS_RESULT_SUCCESS;
+}
+
+/**
* Appends the given filename to the given directory.
*
* @param dir the directory name