Lua remove strncat.c & strcspn.c
Change-Id: I08256f31e733d2674054e8e589d539d1396a0ee6
This commit is contained in:
parent
df8233e4ab
commit
cc0a4c632a
5 changed files with 39 additions and 85 deletions
|
@ -2,9 +2,7 @@ The following files are (with slight modifications for Rockbox) from dietlibc
|
|||
version 0.31 which is licensed under the GPL version 2:
|
||||
|
||||
gmtime.c
|
||||
strcspn.c
|
||||
strftime.c
|
||||
strncat.c
|
||||
strpbrk.c
|
||||
strtol.c
|
||||
strtoul.c
|
||||
|
|
|
@ -31,9 +31,7 @@ rocklib.c
|
|||
rocklib_img.c
|
||||
tlsf_helper.c
|
||||
fscanf.c
|
||||
strcspn.c
|
||||
strftime.c
|
||||
strncat.c
|
||||
strpbrk.c
|
||||
strtoul.c
|
||||
strtol.c
|
||||
|
|
|
@ -178,37 +178,49 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
|
|||
return msg;
|
||||
}
|
||||
|
||||
/* lua 5.2 lobject.c,v 2.58.1.1 2013/04/12 18:48:47 roberto Exp $ */
|
||||
/* number of chars of a literal string without the ending \0 */
|
||||
#define LL(x) (sizeof(x)/sizeof(char) - 1)
|
||||
|
||||
#define RETS "..."
|
||||
#define PRE "[string \""
|
||||
#define POS "\"]"
|
||||
|
||||
#define addstr(a,b,l) ( memcpy(a,b,(l) * sizeof(char)), a += (l) )
|
||||
|
||||
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 */
|
||||
size_t l = strlen(source);
|
||||
if (*source == '=') { /* 'literal' source */
|
||||
if (l <= bufflen) /* small enough? */
|
||||
memcpy(out, source + 1, l * sizeof(char));
|
||||
else { /* truncate it */
|
||||
addstr(out, source + 1, bufflen - 1);
|
||||
*out = '\0';
|
||||
}
|
||||
else { /* out = "source", or "...source" */
|
||||
if (*source == '@') {
|
||||
size_t l;
|
||||
source++; /* skip the `@' */
|
||||
bufflen -= sizeof(" '...' ");
|
||||
l = strlen(source);
|
||||
strcpy(out, "");
|
||||
if (l > bufflen) {
|
||||
source += (l-bufflen); /* get last part of file name */
|
||||
strcat(out, "...");
|
||||
}
|
||||
strcat(out, source);
|
||||
else if (*source == '@') { /* file name */
|
||||
if (l <= bufflen) /* small enough? */
|
||||
memcpy(out, source + 1, l * sizeof(char));
|
||||
else { /* add '...' before rest of name */
|
||||
addstr(out, RETS, LL(RETS));
|
||||
bufflen -= LL(RETS);
|
||||
memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));
|
||||
}
|
||||
else { /* out = [string "string"] */
|
||||
size_t len = strcspn(source, "\n\r"); /* stop at first newline */
|
||||
bufflen -= sizeof(" [string \"...\"] ");
|
||||
if (len > bufflen) len = bufflen;
|
||||
strcpy(out, "[string \"");
|
||||
if (source[len] != '\0') { /* must truncate? */
|
||||
strncat(out, source, len);
|
||||
strcat(out, "...");
|
||||
}
|
||||
else
|
||||
strcat(out, source);
|
||||
strcat(out, "\"]");
|
||||
else { /* string; format as [string "source"] */
|
||||
const char *nl = strchr(source, '\n'); /* find first new line (if any) */
|
||||
addstr(out, PRE, LL(PRE)); /* add prefix */
|
||||
bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */
|
||||
if (l < bufflen && nl == NULL) { /* small one-line source? */
|
||||
addstr(out, source, l); /* keep it */
|
||||
}
|
||||
else {
|
||||
if (nl != NULL) l = nl - source; /* stop at first newline */
|
||||
if (l > bufflen) l = bufflen;
|
||||
addstr(out, source, l);
|
||||
addstr(out, RETS, LL(RETS));
|
||||
}
|
||||
memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
#include "rocklibc.h"
|
||||
|
||||
#undef strcspn
|
||||
size_t strcspn(const char *s, const char *reject)
|
||||
{
|
||||
size_t l=0;
|
||||
int a=1,i,al=strlen(reject);
|
||||
|
||||
while((a)&&(*s))
|
||||
{
|
||||
for(i=0;(a)&&(i<al);i++)
|
||||
if (*s==reject[i]) a=0;
|
||||
if (a) l++;
|
||||
s++;
|
||||
}
|
||||
return l;
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
#include "rocklibc.h"
|
||||
|
||||
/* gcc is broken and has a non-SUSv2 compliant internal prototype.
|
||||
* This causes it to warn about a type mismatch here. Ignore it. */
|
||||
char *strncat(char *s, const char *t, size_t n) {
|
||||
char *dest=s;
|
||||
register char *max;
|
||||
s+=strlen(s);
|
||||
if (__unlikely((max=s+n)==s)) goto fini;
|
||||
for (;;) {
|
||||
if (__unlikely(!(*s = *t)))
|
||||
break;
|
||||
if (__unlikely(++s==max))
|
||||
break;
|
||||
++t;
|
||||
#ifndef WANT_SMALL_STRING_ROUTINES
|
||||
if (__unlikely(!(*s = *t)))
|
||||
break;
|
||||
if (__unlikely(++s==max))
|
||||
break;
|
||||
++t;
|
||||
if (__unlikely(!(*s = *t)))
|
||||
break;
|
||||
if (__unlikely(++s==max))
|
||||
break;
|
||||
++t;
|
||||
if (__unlikely(!(*s = *t)))
|
||||
break;
|
||||
if (__unlikely(++s==max))
|
||||
break;
|
||||
++t;
|
||||
#endif
|
||||
}
|
||||
*s=0;
|
||||
fini:
|
||||
return dest;
|
||||
}
|
Loading…
Reference in a new issue