aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2007-11-19 07:07:50 -0600
committerRob Landley <rob@landley.net>2007-11-19 07:07:50 -0600
commit126f9c5c6f4da006dc389b6eb91d9c8f0d02970e (patch)
tree400d46f91e7c0d0125842afa5701f306448950c3
parente15850ae972957d097eeadfd5721e3ac8f10fd4e (diff)
downloadtoybox-126f9c5c6f4da006dc389b6eb91d9c8f0d02970e.tar.gz
Tighten up error handling, add a umask() call so -m 123 actually works.
-rw-r--r--toys/mkfifo.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/toys/mkfifo.c b/toys/mkfifo.c
index f7cc5b6b..a15c121c 100644
--- a/toys/mkfifo.c
+++ b/toys/mkfifo.c
@@ -1,6 +1,8 @@
/* vi: set sw=4 ts=4: */
/*
* mkfifo.c: Create a named pipe.
+ *
+ * See http://www.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html
*/
#include "toys.h"
@@ -12,25 +14,13 @@ int mkfifo_main(void)
mode_t mode;
if (toys.optflags) {
- long temp;
char *end;
- int len = strlen(toy.mkfifo.mode);
- temp = strtol(toy.mkfifo.mode, &end, 8);
- switch (temp) {
- case LONG_MAX:
- case LONG_MIN:
- case 0:
- if (!errno)
- break;
- error_exit("Invalid mode");
- }
- if (temp > 0777 || *end || len < 3 || len > 4)
+ mode = (mode_t)strtol(toy.mkfifo.mode, &end, 8);
+ if (end<=toy.mkfifo.mode || *end || mode<0 || mode>0777)
error_exit("Invalid mode");
- mode = (mode_t)temp;
- } else {
- mode = 0644;
- }
+ } else mode = 0644;
+ umask(0);
for (i = 0; (arg = toys.optargs[i]); i++)
if (mkfifo(arg, mode))
perror_exit(arg);