summaryrefslogtreecommitdiffstats
path: root/apps/plugins
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2009-07-14 13:57:45 +0000
committerNils Wallménius <nils@rockbox.org>2009-07-14 13:57:45 +0000
commit3d4701a6e41616cf581a297bab1451cf2db70249 (patch)
treef845837c96ffbed7d59ddf8308f3b3e7c40cb8c9 /apps/plugins
parentc2900a1bacd5d98b57a0d15ea2add1bc08764057 (diff)
downloadrockbox-3d4701a6e41616cf581a297bab1451cf2db70249.tar.gz
rockbox-3d4701a6e41616cf581a297bab1451cf2db70249.zip
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
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/chessbox/chessbox_pgn.c2
-rw-r--r--apps/plugins/dict.c3
-rw-r--r--apps/plugins/doom/rockmacros.h1
-rw-r--r--apps/plugins/goban/sgf_output.c2
-rw-r--r--apps/plugins/invadrox.c2
-rw-r--r--apps/plugins/keybox.c18
-rw-r--r--apps/plugins/lib/SOURCES1
-rw-r--r--apps/plugins/lib/configfile.c2
-rw-r--r--apps/plugins/lib/highscore.c5
-rw-r--r--apps/plugins/lib/strncpy.c125
-rw-r--r--apps/plugins/lib/wrappers.h2
-rw-r--r--apps/plugins/lua/lobject.c3
-rw-r--r--apps/plugins/lua/lstrlib.c4
-rw-r--r--apps/plugins/lua/rockconf.h2
-rw-r--r--apps/plugins/mp3_encoder.c5
-rw-r--r--apps/plugins/mpegplayer/mpeg_settings.c2
-rw-r--r--apps/plugins/pictureflow/pictureflow.c5
-rw-r--r--apps/plugins/properties.c30
-rw-r--r--apps/plugins/random_folder_advance_config.c10
-rw-r--r--apps/plugins/rockboy/menu.c10
-rw-r--r--apps/plugins/rockboy/rockmacros.h2
-rw-r--r--apps/plugins/rockpaint.c2
-rw-r--r--apps/plugins/shortcuts/shortcuts_common.c8
-rw-r--r--apps/plugins/sokoban.c11
-rw-r--r--apps/plugins/splitedit.c4
-rw-r--r--apps/plugins/sudoku/sudoku.c8
-rw-r--r--apps/plugins/test_codec.c3
-rw-r--r--apps/plugins/text_editor.c2
-rw-r--r--apps/plugins/zxbox/snapshot.c6
-rw-r--r--apps/plugins/zxbox/spconf.c3
-rw-r--r--apps/plugins/zxbox/sptape.c3
-rw-r--r--apps/plugins/zxbox/tapefile.c6
32 files changed, 200 insertions, 92 deletions
diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c
index a8be179fac..cd163a5e1c 100644
--- a/apps/plugins/chessbox/chessbox_pgn.c
+++ b/apps/plugins/chessbox/chessbox_pgn.c
@@ -543,7 +543,7 @@ char * get_game_text(int selected_item, void *data,
rb->snprintf(text_buffer, 50,"%s vs. %s (%s)", temp_node->white_player,
temp_node->black_player, temp_node->game_date);
- rb->strncpy(buffer, text_buffer, buffer_len);
+ rb->strlcpy(buffer, text_buffer, buffer_len);
return buffer;
}
diff --git a/apps/plugins/dict.c b/apps/plugins/dict.c
index 0c1ddf33a9..fcc55faef1 100644
--- a/apps/plugins/dict.c
+++ b/apps/plugins/dict.c
@@ -283,8 +283,7 @@ enum plugin_status plugin_start(const void* parameter)
while (1)
{
/* copy one lcd line */
- rb->strncpy(output, ptr, display_columns);
- output[display_columns] = '\0';
+ rb->strlcpy(output, ptr, display_columns + 1);
/* typecast to kill a warning... */
if((int)rb->strlen(ptr) < display_columns)
diff --git a/apps/plugins/doom/rockmacros.h b/apps/plugins/doom/rockmacros.h
index 73cd902277..1ead411b85 100644
--- a/apps/plugins/doom/rockmacros.h
+++ b/apps/plugins/doom/rockmacros.h
@@ -59,7 +59,6 @@ int my_close(int id);
#define memcmp(a,b,c) rb->memcmp((a),(b),(c))
#define memchr(a,b,c) rb->memchr((a),(b),(c))
#define strcpy(a,b) rb->strcpy((a),(b))
-#define strncpy(a,b,c) rb->strncpy((a),(b),(c))
#define strlen(a) rb->strlen((a))
#define strcmp(a,b) rb->strcmp((a),(b))
#define strncmp(a,b,c) rb->strncmp((a),(b),(c))
diff --git a/apps/plugins/goban/sgf_output.c b/apps/plugins/goban/sgf_output.c
index c1ac052be7..6a52789f7a 100644
--- a/apps/plugins/goban/sgf_output.c
+++ b/apps/plugins/goban/sgf_output.c
@@ -130,7 +130,7 @@ output_header_props (void)
{
char buffer[128];
- rb->strncpy (buffer, "GM[1]FF[4]CA[UTF-8]AP[Rockbox Goban:1.0]ST[2]\n\n",
+ rb->strlcpy (buffer, "GM[1]FF[4]CA[UTF-8]AP[Rockbox Goban:1.0]ST[2]\n\n",
sizeof (buffer));
write_file (sgf_fd, buffer, rb->strlen (buffer));
diff --git a/apps/plugins/invadrox.c b/apps/plugins/invadrox.c
index c7d5696d19..fa7cb81e02 100644
--- a/apps/plugins/invadrox.c
+++ b/apps/plugins/invadrox.c
@@ -1511,7 +1511,7 @@ void init_invadrox(void)
if (highscore_load(HISCOREFILE, &hiscore, 1) < 0) {
/* Init hiscore to 0 */
- rb->strncpy(hiscore.name, "Invader", sizeof(hiscore.name));
+ rb->strlcpy(hiscore.name, "Invader", sizeof(hiscore.name));
hiscore.score = 0;
hiscore.level = 1;
}
diff --git a/apps/plugins/keybox.c b/apps/plugins/keybox.c
index 08d5131eff..73fd138f09 100644
--- a/apps/plugins/keybox.c
+++ b/apps/plugins/keybox.c
@@ -330,11 +330,11 @@ static void hash_pw(union hash *out)
static void make_key(void)
{
int i;
- char buf[sizeof(master_pw) + sizeof(salt) + 1];
+ char buf[sizeof(master_pw) + sizeof(salt) + 1] = {0};
struct md5_s key_md5;
size_t len = rb->strlen(master_pw);
- rb->strncpy(buf, master_pw, sizeof(buf));
+ rb->strlcpy(buf, master_pw, sizeof(buf));
rb->memcpy(&buf[len], &salt, sizeof(salt));
@@ -418,7 +418,7 @@ static int parse_buffer(void)
break;
}
- rb->strncpy(entry->title, start, FIELD_LEN);
+ rb->strlcpy(entry->title, start, FIELD_LEN);
start = end + 1;
end = rb->strchr(start, '\0'); /* find eol */
@@ -428,7 +428,7 @@ static int parse_buffer(void)
break;
}
- rb->strncpy(entry->name, start, FIELD_LEN);
+ rb->strlcpy(entry->name, start, FIELD_LEN);
start = end + 1;
end = rb->strchr(start, '\0'); /* find eol */
@@ -437,7 +437,7 @@ static int parse_buffer(void)
{
break;
}
- rb->strncpy(entry->password, start, FIELD_LEN);
+ rb->strlcpy(entry->password, start, FIELD_LEN);
start = end + 1;
entry->used = true;
if (i + 1 < MAX_ENTRIES - 1)
@@ -469,13 +469,13 @@ static void write_output(int fd)
for (i = 0; i < pw_list.num_entries; i++)
{
len = rb->strlen(entry->title);
- rb->strncpy(p, entry->title, len+1);
+ rb->strlcpy(p, entry->title, len+1);
p += len+1;
len = rb->strlen(entry->name);
- rb->strncpy(p, entry->name, len+1);
+ rb->strlcpy(p, entry->name, len+1);
p += len+1;
len = rb->strlen(entry->password);
- rb->strncpy(p, entry->password, len+1);
+ rb->strlcpy(p, entry->password, len+1);
p += len+1;
if (entry->next)
entry = entry->next;
@@ -517,7 +517,7 @@ static int enter_pw(char *pw_buf, size_t buflen, bool new_pw)
}
else
{
- rb->strncpy(pw_buf, buf[0], buflen);
+ rb->strlcpy(pw_buf, buf[0], buflen);
hash_pw(&pwhash);
return 0;
}
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index 02adb7089c..72538fc2a0 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -6,6 +6,7 @@ playback_control.c
rgb_hsv.c
buflib.c
display_text.c
+strncpy.c
#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4)
grey_core.c
grey_draw.c
diff --git a/apps/plugins/lib/configfile.c b/apps/plugins/lib/configfile.c
index 5e1e776f39..21b66a317b 100644
--- a/apps/plugins/lib/configfile.c
+++ b/apps/plugins/lib/configfile.c
@@ -139,7 +139,7 @@ int configfile_load(const char *filename, struct configdata *cfg,
break;
case TYPE_STRING:
- rb->strncpy(cfg[i].string, val, cfg[i].max);
+ rb->strlcpy(cfg[i].string, val, cfg[i].max);
break;
}
}
diff --git a/apps/plugins/lib/highscore.c b/apps/plugins/lib/highscore.c
index e8e1c883b0..15ebb05f4d 100644
--- a/apps/plugins/lib/highscore.c
+++ b/apps/plugins/lib/highscore.c
@@ -72,7 +72,7 @@ int highscore_load(char *filename, struct highscore *scores, int num_scores)
scores[i].score = rb->atoi(score);
scores[i].level = rb->atoi(level);
- rb->strncpy(scores[i].name, name, sizeof(scores[i].name)-1);
+ rb->strlcpy(scores[i].name, name, sizeof(scores[i].name));
i++;
}
rb->close(fd);
@@ -100,8 +100,7 @@ int highscore_update(int score, int level, const char *name,
entry = scores + pos;
entry->score = score;
entry->level = level;
- rb->strncpy(entry->name, name, sizeof(entry->name));
- entry->name[sizeof(entry->name)-1] = '\0';
+ rb->strlcpy(entry->name, name, sizeof(entry->name));
return pos;
}
diff --git a/apps/plugins/lib/strncpy.c b/apps/plugins/lib/strncpy.c
new file mode 100644
index 0000000000..7c1973ba66
--- /dev/null
+++ b/apps/plugins/lib/strncpy.c
@@ -0,0 +1,125 @@
+/*
+FUNCTION
+ <<strncpy>>---counted copy string
+
+INDEX
+ strncpy
+
+ANSI_SYNOPSIS
+ #include <string.h>
+ char *strncpy(char *<[dst]>, const char *<[src]>, size_t <[length]>);
+
+TRAD_SYNOPSIS
+ #include <string.h>
+ char *strncpy(<[dst]>, <[src]>, <[length]>)
+ char *<[dst]>;
+ char *<[src]>;
+ size_t <[length]>;
+
+DESCRIPTION
+ <<strncpy>> copies not more than <[length]> characters from the
+ the string pointed to by <[src]> (including the terminating
+ null character) to the array pointed to by <[dst]>. If the
+ string pointed to by <[src]> is shorter than <[length]>
+ characters, null characters are appended to the destination
+ array until a total of <[length]> characters have been
+ written.
+
+RETURNS
+ This function returns the initial value of <[dst]>.
+
+PORTABILITY
+<<strncpy>> is ANSI C.
+
+<<strncpy>> requires no supporting OS subroutines.
+
+QUICKREF
+ strncpy ansi pure
+*/
+
+#include <string.h>
+#include <limits.h>
+
+/*SUPPRESS 560*/
+/*SUPPRESS 530*/
+
+/* Nonzero if either X or Y is not aligned on a "long" boundary. */
+#define UNALIGNED(X, Y) \
+ (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
+
+#if LONG_MAX == 2147483647L
+#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
+#else
+#if LONG_MAX == 9223372036854775807L
+/* Nonzero if X (a long int) contains a NULL byte. */
+#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
+#else
+#error long int is not a 32bit or 64bit type.
+#endif
+#endif
+
+#ifndef DETECTNULL
+#error long int is not a 32bit or 64bit byte
+#endif
+
+#define TOO_SMALL(LEN) ((LEN) < sizeof (long))
+
+char *
+_DEFUN (strncpy, (dst0, src0),
+ char *dst0 _AND
+ _CONST char *src0 _AND
+ size_t count)
+{
+#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
+ char *dscan;
+ _CONST char *sscan;
+
+ dscan = dst0;
+ sscan = src0;
+ while (count > 0)
+ {
+ --count;
+ if ((*dscan++ = *sscan++) == '\0')
+ break;
+ }
+ while (count-- > 0)
+ *dscan++ = '\0';
+
+ return dst0;
+#else
+ char *dst = dst0;
+ _CONST char *src = src0;
+ long *aligned_dst;
+ _CONST long *aligned_src;
+
+ /* If SRC and DEST is aligned and count large enough, then copy words. */
+ if (!UNALIGNED (src, dst) && !TOO_SMALL (count))
+ {
+ aligned_dst = (long*)dst;
+ aligned_src = (long*)src;
+
+ /* SRC and DEST are both "long int" aligned, try to do "long int"
+ sized copies. */
+ while (count >= sizeof (long int) && !DETECTNULL(*aligned_src))
+ {
+ count -= sizeof (long int);
+ *aligned_dst++ = *aligned_src++;
+ }
+
+ dst = (char*)aligned_dst;
+ src = (char*)aligned_src;
+ }
+
+ while (count > 0)
+ {
+ --count;
+ if ((*dst++ = *src++) == '\0')
+ break;
+ }
+
+ while (count-- > 0)
+ *dst++ = '\0';
+
+ return dst0;
+#endif /* not PREFER_SIZE_OVER_SPEED */
+}
diff --git a/apps/plugins/lib/wrappers.h b/apps/plugins/lib/wrappers.h
index 5eb45d02c8..b6fbd51a39 100644
--- a/apps/plugins/lib/wrappers.h
+++ b/apps/plugins/lib/wrappers.h
@@ -51,7 +51,7 @@
#define strcpy rb->strcpy
#define strip_extension rb->strip_extension
#define strlen rb->strlen
-#define strncpy rb->strncpy
+#define strlcpy rb->strlcpy
#define strrchr rb->strrchr
#endif
diff --git a/apps/plugins/lua/lobject.c b/apps/plugins/lua/lobject.c
index 62ad8e9359..7f73114303 100644
--- a/apps/plugins/lua/lobject.c
+++ b/apps/plugins/lua/lobject.c
@@ -181,8 +181,7 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
void luaO_chunkid (char *out, const char *source, size_t bufflen) {
if (*source == '=') {
- strncpy(out, source+1, bufflen); /* remove first char */
- out[bufflen-1] = '\0'; /* ensures null termination */
+ strlcpy(out, source+1, bufflen); /* remove first char */
}
else { /* out = "source", or "...source" */
if (*source == '@') {
diff --git a/apps/plugins/lua/lstrlib.c b/apps/plugins/lua/lstrlib.c
index 3d6103692f..4d58280ba8 100644
--- a/apps/plugins/lua/lstrlib.c
+++ b/apps/plugins/lua/lstrlib.c
@@ -737,9 +737,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
if (isdigit(uchar(*p)))
luaL_error(L, "invalid format (width or precision too long)");
*(form++) = '%';
- strncpy(form, strfrmt, p - strfrmt + 1);
- form += p - strfrmt + 1;
- *form = '\0';
+ strlcpy(form, strfrmt, p - strfrmt + 1);
return p;
}
diff --git a/apps/plugins/lua/rockconf.h b/apps/plugins/lua/rockconf.h
index 639f336b5b..02bd0e76d1 100644
--- a/apps/plugins/lua/rockconf.h
+++ b/apps/plugins/lua/rockconf.h
@@ -63,7 +63,7 @@ long pow(long x, long y);
#define strchr rb->strchr
#define strcmp rb->strcmp
#define strcpy rb->strcpy
-#define strncpy rb->strncpy
+#define strlcpy rb->strlcpy
#define strlen rb->strlen
#endif /* _ROCKCONF_H_ */
diff --git a/apps/plugins/mp3_encoder.c b/apps/plugins/mp3_encoder.c
index 6849daf2f3..9da0d6925f 100644
--- a/apps/plugins/mp3_encoder.c
+++ b/apps/plugins/mp3_encoder.c
@@ -2399,9 +2399,8 @@ char mp3_name[80];
void get_mp3_filename(const char *wav_name)
{
- int slen = rb->strlen(wav_name);
- rb->strncpy(mp3_name, wav_name, 79);
- rb->strncpy(mp3_name + slen - 4, ".mp3", 5);
+ rb->strlcpy(mp3_name, wav_name, sizeof(mp3_name));
+ rb->strlcpy(mp3_name + rb->strlen(mp3_name) - 4, ".mp3", 5);
}
#if CONFIG_KEYPAD == IRIVER_H100_PAD || CONFIG_KEYPAD == IRIVER_H300_PAD
diff --git a/apps/plugins/mpegplayer/mpeg_settings.c b/apps/plugins/mpegplayer/mpeg_settings.c
index 7ec1157615..a9b66fc22f 100644
--- a/apps/plugins/mpegplayer/mpeg_settings.c
+++ b/apps/plugins/mpegplayer/mpeg_settings.c
@@ -344,7 +344,7 @@ static void backlight_brightness_formatter(char *buf, size_t length,
int value, const char *input)
{
if (value < 0)
- rb->strncpy(buf, BACKLIGHT_OPTION_DEFAULT, length);
+ rb->strlcpy(buf, BACKLIGHT_OPTION_DEFAULT, length);
else
rb->snprintf(buf, length, "%d", value + MIN_BRIGHTNESS_SETTING);
diff --git a/apps/plugins/pictureflow/pictureflow.c b/apps/plugins/pictureflow/pictureflow.c
index 496e9c94df..34d1db5d5c 100644
--- a/apps/plugins/pictureflow/pictureflow.c
+++ b/apps/plugins/pictureflow/pictureflow.c
@@ -913,7 +913,7 @@ bool get_albumart_for_index_from_db(const int slide_index, char *buf,
{
if ( slide_index == -1 )
{
- rb->strncpy( buf, EMPTY_SLIDE, buflen );
+ rb->strlcpy( buf, EMPTY_SLIDE, buflen );
}
if (!rb->tagcache_search(&tcs, tag_filename))
@@ -930,8 +930,7 @@ bool get_albumart_for_index_from_db(const int slide_index, char *buf,
#ifdef HAVE_TC_RAMCACHE
if (rb->tagcache_fill_tags(&id3, tcs.result))
{
- rb->strncpy(id3.path, tcs.result, sizeof(id3.path));
- id3.path[sizeof(id3.path) - 1] = 0;
+ rb->strlcpy(id3.path, tcs.result, sizeof(id3.path));
}
else
#endif
diff --git a/apps/plugins/properties.c b/apps/plugins/properties.c
index 18beec2da6..b57150b817 100644
--- a/apps/plugins/properties.c
+++ b/apps/plugins/properties.c
@@ -70,8 +70,7 @@ static bool file_properties(char* selected_file)
char* ptr = rb->strrchr(selected_file, '/') + 1;
int dirlen = (ptr - selected_file);
- rb->strncpy(tstr, selected_file, dirlen);
- tstr[dirlen] = 0;
+ rb->strlcpy(tstr, selected_file, dirlen + 1);
dir = rb->opendir(tstr);
if (dir)
@@ -212,7 +211,7 @@ static bool dir_properties(char* selected_file)
{
DPS dps;
char tstr[64];
- rb->strncpy(dps.dirname, selected_file, MAX_PATH);
+ rb->strlcpy(dps.dirname, selected_file, MAX_PATH);
dps.len = MAX_PATH;
dps.dc = 0;
dps.fc = 0;
@@ -220,7 +219,7 @@ static bool dir_properties(char* selected_file)
if(false == _dir_properties(&dps))
return false;
- rb->strncpy(str_dirname, selected_file, MAX_PATH);
+ rb->strlcpy(str_dirname, selected_file, MAX_PATH);
rb->snprintf(str_dircount, sizeof str_dircount, "Subdirs: %d", dps.dc);
rb->snprintf(str_filecount, sizeof str_filecount, "Files: %d", dps.fc);
rb->snprintf(str_size, sizeof str_size, "Size: %s",
@@ -236,35 +235,35 @@ char * get_props(int selected_item, void* data, char *buffer, size_t buffer_len)
switch(selected_item)
{
case 0:
- rb->strncpy(buffer, str_dirname, buffer_len);
+ rb->strlcpy(buffer, str_dirname, buffer_len);
break;
case 1:
- rb->strncpy(buffer, its_a_dir ? str_dircount : str_filename,
+ rb->strlcpy(buffer, its_a_dir ? str_dircount : str_filename,
buffer_len);
break;
case 2:
- rb->strncpy(buffer, its_a_dir ? str_filecount : str_size, buffer_len);
+ rb->strlcpy(buffer, its_a_dir ? str_filecount : str_size, buffer_len);
break;
case 3:
- rb->strncpy(buffer, its_a_dir ? str_size : str_date, buffer_len);
+ rb->strlcpy(buffer, its_a_dir ? str_size : str_date, buffer_len);
break;
case 4:
- rb->strncpy(buffer, its_a_dir ? "" : str_time, buffer_len);
+ rb->strlcpy(buffer, its_a_dir ? "" : str_time, buffer_len);
break;
case 5:
- rb->strncpy(buffer, its_a_dir ? "" : str_artist, buffer_len);
+ rb->strlcpy(buffer, its_a_dir ? "" : str_artist, buffer_len);
break;
case 6:
- rb->strncpy(buffer, its_a_dir ? "" : str_title, buffer_len);
+ rb->strlcpy(buffer, its_a_dir ? "" : str_title, buffer_len);
break;
case 7:
- rb->strncpy(buffer, its_a_dir ? "" : str_album, buffer_len);
+ rb->strlcpy(buffer, its_a_dir ? "" : str_album, buffer_len);
break;
case 8:
- rb->strncpy(buffer, its_a_dir ? "" : str_duration, buffer_len);
+ rb->strlcpy(buffer, its_a_dir ? "" : str_duration, buffer_len);
break;
default:
- rb->strncpy(buffer, "ERROR", buffer_len);
+ rb->strlcpy(buffer, "ERROR", buffer_len);
break;
}
return buffer;
@@ -284,8 +283,7 @@ enum plugin_status plugin_start(const void* parameter)
struct dirent* entry;
char* ptr = rb->strrchr(file, '/') + 1;
int dirlen = (ptr - file);
- rb->strncpy(str_dirname, file, dirlen);
- str_dirname[dirlen] = 0;
+ rb->strlcpy(str_dirname, file, dirlen + 1);
dir = rb->opendir(str_dirname);
if (dir)
diff --git a/apps/plugins/random_folder_advance_config.c b/apps/plugins/random_folder_advance_config.c
index 28546a340c..c9ffaed319 100644
--- a/apps/plugins/random_folder_advance_config.c
+++ b/apps/plugins/random_folder_advance_config.c
@@ -86,7 +86,7 @@ void traversedir(char* location, char* name)
/* check if path is removed directory, if so dont enter it */
rb->snprintf(path, MAX_PATH, "%s/%s", fullpath, entry->d_name);
while(path[0] == '/')
- rb->strncpy(path, path + 1, rb->strlen(path));
+ rb->strlcpy(path, path + 1, sizeof(path));
for(i = 0; i < num_replaced_dirs; i++)
{
if(!rb->strcmp(path, removed_dirs[i]))
@@ -141,8 +141,8 @@ bool custom_dir(void)
(num_replaced_dirs < MAX_REMOVED_DIRS))
{
num_replaced_dirs ++;
- rb->strncpy(removed_dirs[num_replaced_dirs - 1], line + 2,
- rb->strlen(line));
+ rb->strlcpy(removed_dirs[num_replaced_dirs - 1], line + 2,
+ sizeof(line));
}
}
rb->close(fd2);
@@ -157,7 +157,7 @@ bool custom_dir(void)
{
/* remove preceeding '/'s from the line */
while(line[0] == '/')
- rb->strncpy(line, line + 1, rb->strlen(line));
+ rb->strlcpy(line, line + 1, sizeof(line));
rb->snprintf(formatted_line, MAX_PATH, "/%s", line);
@@ -237,7 +237,7 @@ void generate(void)
char *list_get_name_cb(int selected_item, void* data, char* buf, size_t buf_len)
{
(void)data;
- rb->strncpy(buf, list->folder[selected_item], buf_len);
+ rb->strlcpy(buf, list->folder[selected_item], buf_len);
return buf;
}
diff --git a/apps/plugins/rockboy/menu.c b/apps/plugins/rockboy/menu.c
index 9821ce9ba2..76de224294 100644
--- a/apps/plugins/rockboy/menu.c
+++ b/apps/plugins/rockboy/menu.c
@@ -162,11 +162,10 @@ static void munge_name(char *buf, const size_t bufsiz) {
* checksum or something like that?
*/
static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) {
- char name_buf[40];
+ char name_buf[17];
/* munge state file name */
- strncpy(name_buf, rom.name, 40);
- name_buf[16] = '\0';
+ strlcpy(name_buf, rom.name, sizeof(name_buf));
munge_name(name_buf, strlen(name_buf));
/* glom the whole mess together */
@@ -211,7 +210,7 @@ static bool do_file(char *path, char *desc, bool is_load) {
/* build description buffer */
memset(desc_buf, 0, 20);
if (desc)
- strncpy(desc_buf, desc, 20);
+ strlcpy(desc_buf, desc, 20);
/* save state */
write(fd, desc_buf, 20);
@@ -241,8 +240,7 @@ static bool do_slot(size_t slot_id, bool is_load) {
if (!is_load)
if (rb->kbd_input(desc_buf, 20) || !strlen(desc_buf))
{
- memset(desc_buf, 0, 20);
- strncpy(desc_buf, "Untitled", 20);
+ strlcpy(desc_buf, "Untitled", 20);
}
/* load/save file */
diff --git a/apps/plugins/rockboy/rockmacros.h b/apps/plugins/rockboy/rockmacros.h
index 414b889003..0fd13f6ef9 100644
--- a/apps/plugins/rockboy/rockmacros.h
+++ b/apps/plugins/rockboy/rockmacros.h
@@ -67,7 +67,7 @@ void dynamic_recompile (struct dynarec_block *newblock);
#define strcat(a,b) rb->strcat((a),(b))
#define memset(a,b,c) rb->memset((a),(b),(c))
#define strcpy(a,b) rb->strcpy((a),(b))
-#define strncpy(a,b,c) rb->strncpy((a),(b),(c))
+#define strlcpy(a,b,c) rb->strlcpy((a),(b),(c))
#define strlen(a) rb->strlen((a))
#define strcmp(a,b) rb->strcmp((a),(b))
#define strchr(a,b) rb->strchr((a),(b))
diff --git a/apps/plugins/rockpaint.c b/apps/plugins/rockpaint.c
index 20bebdd11f..5de6c14a6b 100644
--- a/apps/plugins/rockpaint.c
+++ b/apps/plugins/rockpaint.c
@@ -686,7 +686,7 @@ static bool browse( char *dst, int dst_size, const char *start )
if( selected < 0 || selected >= item_count )
break;
struct entry* e = &dc[indexes[selected]];
- rb->strncpy( bbuf_s, e->name, sizeof( bbuf_s ) );
+ rb->strlcpy( bbuf_s, e->name, sizeof( bbuf_s ) );
if( !( e->attr & ATTR_DIRECTORY ) )
{
*tree = backup;
diff --git a/apps/plugins/shortcuts/shortcuts_common.c b/apps/plugins/shortcuts/shortcuts_common.c
index a06abd3f7f..1a781b23eb 100644
--- a/apps/plugins/shortcuts/shortcuts_common.c
+++ b/apps/plugins/shortcuts/shortcuts_common.c
@@ -213,8 +213,7 @@ bool parse_entry_content(char *line, sc_entry_t *entry, int last_segm)
DEBUGF("Bad entry: pathlen=%d, displen=%d\n", path_len, disp_len);
return false;
}
- rb->strncpy(entry->path, path, path_len);
- entry->path[path_len] = '\0';
+ rb->strlcpy(entry->path, path, path_len + 1);
rb->strcpy(entry->disp, disp); /* Safe since we've checked the length */
entry->explicit_disp = expl;
return true;
@@ -295,15 +294,14 @@ bool parse_name_value(char *line, char *name, int namesize,
/* Too long name */
return false;
}
- rb->strncpy(name, line, name_len);
- name[name_len] = '\0';
+ rb->strlcpy(name, line, name_len + 1);
val_len = rb->strlen(line) - name_len - NAME_VALUE_SEPARATOR_LEN;
if (val_len >= valuesize) {
/* Too long value */
return false;
}
- rb->strncpy(value, sep+NAME_VALUE_SEPARATOR_LEN, val_len+1);
+ rb->strlcpy(value, sep+NAME_VALUE_SEPARATOR_LEN, val_len+1);
return true;
}
diff --git a/apps/plugins/sokoban.c b/apps/plugins/sokoban.c
index 8672249bdc..bfd400b408 100644
--- a/apps/plugins/sokoban.c
+++ b/apps/plugins/sokoban.c
@@ -689,7 +689,8 @@ static bool redo(void)
static void init_boards(void)
{
- rb->strncpy(buffered_boards.filename, SOKOBAN_LEVELS_FILE, MAX_PATH);
+ rb->strlcpy(buffered_boards.filename, SOKOBAN_LEVELS_FILE,
+ sizeof(buffered_boards.filename));
current_info.level.index = 0;
current_info.player.row = 0;
@@ -1026,8 +1027,8 @@ static bool save(char *filename, bool solution)
/* Create dir if it doesn't exist */
if ((loc = rb->strrchr(filename, '/')) != NULL) {
- rb->strncpy(dirname, filename, loc - filename);
- dirname[loc - filename] = '\0';
+ rb->strlcpy(dirname, filename, loc - filename + 1);
+
if(!(dir = rb->opendir(dirname)))
rb->mkdir(dirname);
else
@@ -1082,7 +1083,9 @@ static bool load(char *filename, bool silent)
if (rb->strncmp(buf, "Sokoban", 7) != 0) {
rb->close(fd);
- rb->strncpy(buffered_boards.filename, filename, MAX_PATH);
+ rb->strlcpy(buffered_boards.filename, filename,
+ sizeof(buffered_boards.filename));
+
if (!read_levels(true))
return false;
diff --git a/apps/plugins/splitedit.c b/apps/plugins/splitedit.c
index 9f62b7a346..a169a61a47 100644
--- a/apps/plugins/splitedit.c
+++ b/apps/plugins/splitedit.c
@@ -780,11 +780,11 @@ static void save_editor(struct mp3entry *mp3, int splittime)
bool part2_save = true;
/* file name for left part */
- rb->strncpy(part1_name, mp3->path, MAX_PATH);
+ rb->strlcpy(part1_name, mp3->path, MAX_PATH);
generateFileName(part1_name, 1);
/* file name for right part */
- rb->strncpy(part2_name, mp3->path, MAX_PATH);
+ rb->strlcpy(part2_name, mp3->path, MAX_PATH);
generateFileName(part2_name, 2);
while (!exit_request)
diff --git a/apps/plugins/sudoku/sudoku.c b/apps/plugins/sudoku/sudoku.c
index f8a438592d..77f6ca7899 100644
--- a/apps/plugins/sudoku/sudoku.c
+++ b/apps/plugins/sudoku/sudoku.c
@@ -603,7 +603,7 @@ void default_state(struct sudoku_state_t* state)
{
int r,c;
- rb->strncpy(state->filename,GAME_FILE,MAX_PATH);
+ rb->strlcpy(state->filename,GAME_FILE,MAX_PATH);
for (r=0;r<9;r++) {
for (c=0;c<9;c++) {
state->startboard[r][c]=default_game[r][c];
@@ -626,7 +626,7 @@ void clear_state(struct sudoku_state_t* state)
{
int r,c;
- rb->strncpy(state->filename,GAME_FILE,MAX_PATH);
+ rb->strlcpy(state->filename,GAME_FILE,MAX_PATH);
for (r=0;r<9;r++) {
for (c=0;c<9;c++) {
state->startboard[r][c]='0';
@@ -719,7 +719,7 @@ bool load_sudoku(struct sudoku_state_t* state, char* filename)
return(false);
}
- rb->strncpy(state->filename,filename,MAX_PATH);
+ rb->strlcpy(state->filename,filename,MAX_PATH);
n=rb->read(fd,buf,300);
if (n <= 0) {
return(false);
@@ -1111,7 +1111,7 @@ bool sudoku_generate(struct sudoku_state_t* state)
rb->snprintf(str,sizeof(str),"Difficulty: %s",difficulty);
display_board(state);
rb->splash(HZ*3, str);
- rb->strncpy(state->filename,GAME_FILE,MAX_PATH);
+ rb->strlcpy(state->filename,GAME_FILE,MAX_PATH);
} else {
display_board(&new_state);
rb->splash(HZ*2, "Aborted");
diff --git a/apps/plugins/test_codec.c b/apps/plugins/test_codec.c
index a708ed7b07..c51fc4006f 100644
--- a/apps/plugins/test_codec.c
+++ b/apps/plugins/test_codec.c
@@ -451,7 +451,6 @@ static void init_ci(void)
/* strings and memory */
ci.strcpy = rb->strcpy;
- ci.strncpy = rb->strncpy;
ci.strlen = rb->strlen;
ci.strcmp = rb->strcmp;
ci.strcat = rb->strcat;
@@ -716,7 +715,7 @@ enum plugin_status plugin_start(const void* parameter)
/* Test all files in the same directory as the file selected by the
user */
- rb->strncpy(dirpath,parameter,sizeof(dirpath));
+ rb->strlcpy(dirpath,parameter,sizeof(dirpath));
ch = rb->strrchr(dirpath,'/');
ch[1]=0;
diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c
index 703b330d6c..617aeae8b1 100644
--- a/apps/plugins/text_editor.c
+++ b/apps/plugins/text_editor.c
@@ -133,7 +133,7 @@ char *list_get_name_cb(int selected_item, void* data,
rb->snprintf(buf , buf_len, "%s ...", b);
b[buf_len-10] = t;
}
- else rb->strncpy(buf, b, buf_len);
+ else rb->strlcpy(buf, b, buf_len);
return buf;
}
diff --git a/apps/plugins/zxbox/snapshot.c b/apps/plugins/zxbox/snapshot.c
index d078ec78b1..9a68540a04 100644
--- a/apps/plugins/zxbox/snapshot.c
+++ b/apps/plugins/zxbox/snapshot.c
@@ -603,8 +603,7 @@ void save_snapshot_file(char *name)
{
int type;
- rb->strncpy(filenamebuf, name, MAXFILENAME-10);
- filenamebuf[MAXFILENAME-10] = '\0';
+ rb->strlcpy(filenamebuf, name, MAXFILENAME-10 + 1);
type = SN_Z80;
if(check_ext(filenamebuf, "z80")) type = SN_Z80;
@@ -642,8 +641,7 @@ void load_snapshot_file_type(char *name, int type)
int snsh;
SNFILE snfil;
- rb->strncpy(filenamebuf, name, MAXFILENAME-10);
- filenamebuf[MAXFILENAME-10] = '\0';
+ rb->strlcpy(filenamebuf, name, MAXFILENAME-10 + 1);
spcf_find_file_type(filenamebuf, &filetype, &type);
if(type < 0) type = SN_Z80;
diff --git a/apps/plugins/zxbox/spconf.c b/apps/plugins/zxbox/spconf.c
index 5a14959adc..728f78638c 100644
--- a/apps/plugins/zxbox/spconf.c
+++ b/apps/plugins/zxbox/spconf.c
@@ -111,8 +111,7 @@ void spcf_read_command_line(const void* parameter)
file_type = extensions[ix].type;
file_subtype = extensions[ix].subtype;
- rb->strncpy(filenamebuf, parameter, MAXFILENAME - 10);
- filenamebuf[MAXFILENAME-10] = '\0';
+ rb->strlcpy(filenamebuf, parameter, MAXFILENAME - 10 + 1);
if(file_type < 0) file_subtype = -1;
if(!spcf_find_file_type(filenamebuf, &file_type, &file_subtype))
return;
diff --git a/apps/plugins/zxbox/sptape.c b/apps/plugins/zxbox/sptape.c
index f0e04de2fb..21f962ea28 100644
--- a/apps/plugins/zxbox/sptape.c
+++ b/apps/plugins/zxbox/sptape.c
@@ -594,8 +594,7 @@ void start_play_file_type(char *name, int seg, int type)
{
int filetype = FT_TAPEFILE;
- rb->strncpy(tapename, name, MAXFILENAME-10);
- tapename[MAXFILENAME-10] = '\0';
+ rb->strlcpy(tapename, name, MAXFILENAME-10 + 1);
currseg = seg;
tapetype = type;
diff --git a/apps/plugins/zxbox/tapefile.c b/apps/plugins/zxbox/tapefile.c
index 19f6aba980..0e262aa0f7 100644
--- a/apps/plugins/zxbox/tapefile.c
+++ b/apps/plugins/zxbox/tapefile.c
@@ -510,8 +510,7 @@ static int interpret_tzx_header(byte *hb, struct seginfo *csp)
int blen;
rb->snprintf(seg_desc,DESC_LEN, "Begin Group: ");
blen = (int) rb->strlen(seg_desc);
- rb->strncpy(seg_desc+blen, (char *) rbuf, (unsigned) csp->len);
- seg_desc[csp->len + blen] = '\0';
+ rb->strlcpy(seg_desc+blen, (char *) rbuf, (unsigned) csp->len + 1);
}
break;
@@ -618,8 +617,7 @@ static int interpret_tzx_header(byte *hb, struct seginfo *csp)
return 0;
}
csp->ptr += csp->len;
- rb->strncpy(seg_desc, (char *) rbuf, (unsigned) csp->len);
- seg_desc[csp->len] = '\0';
+ rb->strlcpy(seg_desc, (char *) rbuf, (unsigned) csp->len + 1);
break;
case 0x32: