Date: Fri, 28 Jan 2000 19:25:02 -0500 (EST) From: Mike Heffner <mheffner@mailandnews.com> To: FreeBSD-audit <FreeBSD-audit@freebsd.org>, mike@gnu.ai.mit.edu Subject: sort, revised patch Message-ID: <XFMail.20000128192502.mheffner@mailandnews.com>
next in thread | raw e-mail | index | archive | help
Alright, since it was our fourth snow day in a row =), I had time to redo
this. Here's the revised patch, it keeps the original naming scheme for
tempfiles, but puts them in a dir made with mkdtemp(3).
Index: sort.c
===================================================================
RCS file: /home/ncvs/src/gnu/usr.bin/sort/sort.c,v
retrieving revision 1.15
diff -u -r1.15 sort.c
--- sort.c 1999/04/25 22:14:05 1.15
+++ sort.c 2000/01/29 00:12:21
@@ -171,6 +171,8 @@
/* Prefix for temporary file names. */
static char *temp_file_prefix;
+/* Temporary dir for temp files, *with* above prefix */
+static char *temp_dir = NULL;
/* Flag to reverse the order of all comparisons. */
static int reverse;
@@ -288,6 +290,9 @@
for (node = temphead.next; node; node = node->next)
unlink (node->name);
+ if( temp_dir )
+ rmdir(temp_dir);
+
}
/* Allocate N bytes of memory dynamically, with error checking. */
@@ -413,6 +418,7 @@
}
}
+#define DIR_TEMPLATE "sortXXXXXXXXXX"
/* Return a name for a temporary file. */
static char *
@@ -420,14 +426,28 @@
{
static unsigned int seq;
int len = strlen (temp_file_prefix);
- char *name = xmalloc (len + 1 + sizeof ("sort") - 1 + 5 + 5 + 1);
+ char *name;
struct tempnode *node;
node = (struct tempnode *) xmalloc (sizeof (struct tempnode));
+ if( !temp_dir )
+ {
+ temp_dir = xmalloc( len + 1 + strlen(DIR_TEMPLATE) + 1 );
+ sprintf(temp_dir,
+ "%s%s%s",
+ temp_file_prefix,
+ (len && temp_file_prefix[len - 1] != '/') ? "/" : "",
+ DIR_TEMPLATE);
+ if( mkdtemp(temp_dir) == NULL )
+ {
+ error(0, errno, _("can't make temp dir"));
+ exit(2);
+ }
+ }
+ name = xmalloc(strlen(temp_dir) + 1 + strlen("sort") + 5 + 5 + 1);
sprintf (name,
- "%s%ssort%5.5d%5.5d",
- temp_file_prefix,
- (len && temp_file_prefix[len - 1] != '/') ? "/" : "",
+ "%s/sort%5.5d%5.5d",
+ temp_dir,
(unsigned int) getpid () & 0xffff, seq);
/* Make sure that SEQ's value fits in 5 digits. */
---------------------------------
Mike Heffner <spock@techfour.net>
Fredericksburg, VA
ICQ# 882073
Date: 28-Jan-2000 Time: 19:15:54
---------------------------------
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.20000128192502.mheffner>
