Commit e49f2bb1 authored by Johny Mattsson's avatar Johny Mattsson
Browse files

Remove conflicting libc, rename c_xx and os_xx to xx.

c_strtod and c_getenv are kept since strtod doesn't appear in the SDK's libc,
and we want our own c_getenv to initialize the Lua main anyway.
parent 3a3e9ee0
......@@ -8,7 +8,7 @@
#define llimits_h
//#include "c_limits.h"
//#include <limits.h>
#include "lua.h"
......
......@@ -374,7 +374,7 @@ const LUA_REG_TYPE math_map[] = {
*/
#if defined LUA_NUMBER_INTEGRAL
# include "c_limits.h" /* for LONG_MAX */
# include <limits.h> /* for LONG_MAX */
#endif
LUALIB_API int luaopen_math (lua_State *L) {
......
......@@ -14,9 +14,9 @@
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STDLIB
#include C_HEADER_STRING
#include C_HEADER_FCNTL
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#ifndef LUA_CROSS_COMPILER
#include "flash_fs.h"
......@@ -103,7 +103,7 @@ static void setprogdir (lua_State *L) {
char *lb;
DWORD nsize = sizeof(buff)/sizeof(char);
DWORD n = GetModuleFileNameA(NULL, buff, nsize);
if (n == 0 || n == nsize || (lb = c_strrchr(buff, '\\')) == NULL)
if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL)
luaL_error(L, "unable to get ModuleFileName");
else {
*lb = '\0';
......@@ -351,8 +351,8 @@ static const char * pushnexttemplate (lua_State *L, const char *path) {
const char *l;
while (*path == *LUA_PATHSEP) path++; /* skip separators */
if (*path == '\0') return NULL; /* no more templates */
l = c_strchr(path, *LUA_PATHSEP); /* find next separator */
if (l == NULL) l = path + c_strlen(path);
l = strchr(path, *LUA_PATHSEP); /* find next separator */
if (l == NULL) l = path + strlen(path);
lua_pushlstring(L, path, l - path); /* template */
return l;
}
......@@ -404,7 +404,7 @@ static int loader_Lua (lua_State *L) {
static const char *mkfuncname (lua_State *L, const char *modname) {
const char *funcname;
const char *mark = c_strchr(modname, *LUA_IGMARK);
const char *mark = strchr(modname, *LUA_IGMARK);
if (mark) modname = mark + 1;
funcname = luaL_gsub(L, modname, ".", LUA_OFSEP);
funcname = lua_pushfstring(L, POF"%s", funcname);
......@@ -429,7 +429,7 @@ static int loader_Croot (lua_State *L) {
const char *funcname;
const char *filename;
const char *name = luaL_checkstring(L, 1);
const char *p = c_strchr(name, '.');
const char *p = strchr(name, '.');
int stat;
if (p == NULL) return 0; /* is root */
lua_pushlstring(L, name, p - name);
......@@ -474,7 +474,7 @@ static int ll_require (lua_State *L) {
return 1; /* package is already loaded */
}
/* Is this a readonly table? */
void *res = luaR_findglobal(name, c_strlen(name));
void *res = luaR_findglobal(name, strlen(name));
if (res) {
lua_pushrotable(L, res);
return 1;
......@@ -552,7 +552,7 @@ static void modinit (lua_State *L, const char *modname) {
lua_setfield(L, -2, "_M"); /* module._M = module */
lua_pushstring(L, modname);
lua_setfield(L, -2, "_NAME");
dot = c_strrchr(modname, '.'); /* look for last dot in module name */
dot = strrchr(modname, '.'); /* look for last dot in module name */
if (dot == NULL) dot = modname;
else dot++;
/* set _PACKAGE as package name (full module name minus last part) */
......@@ -563,7 +563,7 @@ static void modinit (lua_State *L, const char *modname) {
static int ll_module (lua_State *L) {
const char *modname = luaL_checkstring(L, 1);
if (luaR_findglobal(modname, c_strlen(modname)))
if (luaR_findglobal(modname, strlen(modname)))
return 0;
int loaded = lua_gettop(L) + 1; /* index of _LOADED table */
lua_getfield(L, LUA_REGISTRYINDEX, "_LOADED");
......
......@@ -10,9 +10,9 @@
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STDIO
#include C_HEADER_STRING
#include C_HEADER_STDLIB
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ldo.h"
#include "lmem.h"
......@@ -25,6 +25,7 @@
#else
#include <limits.h>
#endif
const TValue luaO_nilobject_ = {LUA_TVALUE_NIL};
......@@ -113,7 +114,7 @@ int luaO_str2d (const char *s, lua_Number *result) {
*result = cast_num(lres);
}
#else
*result = cast_num(c_strtoul(s, &endptr, 16));
*result = cast_num(strtoul(s, &endptr, 16));
#endif
if (*endptr == '\0') return 1; /* most common case */
while (isspace(cast(unsigned char, *endptr))) endptr++;
......@@ -134,7 +135,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
int n = 1;
pushstr(L, "");
for (;;) {
const char *e = c_strchr(fmt, '%');
const char *e = strchr(fmt, '%');
if (e == NULL) break;
setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
incr_top(L);
......@@ -164,7 +165,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
}
case 'p': {
char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
c_sprintf(buff, "%p", va_arg(argp, void *));
sprintf(buff, "%p", va_arg(argp, void *));
pushstr(L, buff);
break;
}
......@@ -203,7 +204,7 @@ const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
void luaO_chunkid (char *out, const char *source, size_t bufflen) {
if (*source == '=') {
c_strncpy(out, source+1, bufflen); /* remove first char */
strncpy(out, source+1, bufflen); /* remove first char */
out[bufflen-1] = '\0'; /* ensures null termination */
}
else { /* out = "source", or "...source" */
......@@ -211,26 +212,26 @@ void luaO_chunkid (char *out, const char *source, size_t bufflen) {
size_t l;
source++; /* skip the `@' */
bufflen -= sizeof(" '...' ");
l = c_strlen(source);
c_strcpy(out, "");
l = strlen(source);
strcpy(out, "");
if (l > bufflen) {
source += (l-bufflen); /* get last part of file name */
c_strcat(out, "...");
strcat(out, "...");
}
c_strcat(out, source);
strcat(out, source);
}
else { /* out = [string "string"] */
size_t len = c_strcspn(source, "\n\r"); /* stop at first newline */
size_t len = strcspn(source, "\n\r"); /* stop at first newline */
bufflen -= sizeof(" [string \"...\"] ");
if (len > bufflen) len = bufflen;
c_strcpy(out, "[string \"");
strcpy(out, "[string \"");
if (source[len] != '\0') { /* must truncate? */
c_strncat(out, source, len);
c_strcat(out, "...");
strncat(out, source, len);
strcat(out, "...");
}
else
c_strcat(out, source);
c_strcat(out, "\"]");
strcat(out, source);
strcat(out, "\"]");
}
}
}
......@@ -8,11 +8,7 @@
#ifndef lobject_h
#define lobject_h
#ifdef LUA_CROSS_COMPILER
#include <stdarg.h>
#else
#include "c_stdarg.h"
#endif
#include "llimits.h"
#include "lua.h"
......
......@@ -20,10 +20,10 @@ extern const luaR_table lua_rotable[];
void* luaR_findglobal(const char *name, unsigned len) {
unsigned i;
if (c_strlen(name) > LUA_MAX_ROTABLE_NAME)
if (strlen(name) > LUA_MAX_ROTABLE_NAME)
return NULL;
for (i=0; lua_rotable[i].name; i ++)
if (*lua_rotable[i].name != '\0' && c_strlen(lua_rotable[i].name) == len && !c_strncmp(lua_rotable[i].name, name, len)) {
if (*lua_rotable[i].name != '\0' && strlen(lua_rotable[i].name) == len && !strncmp(lua_rotable[i].name, name, len)) {
return (void*)(lua_rotable[i].pentries);
}
return NULL;
......@@ -37,7 +37,7 @@ static const TValue* luaR_auxfind(const luaR_entry *pentry, const char *strkey,
if (pentry == NULL)
return NULL;
while(pentry->key.type != LUA_TNIL) {
if ((strkey && (pentry->key.type == LUA_TSTRING) && (!c_strcmp(pentry->key.id.strkey, strkey))) ||
if ((strkey && (pentry->key.type == LUA_TSTRING) && (!strcmp(pentry->key.id.strkey, strkey))) ||
(!strkey && (pentry->key.type == LUA_TNUMBER) && ((luaR_numkey)pentry->key.id.numkey == numkey))) {
res = &pentry->value;
break;
......@@ -120,7 +120,7 @@ void luaR_getcstr(char *dest, const TString *src, size_t maxsize) {
if (src->tsv.len+1 > maxsize)
dest[0] = '\0';
else {
c_memcpy(dest, getstr(src), src->tsv.len);
memcpy(dest, getstr(src), src->tsv.len);
dest[src->tsv.len] = '\0';
}
}
......
......@@ -67,7 +67,7 @@ static TString *newlstr (lua_State *L, const char *str, size_t l,
ts->tsv.marked = luaC_white(G(L));
ts->tsv.tt = LUA_TSTRING;
if (!readonly) {
c_memcpy(ts+1, str, l*sizeof(char));
memcpy(ts+1, str, l*sizeof(char));
((char *)(ts+1))[l] = '\0'; /* ending 0 */
} else {
*(char **)(ts+1) = (char *)str;
......@@ -92,7 +92,7 @@ static TString *luaS_newlstr_helper (lua_State *L, const char *str, size_t l, in
o != NULL;
o = o->gch.next) {
TString *ts = rawgco2ts(o);
if (ts->tsv.len == l && (c_memcmp(str, getstr(ts), l) == 0)) {
if (ts->tsv.len == l && (memcmp(str, getstr(ts), l) == 0)) {
/* string may be dead */
if (isdead(G(L), o)) changewhite(o);
return ts;
......@@ -115,7 +115,7 @@ static int lua_is_ptr_in_ro_area(const char *p) {
TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
// If the pointer is in a read-only memory and the string is at least 4 chars in length,
// create it as a read-only string instead
if(lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && l == c_strlen(str))
if(lua_is_ptr_in_ro_area(str) && l+1 > sizeof(char**) && l == strlen(str))
return luaS_newlstr_helper(L, str, l, LUAS_READONLY_STRING);
else
return luaS_newlstr_helper(L, str, l, LUAS_REGULAR_STRING);
......@@ -123,7 +123,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
LUAI_FUNC TString *luaS_newrolstr (lua_State *L, const char *str, size_t l) {
if(l+1 > sizeof(char**) && l == c_strlen(str))
if(l+1 > sizeof(char**) && l == strlen(str))
return luaS_newlstr_helper(L, str, l, LUAS_READONLY_STRING);
else // no point in creating a RO string, as it would actually be larger
return luaS_newlstr_helper(L, str, l, LUAS_REGULAR_STRING);
......
......@@ -17,8 +17,8 @@
#define sizeudata(u) (sizeof(union Udata)+(u)->len)
#define luaS_new(L, s) (luaS_newlstr(L, s, c_strlen(s)))
#define luaS_newro(L, s) (luaS_newrolstr(L, s, c_strlen(s)))
#define luaS_new(L, s) (luaS_newlstr(L, s, strlen(s)))
#define luaS_newro(L, s) (luaS_newrolstr(L, s, strlen(s)))
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
(sizeof(s)/sizeof(char))-1))
......
......@@ -353,7 +353,7 @@ static const char *match_capture (MatchState *ms, const char *s, int l) {
l = check_capture(ms, l);
len = ms->capture[l].len;
if ((size_t)(ms->src_end-s) >= len &&
c_memcmp(ms->capture[l].init, s, len) == 0)
memcmp(ms->capture[l].init, s, len) == 0)
return s+len;
else return NULL;
}
......@@ -448,7 +448,7 @@ static const char *lmemfind (const char *s1, size_t l1,
l1 = l1-l2; /* `s2' cannot be found after that */
while (l1 > 0 && (init = (const char *)memchr(s1, *s2, l1)) != NULL) {
init++; /* 1st char is already checked */
if (c_memcmp(init, s2+1, l2) == 0)
if (memcmp(init, s2+1, l2) == 0)
return init-1;
else { /* correct `l1' and `s1' to try again */
l1 -= init-s1;
......@@ -497,7 +497,7 @@ static int str_find_aux (lua_State *L, int find) {
if (init < 0) init = 0;
else if ((size_t)(init) > l1) init = (ptrdiff_t)l1;
if (find && (lua_toboolean(L, 4) || /* explicit request? */
c_strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
strpbrk(p, SPECIALS) == NULL)) { /* or no special characters? */
/* do a plain search */
const char *s2 = lmemfind(s+init, l1-init, p, l2);
if (s2) {
......@@ -724,7 +724,7 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
const char *p = strfrmt;
while (*p != '\0' && c_strchr(FLAGS, *p) != NULL) p++; /* skip flags */
while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
if ((size_t)(p - strfrmt) >= sizeof(FLAGS))
luaL_error(L, "invalid format (repeated flags)");
if (isdigit(uchar(*p))) p++; /* skip width */
......@@ -737,7 +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++) = '%';
c_strncpy(form, strfrmt, p - strfrmt + 1);
strncpy(form, strfrmt, p - strfrmt + 1);
form += p - strfrmt + 1;
*form = '\0';
return p;
......@@ -745,9 +745,9 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
static void addintlen (char *form) {
size_t l = c_strlen(form);
size_t l = strlen(form);
char spec = form[l - 1];
c_strcpy(form + l - 1, LUA_INTFRMLEN);
strcpy(form + l - 1, LUA_INTFRMLEN);
form[l + sizeof(LUA_INTFRMLEN) - 2] = spec;
form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0';
}
......@@ -774,23 +774,23 @@ static int str_format (lua_State *L) {
strfrmt = scanformat(L, strfrmt, form);
switch (*strfrmt++) {
case 'c': {
c_sprintf(buff, form, (int)luaL_checknumber(L, arg));
sprintf(buff, form, (int)luaL_checknumber(L, arg));
break;
}
case 'd': case 'i': {
addintlen(form);
c_sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
sprintf(buff, form, (LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'o': case 'u': case 'x': case 'X': {
addintlen(form);
c_sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
sprintf(buff, form, (unsigned LUA_INTFRM_T)luaL_checknumber(L, arg));
break;
}
#if !defined LUA_NUMBER_INTEGRAL
case 'e': case 'E': case 'f':
case 'g': case 'G': {
c_sprintf(buff, form, (double)luaL_checknumber(L, arg));
sprintf(buff, form, (double)luaL_checknumber(L, arg));
break;
}
#endif
......@@ -801,7 +801,7 @@ static int str_format (lua_State *L) {
case 's': {
size_t l;
const char *s = luaL_checklstring(L, arg, &l);
if (!c_strchr(form, '.') && l >= 100) {
if (!strchr(form, '.') && l >= 100) {
/* no precision and string is too long to be formatted;
keep original string */
lua_pushvalue(L, arg);
......@@ -809,7 +809,7 @@ static int str_format (lua_State *L) {
continue; /* skip the `addsize' at the end */
}
else {
c_sprintf(buff, form, s);
sprintf(buff, form, s);
break;
}
}
......@@ -818,7 +818,7 @@ static int str_format (lua_State *L) {
LUA_QL("format"), *(strfrmt - 1));
}
}
luaL_addlstring(&b, buff, c_strlen(buff));
luaL_addlstring(&b, buff, strlen(buff));
}
}
luaL_pushresult(&b);
......
......@@ -86,7 +86,7 @@ static Node *hashnum (const Table *t, lua_Number n) {
int i;
if (luai_numeq(n, 0)) /* avoid problems with -0 */
return gnode(t, 0);
c_memcpy(a, &n, sizeof(a));
memcpy(a, &n, sizeof(a));
for (i = 1; i < numints; i++) a[0] += a[i];
return hashmod(t, a[0]);
}
......
......@@ -10,7 +10,7 @@
#define LUAC_CROSS_FILE
#include "lua.h"
#include C_HEADER_STRING
#include <string.h>
#include "lobject.h"
#include "lstate.h"
......
......@@ -5,14 +5,15 @@
*/
// #include "c_signal.h"
#include "c_stdio.h"
#include "c_stdlib.h"
#include "c_string.h"
// #include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "flash_fs.h"
#include "user_version.h"
#include "driver/readline.h"
#include "driver/uart.h"
#include "esp_system.h"
#define lua_c
......@@ -167,7 +168,7 @@ static int dofsfile (lua_State *L, const char *name) {
#endif
static int dostring (lua_State *L, const char *s, const char *name) {
int status = luaL_loadbuffer(L, s, c_strlen(s), name) || docall(L, 0, 1);
int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
return report(L, status);
}
......@@ -193,7 +194,7 @@ static int incomplete (lua_State *L, int status) {
size_t lmsg;
const char *msg = lua_tolstring(L, -1, &lmsg);
const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
if (c_strstr(msg, LUA_QL("<eof>")) == tp) {
if (strstr(msg, LUA_QL("<eof>")) == tp) {
lua_pop(L, 1);
return 1;
}
......@@ -209,7 +210,7 @@ static int pushline (lua_State *L, int firstline) {
const char *prmt = get_prompt(L, firstline);
if (lua_readline(L, b, prmt) == 0)
return 0; /* no input */
l = c_strlen(b);
l = strlen(b);
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
b[l-1] = '\0'; /* remove it */
if (firstline && b[0] == '=') /* first line starts with `=' ? */
......@@ -276,7 +277,7 @@ static int handle_script (lua_State *L, char **argv, int n) {
int narg = getargs(L, argv, n); /* collect arguments */
lua_setglobal(L, "arg");
fname = argv[n];
if (c_strcmp(fname, "-") == 0 && c_strcmp(argv[n-1], "--") != 0)
if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
fname = NULL; /* stdin */
status = luaL_loadfile(L, fname);
lua_insert(L, -(narg+1));
......@@ -345,7 +346,7 @@ static int runargs (lua_State *L, char **argv, int n) {
int memlimit=0;
if (*limit == '\0') limit = argv[++i];
lua_assert(limit != NULL);
memlimit = c_atoi(limit);
memlimit = atoi(limit);
lua_gc(L, LUA_GCSETMEMLIMIT, memlimit);
break;
}
......@@ -487,7 +488,7 @@ static void dojob(lua_Load *load){
do{
if(load->done == 1){
l = c_strlen(b);
l = strlen(b);
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
b[l-1] = '\0'; /* remove it */
if (load->firstline && b[0] == '=') /* first line starts with `=' ? */
......@@ -531,8 +532,8 @@ static void dojob(lua_Load *load){
load->done = 0;
load->line_position = 0;
c_memset(load->line, 0, load->len);
c_puts(load->prmt);
memset(load->line, 0, load->len);
puts(load->prmt);
}
#ifndef uart_putc
......@@ -598,7 +599,7 @@ static bool readline(lua_Load *load){
if (load->line_position == 0)
{
/* Get a empty line, then go to get a new line */
c_puts(load->prmt);
puts(load->prmt);
} else {
load->done = 1;
need_dojob = true;
......
......@@ -11,17 +11,10 @@
#ifdef LUAC_CROSS_FILE
#include "luac_cross.h"
#endif
#ifdef LUA_CROSS_COMPILER
#include <stdarg.h>
#include <stddef.h>
#include <ctype.h>
#else
#include "c_stdarg.h"
#include "c_stddef.h"
#include "c_types.h"
#include <ctype.h>
#endif
#include <stdbool.h>
#include "luaconf.h"
......
......@@ -5,8 +5,6 @@
#ifndef luac_cross_h
#define luac_cross_h
#ifdef LUA_CROSS_COMPILER
#define C_HEADER_ASSERT <assert.h>
#define C_HEADER_CTYPE <ctype.h>
#define C_HEADER_ERRNO <errno.h>
......@@ -18,59 +16,8 @@
#define C_HEADER_STRING <string.h>
#define C_HEADER_TIME <time.h>
#ifdef LUA_CROSS_COMPILER
#define ICACHE_RODATA_ATTR
#endif
#define c_abs abs
#define c_exit exit
#define c_fclose fclose
#define c_feof feof
#define c_ferror ferror
#define c_fopen fopen
#define c_fread fread
#define c_free free
#define c_freopen freopen
#define c_getc getc
#define c_getenv getenv
#define c_memcmp memcmp
#define c_memcpy memcpy
#define c_printf printf
#define c_puts puts
#define c_reader reader
#define c_realloc realloc
#define c_sprintf sprintf
#define c_stderr stderr
#define c_stdin stdin
#define c_stdout stdout
#define c_strcat strcat
#define c_strchr strchr
#define c_strcmp strcmp
#define c_strcoll strcoll
#define c_strcpy strcpy
#define c_strcspn strcspn
#define c_strerror strerror
#define c_strlen strlen
#define c_strncat strncat
#define c_strncmp strncmp
#define c_strncpy strncpy
#define c_strpbrk strpbrk
#define c_strrchr strrchr
#define c_strstr strstr
double c_strtod(const char *__n, char **__end_PTR);
#define c_strtoul strtoul
#define c_ungetc ungetc
#else
#define C_HEADER_ASSERT "c_assert.h"
#define C_HEADER_CTYPE "c_ctype.h"
#define C_HEADER_ERRNO "c_errno.h"
#define C_HEADER_FCNTL "c_fcntl.h"
#define C_HEADER_LOCALE "c_locale.h"
#define C_HEADER_MATH "c_math.h"
#define C_HEADER_STDIO "c_stdio.h"
#define C_HEADER_STDLIB "c_stdlib.h"
#define C_HEADER_STRING "c_string.h"
#define C_HEADER_TIME "c_time.h"
#endif /* LUA_CROSS_COMPILER */
#endif /* luac_cross_h */
......@@ -8,13 +8,8 @@
#ifndef lconfig_h
#define lconfig_h
#ifdef LUA_CROSS_COMPILER
#include <limits.h>
#include <stddef.h>
#else
#include "c_limits.h"
#include "c_stddef.h"
#endif
#include "user_config.h"
/*
......@@ -260,7 +255,7 @@
#ifdef LUA_CROSS_COMPILER
#include <stdio.h>
else
#include "c_stdio.h"
#include <stdio.h>
#endif
#define lua_stdin_is_tty() _isatty(_fileno(stdin))
......@@ -312,11 +307,11 @@ else
#define lua_saveline(L,idx) \
if (lua_strlen(L,idx) > 0) /* non-empty line? */ \
add_history(lua_tostring(L, idx)); /* add it to history */
#define lua_freeline(L,b) ((void)L, c_free(b))
#define lua_freeline(L,b) ((void)L, free(b))
#else // #if defined(LUA_CROSS_COMPILER) && defined(LUA_USE_READLINE)
#define lua_readline(L,b,p) \
((void)L, c_fputs(p, c_stdout), c_fflush(c_stdout), /* show prompt */ \
c_fgets(b, LUA_MAXINPUT, c_stdin) != NULL) /* get line */
((void)L, fputs(p, stdout), fflush(stdout), /* show prompt */ \
fgets(b, LUA_MAXINPUT, stdin) != NULL) /* get line */
#define lua_saveline(L,idx) { (void)L; (void)idx; }
#define lua_freeline(L,b) { (void)L; (void)b; }
#endif // #if defined(LUA_USE_READLINE)
......@@ -337,8 +332,8 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
** avoids including 'stdio.h' everywhere.)
*/
#if !defined(LUA_USE_STDIO)
#define luai_writestring(s, l) c_puts(s)
#define luai_writeline() c_puts("\n")
#define luai_writestring(s, l) puts(s)
#define luai_writeline() puts("\n")
#endif // defined(LUA_USE_STDIO)
/*
......@@ -346,7 +341,7 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
** (A format string with one argument is enough for Lua...)
*/
#if !defined(LUA_USE_STDIO)
#define luai_writestringerror(s,p) c_printf((s), (p))
#define luai_writestringerror(s,p) printf((s), (p))
#endif // defined(LUA_USE_STDIO)
......@@ -617,27 +612,23 @@ extern int readline4lua(const char *prompt, char *buffer, int length);
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#endif // #if defined LUA_NUMBER_INTEGRAL
#define lua_number2str(s,n) c_sprintf((s), LUA_NUMBER_FMT, (n))
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */
#if defined LUA_NUMBER_INTEGRAL
#if !defined LUA_INTEGRAL_LONGLONG
#define lua_str2number(s,p) c_strtol((s), (p), 10)
#define lua_str2number(s,p) strtol((s), (p), 10)
#else
#define lua_str2number(s,p) c_strtoll((s), (p), 10)
#define lua_str2number(s,p) strtoll((s), (p), 10)
#endif // #if !defined LUA_INTEGRAL_LONGLONG
#else
#define lua_str2number(s,p) c_strtod((s), (p))
#define lua_str2number(s,p) strtod((s), (p))
#endif // #if defined LUA_NUMBER_INTEGRAL
/*
@@ The luai_num* macros define the primitive operations over numbers.
*/
#if defined(LUA_CORE) || defined(LUA_LIB)
#ifdef LUA_CROSS_COMPILER
#include <math.h>
#else
#include "c_math.h"
#endif
#define luai_numadd(a,b) ((a)+(b))
#define luai_numsub(a,b) ((a)-(b))
#define luai_nummul(a,b) ((a)*(b))
......@@ -782,7 +773,7 @@ union luai_Cast { double l_d; long l_l; };
#include <unistd.h>
#define LUA_TMPNAMBUFSIZE 32
#define lua_tmpnam(b,e) { \
c_strcpy(b, "/tmp/lua_XXXXXX"); \
strcpy(b, "/tmp/lua_XXXXXX"); \
e = mkstemp(b); \
if (e != -1) close(e); \
e = (e == -1); }
......@@ -802,7 +793,7 @@ union luai_Cast { double l_d; long l_l; };
*/
#if defined(LUA_USE_POPEN)
#define lua_popen(L,c,m) ((void)L, c_fflush(NULL), popen(c,m))
#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
#define lua_pclose(L,file) ((void)L, (pclose(file) != -1))
#elif defined(LUA_WIN)
......
......@@ -309,7 +309,7 @@ static void LoadHeader(LoadState* S)
S->numsize=h[10]=s[10]; /* length of lua_Number */
S->toflt=(s[11]>intck); /* check if conversion from int lua_Number to flt is needed */
if(S->toflt) s[11]=h[11];
IF (c_memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
}
/*
......@@ -338,7 +338,7 @@ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
void luaU_header (char* h)
{
int x=1;
c_memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
h+=sizeof(LUA_SIGNATURE)-1;
*h++=(char)LUAC_VERSION;
*h++=(char)LUAC_FORMAT;
......
......@@ -7,11 +7,7 @@
#ifndef lundump_h
#define lundump_h
#ifdef LUA_CROSS_COMPILER
#include <stdint.h>
#else
#include "c_stdint.h"
#endif
#include "lobject.h"
#include "lzio.h"
......
......@@ -239,10 +239,10 @@ static int l_strcmp (const TString *ls, const TString *rs) {
const char *r = getstr(rs);
size_t lr = rs->tsv.len;
for (;;) {
int temp = c_strcoll(l, r);
int temp = strcoll(l, r);
if (temp != 0) return temp;
else { /* strings are equal up to a `\0' */
size_t len = c_strlen(l); /* index of first `\0' in both strings */
size_t len = strlen(l); /* index of first `\0' in both strings */
if (len == lr) /* r is finished? */
return (len == ll) ? 0 : 1;
else if (len == ll) /* l is finished? */
......@@ -349,7 +349,7 @@ void luaV_concat (lua_State *L, int total, int last) {
tl = 0;
for (i=n; i>0; i--) { /* concat all strings */
size_t l = tsvalue(top-i)->len;
c_memcpy(buffer+tl, svalue(top-i), l);
memcpy(buffer+tl, svalue(top-i), l);
tl += l;
}
setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
......
......@@ -62,7 +62,7 @@ size_t luaZ_read (ZIO *z, void *b, size_t n) {
return n; /* return number of missing bytes */
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
if (b)
c_memcpy(b, z->p, m);
memcpy(b, z->p, m);
z->n -= m;
z->i += m;
z->p += m;
......
#include "c_stdlib.h"
#include "c_string.h"
#include <stdlib.h>
#include <string.h>
#include "lualib.h"
#include "lauxlib.h"
#include "lrotable.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment