summaryrefslogtreecommitdiff
path: root/xs_io.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-09-28 09:29:09 +0200
committerdefault <nobody@localhost>2022-09-28 09:29:09 +0200
commita636cf8b25d72900892b18191e0d68de10779e90 (patch)
treedd2fa86101259a499713d810db7d360d25f27aa3 /xs_io.h
parent1d19464a48a7950421a4aff49034bde6fe4f4fa3 (diff)
New function static_get().
Diffstat (limited to 'xs_io.h')
-rw-r--r--xs_io.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/xs_io.h b/xs_io.h
index 523d207..62af82c 100644
--- a/xs_io.h
+++ b/xs_io.h
@@ -6,7 +6,7 @@
d_char *xs_readall(FILE *f);
d_char *xs_readline(FILE *f);
-d_char *xs_read(FILE *f, int size);
+d_char *xs_read(FILE *f, int *size);
#ifdef XS_IMPLEMENTATION
@@ -56,16 +56,18 @@ d_char *xs_readline(FILE *f)
}
-d_char *xs_read(FILE *f, int size)
+d_char *xs_read(FILE *f, int *sz)
/* reads up to size bytes from f */
{
d_char *s;
+ int size = *sz;
+ int rdsz = 0;
errno = 0;
s = xs_str_new(NULL);
- while (size != 0 && !feof(f)) {
+ while (size > 0 && !feof(f)) {
char tmp[2048];
int n, r;
@@ -76,8 +78,11 @@ d_char *xs_read(FILE *f, int size)
s = xs_append_m(s, tmp, r);
size -= r;
+ rdsz += r;
}
+ *sz = rdsz;
+
return s;
}