Factorizing mode expression code

This commit is contained in:
Pierre Pronchery 2005-08-27 21:05:13 +00:00
parent 8f2b158dc9
commit c5a36e759a
2 changed files with 8 additions and 8 deletions

View File

@ -10,6 +10,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#define COMMON_MODE
#include "common.c"
#define OPT_R 1 #define OPT_R 1
@ -114,7 +117,6 @@ int main(int argc, char * argv[])
int opts = 0; int opts = 0;
mode_t mode; mode_t mode;
int o; int o;
char * p;
while((o = getopt(argc, argv, "R")) != -1) while((o = getopt(argc, argv, "R")) != -1)
switch(o) switch(o)
@ -127,9 +129,7 @@ int main(int argc, char * argv[])
} }
if(argc - optind < 2) if(argc - optind < 2)
return _usage(); return _usage();
/* FIXME mode may be an expression */ if(_mode(argv[optind], &mode) != 0)
mode = strtol(argv[optind], &p, 8);
if(argv[optind][0] == '\0' || *p != '\0')
return _usage(); return _usage();
return _chmod(opts, mode, argc - optind - 1, &argv[optind+1]); return _chmod(opts, mode, argc - optind - 1, &argv[optind+1]);
} }

View File

@ -8,6 +8,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#define COMMON_MODE
#include "common.c"
/* mkdir */ /* mkdir */
static int _mkdir_error(char * message, int ret); static int _mkdir_error(char * message, int ret);
@ -77,15 +80,12 @@ int main(int argc, char * argv[])
mode_t mode = 0777; mode_t mode = 0777;
int flagp = 0; int flagp = 0;
int o; int o;
char * p;
while((o = getopt(argc, argv, "pm:")) != -1) while((o = getopt(argc, argv, "pm:")) != -1)
switch(o) switch(o)
{ {
case 'm': case 'm':
/* FIXME mode may be an expression */ if(_mode(optarg, &mode) != 0)
mode = strtol(optarg, &p, 8);
if(*optarg == '\0' || *p != '\0')
return _usage(); return _usage();
break; break;
case 'p': case 'p':