1.1 --- a/templates/native/io.c Mon Feb 13 17:54:29 2017 +0100
1.2 +++ b/templates/native/io.c Mon Feb 13 21:26:38 2017 +0100
1.3 @@ -148,7 +148,7 @@
1.4
1.5 s = __ALLOCATE(have_read + 1, sizeof(char));
1.6 memcpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
1.7 - return __new_str(s);
1.8 + return __new_str(s, have_read);
1.9 }
1.10
1.11 __attr __fn_native_io_fwrite(__attr __args[])
1.12 @@ -158,9 +158,9 @@
1.13 /* fp interpreted as FILE reference */
1.14 FILE *f = (FILE *) fp->datavalue;
1.15 /* str.__data__ interpreted as string */
1.16 - __attr sa = __load_via_object(str->value, __pos___data__);
1.17 - char *s = sa.strvalue;
1.18 - size_t to_write = strlen(sa.strvalue);
1.19 + char *s = __load_via_object(str->value, __pos___data__).strvalue;
1.20 + /* str.__size__ interpreted as int */
1.21 + int to_write = __load_via_object(str->value, __pos___size__).intvalue;
1.22 size_t have_written = fwrite(s, sizeof(char), to_write, f);
1.23 int error;
1.24
1.25 @@ -210,7 +210,7 @@
1.26
1.27 s = __ALLOCATE(have_read + 1, 1);
1.28 memcpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
1.29 - return __new_str(s);
1.30 + return __new_str(s, have_read);
1.31 }
1.32
1.33 __attr __fn_native_io_write(__attr __args[])
1.34 @@ -220,12 +220,13 @@
1.35 /* fd.__data__ interpreted as int */
1.36 int i = __load_via_object(fd->value, __pos___data__).intvalue;
1.37 /* str.__data__ interpreted as string */
1.38 - __attr sa = __load_via_object(str->value, __pos___data__);
1.39 - char *s = sa.strvalue;
1.40 + char *s = __load_via_object(str->value, __pos___data__).strvalue;
1.41 + /* str.__size__ interpreted as int */
1.42 + int size = __load_via_object(str->value, __pos___size__).intvalue;
1.43 ssize_t have_written;
1.44
1.45 errno = 0;
1.46 - have_written = write(i, s, sizeof(char) * strlen(sa.strvalue));
1.47 + have_written = write(i, s, sizeof(char) * size);
1.48
1.49 if (have_written == -1)
1.50 __raise_io_error(__new_int(errno));