summaryrefslogtreecommitdiffstats
path: root/usr.bin/xstr
diff options
context:
space:
mode:
authorkevlo <kevlo@FreeBSD.org>2008-05-13 09:42:03 +0000
committerkevlo <kevlo@FreeBSD.org>2008-05-13 09:42:03 +0000
commite5e2a6d08d5ef5e042c7addcd250881ea564a801 (patch)
tree690374add889c58a9940e527a3b1182034cf4048 /usr.bin/xstr
parentb31256842df0bc175a86de8a1611b7d471be350d (diff)
downloadFreeBSD-src-e5e2a6d08d5ef5e042c7addcd250881ea564a801.zip
FreeBSD-src-e5e2a6d08d5ef5e042c7addcd250881ea564a801.tar.gz
Improve temporary file handling
Obtained from: OpenBSD
Diffstat (limited to 'usr.bin/xstr')
-rw-r--r--usr.bin/xstr/xstr.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/usr.bin/xstr/xstr.c b/usr.bin/xstr/xstr.c
index 7964dd9..c5fcef1 100644
--- a/usr.bin/xstr/xstr.c
+++ b/usr.bin/xstr/xstr.c
@@ -100,6 +100,7 @@ int
main(int argc, char *argv[])
{
int c;
+ int fdesc;
while ((c = getopt(argc, argv, "-cv")) != -1)
switch (c) {
@@ -122,8 +123,16 @@ main(int argc, char *argv[])
signal(SIGINT, onintr);
if (cflg || (argc == 0 && !readstd))
inithash();
- else
- strings = mktemp(strdup(_PATH_TMP));
+ else {
+ strings = strdup(_PATH_TMP);
+ if (strings == NULL)
+ err(1, "strdup() failed");
+ fdesc = mkstemp(strings);
+ if (fdesc == -1)
+ err(1, "Unable to create temporary file");
+ close(fdesc);
+ }
+
while (readstd || argc > 0) {
if (freopen("x.c", "w", stdout) == NULL)
err(1, "x.c");
OpenPOWER on IntegriCloud