mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
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
This commit is contained in:
parent
c2900a1bac
commit
3d4701a6e4
83 changed files with 271 additions and 271 deletions
|
|
@ -52,7 +52,7 @@ common/strcmp.c
|
|||
common/strnatcmp.c
|
||||
common/strcpy.c
|
||||
common/strncmp.c
|
||||
common/strncpy.c
|
||||
common/strlcpy.c
|
||||
common/strrchr.c
|
||||
common/strtok.c
|
||||
common/strstr.c
|
||||
|
|
|
|||
|
|
@ -58,8 +58,7 @@ int strip_volume(const char* name, char* namecopy)
|
|||
name = "/"; /* else this must be the root dir */
|
||||
}
|
||||
|
||||
strncpy(namecopy, name, MAX_PATH);
|
||||
namecopy[MAX_PATH-1] = '\0';
|
||||
strlcpy(namecopy, name, MAX_PATH);
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
|
@ -120,8 +119,7 @@ DIR_UNCACHED* opendir_uncached(const char* name)
|
|||
volume = strip_volume(name, namecopy);
|
||||
pdir->volumecounter = 0;
|
||||
#else
|
||||
strncpy(namecopy,name,sizeof(namecopy)); /* just copy */
|
||||
namecopy[sizeof(namecopy)-1] = '\0';
|
||||
strlcpy(namecopy, name, sizeof(namecopy)); /* just copy */
|
||||
#endif
|
||||
|
||||
if ( fat_opendir(IF_MV2(volume,) &pdir->fatdir, 0, NULL) < 0 ) {
|
||||
|
|
@ -204,7 +202,7 @@ struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir)
|
|||
if ( !entry.name[0] )
|
||||
return NULL;
|
||||
|
||||
strncpy(theent->d_name, entry.name, sizeof( theent->d_name ) );
|
||||
strlcpy(theent->d_name, entry.name, sizeof(theent->d_name));
|
||||
theent->attribute = entry.attr;
|
||||
theent->size = entry.filesize;
|
||||
theent->startcluster = entry.firstcluster;
|
||||
|
|
@ -230,8 +228,7 @@ int mkdir_uncached(const char *name)
|
|||
return -1;
|
||||
}
|
||||
|
||||
strncpy(namecopy,name,sizeof(namecopy));
|
||||
namecopy[sizeof(namecopy)-1] = 0;
|
||||
strlcpy(namecopy, name, sizeof(namecopy));
|
||||
|
||||
/* Split the base name and the path */
|
||||
end = strrchr(namecopy, '/');
|
||||
|
|
|
|||
|
|
@ -232,11 +232,11 @@ static int dircache_scan(IF_MV2(int volume,) struct travel_data *td)
|
|||
return -2;
|
||||
|
||||
td->pathpos = strlen(dircache_cur_path);
|
||||
strncpy(&dircache_cur_path[td->pathpos], "/",
|
||||
sizeof(dircache_cur_path) - td->pathpos - 1);
|
||||
strlcpy(&dircache_cur_path[td->pathpos], "/",
|
||||
sizeof(dircache_cur_path) - td->pathpos);
|
||||
#ifdef SIMULATOR
|
||||
strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name,
|
||||
sizeof(dircache_cur_path) - td->pathpos - 2);
|
||||
strlcpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name,
|
||||
sizeof(dircache_cur_path) - td->pathpos - 1);
|
||||
|
||||
td->newdir = opendir_uncached(dircache_cur_path);
|
||||
if (td->newdir == NULL)
|
||||
|
|
@ -245,8 +245,8 @@ static int dircache_scan(IF_MV2(int volume,) struct travel_data *td)
|
|||
return -3;
|
||||
}
|
||||
#else
|
||||
strncpy(&dircache_cur_path[td->pathpos+1], td->entry.name,
|
||||
sizeof(dircache_cur_path) - td->pathpos - 2);
|
||||
strlcpy(&dircache_cur_path[td->pathpos+1], td->entry.name,
|
||||
sizeof(dircache_cur_path) - td->pathpos - 1);
|
||||
|
||||
td->newdir = *td->dir;
|
||||
if (fat_opendir(IF_MV2(volume,) &td->newdir,
|
||||
|
|
@ -399,7 +399,7 @@ static struct dircache_entry* dircache_get_entry(const char *path,
|
|||
char* part;
|
||||
char* end;
|
||||
|
||||
strncpy(namecopy, path, sizeof(namecopy) - 1);
|
||||
strlcpy(namecopy, path, sizeof(namecopy));
|
||||
cache_entry = dircache_root;
|
||||
before = NULL;
|
||||
|
||||
|
|
@ -926,7 +926,7 @@ static struct dircache_entry* dircache_new_entry(const char *path, int attribute
|
|||
char *new;
|
||||
long last_cache_size = dircache_size;
|
||||
|
||||
strncpy(basedir, path, sizeof(basedir)-1);
|
||||
strlcpy(basedir, path, sizeof(basedir));
|
||||
new = strrchr(basedir, '/');
|
||||
if (new == NULL)
|
||||
{
|
||||
|
|
@ -997,8 +997,8 @@ void dircache_bind(int fd, const char *path)
|
|||
{
|
||||
if (fdbind_idx >= MAX_PENDING_BINDINGS)
|
||||
return ;
|
||||
strncpy(fdbind_cache[fdbind_idx].path, path,
|
||||
sizeof(fdbind_cache[fdbind_idx].path)-1);
|
||||
strlcpy(fdbind_cache[fdbind_idx].path, path,
|
||||
sizeof(fdbind_cache[fdbind_idx].path));
|
||||
fdbind_cache[fdbind_idx].fd = fd;
|
||||
fdbind_idx++;
|
||||
return ;
|
||||
|
|
@ -1141,7 +1141,7 @@ void dircache_rename(const char *oldpath, const char *newpath)
|
|||
/* Generate the absolute path for destination if necessary. */
|
||||
if (newpath[0] != '/')
|
||||
{
|
||||
strncpy(absolute_path, oldpath, sizeof(absolute_path)-1);
|
||||
strlcpy(absolute_path, oldpath, sizeof(absolute_path));
|
||||
p = strrchr(absolute_path, '/');
|
||||
if (!p)
|
||||
{
|
||||
|
|
@ -1151,7 +1151,7 @@ void dircache_rename(const char *oldpath, const char *newpath)
|
|||
}
|
||||
|
||||
*p = '\0';
|
||||
strncpy(p, absolute_path, sizeof(absolute_path)-1-strlen(p));
|
||||
strlcpy(p, absolute_path, sizeof(absolute_path)-strlen(p));
|
||||
newpath = absolute_path;
|
||||
}
|
||||
|
||||
|
|
@ -1246,7 +1246,7 @@ struct dircache_entry* readdir_cached(DIR_CACHED* dir)
|
|||
if (regentry == NULL)
|
||||
return NULL;
|
||||
|
||||
strncpy(dir->secondary_entry.d_name, regentry->d_name, MAX_PATH-1);
|
||||
strlcpy(dir->secondary_entry.d_name, regentry->d_name, MAX_PATH);
|
||||
dir->secondary_entry.size = regentry->size;
|
||||
dir->secondary_entry.startcluster = regentry->startcluster;
|
||||
dir->secondary_entry.attribute = regentry->attribute;
|
||||
|
|
@ -1268,7 +1268,7 @@ struct dircache_entry* readdir_cached(DIR_CACHED* dir)
|
|||
|
||||
dir->entry = ce->next;
|
||||
|
||||
strncpy(dir->secondary_entry.d_name, ce->d_name, MAX_PATH-1);
|
||||
strlcpy(dir->secondary_entry.d_name, ce->d_name, MAX_PATH);
|
||||
/* Can't do `dir->secondary_entry = *ce`
|
||||
because that modifies the d_name pointer. */
|
||||
dir->secondary_entry.size = ce->size;
|
||||
|
|
|
|||
|
|
@ -132,8 +132,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache)
|
|||
}
|
||||
#endif
|
||||
|
||||
strncpy(pathnamecopy,pathname,sizeof(pathnamecopy));
|
||||
pathnamecopy[sizeof(pathnamecopy)-1] = 0;
|
||||
strlcpy(pathnamecopy, pathname, sizeof(pathnamecopy));
|
||||
|
||||
/* locate filename */
|
||||
name=strrchr(pathnamecopy+1,'/');
|
||||
|
|
|
|||
52
firmware/common/strlcpy.c
Normal file
52
firmware/common/strlcpy.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* $OpenBSD: strlcpy.c,v 1.11 2006/05/05 15:27:38 millert Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Copy src to string dst of size siz. At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
|
||||
/* Copy as many bytes as will fit */
|
||||
if (n != 0) {
|
||||
while (--n != 0) {
|
||||
if ((*d++ = *s++) == '\0')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Not enough room in dst, add NUL and traverse rest of src */
|
||||
if (n == 0) {
|
||||
if (siz != 0)
|
||||
*d = '\0'; /* NUL-terminate dst */
|
||||
while (*s++)
|
||||
;
|
||||
}
|
||||
|
||||
return(s - src - 1); /* count does not include NUL */
|
||||
}
|
||||
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
/*
|
||||
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 */
|
||||
}
|
||||
|
|
@ -1183,7 +1183,7 @@ static int write_long_name(struct fat_file* file,
|
|||
/* shortname entry */
|
||||
unsigned short date=0, time=0, tenth=0;
|
||||
LDEBUGF("Shortname entry: %s\n", shortname);
|
||||
strncpy(entry + FATDIR_NAME, shortname, 11);
|
||||
memcpy(entry + FATDIR_NAME, shortname, 11);
|
||||
entry[FATDIR_ATTR] = is_directory?FAT_ATTR_DIRECTORY:0;
|
||||
entry[FATDIR_NTRES] = 0;
|
||||
|
||||
|
|
@ -1271,7 +1271,7 @@ static int add_dir_entry(struct fat_dir* dir,
|
|||
/* The "." and ".." directory entries must not be long names */
|
||||
if(dotdir) {
|
||||
int i;
|
||||
strncpy(shortname, name, 12);
|
||||
strlcpy(shortname, name, 12);
|
||||
for(i = strlen(shortname); i < 12; i++)
|
||||
shortname[i] = ' ';
|
||||
|
||||
|
|
|
|||
|
|
@ -1152,7 +1152,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
|
|||
}
|
||||
|
||||
end = strchr(s->line, '\0');
|
||||
strncpy(end, string, current_vp->width/2);
|
||||
strlcpy(end, string, current_vp->width/2);
|
||||
|
||||
s->vp = current_vp;
|
||||
s->y = y;
|
||||
|
|
|
|||
|
|
@ -845,7 +845,7 @@ void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string,
|
|||
}
|
||||
|
||||
end = strchr(s->line, '\0');
|
||||
strncpy(end, string, current_vp->width/2);
|
||||
strlcpy(end, string, current_vp->width/2);
|
||||
|
||||
s->vp = current_vp;
|
||||
s->y = y;
|
||||
|
|
|
|||
|
|
@ -1154,7 +1154,7 @@ void lcd_puts_scroll_style_offset(int x, int y, const unsigned char *string,
|
|||
}
|
||||
|
||||
end = strchr(s->line, '\0');
|
||||
strncpy(end, (char *)string, current_vp->width/2);
|
||||
strlcpy(end, (char *)string, current_vp->width/2);
|
||||
|
||||
s->vp = current_vp;
|
||||
s->y = y;
|
||||
|
|
|
|||
|
|
@ -1167,7 +1167,7 @@ void LCDFN(puts_scroll_style_offset)(int x, int y, const unsigned char *string,
|
|||
}
|
||||
|
||||
end = strchr(s->line, '\0');
|
||||
strncpy(end, (char *)string, current_vp->width/2);
|
||||
strlcpy(end, (char *)string, current_vp->width/2);
|
||||
|
||||
s->vp = current_vp;
|
||||
s->y = y;
|
||||
|
|
|
|||
|
|
@ -496,7 +496,7 @@ void lcd_puts_scroll_offset(int x, int y, const unsigned char *string,
|
|||
}
|
||||
|
||||
end = strchr(s->line, '\0');
|
||||
strncpy(end, string, utf8seek(s->line, current_vp->width));
|
||||
strlcpy(end, string, utf8seek(s->line, current_vp->width));
|
||||
|
||||
s->vp = current_vp;
|
||||
s->y = y;
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ char *create_numbered_filename(char *buffer, const char *path,
|
|||
char fmtstring[12];
|
||||
|
||||
if (buffer != path)
|
||||
strncpy(buffer, path, MAX_PATH);
|
||||
strlcpy(buffer, path, MAX_PATH);
|
||||
|
||||
pathlen = strlen(buffer);
|
||||
|
||||
|
|
@ -185,7 +185,7 @@ char *create_datetime_filename(char *buffer, const char *path,
|
|||
last_tm = *tm;
|
||||
|
||||
if (buffer != path)
|
||||
strncpy(buffer, path, MAX_PATH);
|
||||
strlcpy(buffer, path, MAX_PATH);
|
||||
|
||||
pathlen = strlen(buffer);
|
||||
snprintf(buffer + pathlen, MAX_PATH - pathlen,
|
||||
|
|
|
|||
|
|
@ -35,13 +35,14 @@ char *_EXFUN(strerror,(int));
|
|||
size_t _EXFUN(strlen,(const char *));
|
||||
char *_EXFUN(strncat,(char *, const char *, size_t));
|
||||
int _EXFUN(strncmp,(const char *, const char *, size_t));
|
||||
char *_EXFUN(strncpy,(char *, const char *, size_t));
|
||||
char *_EXFUN(strpbrk,(const char *, const char *));
|
||||
char *_EXFUN(strrchr,(const char *, int));
|
||||
size_t _EXFUN(strspn,(const char *, const char *));
|
||||
char *_EXFUN(strstr,(const char *, const char *));
|
||||
char *_EXFUN(strcasestr,(const char *, const char *));
|
||||
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
char *_EXFUN(strtok,(char *, const char *));
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ void _logf(const char *format, ...)
|
|||
while(len > MAX_LOGF_ENTRY)
|
||||
{
|
||||
ptr = logfbuffer[logfindex];
|
||||
strncpy(ptr, buf + tlen, MAX_LOGF_ENTRY-1);
|
||||
strlcpy(ptr, buf + tlen, MAX_LOGF_ENTRY);
|
||||
ptr[MAX_LOGF_ENTRY] = LOGF_TERMINATE_CONTINUE_LINE;
|
||||
logfindex++;
|
||||
check_logfindex();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue