summaryrefslogtreecommitdiff
path: root/tempfile.c
diff options
context:
space:
mode:
authorManoj Srivastava <srivasta@debian.org>2009-05-01 13:53:05 -0500
committerClint Adams <schizo@debian.org>2009-05-01 17:56:39 -0400
commit965886b62fddbf98cfced65e923e5d89990bfa08 (patch)
tree48709c730238a5ca79f3c05452341af95be7c1c3 /tempfile.c
parent60139002e13ba98ef48ddcf324c57f44507c6336 (diff)
downloaddebianutils-965886b62fddbf98cfced65e923e5d89990bfa08.tar.gz
tempfile with a suffix no longer needs hardlinks
"tempfile -s" did not work on FAT filesystems, since the implementaion required hardlinks. With this commit, we add the suffix to the output of tempnam early, and create the suffixed file, instead f creating the unsuffixed file, harlinking to the suffixed file, and unlinking. Signed-Off-By: Manoj Srivastava <srivasta@debian.org> Signed-off-by: Manoj Srivastava <srivasta@debian.org>
Diffstat (limited to 'tempfile.c')
-rw-r--r--tempfile.c40
1 files changed, 16 insertions, 24 deletions
diff --git a/tempfile.c b/tempfile.c
index 1fc50d6..c3a3b97 100644
--- a/tempfile.c
+++ b/tempfile.c
@@ -59,7 +59,7 @@ parsemode (const char *in, mode_t *out)
int
main (int argc, char **argv)
{
- char *name=0, *dir=0, *pfx=0, *sfx=0;
+ char *name=0, *dir=0, *pfx=0, *sfx=0, *filename=0;
mode_t mode = 0600;
int fd, optc;
struct option long_options[] = {
@@ -117,41 +117,33 @@ main (int argc, char **argv)
for (;;) {
if (!(name = tempnam(dir, pfx)))
syserror("tempnam");
- if ((fd = open(name, O_RDWR | O_CREAT | O_EXCL, mode)) < 0) {
+ if(sfx) {
+ char *namesfx;
+ if (!(namesfx = (char *)malloc(strlen(name) + strlen(sfx) + 1)))
+ syserror("malloc");
+ strcpy(namesfx, name);
+ strcat(namesfx, sfx);
+ filename = namesfx;
+ }
+ else
+ filename = name;
+
+ if ((fd = open(filename, O_RDWR | O_CREAT | O_EXCL, mode)) < 0) {
if (errno == EEXIST) {
free(name);
+ free(filename);
continue;
}
syserror("open");
}
- if (sfx) {
- char *namesfx;
- if (!(namesfx = malloc(strlen(name) + strlen(sfx) + 1)))
- syserror("malloc");
- strcpy(namesfx, name);
- strcat(namesfx, sfx);
- if (link(name, namesfx) < 0) {
- if (errno == EEXIST) {
- if (unlink(name) < 0)
- syserror("unlink");
- free(name);
- free(namesfx);
- continue;
- }
- syserror("link");
- }
- if (unlink(name) < 0)
- syserror("unlink");
- free(name);
- name = namesfx;
- }
break;
}
}
if (close(fd))
syserror("close");
- puts(name);
+ puts(filename);
+ free(filename);
free(name);
exit(0);
}