Make use of g_path_is_absolute()

No reason to roll our own.. in multiple places
This commit is contained in:
TingPing 2015-02-28 07:23:11 -05:00
parent d78db5070a
commit 749e5b20da

View File

@ -501,34 +501,6 @@ log_insert_vars (char *buf, int bufsize, char *fmt, char *c, char *n, char *s)
} }
} }
static int
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.
*/
#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;
}
}
static char * static char *
log_create_pathname (char *servname, char *channame, char *netname) log_create_pathname (char *servname, char *channame, char *netname)
{ {
@ -563,8 +535,10 @@ log_create_pathname (char *servname, char *channame, char *netname)
now = time (NULL); now = time (NULL);
strftime_utf8 (fnametime, sizeof (fnametime), fname, now); strftime_utf8 (fnametime, sizeof (fnametime), fname, now);
/* create final path/filename */ /* If one uses log mask variables, such as "%c/...", %c will be empty upon
if (logmask_is_fullpath ()) * connecting since there's no channel name yet, so we have to make sure
* we won't try to write to the FS root. */
if (g_path_is_absolute (prefs.hex_irc_logmask))
{ {
g_snprintf (fname, sizeof (fname), "%s", fnametime); g_snprintf (fname, sizeof (fname), "%s", fnametime);
} }
@ -2186,12 +2160,8 @@ sound_play (const char *file, gboolean quiet)
return; return;
} }
#ifdef WIN32
/* check for fullpath */ /* check for fullpath */
if (file[0] == '\\' || (((file[0] >= 'A' && file[0] <= 'Z') || (file[0] >= 'a' && file[0] <= 'z')) && file[1] == ':')) if (g_path_is_absolute (file))
#else
if (file[0] == '/')
#endif
{ {
wavfile = g_strdup (file); wavfile = g_strdup (file);
} }