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);
230 if (len > 0 && home[len - 1] ==
'/')
235 if (! g_ascii_strncasecmp (name, home, len) && name[len] ==
'/')
237 if (! strncmp (name, home, len) && name[len] ==
'/')
239 return name + len + 1;
241 if (! strncmp (name,
"file:///", 8))
258 * first = * second =
NULL;
262 if ((c = strrchr (name,
'/')))
273 if ((c = strrchr (name,
'/')))
284 if ((c = strrchr (name,
'/')))
290 if ((c = strrchr (* base,
'.')))
302 if (! strncmp (name,
"http://", 7))
304 else if (! strncmp (name,
"https://", 8))
306 else if (! strncmp (name,
"mms://", 6))
313 if ((c = strchr (name,
'/')))
315 if ((c = strchr (name,
':')))
317 if ((c = strchr (name,
'?')))
349 char * * _artist,
char * * _album)
352 static const char *
const skip[] = {
"music"};
358 if (title && artist && album)
367 char buf[strlen (name) + 1];
368 memcpy (buf, name,
sizeof buf);
370 if (! strncmp (buf,
"file:///", 8))
372 char * base, * first, * second;
378 for (
int i = 0; i < G_N_ELEMENTS (skip); i ++)
380 if (first && ! g_ascii_strcasecmp (first, skip[i]))
382 if (second && ! g_ascii_strcasecmp (second, skip[i]))
388 if (second && ! artist && ! album)
char * write_temp_file(void *data, int64_t len)
static char * stream_name(char *name)
bool_t(* DirForeachFunc)(const char *path, const char *basename, void *user_data)
bool_t dir_foreach(const char *path, DirForeachFunc func, void *user)
static char * get_nonblank_field(const Tuple *tuple, int field)
char * construct_uri(const char *string, const char *playlist_name)
EXPORT void string_replace_char(char *string, char old_c, char new_c)
EXPORT void str_decode_percent(const char *str, int len, char *out)
static void split_filename(char *name, char **base, char **first, char **second)
static char * str_get_decoded(char *str)
char * get_path_to_self(void)
bool_t get_bool(const char *section, const char *name)
EXPORT void str_encode_percent(const char *str, int len, char *out)
void str_unref(char *str)
EXPORT char * tuple_get_str(const Tuple *tuple, int nfield, const char *field)
void describe_song(const char *name, const Tuple *tuple, char **_title, char **_artist, char **_album)
void make_directory(const char *path, mode_t mode)
EXPORT char * filename_to_uri(const char *name)
static char * skip_top_folders(char *name)
char * str_get(const char *str)