1.1 --- a/templates/native/io.c Sat Feb 11 15:34:30 2017 +0100
1.2 +++ b/templates/native/io.c Sat Feb 11 16:04:40 2017 +0100
1.3 @@ -1,6 +1,6 @@
1.4 /* Native functions for input/output.
1.5
1.6 -Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk>
1.7 +Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.8
1.9 This program is free software; you can redistribute it and/or modify it under
1.10 the terms of the GNU General Public License as published by the Free Software
1.11 @@ -150,7 +150,7 @@
1.12
1.13 s = __ALLOCATE(have_read + 1, sizeof(char));
1.14 memcpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
1.15 - return __new_str(s, have_read);
1.16 + return __new_str(s);
1.17 }
1.18
1.19 __attr __fn_native_io_fwrite(__attr __args[])
1.20 @@ -162,7 +162,7 @@
1.21 /* str.__data__ interpreted as string */
1.22 __attr sa = __load_via_object(str->value, __pos___data__);
1.23 char *s = sa.strvalue;
1.24 - size_t to_write = sa.size;
1.25 + size_t to_write = strlen(sa.strvalue);
1.26 size_t have_written = fwrite(s, sizeof(char), to_write, f);
1.27 int error;
1.28
1.29 @@ -212,7 +212,7 @@
1.30
1.31 s = __ALLOCATE(have_read + 1, 1);
1.32 memcpy(s, (char *) buf, have_read); /* does not null terminate but final byte should be zero */
1.33 - return __new_str(s, have_read);
1.34 + return __new_str(s);
1.35 }
1.36
1.37 __attr __fn_native_io_write(__attr __args[])
1.38 @@ -227,7 +227,7 @@
1.39 ssize_t have_written;
1.40
1.41 errno = 0;
1.42 - have_written = write(i, s, sizeof(char) * sa.size);
1.43 + have_written = write(i, s, sizeof(char) * strlen(sa.strvalue));
1.44
1.45 if (have_written == -1)
1.46 __raise_io_error(__new_int(errno));