#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
-#include <libgen.h>
#include <limits.h>
#include <pwd.h>
#include <regex.h>
*/
static int to_absolute_path(char *path, const char *reference)
{
- char *ref_tmp = NULL, *dirpath = NULL;
+ const char *dirpath = NULL;
char abs_path[PATH_MAX];
int path_len;
return true;
}
- ref_tmp = safe_strdup(reference);
- dirpath = dirname(ref_tmp); /* get directory name of */
+ dirpath = mutt_dirname(reference);
strfcpy(abs_path, dirpath, PATH_MAX);
safe_strncat(abs_path, sizeof(abs_path), "/", 1); /* append a / at the end of the path */
- FREE(&ref_tmp);
path_len = PATH_MAX - strlen(path);
safe_strncat(abs_path, sizeof(abs_path), path, path_len > 0 ? path_len : 0);
* | mutt_copy_bytes() | Copy some content from one file to another
* | mutt_copy_stream() | Copy the contents of one file into another
* | mutt_decrease_mtime() | Decrease a file's modification time by 1 second
+ * | mutt_dirname() | Return a path up to, but not including, the final '/'
* | mutt_lock_file() | (try to) lock a file
* | mutt_mkdir() | Recursively create directories
* | mutt_quote_filename() | Quote a filename to survive the shell's quoting rules
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <libgen.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
return mtime;
}
+/**
+ * mutt_dirname - Return a path up to, but not including, the final '/'
+ * @param p Path
+ * @retval ptr The directory containing p
+ *
+ * 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.
+ *
+ * mutt_dirname() returns a static string which must not be free()'d.
+ */
+const char *mutt_dirname(const char *p)
+{
+ static char buf[_POSIX_PATH_MAX];
+ strfcpy(buf, p, sizeof(buf));
+ return dirname(buf);
+}
+
/**
* mutt_set_mtime - Set the modification time of one file from another
* @param from Filename whose mtime should be copied
int mutt_copy_bytes(FILE *in, FILE *out, size_t size);
int mutt_copy_stream(FILE *fin, FILE *fout);
time_t mutt_decrease_mtime(const char *f, struct stat *st);
+const char *mutt_dirname(const char *p);
int mutt_lock_file(const char *path, int fd, int excl, int timeout);
int mutt_mkdir(const char *path, mode_t mode);
size_t mutt_quote_filename(char *d, size_t l, const char *f);
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
-#include <libgen.h>
#ifdef ENABLE_NLS
#include <libintl.h>
#endif
/* user confirmed with MUTT_YES or set OPT_CONFIRMCREATE */
if (ret == 0)
{
- strncpy(tmp, s, sizeof(tmp) - 1);
-
/* create dir recursively */
- if (mutt_mkdir(dirname(tmp), S_IRWXU) == -1)
+ if (mutt_mkdir(mutt_dirname(s), S_IRWXU) == -1)
{
/* report failure & abort */
mutt_perror(s);