diff options
| author | Ruben Pollan | 2018-10-15 12:06:34 -0500 |
|---|---|---|
| committer | Ruben Pollan | 2018-10-15 12:06:34 -0500 |
| commit | 3c9e56c5b7fbf1a16ea73f6d542f988bb1cebb28 (patch) | |
| tree | f9d7a1e3e82af940e3e832e27271bc2147356559 | |
| parent | d4613247e513da1d1517c86e67472b31e98a4167 (diff) | |
| download | systray-3c9e56c5b7fbf1a16ea73f6d542f988bb1cebb28.tar.bz2 | |
linux: use TMPDIR to store icons if defined
TMPDIR is the canonical environment variable in Unix and POSIX that
should be used to specify a temporary directory:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03
Let's use it if is defined to store temporary icon files and default to
'/tmp' if is not defined.
| -rw-r--r-- | systray_linux.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/systray_linux.c b/systray_linux.c index 3ed8ada..7ed58cd 100644 --- a/systray_linux.c +++ b/systray_linux.c @@ -48,9 +48,16 @@ void _unlink_temp_file() { // runs in main thread, should always return FALSE to prevent gtk to execute it again gboolean do_set_icon(gpointer data) { - GBytes* bytes = (GBytes*)data; _unlink_temp_file(); - strcpy(temp_file_name, "/tmp/systray_XXXXXX"); + char *tmpdir = getenv("TMPDIR"); + if (NULL == tmpdir) { + tmpdir = "/tmp"; + } + strncpy(temp_file_name, tmpdir, PATH_MAX-1); + strncat(temp_file_name, "/systray_XXXXXX", PATH_MAX-1); + temp_file_name[PATH_MAX-1] = '\0'; + + GBytes* bytes = (GBytes*)data; int fd = mkstemp(temp_file_name); if (fd == -1) { printf("failed to create temp icon file %s: %s\n", temp_file_name, strerror(errno)); |
