2003-12-23 23:45:41 +00:00

39 lines
1.1 KiB
Plaintext

$OpenBSD: patch-tools_fax2ps_c,v 1.3 2003/12/23 23:45:41 brad Exp $
--- tools/fax2ps.c.orig 2003-10-04 07:43:17.000000000 -0400
+++ tools/fax2ps.c 2003-12-13 02:13:27.000000000 -0500
@@ -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>
@@ -372,15 +373,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);