diff options
| author | William Wilgus <me.theuser@yahoo.com> | 2018-10-28 13:21:42 -0400 |
|---|---|---|
| committer | William Wilgus <me.theuser@yahoo.com> | 2018-10-30 04:17:06 +0100 |
| commit | cc0a4c632aeda82ab4517355b4b4489190da013e (patch) | |
| tree | 49d40380d8a48c5b374a2bd63b53a73c443bf2e3 /apps/plugins/lua | |
| parent | df8233e4abbd0d626158abc5388957cc28b06c50 (diff) | |
| download | rockbox-cc0a4c632aeda82ab4517355b4b4489190da013e.zip rockbox-cc0a4c632aeda82ab4517355b4b4489190da013e.tar.gz rockbox-cc0a4c632aeda82ab4517355b4b4489190da013e.tar.bz2 rockbox-cc0a4c632aeda82ab4517355b4b4489190da013e.tar.xz | |
Lua remove strncat.c & strcspn.c
Change-Id: I08256f31e733d2674054e8e589d539d1396a0ee6
Diffstat (limited to 'apps/plugins/lua')
| -rw-r--r-- | apps/plugins/lua/README | 2 | ||||
| -rw-r--r-- | apps/plugins/lua/SOURCES | 2 | ||||
| -rw-r--r-- | apps/plugins/lua/lobject.c | 66 | ||||
| -rw-r--r-- | apps/plugins/lua/strcspn.c | 17 | ||||
| -rw-r--r-- | apps/plugins/lua/strncat.c | 37 |
5 files changed, 39 insertions, 85 deletions
diff --git a/apps/plugins/lua/README b/apps/plugins/lua/README index 5b53eb3..06cfd6f 100644 --- a/apps/plugins/lua/README +++ b/apps/plugins/lua/README @@ -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 diff --git a/apps/plugins/lua/SOURCES b/apps/plugins/lua/SOURCES index 3fea681..ff40046 100644 --- a/apps/plugins/lua/SOURCES +++ b/apps/plugins/lua/SOURCES @@ -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 diff --git a/apps/plugins/lua/lobject.c b/apps/plugins/lua/lobject.c index 62ad8e9..a351ff4 100644 --- a/apps/plugins/lua/lobject.c +++ b/apps/plugins/lua/lobject.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)); } } + diff --git a/apps/plugins/lua/strcspn.c b/apps/plugins/lua/strcspn.c deleted file mode 100644 index 0a19eae..0000000 --- a/apps/plugins/lua/strcspn.c +++ /dev/null @@ -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; -} diff --git a/apps/plugins/lua/strncat.c b/apps/plugins/lua/strncat.c deleted file mode 100644 index 1473974..0000000 --- a/apps/plugins/lua/strncat.c +++ /dev/null @@ -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; -} |