diff --git a/src/common/text.c b/src/common/text.c index c6c6d138..f64f401d 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -482,26 +482,9 @@ logmask_is_fullpath () /* Check if final path/filename is absolute or relative. * If one uses log mask variables, such as "%c/...", %c will be empty upon * connecting since there's no channel name yet, so we have to make sure - * we won't try to write to the FS root. On Windows we can be sure it's - * full path if the 2nd character is a colon since Windows doesn't allow - * colons in filenames. + * we won't try to write to the FS root. */ -#ifdef WIN32 - /* Treat it as full path if it - * - starts with '\' which denotes the root directory of the current drive letter - * - starts with a drive letter and followed by ':' - */ - if (prefs.hex_irc_logmask[0] == '\\' || (((prefs.hex_irc_logmask[0] >= 'A' && prefs.hex_irc_logmask[0] <= 'Z') || (prefs.hex_irc_logmask[0] >= 'a' && prefs.hex_irc_logmask[0] <= 'z')) && prefs.hex_irc_logmask[1] == ':')) -#else - if (prefs.hex_irc_logmask[0] == '/') -#endif - { - return 1; - } - else - { - return 0; - } + return file_is_absolute (prefs.hex_irc_logmask); } static char * @@ -2252,12 +2235,7 @@ sound_play (const char *file, gboolean quiet) return; } -#ifdef WIN32 - /* check for fullpath */ - if (file[0] == '\\' || (((file[0] >= 'A' && file[0] <= 'Z') || (file[0] >= 'a' && file[0] <= 'z')) && file[1] == ':')) -#else - if (file[0] == '/') -#endif + if (file_is_absolute (file)) { wavfile = g_strdup (file); } diff --git a/src/common/util.c b/src/common/util.c index 7b016cc1..8f215001 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1964,3 +1964,25 @@ strftime_utf8 (char *dest, gsize destsize, const char *format, time_t time) g_date_free (date); return result; } + +gboolean +file_is_absolute (const gchar *filename) +{ + /* + * On Windows we can be sure it's + * full path if the 2nd character is a colon since Windows doesn't allow + * colons in filenames. + */ +#ifdef WIN32 + /* Treat it as full path if it: + * - starts with '\' which denotes the root directory of the current drive letter + * - starts with a drive letter and followed by ':' + */ + if (filename[0] == '\\' || (((filename[0] >= 'A' && filename[0] <= 'Z') || (filename[0] >= 'a' && filename[0] <= 'z')) && filename[1] == ':')) +#else + if (filename[0] == '/') +#endif + return TRUE; + + return FALSE; +} diff --git a/src/common/util.h b/src/common/util.h index 9a049c2a..217a4fe8 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -50,6 +50,7 @@ char *country (char *); void country_search (char *pattern, void *ud, void (*print)(void *, char *, ...)); char *get_sys_str (int with_cpu); void util_exec (const char *cmd); +gboolean file_is_absolute (const gchar *filename); #define STRIP_COLOR 1 #define STRIP_ATTRIB 2 #define STRIP_HIDDEN 4