mirror of
https://github.com/moparisthebest/hexchat
synced 2024-11-28 20:22:15 -05:00
Create file_is_absolute() util
This was duplicated multiple times already
This commit is contained in:
parent
6617d92512
commit
5ad6a8d361
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user