summaryrefslogtreecommitdiffstats
path: root/dbus/dbus-sysdeps.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2006-08-30 01:27:44 +0000
committerHavoc Pennington <hp@redhat.com>2006-08-30 01:27:44 +0000
commitafc2a6e56a65ff9154d4eb1b346157a7d625945d (patch)
treea1f85ab97ba8697d11083b836a5d80915d442223 /dbus/dbus-sysdeps.c
parent338c96b4c69c9d870f41aa6d836338d89e6ed9c3 (diff)
2006-08-29 Havoc Pennington <hp@redhat.com>
* test/test-service.c (path_message_func): fix lack of return value * dbus/dbus-sysdeps.c (_dbus_printf_string_upper_bound): fix formatting, remove #ifdef, and fix docs. #ifdef doesn't make any more sense than on anything else in this file. (_dbus_get_tmpdir): add const to return value, and keep the results of the various getenv around in a static variable.
Diffstat (limited to 'dbus/dbus-sysdeps.c')
-rw-r--r--dbus/dbus-sysdeps.c59
1 files changed, 35 insertions, 24 deletions
diff --git a/dbus/dbus-sysdeps.c b/dbus/dbus-sysdeps.c
index 0a97a1d8..3dfe0e8b 100644
--- a/dbus/dbus-sysdeps.c
+++ b/dbus/dbus-sysdeps.c
@@ -2987,47 +2987,58 @@ _dbus_full_duplex_pipe (int *fd1,
}
-#ifndef DBUS_WIN
/**
- * Measure the message length without terminating nul
+ * Measure the length of the given format string and arguments,
+ * not including the terminating nul.
+ *
+ * @param format a printf-style format string
+ * @param args arguments for the format string
+ * @returns length of the given format string and args
*/
-int _dbus_printf_string_upper_bound (const char *format,
- va_list args)
+int
+_dbus_printf_string_upper_bound (const char *format,
+ va_list args)
{
char c;
return vsnprintf (&c, 1, format, args);
}
-#endif
-
-
/**
* Gets the temporary files directory by inspecting the environment variables
* TMPDIR, TMP, and TEMP in that order. If none of those are set "/tmp" is returned
*
- * @returns char* - location of temp directory
+ * @returns location of temp directory
*/
-char*
+const char*
_dbus_get_tmpdir(void)
{
- char* tmpdir;
+ static const char* tmpdir = NULL;
- tmpdir = getenv("TMPDIR");
- if (tmpdir) {
- return tmpdir;
- }
+ if (tmpdir == NULL)
+ {
+ /* TMPDIR is what glibc uses, then
+ * glibc falls back to the P_tmpdir macro which
+ * just expands to "/tmp"
+ */
+ if (tmpdir == NULL)
+ tmpdir = getenv("TMPDIR");
- tmpdir = getenv("TMP");
- if (tmpdir) {
- return tmpdir;
- }
-
- tmpdir = getenv("TEMP");
- if (tmpdir) {
- return tmpdir;
- }
+ /* These two env variables are probably
+ * broken, but maybe some OS uses them?
+ */
+ if (tmpdir == NULL)
+ tmpdir = getenv("TMP");
+ if (tmpdir == NULL)
+ tmpdir = getenv("TEMP");
- return "/tmp";
+ /* And this is the sane fallback. */
+ if (tmpdir == NULL)
+ tmpdir = "/tmp";
+ }
+
+ _dbus_assert(tmpdir != NULL);
+
+ return tmpdir;
}
/** @} end of sysdeps */