From 152e76d1d1dcc649357b52f30943345b06aa162c Mon Sep 17 00:00:00 2001 From: marcel Date: Sat, 29 Jul 2006 19:39:03 +0000 Subject: 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. --- usr.sbin/kldxref/kldxref.c | 13 +++++++------ 1 file 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; -- cgit v1.1