* Unlike the IEEE Std 1003.1-2001 specification of dirname(3), this
* implementation does not modify its parameter, so callers need not manually
* copy their paths into a modifiable buffer prior to calling this function.
- *
- * @warning mutt_file_dirname() returns a static string which must not be free()'d.
*/
-const char *mutt_file_dirname(const char *p)
+char *mutt_file_dirname(const char *p)
{
- static char buf[_POSIX_PATH_MAX];
+ char *buf = mutt_mem_malloc(_POSIX_PATH_MAX);
mutt_str_strfcpy(buf, p, sizeof(buf));
return dirname(buf);
}
*/
int mutt_file_to_absolute_path(char *path, const char *reference)
{
- const char *dirpath = NULL;
char abs_path[PATH_MAX];
int path_len;
return true;
}
- dirpath = mutt_file_dirname(reference);
+ char *dirpath = mutt_file_dirname(reference);
mutt_str_strfcpy(abs_path, dirpath, PATH_MAX);
+ FREE(&dirpath);
mutt_str_strncat(abs_path, sizeof(abs_path), "/", 1); /* append a / at the end of the path */
path_len = PATH_MAX - strlen(path);
int mutt_file_copy_bytes(FILE *in, FILE *out, size_t size);
int mutt_file_copy_stream(FILE *fin, FILE *fout);
time_t mutt_file_decrease_mtime(const char *f, struct stat *st);
-const char *mutt_file_dirname(const char *p);
+char * mutt_file_dirname(const char *p);
int mutt_file_fclose(FILE **f);
FILE * mutt_file_fopen(const char *path, const char *mode);
int mutt_file_fsync_close(FILE **f);
if (ret == 0)
{
/* create dir recursively */
- if (mutt_file_mkdir(mutt_file_dirname(s), S_IRWXU) == -1)
+ char *tmp_path = mutt_file_dirname(s);
+ if (mutt_file_mkdir(tmp_path, S_IRWXU) == -1)
{
/* report failure & abort */
mutt_perror(s);
+ FREE(&tmp_path);
return 1;
}
+ FREE(&tmp_path);
}
}
else