fix
This commit is contained in:
parent
8db46ac91d
commit
4d8b780c00
@ -100,7 +100,7 @@ int main(int argc, char **argv) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc - i < 1) {
|
if (argc - i < 2) {
|
||||||
fprintf(stderr, "chmod: missing operand\n");
|
fprintf(stderr, "chmod: missing operand\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,24 @@ unsigned int a_flag;
|
|||||||
unsigned int l_flag;
|
unsigned int l_flag;
|
||||||
|
|
||||||
void PrintPerm(struct stat sb) {
|
void PrintPerm(struct stat sb) {
|
||||||
printf("%c", (S_ISDIR(sb.st_mode)) ? 'd' : '-');
|
if (S_ISDIR(sb.st_mode))
|
||||||
|
printf("d");
|
||||||
|
|
||||||
|
else if (S_ISLNK(sb.st_mode))
|
||||||
|
printf("l");
|
||||||
|
|
||||||
|
else if (S_ISCHR(sb.st_mode))
|
||||||
|
printf("c");
|
||||||
|
|
||||||
|
else if (S_ISFIFO(sb.st_mode))
|
||||||
|
printf("p");
|
||||||
|
|
||||||
|
else if (S_ISSOCK(sb.st_mode))
|
||||||
|
printf("s");
|
||||||
|
|
||||||
|
else
|
||||||
|
printf("-");
|
||||||
|
|
||||||
printf("%c%c%c", (sb.st_mode & S_IRUSR) ? 'r' : '-', (sb.st_mode & S_IWUSR) ? 'w' : '-', (sb.st_mode & S_IXUSR) ? 'x' : '-');
|
printf("%c%c%c", (sb.st_mode & S_IRUSR) ? 'r' : '-', (sb.st_mode & S_IWUSR) ? 'w' : '-', (sb.st_mode & S_IXUSR) ? 'x' : '-');
|
||||||
printf("%c%c%c", (sb.st_mode & S_IRGRP) ? 'r' : '-', (sb.st_mode & S_IWGRP) ? 'w' : '-', (sb.st_mode & S_IXGRP) ? 'x' : '-');
|
printf("%c%c%c", (sb.st_mode & S_IRGRP) ? 'r' : '-', (sb.st_mode & S_IWGRP) ? 'w' : '-', (sb.st_mode & S_IXGRP) ? 'x' : '-');
|
||||||
printf("%c%c%c", (sb.st_mode & S_IROTH) ? 'r' : '-', (sb.st_mode & S_IWOTH) ? 'w' : '-', (sb.st_mode & S_IXOTH) ? 'x' : '-');
|
printf("%c%c%c", (sb.st_mode & S_IROTH) ? 'r' : '-', (sb.st_mode & S_IWOTH) ? 'w' : '-', (sb.st_mode & S_IXOTH) ? 'x' : '-');
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "parse_mode.h"
|
||||||
|
|
||||||
long parse_int(const char *str) {
|
long parse_int(const char *str) {
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
@ -33,14 +34,8 @@ int main(const int argc, const char **argv) {
|
|||||||
if (argv[i][0] != '-')
|
if (argv[i][0] != '-')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
else if (!strncmp("-m=", argv[i], 3)) {
|
else if (!strncmp("-m=", argv[i], 3))
|
||||||
char *ptr = NULL;
|
mode = mu_parse_mode(argv[i] + 3);
|
||||||
mode = (mode_t)strtol(argv[i] + 3, &ptr, 8);
|
|
||||||
if (*ptr) {
|
|
||||||
fprintf(stderr, "mknod: invalid mode %s\n", argv[i] + 3);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long major = 0;
|
long major = 0;
|
||||||
@ -76,7 +71,7 @@ int main(const int argc, const char **argv) {
|
|||||||
|
|
||||||
else {
|
else {
|
||||||
printf("mknod [-m=mode] [NAME] [TYPE] [MAJOR MINOR]\n");
|
printf("mknod [-m=mode] [NAME] [TYPE] [MAJOR MINOR]\n");
|
||||||
printf("Types:\n b - block deviece\n c or u - character device\n p - named pipe (MAJOR MINOR must be omitted)\n s - socket\n");
|
printf("Types:\n b - block deviece\n c or u - character device\n p - fifo (MAJOR MINOR must be omitted)\n s - socket\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,42 +3,20 @@
|
|||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
int mu_parse_mode(const char *s) {
|
#define U(x) (x << 6)
|
||||||
|
#define G(x) (x << 3)
|
||||||
|
#define O(x) (x)
|
||||||
|
#define A(x) (U(x) | G(x) | O(x))
|
||||||
|
|
||||||
|
#define FULL_PERM ((S_IRUSR | S_IRGRP | S_IROTH) | (S_IWUSR | S_IWGRP | S_IWOTH) | (S_IXUSR | S_IXGRP | S_IXOTH))
|
||||||
|
mode_t mu_parse_mode(const char *s) {
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
long mode = strtol(s, &p, 8);
|
mode_t mode = (mode_t)strtol(s, &p, 8);
|
||||||
if (!*p)
|
if (!*p)
|
||||||
return mode;
|
return mode;
|
||||||
|
|
||||||
int group = 0;
|
//TODO
|
||||||
int other = 0;
|
return A(7);
|
||||||
int user = 0;
|
|
||||||
|
|
||||||
int i;
|
|
||||||
for (i = 0; s[i]; i++) {
|
|
||||||
switch (s[i]) {
|
|
||||||
case 'u':
|
|
||||||
user = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'g':
|
|
||||||
group = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'o':
|
|
||||||
other = 1;
|
|
||||||
|
|
||||||
case 'a':
|
|
||||||
group = 1;
|
|
||||||
other = 1;
|
|
||||||
user = 1;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return mode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user