29 #include <mach-o/dyld.h>
50 DIR * dir = opendir (path);
54 struct dirent *
entry;
55 while ((entry = readdir (dir)))
57 if (entry->d_name[0] ==
'.')
60 char * full = g_strdup_printf (
"%s" G_DIR_SEPARATOR_S
"%s", path, entry->d_name);
75 if (strstr (
string,
"://"))
76 return strdup (
string);
80 if (
string[0] &&
string[1] ==
':' &&
string[2] ==
'\\')
87 const char * slash = strrchr (playlist_name,
'/');
91 int pathlen = slash + 1 - playlist_name;
92 int rellen = strlen (
string);
94 char buf[pathlen + 3 * rellen + 1];
95 memcpy (buf, playlist_name, pathlen);
100 strcpy (tmp,
string);
115 if (stat (filename, & info))
118 return info.st_mtime;
124 if (g_mkdir_with_parents(path, mode) == 0)
127 g_printerr(
_(
"Could not create directory (%s): %s\n"), path,
133 char *
name = g_strdup_printf (
"%s/audacious-temp-XXXXXX", g_get_tmp_dir ());
135 int handle = g_mkstemp (name);
138 fprintf (stderr,
"Error creating temporary file: %s\n", strerror (errno));
145 int64_t written = write (handle, data, len);
148 fprintf (stderr,
"Error writing %s: %s\n", name, strerror (errno));
154 data = (
char *) data + written;
158 if (close (handle) < 0)
160 fprintf (stderr,
"Error closing %s: %s\n", name, strerror (errno));
170 #if defined _WIN32 || defined HAVE_PROC_SELF_EXE
172 char * buf = g_malloc (size);
179 if (! (len = GetModuleFileName (
NULL, buf, size)))
181 fprintf (stderr,
"GetModuleFileName failed.\n");
186 if ((len = readlink (
"/proc/self/exe", buf, size)) < 0)
188 fprintf (stderr,
"Cannot access /proc/self/exe: %s.\n", strerror (errno));
201 buf = g_realloc (buf, size);
203 #elif defined __APPLE__
204 unsigned int size = 256;
205 char * buf = g_malloc (size);
211 if (! (res = _NSGetExecutablePath (buf, &size)))
215 buf = g_realloc (buf, size);
243 if (len > 0 && home[len - 1] ==
'/')
248 if (! g_ascii_strncasecmp (name, home, len) && name[len] ==
'/')
250 if (! strncmp (name, home, len) && name[len] ==
'/')
252 return name + len + 1;
254 if (! strncmp (name,
"file:///", 8))
271 * first = * second =
NULL;
275 if ((c = strrchr (name,
'/')))
286 if ((c = strrchr (name,
'/')))
297 if ((c = strrchr (name,
'/')))
303 if ((c = strrchr (* base,
'.')))
315 if (! strncmp (name,
"http://", 7))
317 else if (! strncmp (name,
"https://", 8))
319 else if (! strncmp (name,
"mms://", 6))
326 if ((c = strchr (name,
'/')))
328 if ((c = strchr (name,
':')))
330 if ((c = strchr (name,
'?')))
362 char * * _artist,
char * * _album)
365 static const char *
const skip[] = {
"music"};
371 if (title && artist && album)
380 char buf[strlen (name) + 1];
381 memcpy (buf, name,
sizeof buf);
383 if (! strncmp (buf,
"file:///", 8))
385 char * base, * first, * second;
391 for (
int i = 0; i < G_N_ELEMENTS (skip); i ++)
393 if (first && ! g_ascii_strcasecmp (first, skip[i]))
395 if (second && ! g_ascii_strcasecmp (second, skip[i]))
401 if (second && ! artist && ! album)