u3: refactors _cu_rock_save(), splitting out path/directory format/creation
@@ -444,13 +444,10 @@ u3u_uniq(void)
ur_hcon_free(rot_u);
}
+/* _cu_rock_path_make(): format rock path, creating directory if necessary..
+*/
static c3_o
-_cu_rock_save(c3_c* dir_c, c3_d eve_d, c3_d len_d, c3_y* byt_y)
-{
- c3_i fid_i;
-
- // open rock file, creating the containing directory if necessary
- //
+_cu_rock_path_make(c3_c* dir_c, c3_d eve_d, c3_c** out_c)
{
c3_w nam_w = 1 + snprintf(0, 0, "%s/.urb/roc/%" PRIu64 ".jam", dir_c, eve_d);
c3_c* nam_c = c3_malloc(nam_w);
@@ -501,6 +498,24 @@ _cu_rock_save(c3_c* dir_c, c3_d eve_d, c3_d len_d, c3_y* byt_y)
return c3n;
}
+ *out_c = nam_c;
+ return c3y;
+}
+
+static c3_o
+_cu_rock_save(c3_c* dir_c, c3_d eve_d, c3_d len_d, c3_y* byt_y)
+{
+ c3_i fid_i;
+
+ // open rock file, creating the containing directory if necessary
+ //
+ {
+ c3_c* nam_c;
+
+ if ( c3n == _cu_rock_path_make(dir_c, eve_d, &nam_c) ) {
+ return c3n;
+ }
+
if ( -1 == (fid_i = open(nam_c, O_RDWR | O_CREAT | O_TRUNC, 0644)) ) {
fprintf(stderr, "rock: open failed (%s, %" PRIu64 "): %s\r\n",
dir_c, eve_d, strerror(errno));
