size_t len;
size_t at;
size_t num;
+ size_t until;
va_list va;
return_val_if_fail (path != NULL, NULL);
path = first;
va_start (va, path);
while (path != NULL) {
- if (at != 0 && built[at - 1] != delim && path[0] != delim)
- built[at++] = delim;
num = strlen (path);
+
+ /* Trim end of the path */
+ until = (at > 0) ? 0 : 1;
+ while (num > until && is_path_component_or_null (path[num - 1]))
+ num--;
+
+ if (at != 0) {
+ if (num == 0)
+ continue;
+ built[at++] = delim;
+ }
+
assert (at + num < len);
memcpy (built + at, path, num);
-
at += num;
+
path = va_arg (va, const char *);
+
+ /* Trim beginning of path */
+ while (path && path[0] && is_path_component_or_null (path[0]))
+ path++;
}
va_end (va);
if (!path)
ret = false;
- } else {
- if ((file->flags & P11_SAVE_OVERWRITE) &&
+ } else if ((file->flags & P11_SAVE_OVERWRITE) &&
unlink (path) < 0 && errno != ENOENT) {
- p11_message ("couldn't remove original file: %s: %s",
- path, strerror (errno));
- ret = false;
- }
+ p11_message ("couldn't remove original file: %s: %s",
+ path, strerror (errno));
+ ret = false;
+ }
- if (ret == true &&
- rename (file->temp, file->path) < 0) {
- p11_message ("couldn't complete writing file: %s: %s",
- file->path, strerror (errno));
- ret = false;
- }
+ if (ret == true &&
+ rename (file->temp, path) < 0) {
+ p11_message ("couldn't complete writing file: %s: %s",
+ path, strerror (errno));
+ ret = false;
}
unlink (file->temp);
static bool
mkdir_with_parents (const char *path)
{
- int mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
char *parent;
bool ret;
+#ifdef OS_UNIX
+ int mode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
if (mkdir (path, mode) == 0)
+#else
+ if (mkdir (path) == 0)
+#endif
return true;
switch (errno) {
ret = mkdir_with_parents (parent);
free (parent);
if (ret == true) {
+#ifdef OS_UNIX
if (mkdir (path, mode) == 0)
+#else
+ if (mkdir (path) == 0)
+#endif
return true;
}
}