35 #include <mach-o/dyld.h>
56 DIR * dir = opendir (path);
60 struct dirent *
entry;
61 while ((entry = readdir (dir)))
63 if (entry->d_name[0] ==
'.')
66 char * full = g_strdup_printf (
"%s" G_DIR_SEPARATOR_S
"%s", path, entry->d_name);
81 if (strstr (
string,
"://"))
82 return strdup (
string);
86 if (
string[0] &&
string[1] ==
':' &&
string[2] ==
'\\')
93 const char * slash = strrchr (playlist_name,
'/');
97 int pathlen = slash + 1 - playlist_name;
98 char buf[pathlen + 3 * strlen (
string) + 1];
99 memcpy (buf, playlist_name, pathlen);
109 if (stat (filename, & info))
112 return info.st_mtime;
118 if (g_mkdir_with_parents(path, mode) == 0)
121 g_printerr(
_(
"Could not create directory (%s): %s\n"), path,
127 char *
name = g_strdup_printf (
"%s/audacious-temp-XXXXXX", g_get_tmp_dir ());
129 int handle = g_mkstemp (name);
132 fprintf (stderr,
"Error creating temporary file: %s\n", strerror (errno));
139 int64_t written = write (handle, data, len);
142 fprintf (stderr,
"Error writing %s: %s\n", name, strerror (errno));
148 data = (
char *) data + written;
152 if (close (handle) < 0)
154 fprintf (stderr,
"Error closing %s: %s\n", name, strerror (errno));
164 #if defined _WIN32 || defined HAVE_PROC_SELF_EXE
166 char * buf = g_malloc (size);
173 if (! (len = GetModuleFileName (
NULL, buf, size)))
175 fprintf (stderr,
"GetModuleFileName failed.\n");
180 if ((len = readlink (
"/proc/self/exe", buf, size)) < 0)
182 fprintf (stderr,
"Cannot access /proc/self/exe: %s.\n", strerror (errno));
195 buf = g_realloc (buf, size);
218 if (len > 0 && home[len - 1] ==
'/')
223 if (! g_ascii_strncasecmp (name, home, len) && name[len] ==
'/')
225 if (! strncmp (name, home, len) && name[len] ==
'/')
227 return name + len + 1;
229 if (! strncmp (name,
"file:///", 8))
246 * first = * second =
NULL;
250 if ((c = strrchr (name,
'/')))
261 if ((c = strrchr (name,
'/')))
272 if ((c = strrchr (name,
'/')))
278 if ((c = strrchr (* base,
'.')))
290 if (! strncmp (name,
"http://", 7))
292 else if (! strncmp (name,
"https://", 8))
294 else if (! strncmp (name,
"mms://", 6))
301 if ((c = strchr (name,
'/')))
303 if ((c = strchr (name,
':')))
305 if ((c = strchr (name,
'?')))
337 char * * _artist,
char * * _album)
340 static const char *
const skip[] = {
"music"};
346 if (title && artist && album)
355 char buf[strlen (name) + 1];
356 memcpy (buf, name,
sizeof buf);
358 if (! strncmp (buf,
"file:///", 8))
360 char * base, * first, * second;
366 for (
int i = 0; i < G_N_ELEMENTS (skip); i ++)
368 if (first && ! g_ascii_strcasecmp (first, skip[i]))
370 if (second && ! g_ascii_strcasecmp (second, skip[i]))
376 if (second && ! artist && ! album)