dbus/dbus dbus-sysdeps.c,1.108,1.109 dbus-sysdeps.h,1.54,1.55
Havoc Pennington
hp at kemper.freedesktop.org
Tue Aug 29 18:27:46 PDT 2006
Update of /cvs/dbus/dbus/dbus
In directory kemper:/tmp/cvs-serv19016/dbus
Modified Files:
dbus-sysdeps.c dbus-sysdeps.h
Log Message:
2006-08-29 Havoc Pennington <hp at 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.
Index: dbus-sysdeps.c
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -u -d -r1.108 -r1.109
--- dbus-sysdeps.c 18 Aug 2006 15:46:59 -0000 1.108
+++ dbus-sysdeps.c 30 Aug 2006 01:27:44 -0000 1.109
@@ -2987,47 +2987,58 @@
}
-#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 */
Index: dbus-sysdeps.h
===================================================================
RCS file: /cvs/dbus/dbus/dbus/dbus-sysdeps.h,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- dbus-sysdeps.h 14 Aug 2006 19:11:35 -0000 1.54
+++ dbus-sysdeps.h 30 Aug 2006 01:27:44 -0000 1.55
@@ -323,7 +323,7 @@
dbus_bool_t _dbus_file_exists (const char *file);
dbus_bool_t _dbus_user_at_console (const char *username,
DBusError *error);
-char* _dbus_get_tmpdir(void);
+const char* _dbus_get_tmpdir (void);
/* Define DBUS_VA_COPY() to do the right thing for copying va_list variables.
* config.h may have already defined DBUS_VA_COPY as va_copy or __va_copy.
More information about the dbus-commit
mailing list