summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorJason McIntyre <jmc@cvs.openbsd.org>2006-01-06 10:01:26 +0000
committerJason McIntyre <jmc@cvs.openbsd.org>2006-01-06 10:01:26 +0000
commit895d2877a3ae17918fd59e3d9151e6494c2cfee3 (patch)
tree6f73e0f1d9eab0ad835a53d79e3642e5ec93a117 /lib/libc
parentbf3b1f2d138ab4285d79b476cbb41edc4ef7c3b8 (diff)
in code fragment:
- allocate enough space for sfn. - remove variable initializations that get overwritten anyway. - change spaces to tabs. - change "sizeof sfn" to "sizeof(sfn)". - change fprintf(stderr) to warn(). from ray lai; ok millert
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/mktemp.328
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/libc/stdio/mktemp.3 b/lib/libc/stdio/mktemp.3
index 655fd0c8f72..eff4da2c4be 100644
--- a/lib/libc/stdio/mktemp.3
+++ b/lib/libc/stdio/mktemp.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: mktemp.3,v 1.37 2005/07/26 03:30:25 jaredy Exp $
+.\" $OpenBSD: mktemp.3,v 1.38 2006/01/06 10:01:25 jmc Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -142,32 +142,32 @@ Doing this correctly requires a good understanding of the code in question.
.Pp
For instance, code of this form:
.Bd -literal -offset indent
-char sfn[15] = "";
+char sfn[19];
FILE *sfp;
-strlcpy(sfn, "/tmp/ed.XXXXXXXXXX", sizeof sfn);
+strlcpy(sfn, "/tmp/ed.XXXXXXXXXX", sizeof(sfn));
if (mktemp(sfn) == NULL || (sfp = fopen(sfn, "w+")) == NULL) {
- fprintf(stderr, "%s: %s\en", sfn, strerror(errno));
- return (NULL);
+ warn("%s", sfn);
+ return (NULL);
}
return (sfp);
.Ed
.Pp
should be rewritten like this:
.Bd -literal -offset indent
-char sfn[15] = "";
+char sfn[19];
FILE *sfp;
-int fd = -1;
+int fd;
-strlcpy(sfn, "/tmp/ed.XXXXXXXXXX", sizeof sfn);
+strlcpy(sfn, "/tmp/ed.XXXXXXXXXX", sizeof(sfn));
if ((fd = mkstemp(sfn)) == -1 ||
(sfp = fdopen(fd, "w+")) == NULL) {
- if (fd != -1) {
- unlink(sfn);
- close(fd);
- }
- fprintf(stderr, "%s: %s\en", sfn, strerror(errno));
- return (NULL);
+ if (fd != -1) {
+ unlink(sfn);
+ close(fd);
+ }
+ warn("%s", sfn);
+ return (NULL);
}
return (sfp);
.Ed