diff options
| author | Jon French | 2018-10-16 16:25:39 +0100 |
|---|---|---|
| committer | Jon French | 2018-10-16 17:03:30 +0100 |
| commit | 315fccb1b063f5ffa131b5a761fa1b2d33fa130f (patch) | |
| tree | eed4db4a25e3c1c44d7394f4749ef1612c7af105 /lib | |
| parent | 45ce9105ce90efeccb9d0a183390027cdb1536af (diff) | |
| parent | 58c1292f2f5a54f069e00e4065c00936963db8cd (diff) | |
Merge branch 'sail2' into rmem_interpreter
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sail.c | 18 | ||||
| -rw-r--r-- | lib/sail.h | 1 |
2 files changed, 19 insertions, 0 deletions
@@ -151,7 +151,25 @@ void string_drop(sail_string *dst, sail_string s, sail_int ns) *dst = realloc(*dst, (len - n) + 1); memcpy(*dst, s + n, len - n); (*dst)[len - n] = '\0'; + } else { + *dst = realloc(*dst, 1); + **dst = '\0'; + } +} + +void string_take(sail_string *dst, sail_string s, sail_int ns) +{ + size_t len = strlen(s); + mach_int n = CREATE_OF(mach_int, sail_int)(ns); + mach_int to_copy; + if (len <= n) { + to_copy = len; + } else { + to_copy = n; } + *dst = realloc(*dst, to_copy + 1); + memcpy(*dst, s, to_copy); + *dst[to_copy] = '\0'; } /* ***** Sail integers ***** */ @@ -327,6 +327,7 @@ void random_real(real *rop, unit); void string_length(sail_int *len, sail_string s); void string_drop(sail_string *dst, sail_string s, sail_int len); +void string_take(sail_string *dst, sail_string s, sail_int len); /* ***** Printing ***** */ |
