Przeglądaj źródła

libcompat: Make sure P_tmpdir is always defined

This will guarantee the macro constant is always defined, which allows
us to remove an equivalent code branch, which in normal conditions is
dead code.

As a side effect this unconfuses static code analyzers like cppcheck or
coverity.
Guillem Jover 12 lat temu
rodzic
commit
99e299736d
3 zmienionych plików z 5 dodań i 4 usunięć
  1. 1 0
      configure.ac
  2. 4 0
      lib/compat/compat.h
  3. 0 4
      lib/dpkg/path.c

+ 1 - 0
configure.ac

@@ -93,6 +93,7 @@ DPKG_CHECK_DECL([makedev], [sys/types.h])
 DPKG_CHECK_DECL([WCOREDUMP], [sys/wait.h])
 DPKG_CHECK_DECL([TIOCNOTTY], [sys/ioctl.h])
 DPKG_CHECK_DECL([O_NOFOLLOW], [fcntl.h])
+DPKG_CHECK_DECL([P_tmpdir], [stdio.h])
 DPKG_CHECK_PROGNAME
 DPKG_CHECK_COMPAT_FUNCS([getopt getopt_long obstack_free \
                          strnlen strndup strerror strsignal asprintf \

+ 4 - 0
lib/compat/compat.h

@@ -38,6 +38,10 @@ extern "C" {
 #define O_NOFOLLOW 0
 #endif
 
+#ifndef HAVE_P_TMPDIR
+#define P_tmpdir "/tmp"
+#endif
+
 /*
  * Define WCOREDUMP if we don't have it already, coredumps won't be
  * detected, though.

+ 0 - 4
lib/dpkg/path.c

@@ -106,12 +106,8 @@ path_make_temp_template(const char *suffix)
 	char *template;
 
 	tmpdir = getenv("TMPDIR");
-#ifdef P_tmpdir
 	if (!tmpdir)
 		tmpdir = P_tmpdir;
-#endif
-	if (!tmpdir)
-		tmpdir = "/tmp";
 
 	m_asprintf(&template, "%s/%s.XXXXXX", tmpdir, suffix);