Mercurial > hg > toybox
comparison toys/mkfifo.c @ 551:2548e6e590b2
Add string to mode_t parser
added new function string_to_mode(char *m_string, mode_t base) which
parses a given string and converts it to a mode_t.
If either + or - are part of m_string the permissions are either
added or removed from base.
Currently support for permision copy is missing (e.g. g=u),
but all other flags should work.
Format for m_string: either symbolic modes or octal representation.
symbolic modes:
[auog][[+-=][rwxst]*]
examples:
string_to_mode("u=rwx,g=rw,o=r", 0);
string_to_mode("a-x", 0777);
string_to_mode("0744", 0);
author | Daniel Walter <d.walter@0x90.at> |
---|---|
date | Mon, 19 Mar 2012 19:57:56 -0500 |
parents | 6fedb88874a4 |
children |
comparison
equal
deleted
inserted
replaced
550:b2194045c40e | 551:2548e6e590b2 |
---|---|
6 * | 6 * |
7 * See http://pubs.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html | 7 * See http://pubs.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html |
8 * | 8 * |
9 * TODO: Add -m | 9 * TODO: Add -m |
10 | 10 |
11 USE_MKFIFO(NEWTOY(mkfifo, "<1", TOYFLAG_BIN)) | 11 USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN)) |
12 | 12 |
13 config MKFIFO | 13 config MKFIFO |
14 bool "mkfifo" | 14 bool "mkfifo" |
15 default y | 15 default y |
16 help | 16 help |
20 */ | 20 */ |
21 | 21 |
22 #include "toys.h" | 22 #include "toys.h" |
23 | 23 |
24 DEFINE_GLOBALS( | 24 DEFINE_GLOBALS( |
25 long mode; | 25 char *m_string; |
26 mode_t mode; | |
26 ) | 27 ) |
27 | 28 |
28 #define TT this.mkfifo | 29 #define TT this.mkfifo |
30 #define FLAG_m (1) | |
29 | 31 |
30 void mkfifo_main(void) | 32 void mkfifo_main(void) |
31 { | 33 { |
32 char **s; | 34 char **s; |
33 | 35 |
34 TT.mode = 0666; | 36 TT.mode = 0666; |
37 if (toys.optflags & FLAG_m) { | |
38 TT.mode = string_to_mode(TT.m_string, 0); | |
39 } | |
35 | 40 |
36 for (s = toys.optargs; *s; s++) { | 41 for (s = toys.optargs; *s; s++) { |
37 if (mknod(*s, S_IFIFO | TT.mode, 0) < 0) { | 42 if (mknod(*s, S_IFIFO | TT.mode, 0) < 0) { |
38 perror_msg("cannot create fifo '%s'", *s); | 43 perror_msg("cannot create fifo '%s'", *s); |
39 toys.exitval = 1; | 44 toys.exitval = 1; |