source: rtems/cpukit/libmisc/shell/main_chmod.c @ 35d09ba

4.104.115
Last change on this file since 35d09ba was 35d09ba, checked in by Joel Sherrill <joel.sherrill@…>, on 07/22/09 at 15:17:37

2009-07-22 Joel Sherrill <joel.sherrill@…>

  • libmisc/Makefile.am, libmisc/shell/main_chmod.c, libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c, libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c, libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c, libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c, libmisc/shell/shell.h, libmisc/shell/shell_script.c, libmisc/stringto/stringto_template.h: Convert all shell code to use stringto.h mehods with better error checking.
  • libmisc/shell/str2int.c: Removed.
  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*
2 *  CHMOD Shell Command Implmentation
3 *
4 *  Author: Fernando RUIZ CASAS
5 *  Work: fernando.ruiz@ctv.es
6 *  Home: correo@fernando-ruiz.com
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.rtems.com/license/LICENSE.
11 *
12 *  $Id$
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
31int rtems_shell_main_chmod(
32  int argc,
33  char *argv[]
34)
35{
36  int           n;
37  mode_t        mode;
38  unsigned long tmp;
39
40  if (argc < 2) {
41    fprintf(stderr,"%s: too few arguments\n", argv[0]);
42    return -1;
43  }
44
45  /*
46   *  Convert arguments into numbers
47   */
48  if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
49    printf( "Mode argument (%s) is not a number\n", argv[1] );
50    return -1;
51  }
52  mode = (mode_t) (tmp & 0777);
53
54  /*
55   *  Now change the files modes
56   */
57  for (n=2 ; n < argc ; n++)
58    chmod(argv[n++], mode);
59
60  return 0;
61}
62
63rtems_shell_cmd_t rtems_shell_CHMOD_Command = {
64  "chmod",                                      /* name */
65  "chmod 0777 n1 n2... # change filemode",      /* usage */
66  "files",                                      /* topic */
67  rtems_shell_main_chmod,                       /* command */
68  NULL,                                         /* alias */
69  NULL                                          /* next */
70};
Note: See TracBrowser for help on using the repository browser.