version 1.15, 2009/10/27 23:59:40 |
version 1.16, 2013/03/12 15:07:12 |
|
|
/* $OpenBSD$ */ |
/* $OpenBSD$ */ |
|
|
/* |
/* |
* Copyright (c) 1996, 1997, 2001 Todd C. Miller <Todd.Miller@courtesan.com> |
* Copyright (c) 1996, 1997, 2001-2003, 2013 |
|
* Todd C. Miller <Todd.Miller@courtesan.com> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
{ |
{ |
int ch, fd, uflag = 0, quiet = 0, tflag = 0, makedir = 0; |
int ch, fd, uflag = 0, quiet = 0, tflag = 0, makedir = 0; |
char *cp, *template, *tempfile, *prefix = _PATH_TMP; |
char *cp, *template, *tempfile, *prefix = _PATH_TMP; |
int plen; |
size_t len; |
|
|
while ((ch = getopt(argc, argv, "dp:qtu")) != -1) |
while ((ch = getopt(argc, argv, "dp:qtu")) != -1) |
switch(ch) { |
switch(ch) { |
|
|
cp = getenv("TMPDIR"); |
cp = getenv("TMPDIR"); |
if (cp != NULL && *cp != '\0') |
if (cp != NULL && *cp != '\0') |
prefix = cp; |
prefix = cp; |
plen = strlen(prefix); |
len = strlen(prefix); |
while (plen != 0 && prefix[plen - 1] == '/') |
while (len != 0 && prefix[len - 1] == '/') |
plen--; |
len--; |
|
|
if (asprintf(&tempfile, "%.*s/%s", plen, prefix, template) < 0) |
if (asprintf(&tempfile, "%.*s/%s", (int)len, prefix, template) < 0) |
tempfile = NULL; |
tempfile = NULL; |
} else |
} else { |
|
len = strlen(template); |
|
if (len < 6 || strcmp(&template[len - 6], "XXXXXX")) { |
|
if (!quiet) { |
|
warningx("insufficient number of Xs in template `%s'", |
|
template); |
|
} |
|
exit(1); |
|
} |
tempfile = strdup(template); |
tempfile = strdup(template); |
|
} |
if (tempfile == NULL) { |
if (tempfile == NULL) { |
if (!quiet) |
if (!quiet) |
warnx("cannot allocate memory"); |
warnx("cannot allocate memory"); |