summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen/setmode.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2006-03-12 18:36:46 +0000
committerotto <otto@openbsd.org>2006-03-12 18:36:46 +0000
commit1d1d1b9368c84f6023f0ee807a9a304922ccb8ef (patch)
tree20b9977ae9fc2e0d06271e0401b487d12d7c78ff /lib/libc/gen/setmode.c
parentsync with pcn(4) reality (diff)
downloadwireguard-openbsd-1d1d1b9368c84f6023f0ee807a9a304922ccb8ef.tar.xz
wireguard-openbsd-1d1d1b9368c84f6023f0ee807a9a304922ccb8ef.zip
Cleanup to avoid a save errno dance; from Andrey Matveev; ok pat@
jaredy@ ray@
Diffstat (limited to 'lib/libc/gen/setmode.c')
-rw-r--r--lib/libc/gen/setmode.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c
index e0b6dfc1a1d..843b46183c9 100644
--- a/lib/libc/gen/setmode.c
+++ b/lib/libc/gen/setmode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: setmode.c,v 1.18 2005/10/26 20:37:13 otto Exp $ */
+/* $OpenBSD: setmode.c,v 1.19 2006/03/12 18:36:46 otto Exp $ */
/* $NetBSD: setmode.c,v 1.15 1997/02/07 22:21:06 christos Exp $ */
/*
@@ -162,15 +162,15 @@ void *
setmode(const char *p)
{
char op, *ep;
- BITCMD *set, *saveset = NULL, *endset;
+ BITCMD *set, *saveset, *endset;
sigset_t sigset, sigoset;
mode_t mask, perm, permXbits, who;
- int equalopdone, setlen, serrno;
+ int equalopdone, setlen;
u_long perml;
if (!*p) {
errno = EINVAL;
- goto out;
+ return (NULL);
}
/*
@@ -188,7 +188,7 @@ setmode(const char *p)
setlen = SET_LEN + 2;
if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL)
- goto out;
+ return (NULL);
saveset = set;
endset = set + (setlen - 2);
@@ -200,8 +200,9 @@ setmode(const char *p)
perml = strtoul(p, &ep, 8);
/* The test on perml will also catch overflow. */
if (*ep != '\0' || (perml & ~(STANDARD_BITS|S_ISTXT))) {
+ free(saveset);
errno = ERANGE;
- goto out;
+ return (NULL);
}
perm = (mode_t)perml;
ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
@@ -235,8 +236,9 @@ setmode(const char *p)
}
getop: if ((op = *p++) != '+' && op != '-' && op != '=') {
+ free(saveset);
errno = EINVAL;
- goto out;
+ return (NULL);
}
if (op == '=')
equalopdone = 0;
@@ -331,11 +333,6 @@ apply: if (!*p)
dumpmode(saveset);
#endif
return (saveset);
-out:
- serrno = errno;
- free(saveset);
- errno = serrno;
- return (NULL);
}
static BITCMD *