FreeCalypso > hg > freecalypso-tools
comparison rvinterf/etmsync/hostmkdir.c @ 276:d332fbf5c145
etmsync: host_mkdir() function factored out of fc-fsio
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 17 Nov 2017 00:26:09 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
275:81da9717babe | 276:d332fbf5c145 |
---|---|
1 /* | |
2 * host_mkdir() function has been factored out into this module. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <sys/stat.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <unistd.h> | |
10 #include "exitcodes.h" | |
11 | |
12 host_mkdir(pathname) | |
13 char *pathname; | |
14 { | |
15 int rc; | |
16 struct stat st; | |
17 | |
18 rc = stat(pathname, &st); | |
19 if (rc < 0) { | |
20 rc = mkdir(pathname, 0777); | |
21 if (rc < 0) { | |
22 perror(pathname); | |
23 return(ERROR_UNIX); | |
24 } | |
25 return(0); | |
26 } else { | |
27 if (S_ISDIR(st.st_mode)) | |
28 return(0); | |
29 else { | |
30 fprintf(stderr, | |
31 "error: %s already exists and is not a directory\n", | |
32 pathname); | |
33 return(ERROR_UNIX); | |
34 } | |
35 } | |
36 } |