Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief CHMOD Shell Command Implmentation |
---|
5 | */ |
---|
6 | |
---|
7 | /* |
---|
8 | * Copyright (c) 2001 Fernando Ruiz Casas <fruizcasas@gmail.com> |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.org/license/LICENSE. |
---|
13 | */ |
---|
14 | |
---|
15 | #ifdef HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <stdio.h> |
---|
20 | #include <unistd.h> |
---|
21 | #include <string.h> |
---|
22 | #include <errno.h> |
---|
23 | #include <sys/types.h> |
---|
24 | #include <sys/stat.h> |
---|
25 | |
---|
26 | #include <rtems.h> |
---|
27 | #include <rtems/shell.h> |
---|
28 | #include <rtems/stringto.h> |
---|
29 | #include "internal.h" |
---|
30 | |
---|
31 | static int rtems_shell_main_chmod( |
---|
32 | int argc, |
---|
33 | char *argv[] |
---|
34 | ) |
---|
35 | { |
---|
36 | int n; |
---|
37 | mode_t mode; |
---|
38 | unsigned long tmp; |
---|
39 | int sc; |
---|
40 | |
---|
41 | if (argc < 2) { |
---|
42 | fprintf(stderr,"%s: too few arguments\n", argv[0]); |
---|
43 | return -1; |
---|
44 | } |
---|
45 | |
---|
46 | /* |
---|
47 | * Convert arguments into numbers |
---|
48 | */ |
---|
49 | if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { |
---|
50 | printf( "Mode argument (%s) is not a number\n", argv[1] ); |
---|
51 | return -1; |
---|
52 | } |
---|
53 | mode = (mode_t) (tmp & 0777); |
---|
54 | |
---|
55 | /* |
---|
56 | * Now change the files modes |
---|
57 | */ |
---|
58 | for (n=2 ; n < argc ; n++) { |
---|
59 | sc = chmod(argv[n], mode); |
---|
60 | _Assert_Unused_variable_unequal(sc, -1); |
---|
61 | } |
---|
62 | |
---|
63 | return 0; |
---|
64 | } |
---|
65 | |
---|
66 | rtems_shell_cmd_t rtems_shell_CHMOD_Command = { |
---|
67 | "chmod", /* name */ |
---|
68 | "chmod 0777 n1 n2... # change filemode", /* usage */ |
---|
69 | "files", /* topic */ |
---|
70 | rtems_shell_main_chmod, /* command */ |
---|
71 | NULL, /* alias */ |
---|
72 | NULL /* next */ |
---|
73 | }; |
---|
Note: See
TracBrowser
for help on using the repository browser.