version 1.13, 2006/05/10 14:32:51 |
version 1.14, 2006/05/25 03:20:32 |
|
|
#include <err.h> |
#include <err.h> |
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
|
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "common.h" |
#include "common.h" |
|
|
{ |
{ |
FILE *file; |
FILE *file; |
size_t nread, nwritten; |
size_t nread, nwritten; |
|
int fd; |
char *filename; |
char *filename; |
char buf[BUFSIZ], *text; |
char buf[BUFSIZ], *text; |
|
|
|
|
} |
} |
|
|
/* Create temp file. */ |
/* Create temp file. */ |
filename = xmktemp(text); |
if (asprintf(&filename, "%s/sdiff.XXXXXXXXXX", tmpdir) == -1) |
|
err(2, "asprintf"); |
|
if ((fd = mkstemp(filename)) == -1) |
|
err(2, "mkstemp"); |
|
if (text != NULL) { |
|
size_t len; |
|
|
|
len = strlen(text); |
|
if ((nwritten = write(fd, text, len)) == -1 || |
|
nwritten != len) { |
|
warn("error writing to temp file"); |
|
cleanup(filename); |
|
} |
|
} |
|
close(fd); |
|
|
/* text is no longer used. */ |
/* text is no longer used. */ |
free(text); |
free(text); |
|
|
|
|
warn("could not delete: %s", filename); |
warn("could not delete: %s", filename); |
fclose(file); |
fclose(file); |
|
|
/* filename was malloc()ed in xmktemp(). */ |
|
free(filename); |
free(filename); |
|
|
return (0); |
return (0); |