openbsd-ports/graphics/tiff/patches/patch-tools_fax2ps_c
2002-01-19 09:34:42 +00:00

39 lines
1.1 KiB
Plaintext

$OpenBSD: patch-tools_fax2ps_c,v 1.2 2002/01/19 09:34:42 brad Exp $
--- tools/fax2ps.c.orig Wed Mar 28 20:45:43 2001
+++ tools/fax2ps.c Fri Jan 18 23:48:37 2002
@@ -23,6 +23,7 @@
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
+#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
@@ -370,15 +371,19 @@ main(int argc, char** argv)
} while (++optind < argc);
} else {
int n;
+ int sfd = -1;
FILE* fd;
- char temp[1024], buf[16*1024];
+ char temp[15] = "", buf[16*1024];
- strcpy(temp, "/tmp/fax2psXXXXXX");
- (void) mktemp(temp);
- fd = fopen(temp, "w");
- if (fd == NULL) {
- fprintf(stderr, "Could not create temp file \"%s\"\n", temp);
- exit(-2);
+ strlcpy(temp, "/tmp/fax2ps.XXXXXX", sizeof temp);
+ if ((sfd = mkstemp(temp)) == -1 ||
+ (fd = fdopen(sfd, "w+")) == NULL) {
+ if (sfd != -1) {
+ unlink(temp);
+ close(sfd);
+ }
+ fprintf(stderr, "%s: %s\n", temp, strerror(errno));
+ exit(-2);
}
while ((n = read(fileno(stdin), buf, sizeof (buf))) > 0)
write(fileno(fd), buf, n);