Dolda2000 GitWeb
/
utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
b2fa28e
)
nextep: Create data directory only if necessary.
author
Fredrik Tolf
<fredrik@dolda2000.com>
Fri, 30 Sep 2011 13:09:22 +0000
(15:09 +0200)
committer
Fredrik Tolf
<fredrik@dolda2000.com>
Fri, 30 Sep 2011 13:09:22 +0000
(15:09 +0200)
nextep.c
patch
|
blob
|
blame
|
history
diff --git
a/nextep.c
b/nextep.c
index
a7bc746
..
0a8b6b6
100644
(file)
--- a/
nextep.c
+++ b/
nextep.c
@@
-6,6
+6,15
@@
#include <errno.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/stat.h>
+static int ensuredir(char *base, char *dir)
+{
+ if(access(dir, X_OK)) {
+ if((mkdir(base, 0777) && (errno != EEXIST)) || mkdir(dir, 0777))
+ return(1);
+ }
+ return(0);
+}
+
static void usage(FILE *out)
{
fprintf(out, "usage: nextep [-h] [-f FILE] [-s SET-VALUE] [DIR]\n");
static void usage(FILE *out)
{
fprintf(out, "usage: nextep [-h] [-f FILE] [-s SET-VALUE] [DIR]\n");
@@
-55,12
+64,6
@@
int main(int argc, char **argv)
}
snprintf(buf, sizeof(buf), "%s/.nextep", p);
snprintf(base, sizeof(base), "%s/%s", buf, dir);
}
snprintf(buf, sizeof(buf), "%s/.nextep", p);
snprintf(base, sizeof(base), "%s/%s", buf, dir);
- if(access(base, X_OK)) {
- if((mkdir(buf, 0777) && (errno != EEXIST)) || mkdir(base, 0777)) {
- fprintf(stderr, "nextep: %s: %s\n", base, strerror(errno));
- exit(1);
- }
- }
snprintf(fpath, sizeof(fpath), "%s/%s", base, file);
if(value == NULL) {
if((fp = fopen(fpath, "r")) == NULL) {
snprintf(fpath, sizeof(fpath), "%s/%s", base, file);
if(value == NULL) {
if((fp = fopen(fpath, "r")) == NULL) {
@@
-79,6
+82,10
@@
int main(int argc, char **argv)
exit(1);
}
} else {
exit(1);
}
} else {
+ if(ensuredir(buf, base)) {
+ fprintf(stderr, "nextep: %s: %s\n", base, strerror(errno));
+ exit(1);
+ }
if((fp = fopen(fpath, "w")) == NULL) {
fprintf(stderr, "nextep: %s: %s\n", fpath, strerror(errno));
exit(1);
if((fp = fopen(fpath, "w")) == NULL) {
fprintf(stderr, "nextep: %s: %s\n", fpath, strerror(errno));
exit(1);