summaryrefslogtreecommitdiffstats
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/lua/README2
-rw-r--r--apps/plugins/lua/SOURCES2
-rw-r--r--apps/plugins/lua/lobject.c66
-rw-r--r--apps/plugins/lua/strcspn.c17
-rw-r--r--apps/plugins/lua/strncat.c37
5 files changed, 39 insertions, 85 deletions
diff --git a/apps/plugins/lua/README b/apps/plugins/lua/README
index 5b53eb354e..06cfd6f8f8 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 3fea681a50..ff40046eb0 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 62ad8e9359..a351ff41da 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 0a19eaebf2..0000000000
--- 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 147397440a..0000000000
--- 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;
-}