28 #include <mach-o/dyld.h>
48 DIR * dir = opendir (path);
52 struct dirent *
entry;
53 while ((entry = readdir (dir)))
55 if (entry->d_name[0] ==
'.')
58 char * full = g_strdup_printf (
"%s" G_DIR_SEPARATOR_S
"%s", path, entry->d_name);
73 if (strstr (
string,
"://"))
74 return strdup (
string);
78 if (
string[0] &&
string[1] ==
':' &&
string[2] ==
'\\')
85 const char * slash = strrchr (playlist_name,
'/');
89 int pathlen = slash + 1 - playlist_name;
90 int rellen = strlen (
string);
92 char buf[pathlen + 3 * rellen + 1];
93 memcpy (buf, playlist_name, pathlen);
111 if (g_mkdir_with_parents(path, mode) == 0)
114 g_printerr(
_(
"Could not create directory (%s): %s\n"), path,
120 char *
name = g_strdup_printf (
"%s/audacious-temp-XXXXXX", g_get_tmp_dir ());
122 int handle = g_mkstemp (name);
125 fprintf (stderr,
"Error creating temporary file: %s\n", strerror (errno));
132 int64_t written = write (handle, data, len);
135 fprintf (stderr,
"Error writing %s: %s\n", name, strerror (errno));
141 data = (
char *) data + written;
145 if (close (handle) < 0)
147 fprintf (stderr,
"Error closing %s: %s\n", name, strerror (errno));
157 #if defined _WIN32 || defined HAVE_PROC_SELF_EXE
159 char * buf = g_malloc (size);
166 if (! (len = GetModuleFileName (
NULL, buf, size)))
168 fprintf (stderr,
"GetModuleFileName failed.\n");
173 if ((len = readlink (
"/proc/self/exe", buf, size)) < 0)
175 fprintf (stderr,
"Cannot access /proc/self/exe: %s.\n", strerror (errno));
188 buf = g_realloc (buf, size);
190 #elif defined __APPLE__
191 unsigned int size = 256;
192 char * buf = g_malloc (size);
198 if (! (res = _NSGetExecutablePath (buf, &size)))
202 buf = g_realloc (buf, size);
222 static const char * home;
227 home = g_get_home_dir ();
230 if (len > 0 && home[len - 1] == G_DIR_SEPARATOR)
235 if (! g_ascii_strncasecmp (name, home, len) && name[len] ==
'\\')
237 if (! strncmp (name, home, len) && name[len] ==
'/')
239 return name + len + 1;
242 if (g_ascii_isalpha (name[0]) && name[1] ==
':' && name[2] ==
'\\')
263 * first = * second =
NULL;
267 if ((c = strrchr (name, G_DIR_SEPARATOR)))
278 if ((c = strrchr (name, G_DIR_SEPARATOR)))
289 if ((c = strrchr (name, G_DIR_SEPARATOR)))
295 if ((c = strrchr (* base,
'.')))
307 if (! strncmp (name,
"http://", 7))
309 else if (! strncmp (name,
"https://", 8))
311 else if (! strncmp (name,
"mms://", 6))
318 if ((c = strchr (name,
'/')))
320 if ((c = strchr (name,
':')))
322 if ((c = strchr (name,
'?')))
354 char * * _artist,
char * * _album)
357 static const char *
const skip[] = {
"music"};
363 if (title && artist && album)
372 if (! strncmp (name,
"file:///", 8))
378 char * base, * first, * second;
384 for (
int i = 0; i < G_N_ELEMENTS (skip); i ++)
386 if (first && ! g_ascii_strcasecmp (first, skip[i]))
388 if (second && ! g_ascii_strcasecmp (second, skip[i]))
394 if (second && ! artist && ! album)
409 char buf[strlen (name) + 1];