diff options
author | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-07-09 17:48:28 +0200 |
---|---|---|
committer | Lukas Fleischer <calcurse@cryptocrack.de> | 2011-07-09 17:52:25 +0200 |
commit | 34f094312fc2e9dce7621449e07f25c748039f97 (patch) | |
tree | 9288b738318949c05a24adc0affa19a5368c3af1 /src | |
parent | 585ed53748099de4f3c78bb03ccd89ca28353195 (diff) | |
download | calcurse-34f094312fc2e9dce7621449e07f25c748039f97.tar.gz calcurse-34f094312fc2e9dce7621449e07f25c748039f97.zip |
Honor "TMPDIR" environment variable
Replace all hardcoded paths referring to "/tmp" with a new function that
honors the "TMPDIR" environment variable as well as P_tmpdir and uses
"/tmp" as a fallback.
Thanks-to: Erik Saule <esaule@bmi.osu.edu>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/calcurse.h | 1 | ||||
-rw-r--r-- | src/io.c | 6 | ||||
-rw-r--r-- | src/utils.c | 15 |
3 files changed, 20 insertions, 2 deletions
diff --git a/src/calcurse.h b/src/calcurse.h index 6642ae9..e3822ef 100644 --- a/src/calcurse.h +++ b/src/calcurse.h @@ -854,6 +854,7 @@ long now (void); char *nowstr (void); long mystrtol (const char *); void print_bool_option_incolor (WINDOW *, unsigned, int, int); +const char *get_tempdir (void); char *new_tempfile (const char *, int); void erase_note (char **, enum eraseflg); int parse_date (char *, enum datefmt, int *, int *, int *, @@ -220,7 +220,8 @@ get_export_stream (enum export_type type) (void)snprintf (stream_name, BUFSIZ, "%s/calcurse.%s", home, file_ext[type]); else - (void)snprintf (stream_name, BUFSIZ, "/tmp/calcurse.%s", file_ext[type]); + (void)snprintf (stream_name, BUFSIZ, "%s/calcurse.%s", get_tempdir (), + file_ext[type]); while (stream == NULL) { @@ -2857,10 +2858,11 @@ io_import_data (enum import_type type, struct conf *conf, char *stream_name) struct io_file * io_log_init (void) { - const char *logprefix = "/tmp/calcurse_log."; + char logprefix[BUFSIZ]; char *logname; struct io_file *log; + snprintf (logprefix, BUFSIZ, "%s/calcurse_log.", get_tempdir ()); logname = new_tempfile (logprefix, NOTESIZ); RETVAL_IF (logname == NULL, 0, _("Warning: could not create temporary log file, Aborting...")); diff --git a/src/utils.c b/src/utils.c index c861195..b165111 100644 --- a/src/utils.c +++ b/src/utils.c @@ -726,6 +726,21 @@ print_bool_option_incolor (WINDOW *win, unsigned option, int pos_y, int pos_x) wins_doupdate (); } + +/* + * Get the name of the default directory for temporary files. + */ +const char * +get_tempdir (void) +{ + if (getenv ("TMPDIR")) + return getenv ("TMPDIR"); + else if (P_tmpdir) + return P_tmpdir; + else + return "/tmp"; +} + /* * Create a new unique file, and return a newly allocated string which contains * the random part of the file name. |