From c38910d9e73f3c195fc2d67d1270c3dfedeec260 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 22 Jul 2015 19:42:12 -0700 Subject: [PATCH] maint: remove dead code * sed/utils.c (ck_mkstemp): Remove $TMP/$TMPDIR-envvar-using code that would have been run only if this function's second parameter were to be NULL, but that could never happen, given the current and sole caller. Also, use mode_t as the type for the saved umask value, not "int". Also, move each declaration down to point of definition. * sed/utils.h (ck_mkstemp): Mark each of the four parameters as nonnull. --- sed/utils.c | 26 ++++---------------------- sed/utils.h | 2 +- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/sed/utils.c b/sed/utils.c index 37666b9..5d1ec18 100644 --- a/sed/utils.c +++ b/sed/utils.c @@ -165,38 +165,20 @@ FILE * ck_mkstemp (char **p_filename, const char *tmpdir, const char *base, const char *mode) { - char *template; - FILE *fp; - int fd; - int save_umask; - - if (tmpdir == NULL) - tmpdir = getenv("TMPDIR"); - if (tmpdir == NULL) - { - tmpdir = getenv("TMP"); - if (tmpdir == NULL) -#ifdef P_tmpdir - tmpdir = P_tmpdir; -#else - tmpdir = "/tmp"; -#endif - } - - template = xmalloc (strlen (tmpdir) + strlen (base) + 8); + char *template = xmalloc (strlen (tmpdir) + strlen (base) + 8); sprintf (template, "%s/%sXXXXXX", tmpdir, base); /* The ownership might change, so omit some permissions at first so unauthorized users cannot nip in before the file is ready. mkstemp forces O_BINARY on cygwin, so use mkostemp instead. */ - save_umask = umask (0700); - fd = mkostemp (template, 0); + mode_t save_umask = umask (0700); + int fd = mkostemp (template, 0); umask (save_umask); if (fd == -1) panic(_("couldn't open temporary file %s: %s"), template, strerror(errno)); *p_filename = template; - fp = fdopen (fd, mode); + FILE *fp = fdopen (fd, mode); register_open_file (fp, template, true); return fp; } diff --git a/sed/utils.h b/sed/utils.h index 62a46dc..9082d66 100644 --- a/sed/utils.h +++ b/sed/utils.h @@ -32,7 +32,7 @@ const char *follow_symlink (const char *path); size_t ck_getdelim (char **text, size_t *buflen, char buffer_delimiter, FILE *stream); FILE * ck_mkstemp (char **p_filename, const char *tmpdir, const char *base, - const char *mode); + const char *mode) _GL_ARG_NONNULL ((1, 2, 3, 4)); void ck_rename (const char *from, const char *to, const char *unlink_if_fail); void *ck_malloc (size_t size); -- 2.3.7