aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/3002-stdio-implement-fopencookie-3.patch
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-11-17 21:10:34 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2017-11-17 21:11:10 +0000
commit036898cc239499f2dbf57d6230e842947b99882d (patch)
tree796c0eff98903c3811220f1db249557f4ea47a25 /main/musl/3002-stdio-implement-fopencookie-3.patch
parent9949cdbaf2d26500ed011ee266370c83e048ff90 (diff)
downloadaports-036898cc239499f2dbf57d6230e842947b99882d.tar.bz2
aports-036898cc239499f2dbf57d6230e842947b99882d.tar.xz
main/musl: update fopencookie patch to v9
dalias actually likes this version, so hopefully it should be in musl soon
Diffstat (limited to 'main/musl/3002-stdio-implement-fopencookie-3.patch')
-rw-r--r--main/musl/3002-stdio-implement-fopencookie-3.patch48
1 files changed, 26 insertions, 22 deletions
diff --git a/main/musl/3002-stdio-implement-fopencookie-3.patch b/main/musl/3002-stdio-implement-fopencookie-3.patch
index 4b863e9095..881a86a16b 100644
--- a/main/musl/3002-stdio-implement-fopencookie-3.patch
+++ b/main/musl/3002-stdio-implement-fopencookie-3.patch
@@ -1,4 +1,4 @@
-From 1f6d9870ebc905990d230a3887d2e91a9edfde93 Mon Sep 17 00:00:00 2001
+From f501fa8271c7464c9c75762d2c9f43e494e416d8 Mon Sep 17 00:00:00 2001
From: William Pitcock <nenolod@dereferenced.org>
Date: Sun, 24 Sep 2017 16:37:48 -0500
Subject: [PATCH] stdio: implement fopencookie(3)
@@ -9,6 +9,13 @@ stdio implementation, using four hook functions which operate on a
Changelog:
+v9:
+- make read function more robust, should have been in v8 but i forgot to commit
+
+v8:
+- fix possible ungetc() underflow
+- style cleanups
+
v7:
- include GNU typedefs for cookie i/o functions
@@ -38,8 +45,8 @@ v1:
- initial proof of concept
---
include/stdio.h | 14 +++++
- src/stdio/fopencookie.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++
- 2 files changed, 155 insertions(+)
+ src/stdio/fopencookie.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 152 insertions(+)
create mode 100644 src/stdio/fopencookie.c
diff --git a/include/stdio.h b/include/stdio.h
@@ -69,10 +76,10 @@ index 884d2e6a..2932c76f 100644
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
diff --git a/src/stdio/fopencookie.c b/src/stdio/fopencookie.c
new file mode 100644
-index 00000000..bcf42c10
+index 00000000..2f46dd53
--- /dev/null
+++ b/src/stdio/fopencookie.c
-@@ -0,0 +1,141 @@
+@@ -0,0 +1,138 @@
+#define _GNU_SOURCE
+#include "stdio_impl.h"
+#include <stdlib.h>
@@ -97,31 +104,31 @@ index 00000000..bcf42c10
+ struct fcookie *fc = f->cookie;
+ ssize_t ret = -1;
+ size_t remain = len, readlen = 0;
++ size_t len2 = len - !!f->buf_size;
+
+ if (!fc->iofuncs.read) goto bail;
+
-+ ret = fc->iofuncs.read(fc->cookie, (char *) buf, len > 1 ? (len - 1) : 1);
-+ if (ret <= 0) goto bail;
++ if (len2) {
++ ret = fc->iofuncs.read(fc->cookie, (char *) buf, len2);
++ if (ret <= 0) goto bail;
+
-+ readlen += ret;
-+ remain -= ret;
++ readlen += ret;
++ remain -= ret;
++ }
++
++ if (!f->buf_size || remain > !!f->buf_size) return readlen;
+
+ f->rpos = f->buf;
+ ret = fc->iofuncs.read(fc->cookie, (char *) f->rpos, f->buf_size);
+ if (ret <= 0) goto bail;
+ f->rend = f->rpos + ret;
+
-+ if (remain > 0) {
-+ if (remain > f->buf_size) remain = f->buf_size;
-+ memcpy(buf + readlen, f->rpos, remain);
-+ readlen += remain;
-+ f->rpos += remain;
-+ }
++ buf[readlen++] = *f->rpos++;
+
+ return readlen;
+
+bail:
-+ f->flags |= F_EOF ^ ((F_ERR^F_EOF) & ret);
++ f->flags |= ret == 0 ? F_EOF : F_ERR;
+ f->rpos = f->rend = f->buf;
+ return readlen;
+}
@@ -149,7 +156,7 @@ index 00000000..bcf42c10
+{
+ struct fcookie *fc = f->cookie;
+ int res;
-+ if (whence > 2) {
++ if (whence > 2U) {
+ errno = EINVAL;
+ return -1;
+ }
@@ -184,7 +191,7 @@ index 00000000..bcf42c10
+ if (!(f=malloc(sizeof *f))) return 0;
+
+ /* Zero-fill only the struct, not the buffer */
-+ memset(f, 0, sizeof(FILE));
++ memset(&f->f, 0, sizeof f->f);
+
+ /* Impose mode restrictions */
+ if (!strchr(mode, '+')) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD;
@@ -198,13 +205,10 @@ index 00000000..bcf42c10
+
+ f->f.fd = -1;
+ f->f.cookie = &f->fc;
-+ f->f.buf = f->buf;
++ f->f.buf = f->buf + UNGET;
+ f->f.buf_size = BUFSIZ;
+ f->f.lbf = EOF;
+
-+ /* enable opportunistic stdio locking */
-+ f->f.lock = 0;
-+
+ /* Initialize op ptrs. No problem if some are unneeded. */
+ f->f.read = cookieread;
+ f->f.write = cookiewrite;