Changeset 081d60f in mainline for uspace/app/bdsh/cmds/modules/rm


Ignore:
Timestamp:
2012-04-04T03:55:26Z (14 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1dbe465
Parents:
e4fbccd
Message:

Fix some style issues in bdsh.

  • Slight indentation fix in sleep.c
  • Use a better name in sleep.c
  • Remove static things from header files in various commands
Location:
uspace/app/bdsh/cmds/modules/rm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    re4fbccd r081d60f  
    4646#define RM_VERSION "0.0.1"
    4747
    48 static rm_job_t rm;
    49 
    5048static struct option const long_options[] = {
    5149        { "help", no_argument, 0, 'h' },
     
    5755};
    5856
     57/* Return values for rm_scope() */
     58#define RM_BOGUS 0
     59#define RM_FILE  1
     60#define RM_DIR   2
     61
     62/* Flags for rm_update() */
     63#define _RM_ENTRY   0
     64#define _RM_ADVANCE 1
     65#define _RM_REWIND  2
     66#define _RM_EXIT    3
     67
     68/* A simple job structure */
     69typedef struct {
     70        /* Options set at run time */
     71        unsigned int force;      /* -f option */
     72        unsigned int recursive;  /* -r option */
     73        unsigned int safe;       /* -s option */
     74
     75        /* Keeps track of the job in progress */
     76        int advance; /* How far deep we've gone since entering */
     77        DIR *entry;  /* Entry point to the tree being removed */
     78        char *owd;   /* Where we were when we invoked rm */
     79        char *cwd;   /* Current directory being transversed */
     80        char *nwd;   /* Next directory to be transversed */
     81
     82        /* Counters */
     83        int f_removed; /* Number of files unlinked */
     84        int d_removed; /* Number of directories unlinked */
     85} rm_job_t;
     86
     87static rm_job_t rm;
     88
     89static unsigned int rm_recursive(const char *);
     90
    5991static unsigned int rm_start(rm_job_t *rm)
    6092{
     
    95127        if (NULL != rm->cwd)
    96128                free(rm->cwd);
     129}
     130
     131static unsigned int rm_single(const char *path)
     132{
     133        if (unlink(path)) {
     134                cli_error(CL_EFAIL, "rm: could not remove file %s", path);
     135                return 1;
     136        }
     137        return 0;
     138}
     139
     140static unsigned int rm_scope(const char *path)
     141{
     142        int fd;
     143        DIR *dirp;
     144
     145        dirp = opendir(path);
     146        if (dirp) {
     147                closedir(dirp);
     148                return RM_DIR;
     149        }
     150
     151        fd = open(path, O_RDONLY);
     152        if (fd > 0) {
     153                close(fd);
     154                return RM_FILE;
     155        }
     156
     157        return RM_BOGUS;
    97158}
    98159
     
    154215
    155216        return ret + 1;
    156 }
    157 
    158 static unsigned int rm_single(const char *path)
    159 {
    160         if (unlink(path)) {
    161                 cli_error(CL_EFAIL, "rm: could not remove file %s", path);
    162                 return 1;
    163         }
    164         return 0;
    165 }
    166 
    167 static unsigned int rm_scope(const char *path)
    168 {
    169         int fd;
    170         DIR *dirp;
    171 
    172         dirp = opendir(path);
    173         if (dirp) {
    174                 closedir(dirp);
    175                 return RM_DIR;
    176         }
    177 
    178         fd = open(path, O_RDONLY);
    179         if (fd > 0) {
    180                 close(fd);
    181                 return RM_FILE;
    182         }
    183 
    184         return RM_BOGUS;
    185217}
    186218
  • uspace/app/bdsh/cmds/modules/rm/rm.h

    re4fbccd r081d60f  
    22#define RM_H
    33
    4 /* Return values for rm_scope() */
    5 #define RM_BOGUS 0
    6 #define RM_FILE  1
    7 #define RM_DIR   2
    8 
    9 /* Flags for rm_update() */
    10 #define _RM_ENTRY   0
    11 #define _RM_ADVANCE 1
    12 #define _RM_REWIND  2
    13 #define _RM_EXIT    3
    14 
    15 /* A simple job structure */
    16 typedef struct {
    17         /* Options set at run time */
    18         unsigned int force;      /* -f option */
    19         unsigned int recursive;  /* -r option */
    20         unsigned int safe;       /* -s option */
    21 
    22         /* Keeps track of the job in progress */
    23         int advance; /* How far deep we've gone since entering */
    24         DIR *entry;  /* Entry point to the tree being removed */
    25         char *owd;   /* Where we were when we invoked rm */
    26         char *cwd;   /* Current directory being transversed */
    27         char *nwd;   /* Next directory to be transversed */
    28 
    29         /* Counters */
    30         int f_removed; /* Number of files unlinked */
    31         int d_removed; /* Number of directories unlinked */
    32 } rm_job_t;
    33 
    34 
    354/* Prototypes for the rm command, excluding entry points */
    36 static unsigned int rm_start(rm_job_t *);
    37 static void rm_end(rm_job_t *rm);
    38 static unsigned int rm_recursive(const char *);
    39 static unsigned int rm_single(const char *);
    40 static unsigned int rm_scope(const char *);
    415
    426#endif /* RM_H */
Note: See TracChangeset for help on using the changeset viewer.