/* Automatically generated by mknewcmd on Mon Aug 11 00:06:46 PHT 2008
* This is machine generated output. The author of mknewcmd claims no
* copyright over the contents of this file. Where legally permitted, the
* contents herein are donated to the public domain.
*
* You should apply any license and copyright that you wish to this file,
* replacing this header in its entirety. */
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "config.h"
#include "errors.h"
#include "entry.h"
#include "mkdir.h"
#include "cmds.h"
static char *cmdname = "mkdir";
/* Dispays help for mkdir in various levels */
void * help_cmd_mkdir(unsigned int level)
{
if (level == HELP_SHORT) {
printf("`%s' creates a new directory\n", cmdname
);
} else {
help_cmd_mkdir(HELP_SHORT);
printf(" `%s' <directory>\n", cmdname
);
}
return CMD_VOID;
}
/* Main entry point for mkdir, accepts an array of arguments */
int * cmd_mkdir(char **argv)
{
unsigned int argc;
DIR *dirp;
/* Count the arguments */
for (argc = 0; argv[argc] != NULL; argc ++);
if (argc != 2) {
printf("%s - too many arguments. Try `help %s extended'\n",
cmdname, cmdname);
return CMD_FAILURE;
}
dirp = opendir(argv[1]);
if (dirp) {
closedir(dirp);
cli_error(CL_EEXISTS, "Can not create directory %s", argv[1]);
return CMD_FAILURE;
}
if (mkdir(argv[1], 0) != 0) {
cli_error(CL_EFAIL, "Could not create %s", argv[1]);
return CMD_FAILURE;
}
return CMD_SUCCESS;
}