summaryrefslogtreecommitdiffstats
path: root/usr.sbin/kldxref
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2006-07-29 19:39:03 +0000
committermarcel <marcel@FreeBSD.org>2006-07-29 19:39:03 +0000
commit152e76d1d1dcc649357b52f30943345b06aa162c (patch)
tree9babf20513a7235dd154426c6e16a1eb813f1678 /usr.sbin/kldxref
parente07cc0214a55c667871ff33ceb54311ec000283e (diff)
downloadFreeBSD-src-152e76d1d1dcc649357b52f30943345b06aa162c.zip
FreeBSD-src-152e76d1d1dcc649357b52f30943345b06aa162c.tar.gz
Change maketempfile() to return a FILE* so as to eliminate the fopen()
that immediately follows the only call to it. maketempfile() uses mkstemp(), so the temporary file has already been opened and using fopen() again just opens the file twice. This also fixes the invalid mode used on the fopen(). While here, assign NULL to fxref after fclose() because we test for fxref being !NULL to determine if we have the (temporary) hints file open.
Diffstat (limited to 'usr.sbin/kldxref')
-rw-r--r--usr.sbin/kldxref/kldxref.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/usr.sbin/kldxref/kldxref.c b/usr.sbin/kldxref/kldxref.c
index c095e9cc..4fa7c6d 100644
--- a/usr.sbin/kldxref/kldxref.c
+++ b/usr.sbin/kldxref/kldxref.c
@@ -86,7 +86,7 @@ static const char *xref_file = "linker.hints";
static char recbuf[MAXRECSIZE];
static int recpos, reccnt;
-void maketempfile(char *, const char *);
+FILE *maketempfile(char *, const char *);
static void usage(void);
static void
@@ -253,10 +253,11 @@ read_kld(char *filename, char *kldname)
return error;
}
-void
+FILE *
maketempfile(char *dest, const char *root)
{
char *p;
+ int fd;
strncpy(dest, root, MAXPATHLEN - 1);
dest[MAXPATHLEN] = '\0';
@@ -266,8 +267,8 @@ maketempfile(char *dest, const char *root)
else
p = dest;
strcpy(p, "lhint.XXXXXX");
- if (mkstemp(dest) == -1)
- err(1, "%s", dest);
+ fd = mkstemp(dest);
+ return ((fd == -1) ? NULL : fdopen(fd, "w+"));
}
static char xrefname[MAXPATHLEN], tempname[MAXPATHLEN];
@@ -322,6 +323,7 @@ main(int argc, char *argv[])
p = fts_read(ftsp);
if ((p == NULL || p->fts_info == FTS_D) && !dflag && fxref) {
fclose(fxref);
+ fxref = NULL;
if (reccnt) {
rename(tempname, xrefname);
} else {
@@ -334,8 +336,7 @@ main(int argc, char *argv[])
if (p && p->fts_info == FTS_D && !dflag) {
snprintf(xrefname, sizeof(xrefname), "%s/%s",
ftsp->fts_path, xref_file);
- maketempfile(tempname, ftsp->fts_path);
- fxref = fopen(tempname, "w+t");
+ fxref = maketempfile(tempname, ftsp->fts_path);
if (fxref == NULL)
err(1, "can't create %s", tempname);
ival = 1;
OpenPOWER on IntegriCloud