// Copyright (2013) Jann Horn <jann@thejh.net>
-// This code is licensed under the AGPLv3.
HEADER #include <stdio.h>
HEADER #include <sys/types.h>
HEADER #include <dirent.h>
+#include <sys/stat.h>
#include <errno.h>
errno = errno_;
return feach_res;
}
+
+PUBLIC_FN int mkdir_maybe(const char *path, mode_t mode) {
+ int r = mkdir(path, mode);
+ if (r && errno != EEXIST) {
+ return r;
+ }
+ return 0;
+}
+
+HEADER // requires stdio.h
+HEADER #define FDIR_FOREACH(dir, element_name, code) { \
+HEADER struct dirent element_name; \
+HEADER struct dirent *__jh_fdir_foreach_res; \
+HEADER while (1) { \
+HEADER int __jh_fdir_foreach_rd_res = readdir_r(dir, &element_name, &__jh_fdir_foreach_res); \
+HEADER if(__jh_fdir_foreach_rd_res) {*(char*)0 = 0; /*crash, boom – EBADF happened (probably)*/} \
+HEADER if (__jh_fdir_foreach_res == NULL) goto end; \
+HEADER {code} \
+HEADER } \
+HEADER end:; \
+HEADER }