diff options
| author | bellard <bellard> | 2002-11-22 14:12:28 +0000 |
|---|---|---|
| committer | bellard <bellard> | 2002-11-22 14:12:28 +0000 |
| commit | 2f219d87020558965734ae6db7eda2989eeb38e7 (patch) | |
| tree | f46d65e19aad96b076c8d9f7fce2734dce78d936 | |
| parent | 63965fc585a3149c0488a13ecfcc0d1aa9317bb7 (diff) | |
| download | tinycc-2f219d87020558965734ae6db7eda2989eeb38e7.tar.gz tinycc-2f219d87020558965734ae6db7eda2989eeb38e7.tar.bz2 | |
use CH_EOB
| -rw-r--r-- | tcc.c | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -1150,7 +1150,8 @@ TokenSym *tok_alloc(const char *str, int len) ts->sym_identifier = NULL; ts->len = len; ts->hash_next = NULL; - memcpy(ts->str, str, len + 1); + memcpy(ts->str, str, len); + ts->str[len] = '\0'; *pts = ts; return ts; } @@ -7557,24 +7558,35 @@ static int tcc_compile(TCCState *s1) return s1->nb_errors != 0 ? -1 : 0; } +#ifdef LIBTCC int tcc_compile_string(TCCState *s, const char *str) { BufferedFile bf1, *bf = &bf1; - int ret; + int ret, len; + char *buf; /* init file structure */ bf->fd = -1; - bf->buf_ptr = (char *)str; - bf->buf_end = (char *)str + strlen(bf->buffer); + /* XXX: avoid copying */ + len = strlen(str); + buf = tcc_malloc(len + 1); + if (!buf) + return -1; + buf[len] = CH_EOB; + bf->buf_ptr = buf; + bf->buf_end = buf + len; pstrcpy(bf->filename, sizeof(bf->filename), "<string>"); bf->line_num = 1; file = bf; ret = tcc_compile(s); + tcc_free(buf); + /* currently, no need to close */ return ret; } +#endif /* define a preprocessor symbol. A value can also be provided with the '=' operator */ void tcc_define_symbol(TCCState *s1, const char *sym, const char *value) |
