#include <errno.h>
#include <sys/param.h>
-static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
+static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
"Create the DIRECTORY(ies), if they do not already exist\n\n"
-"-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
-"-p\tno error if existing, make parent directories as needed\n";
+"Options:\n"
+"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
+"\t-p\tno error if existing, make parent directories as needed\n";
static int parentFlag = FALSE;
-static mode_t mode = 777;
+static mode_t mode = 0777;
extern int mkdir_main(int argc, char **argv)
while (argc > 0) {
int status;
struct stat statBuf;
- status=stat(*argv, &statBuf);
+ char buf[NAME_MAX];
+
+ strcpy (buf, *argv);
+ status=stat(buf, &statBuf);
if (status != -1 && status != ENOENT ) {
- fprintf(stderr, "%s: File exists\n", *argv);
+ fprintf(stderr, "%s: File exists\n", buf);
exit( FALSE);
}
- if (parentFlag == TRUE)
- createPath(*argv, mode);
+ if (parentFlag == TRUE) {
+ strcat( buf, "/");
+ createPath(buf, mode);
+ }
else {
- if (mkdir (*argv, mode) != 0) {
- perror(*argv);
+ if (mkdir (buf, mode) != 0) {
+ perror(buf);
exit( FALSE);
}
}