Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
80fa9183
Commit
80fa9183
authored
Jan 01, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mapper: allocate playlist path from heap
Don't pass a static buffer to map_spl_utf8_to_fs().
parent
886ed1b2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
47 deletions
+60
-47
mapper.c
src/mapper.c
+9
-12
mapper.h
src/mapper.h
+4
-3
playlist.c
src/playlist.c
+6
-4
stored_playlist.c
src/stored_playlist.c
+41
-28
No files found.
src/mapper.c
View file @
80fa9183
...
@@ -164,23 +164,20 @@ map_fs_to_utf8(const char *path_fs, char *buffer)
...
@@ -164,23 +164,20 @@ map_fs_to_utf8(const char *path_fs, char *buffer)
return
fs_charset_to_utf8
(
buffer
,
path_fs
);
return
fs_charset_to_utf8
(
buffer
,
path_fs
);
}
}
static
char
*
rpp2app_r
(
char
*
dst
,
const
char
*
rel_path
)
{
pfx_dir
(
dst
,
rel_path
,
strlen
(
rel_path
),
playlist_dir
,
playlist_dir_length
);
return
dst
;
}
const
char
*
const
char
*
map_spl_path
(
void
)
map_spl_path
(
void
)
{
{
return
playlist_dir
;
return
playlist_dir
;
}
}
c
onst
c
har
*
char
*
map_spl_utf8_to_fs
(
const
char
*
name
,
char
*
buffer
)
map_spl_utf8_to_fs
(
const
char
*
name
)
{
{
rpp2app_r
(
buffer
,
utf8_to_fs_charset
(
buffer
,
name
));
char
*
filename
=
g_strconcat
(
name
,
"."
PLAYLIST_FILE_SUFFIX
,
NULL
);
g_strlcat
(
buffer
,
"."
PLAYLIST_FILE_SUFFIX
,
MPD_PATH_MAX
);
char
*
path
;
return
buffer
;
path
=
g_build_filename
(
playlist_dir
,
filename
,
NULL
);
g_free
(
filename
);
return
path
;
}
}
src/mapper.h
View file @
80fa9183
...
@@ -93,9 +93,10 @@ map_spl_path(void);
...
@@ -93,9 +93,10 @@ map_spl_path(void);
/**
/**
* Maps a playlist name (without the ".m3u" suffix) to a file system
* Maps a playlist name (without the ".m3u" suffix) to a file system
* path.
* path. The return value is allocated on the heap and must be freed
* with g_free().
*/
*/
c
onst
c
har
*
char
*
map_spl_utf8_to_fs
(
const
char
*
name
,
char
*
buffer
);
map_spl_utf8_to_fs
(
const
char
*
name
);
#endif
#endif
src/playlist.c
View file @
80fa9183
...
@@ -1203,17 +1203,19 @@ enum playlist_result savePlaylist(const char *utf8file)
...
@@ -1203,17 +1203,19 @@ enum playlist_result savePlaylist(const char *utf8file)
{
{
FILE
*
fp
;
FILE
*
fp
;
struct
stat
sb
;
struct
stat
sb
;
char
path_max_tmp
[
MPD_PATH_MAX
];
char
*
path
;
const
char
*
path
;
if
(
!
is_valid_playlist_name
(
utf8file
))
if
(
!
is_valid_playlist_name
(
utf8file
))
return
PLAYLIST_RESULT_BAD_NAME
;
return
PLAYLIST_RESULT_BAD_NAME
;
path
=
map_spl_utf8_to_fs
(
utf8file
,
path_max_tmp
);
path
=
map_spl_utf8_to_fs
(
utf8file
);
if
(
!
stat
(
path
,
&
sb
))
if
(
!
stat
(
path
,
&
sb
))
{
g_free
(
path
);
return
PLAYLIST_RESULT_LIST_EXISTS
;
return
PLAYLIST_RESULT_LIST_EXISTS
;
}
while
(
!
(
fp
=
fopen
(
path
,
"w"
))
&&
errno
==
EINTR
);
while
(
!
(
fp
=
fopen
(
path
,
"w"
))
&&
errno
==
EINTR
);
g_free
(
path
);
if
(
fp
==
NULL
)
if
(
fp
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
return
PLAYLIST_RESULT_ERRNO
;
...
...
src/stored_playlist.c
View file @
80fa9183
...
@@ -115,14 +115,14 @@ static enum playlist_result
...
@@ -115,14 +115,14 @@ static enum playlist_result
spl_save
(
GPtrArray
*
list
,
const
char
*
utf8path
)
spl_save
(
GPtrArray
*
list
,
const
char
*
utf8path
)
{
{
FILE
*
file
;
FILE
*
file
;
char
path_max_tmp
[
MPD_PATH_MAX
];
char
*
path_fs
;
const
char
*
path_fs
;
assert
(
utf8path
!=
NULL
);
assert
(
utf8path
!=
NULL
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
,
path_max_tmp
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
);
while
(
!
(
file
=
fopen
(
path_fs
,
"w"
))
&&
errno
==
EINTR
);
while
(
!
(
file
=
fopen
(
path_fs
,
"w"
))
&&
errno
==
EINTR
);
g_free
(
path_fs
);
if
(
file
==
NULL
)
if
(
file
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
return
PLAYLIST_RESULT_ERRNO
;
...
@@ -142,14 +142,15 @@ spl_load(const char *utf8path)
...
@@ -142,14 +142,15 @@ spl_load(const char *utf8path)
GPtrArray
*
list
;
GPtrArray
*
list
;
char
buffer
[
MPD_PATH_MAX
];
char
buffer
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
char
path_max_tmp
[
MPD_PATH_MAX
];
c
onst
c
har
*
path_fs
;
char
*
path_fs
;
if
(
!
is_valid_playlist_name
(
utf8path
))
if
(
!
is_valid_playlist_name
(
utf8path
))
return
NULL
;
return
NULL
;
path_fs
=
map_spl_utf8_to_fs
(
utf8path
,
path_max_tmp
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
);
while
(
!
(
file
=
fopen
(
path_fs
,
"r"
))
&&
errno
==
EINTR
);
while
(
!
(
file
=
fopen
(
path_fs
,
"r"
))
&&
errno
==
EINTR
);
g_free
(
path_fs
);
if
(
file
==
NULL
)
if
(
file
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -257,16 +258,16 @@ spl_move_index(const char *utf8path, unsigned src, unsigned dest)
...
@@ -257,16 +258,16 @@ spl_move_index(const char *utf8path, unsigned src, unsigned dest)
enum
playlist_result
enum
playlist_result
spl_clear
(
const
char
*
utf8path
)
spl_clear
(
const
char
*
utf8path
)
{
{
char
filename
[
MPD_PATH_MAX
];
char
*
path_fs
;
const
char
*
path_fs
;
FILE
*
file
;
FILE
*
file
;
if
(
!
is_valid_playlist_name
(
utf8path
))
if
(
!
is_valid_playlist_name
(
utf8path
))
return
PLAYLIST_RESULT_BAD_NAME
;
return
PLAYLIST_RESULT_BAD_NAME
;
path_fs
=
map_spl_utf8_to_fs
(
utf8path
,
filename
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
);
while
(
!
(
file
=
fopen
(
path_fs
,
"w"
))
&&
errno
==
EINTR
);
while
(
!
(
file
=
fopen
(
path_fs
,
"w"
))
&&
errno
==
EINTR
);
g_free
(
path_fs
);
if
(
file
==
NULL
)
if
(
file
==
NULL
)
return
PLAYLIST_RESULT_ERRNO
;
return
PLAYLIST_RESULT_ERRNO
;
...
@@ -279,12 +280,13 @@ spl_clear(const char *utf8path)
...
@@ -279,12 +280,13 @@ spl_clear(const char *utf8path)
enum
playlist_result
enum
playlist_result
spl_delete
(
const
char
*
name_utf8
)
spl_delete
(
const
char
*
name_utf8
)
{
{
char
filename
[
MPD_PATH_MAX
];
char
*
path_fs
;
const
char
*
path_fs
;
int
ret
;
path_fs
=
map_spl_utf8_to_fs
(
name_utf8
,
filename
);
if
(
unlink
(
path_fs
)
<
0
)
path_fs
=
map_spl_utf8_to_fs
(
name_utf8
);
ret
=
unlink
(
path_fs
);
g_free
(
path_fs
);
if
(
ret
<
0
)
return
errno
==
ENOENT
return
errno
==
ENOENT
?
PLAYLIST_RESULT_NO_SUCH_LIST
?
PLAYLIST_RESULT_NO_SUCH_LIST
:
PLAYLIST_RESULT_ERRNO
;
:
PLAYLIST_RESULT_ERRNO
;
...
@@ -323,15 +325,15 @@ spl_append_song(const char *utf8path, struct song *song)
...
@@ -323,15 +325,15 @@ spl_append_song(const char *utf8path, struct song *song)
{
{
FILE
*
file
;
FILE
*
file
;
struct
stat
st
;
struct
stat
st
;
char
path_max_tmp
[
MPD_PATH_MAX
];
char
*
path_fs
;
const
char
*
path_fs
;
if
(
!
is_valid_playlist_name
(
utf8path
))
if
(
!
is_valid_playlist_name
(
utf8path
))
return
PLAYLIST_RESULT_BAD_NAME
;
return
PLAYLIST_RESULT_BAD_NAME
;
path_fs
=
map_spl_utf8_to_fs
(
utf8path
,
path_max_tmp
);
path_fs
=
map_spl_utf8_to_fs
(
utf8path
);
while
(
!
(
file
=
fopen
(
path_fs
,
"a"
))
&&
errno
==
EINTR
);
while
(
!
(
file
=
fopen
(
path_fs
,
"a"
))
&&
errno
==
EINTR
);
g_free
(
path_fs
);
if
(
file
==
NULL
)
{
if
(
file
==
NULL
)
{
int
save_errno
=
errno
;
int
save_errno
=
errno
;
while
(
fclose
(
file
)
!=
0
&&
errno
==
EINTR
);
while
(
fclose
(
file
)
!=
0
&&
errno
==
EINTR
);
...
@@ -381,20 +383,10 @@ spl_append_uri(const char *url, const char *utf8file)
...
@@ -381,20 +383,10 @@ spl_append_uri(const char *url, const char *utf8file)
return
PLAYLIST_RESULT_NO_SUCH_SONG
;
return
PLAYLIST_RESULT_NO_SUCH_SONG
;
}
}
enum
playlist_result
static
enum
playlist_result
spl_rename
(
const
char
*
utf8from
,
const
char
*
utf8to
)
spl_rename
_internal
(
const
char
*
from_path_fs
,
const
char
*
to_path_fs
)
{
{
struct
stat
st
;
struct
stat
st
;
char
from
[
MPD_PATH_MAX
];
char
to
[
MPD_PATH_MAX
];
const
char
*
from_path_fs
,
*
to_path_fs
;
if
(
!
is_valid_playlist_name
(
utf8from
)
||
!
is_valid_playlist_name
(
utf8to
))
return
PLAYLIST_RESULT_BAD_NAME
;
from_path_fs
=
map_spl_utf8_to_fs
(
utf8from
,
from
);
to_path_fs
=
map_spl_utf8_to_fs
(
utf8to
,
to
);
if
(
stat
(
from_path_fs
,
&
st
)
!=
0
)
if
(
stat
(
from_path_fs
,
&
st
)
!=
0
)
return
PLAYLIST_RESULT_NO_SUCH_LIST
;
return
PLAYLIST_RESULT_NO_SUCH_LIST
;
...
@@ -408,3 +400,24 @@ spl_rename(const char *utf8from, const char *utf8to)
...
@@ -408,3 +400,24 @@ spl_rename(const char *utf8from, const char *utf8to)
idle_add
(
IDLE_STORED_PLAYLIST
);
idle_add
(
IDLE_STORED_PLAYLIST
);
return
PLAYLIST_RESULT_SUCCESS
;
return
PLAYLIST_RESULT_SUCCESS
;
}
}
enum
playlist_result
spl_rename
(
const
char
*
utf8from
,
const
char
*
utf8to
)
{
char
*
from_path_fs
,
*
to_path_fs
;
static
enum
playlist_result
ret
;
if
(
!
is_valid_playlist_name
(
utf8from
)
||
!
is_valid_playlist_name
(
utf8to
))
return
PLAYLIST_RESULT_BAD_NAME
;
from_path_fs
=
map_spl_utf8_to_fs
(
utf8from
);
to_path_fs
=
map_spl_utf8_to_fs
(
utf8to
);
ret
=
spl_rename_internal
(
from_path_fs
,
to_path_fs
);
g_free
(
from_path_fs
);
g_free
(
to_path_fs
);
return
ret
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment