diff options
| author | Mr. Goblin <mrgoblin@mrgoblin.net> | 2026-09-19 15:06:12 +0300 |
|---|---|---|
| committer | Mr. Goblin <mrgoblin@mrgoblin.net> | 2026-09-19 15:06:12 +0300 |
| commit | 2b022e27d1939b46097e523c0973ffbf48d284b1 (patch) | |
| tree | 8c2ca372445f65ed84231bc99c82b7033ecbb511 /src/db.c | |
| parent | 80f5d3071d92b57204e48f3cd9789651ab2ba83b (diff) | |
man page, dist.sh, README is now plain text, Makefile is now posix
Diffstat (limited to 'src/db.c')
| -rw-r--r-- | src/db.c | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -78,15 +78,15 @@ does_dir_exist(const char *path) res.code = dbe_ok; res.data = 1; code = stat(path, &st); - if (code != 0) { - if (errno == ENOENT) + if (0 != code) { + if (ENOENT == errno) res.data = 0; - else if (errno == EACCES) + else if (EACCES == errno) res.code = dbe_access; else res.code = dbe_unknown; } else { - res.data = ((st.st_mode & S_IFMT) == S_IFDIR) ? 1 : 0; + res.data = S_IFDIR == (st.st_mode & S_IFMT); } return res; } @@ -97,15 +97,15 @@ make_dir_ifne(const char *path, int rights) struct db_value_int val = {0}; int code; val = does_dir_exist(path); - if (val.code != dbe_ok) + if (dbe_ok != val.code) return val.code; else if (val.data) return dbe_ok; code = mkdir(path, rights); if (code != 0) { - if (errno == EACCES) + if (EACCES == errno) return dbe_access; - else if (errno == EEXIST) + else if (EEXIST == errno) return dbe_notdir; } return dbe_ok; @@ -117,18 +117,20 @@ do_make_dir_path(const char *path, int rights) char buf[DIR_NAME_BUF_SIZE] = {0}; const char *p = find_chr_or_zero(path, '/'); unsigned sz = p - path + 1, code; - if (sz > sizeof(buf)) + if (sizeof(buf) < sz) return dbe_inval; strncpy(buf, path, sz); buf[sz-1] = '\0'; code = make_dir_ifne(buf, rights); - if (code != dbe_ok) + if (dbe_ok != code) return code; if (*p) { code = chdir(buf); if (0 != code) return dbe_access; - do_make_dir_path(p+1, rights); + code = do_make_dir_path(p+1, rights); + if (dbe_ok != code) + return code; code = chdir(".."); if (0 != code) return dbe_access; @@ -171,20 +173,20 @@ main(void) for (i = 0; i < 10; i++) TEST_CODE(make_dir_path(path, 0777)); pid = fork(); - if (pid == -1) { + if (-1 == pid) { fprintf(stderr, "can't fork\n"); return 1; - } else if (pid == 0) { + } else if (0 == pid) { execlp("ls", "ls", "-laR", NULL); _exit(128); } else { wait(NULL); } pid = fork(); - if (pid == -1) { + if (-1 == pid) { fprintf(stderr, "can't fork\n"); return 1; - } else if (pid == 0) { + } else if (0 == pid) { execlp("rm", "rm", "-rf", "test_db", NULL); _exit(127); } else { |
