Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/pax Honor the contents of $TMPDIR for the creation of te...



details:   https://anonhg.NetBSD.org/src/rev/83ef1e504a92
branches:  trunk
changeset: 474324:83ef1e504a92
user:      kleink <kleink%NetBSD.org@localhost>
date:      Sat Jul 03 14:42:39 1999 +0000

description:
Honor the contents of $TMPDIR for the creation of temporary files, and use
_PATH_TMP instead of hardcoding /tmp if not set in the environment; fixes
PR bin/7796 from Chris Demetriou.

diffstat:

 bin/pax/pax.h    |   8 +++++++-
 bin/pax/tables.c |  44 ++++++++++++++++++++------------------------
 2 files changed, 27 insertions(+), 25 deletions(-)

diffs (118 lines):

diff -r 63a5ade25a70 -r 83ef1e504a92 bin/pax/pax.h
--- a/bin/pax/pax.h     Sat Jul 03 14:29:29 1999 +0000
+++ b/bin/pax/pax.h     Sat Jul 03 14:42:39 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pax.h,v 1.5 1998/03/26 02:14:00 mycroft Exp $  */
+/*     $NetBSD: pax.h,v 1.6 1999/07/03 14:42:39 kleink Exp $   */
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -244,3 +244,9 @@
 #define HEX    16
 #define OCT    8
 #define _PAX_  1
+
+/*
+ * Pathname base component of the temporary file template, to be created in
+ * ${TMPDIR} or, as a fall-back, _PATH_TMP.
+ */
+#define TMPFILE        "paxXXXXXX"
diff -r 63a5ade25a70 -r 83ef1e504a92 bin/pax/tables.c
--- a/bin/pax/tables.c  Sat Jul 03 14:29:29 1999 +0000
+++ b/bin/pax/tables.c  Sat Jul 03 14:42:39 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tables.c,v 1.8 1999/02/12 15:04:00 kleink Exp $        */
+/*     $NetBSD: tables.c,v 1.9 1999/07/03 14:42:39 kleink Exp $        */
 
 /*-
  * Copyright (c) 1992 Keith Muller.
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)tables.c   8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: tables.c,v 1.8 1999/02/12 15:04:00 kleink Exp $");
+__RCSID("$NetBSD: tables.c,v 1.9 1999/07/03 14:42:39 kleink Exp $");
 #endif
 #endif /* not lint */
 
@@ -53,6 +53,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <fcntl.h>
+#include <paths.h>
 #include <string.h>
 #include <unistd.h>
 #include <errno.h>
@@ -364,7 +365,8 @@
 ftime_start()
 #endif
 {
-       char *pt;
+       const char *tmpdir;
+       char template[MAXPATHLEN];
 
        if (ftab != NULL)
                return(0);
@@ -377,19 +379,16 @@
         * get random name and create temporary scratch file, unlink name
         * so it will get removed on exit
         */
-       pt = strdup("/tmp/paxXXXXXX");
-       if (pt == NULL) {
-               tty_warn(1, "Unable to allocate memory");
-               return(-1);
-       }
-       if ((ffd = mkstemp(pt)) == -1) {
-               syswarn(1, errno, "Unable to create temporary file: %s", pt);
-               free(pt);
+       if ((tmpdir = getenv("TMPDIR")) == NULL)
+               tmpdir = _PATH_TMP;
+       (void)snprintf(template, sizeof(template), "%s/%s", tmpdir, TMPFILE);
+       if ((ffd = mkstemp(template)) == -1) {
+               syswarn(1, errno, "Unable to create temporary file: %s",
+                   template);
                return(-1);
        }
 
-       (void)unlink(pt);
-       free(pt);
+       (void)unlink(template);
        return(0);
 }
 
@@ -1219,7 +1218,8 @@
 dir_start()
 #endif
 {
-       char *pt;
+       const char *tmpdir;
+       char template[MAXPATHLEN];
 
        if (dirfd != -1)
                return(0);
@@ -1227,19 +1227,15 @@
        /*
         * unlink the file so it goes away at termination by itself
         */
-       pt = strdup("/tmp/paxXXXXXX");
-       if (pt == NULL) {
-               tty_warn(1, "Unable to allocate memory");
-               return(-1);
-       }
-       if ((dirfd = mkstemp(pt)) >= 0) {
-               (void)unlink(pt);
-               free(pt);
+       if ((tmpdir = getenv("TMPDIR")) == NULL)
+               tmpdir = _PATH_TMP;
+       (void)snprintf(template, sizeof(template), "%s/%s", tmpdir, TMPFILE);
+       if ((dirfd = mkstemp(template)) >= 0) {
+               (void)unlink(template);
                return(0);
        }
        tty_warn(1, "Unable to create temporary file for directory times: %s",
-           pt);
-       free(pt);
+           template);
        return(-1);
 }
 



Home | Main Index | Thread Index | Old Index