#include <string.h>
#include <errno.h>
#include <assert.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
#include "binary_storage.h"
#include "utils.h"
debug_print("path=%s sidecar_path=%s\n", path, sidecar_path);
char *buffer = __read_file(sidecar_path, buffer_size);
- free (sidecar_path);
+ strfree (sidecar_path);
return buffer;
}
return 0;
}
+static int ensure_dirs(char *path) {
+ int n = strlen( path );
+ char *p = stralloc( n+1 );
+ memcpy( p, path, n+1 );
+ char *e = p + 1;
+ for ( ;; ) {
+ while ( *e && *e != '/' ) e++;
+ if ( *e ) {
+ *e = 0;
+ if ( access( p, F_OK ) && mkdir( p, 0777 ) ) {
+ return 1;
+ }
+ *(e++) = '/';
+ } else {
+ return 0;
+ }
+ }
+}
+
/**
*
* @param path - path to file.
int status;
char *sidecar_path = get_sidecar_path(path);
+
+ if ( ensure_dirs( sidecar_path ) ) {
+ return -ENOATTR;
+ }
+
FILE *file = fopen(sidecar_path, "w");
strfree(sidecar_path);