Subversion Repositories HelenOS

Rev

Rev 3277 | Rev 3294 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3277 post 1
/* Automatically generated by mknewcmd on Mon Aug 11 00:06:46 PHT 2008
2
 * This is machine generated output. The author of mknewcmd claims no
3
 * copyright over the contents of this file. Where legally permitted, the
4
 * contents herein are donated to the public domain.
5
 *
6
 * You should apply any license and copyright that you wish to this file,
7
 * replacing this header in its entirety. */
8
 
9
#include <stdio.h>
10
#include <stdlib.h>
3286 post 11
#include <dirent.h>
12
#include <fcntl.h>
13
#include <sys/types.h>
14
#include <sys/stat.h>
15
 
16
#include "config.h"
17
#include "errors.h"
3277 post 18
#include "entry.h"
19
#include "mkdir.h"
20
#include "cmds.h"
21
 
22
static char *cmdname = "mkdir";
23
 
24
/* Dispays help for mkdir in various levels */
25
void * help_cmd_mkdir(unsigned int level)
26
{
3286 post 27
    if (level == HELP_SHORT) {
28
        printf("`%s' creates a new directory\n", cmdname);
29
    } else {
30
        help_cmd_mkdir(HELP_SHORT);
31
        printf("  `%s' <directory>\n", cmdname);
32
    }
33
 
34
    return CMD_VOID;
3277 post 35
}
36
 
37
/* Main entry point for mkdir, accepts an array of arguments */
38
int * cmd_mkdir(char **argv)
39
{
40
    unsigned int argc;
3286 post 41
    DIR *dirp;
3277 post 42
 
43
    /* Count the arguments */
44
    for (argc = 0; argv[argc] != NULL; argc ++);
45
 
3286 post 46
    if (argc != 2) {
47
        printf("%s - too many arguments. Try `help %s extended'\n",
48
            cmdname, cmdname);
49
        return CMD_FAILURE;
50
    }
3277 post 51
 
3286 post 52
    dirp = opendir(argv[1]);
53
    if (dirp) {
54
        closedir(dirp);
55
        cli_error(CL_EEXISTS, "Can not create directory %s", argv[1]);
56
        return CMD_FAILURE;
3277 post 57
    }
58
 
3286 post 59
    if (mkdir(argv[1], 0) != 0) {
60
        cli_error(CL_EFAIL, "Could not create %s", argv[1]);
61
        return CMD_FAILURE;
62
    }
3277 post 63
 
3286 post 64
    return CMD_SUCCESS;
3277 post 65
}
66