-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathsc_mkdir.c
More file actions
32 lines (29 loc) · 768 Bytes
/
sc_mkdir.c
File metadata and controls
32 lines (29 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#define _XOPEN_SOURCE /* for S_IFDIR */
#include "sc_mkdir.h"
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#ifdef _WIN32
# include <direct.h>
#endif /* _WIN32 */
/* cross-platform mkdir */
int sc_mkdir( const char * path ) {
#ifdef _WIN32
return mkdir( path );
#else
return mkdir( path, 0777 );
#endif /* _WIN32 */
}
/* return -1 if error, 0 if created, 1 if dir existed already */
int mkDirIfNone( const char * path ) {
struct stat s;
if( stat( path, &s ) != 0 ) {
if( errno == ENOENT ) {
return sc_mkdir( path );
}
} else if( s.st_mode & S_IFDIR ) {
return 1;
}
/* either stat returned an error other than ENOENT, or 'path' exists but isn't a dir */
return -1;
}