From 3d4701a6e41616cf581a297bab1451cf2db70249 Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Tue, 14 Jul 2009 13:57:45 +0000 Subject: FS#10080 * Move strncpy() from core to the pluginlib * Introduce strlcpy() and use that instead in most places (use memcpy in a few) in core and some plugins * Drop strncpy() from the codec api as no codec used it * Bump codec and plugin api versions git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21863 a1c6a512-1295-4272-9138-f99709370657 --- apps/playlist.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'apps/playlist.c') diff --git a/apps/playlist.c b/apps/playlist.c index 1d291cf6d0..b70fdc8a1f 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -1349,8 +1349,7 @@ static int get_filename(struct playlist_info* playlist, int index, int seek, if (playlist->in_ram && !control_file && max < 0) { - strncpy(tmp_buf, &playlist->buffer[seek], sizeof(tmp_buf)); - tmp_buf[MAX_PATH] = '\0'; + strlcpy(tmp_buf, &playlist->buffer[seek], sizeof(tmp_buf)); max = strlen(tmp_buf) + 1; } else if (max < 0) @@ -1402,8 +1401,7 @@ static int get_filename(struct playlist_info* playlist, int index, int seek, } } - strncpy(dir_buf, playlist->filename, playlist->dirlen-1); - dir_buf[playlist->dirlen-1] = 0; + strlcpy(dir_buf, playlist->filename, playlist->dirlen); return (format_track_path(buf, tmp_buf, buf_length, max, dir_buf)); } @@ -1471,8 +1469,7 @@ static int get_next_dir(char *dir, bool is_forward, bool recursion) else { /* start with current directory */ - strncpy(dir, playlist->filename, playlist->dirlen-1); - dir[playlist->dirlen-1] = '\0'; + strlcpy(dir, playlist->filename, playlist->dirlen); } /* use the tree browser dircache to load files */ @@ -1671,13 +1668,13 @@ static int format_track_path(char *dest, char *src, int buf_length, int max, if('/' == src[0]) { - strncpy(dest, src, buf_length); + strlcpy(dest, src, buf_length); } else { /* handle dos style drive letter */ if (':' == src[1]) - strncpy(dest, &src[2], buf_length); + strlcpy(dest, &src[2], buf_length); else if (!strncmp(src, "../", 3)) { /* handle relative paths */ @@ -1904,7 +1901,7 @@ void playlist_init(void) struct playlist_info* playlist = ¤t_playlist; playlist->current = true; - strncpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, + strlcpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, sizeof(playlist->control_filename)); playlist->fd = -1; playlist->control_fd = -1; @@ -2721,7 +2718,7 @@ int playlist_set_current(struct playlist_info* playlist) empty_playlist(¤t_playlist, false); - strncpy(current_playlist.filename, playlist->filename, + strlcpy(current_playlist.filename, playlist->filename, sizeof(current_playlist.filename)); current_playlist.utf8 = playlist->utf8; @@ -3240,7 +3237,7 @@ char *playlist_name(const struct playlist_info* playlist, char *buf, if (!playlist) playlist = ¤t_playlist; - strncpy(buf, playlist->filename+playlist->dirlen, buf_size); + strlcpy(buf, playlist->filename+playlist->dirlen, buf_size); if (!buf[0]) return NULL; @@ -3260,7 +3257,7 @@ char *playlist_get_name(const struct playlist_info* playlist, char *buf, if (!playlist) playlist = ¤t_playlist; - strncpy(buf, playlist->filename, buf_size); + strlcpy(buf, playlist->filename, buf_size); if (!buf[0]) return NULL; -- cgit v1.2.3