blob: 93b8cc9c18028feab0be40d109f3df3d79eea2d9 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001From 84e12bf7ece49073c559dfd58005132a6099a964 Mon Sep 17 00:00:00 2001
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002From: =?UTF-8?q?Neal=20Gompa=20=28=E3=83=8B=E3=83=BC=E3=83=AB=E3=83=BB?=
3 =?UTF-8?q?=E3=82=B3=E3=82=99=E3=83=B3=E3=83=8F=E3=82=9A=29?=
4 <ngompa13@gmail.com>
5Date: Mon, 23 Nov 2015 18:19:41 -0500
6Subject: [PATCH 2/2] Fixes to internal fopencookie() implementation
7
8Credits to the fixes go to nsz on #musl on Freenode,
9who gloriously fixed the implementation such that
10the tests all pass.
11
12Upstream-Status: Denied [https://github.com/openSUSE/libsolv/pull/112]
13Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
Brad Bishop316dfdd2018-06-25 12:45:53 -040014
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015---
16 ext/solv_xfopen_fallback_fopencookie.c | 19 ++++++++++---------
17 ext/solv_xfopen_fallback_fopencookie.h | 10 +++++-----
18 2 files changed, 15 insertions(+), 14 deletions(-)
19
20diff --git a/ext/solv_xfopen_fallback_fopencookie.c b/ext/solv_xfopen_fallback_fopencookie.c
21index 0ce2571..89426a9 100644
22--- a/ext/solv_xfopen_fallback_fopencookie.c
23+++ b/ext/solv_xfopen_fallback_fopencookie.c
24@@ -1,10 +1,10 @@
25-/*
26+/*
27 * Provides a very limited fopencookie() for environments with a libc
28 * that lacks it.
29- *
30- * Author: zhasha
31+ *
32+ * Authors: zhasha & nsz
33 * Modified for libsolv by Neal Gompa
34- *
35+ *
36 * This program is licensed under the BSD license, read LICENSE.BSD
37 * for further information.
38 *
39@@ -33,7 +33,7 @@ static void *proxy(void *arg)
40 {
41 struct ctx *ctx = arg;
42 ssize_t r;
43- size_t n;
44+ size_t n, k;
45
46 pthread_detach(pthread_self());
47
48@@ -47,17 +47,18 @@ static void *proxy(void *arg)
49 }
50 if (r == 0) { break; }
51
52+ n = r, k = 0;
53 while (n > 0) {
54 r = ctx->io.write ?
55- (ctx->io.write)(ctx->cookie, ctx->buf + ((size_t)r - n), n) :
56- write(ctx->fd, ctx->buf + ((size_t)r - n), n);
57+ (ctx->io.write)(ctx->cookie, ctx->buf + k, n) :
58+ write(ctx->fd, ctx->buf + k, n);
59 if (r < 0) {
60 if (errno != EINTR) { break; }
61 continue;
62 }
63 if (r == 0) { break; }
64
65- n -= (size_t)r;
66+ n -= r, k += r;
67 }
68 if (n > 0) { break; }
69 }
70@@ -77,8 +78,8 @@ FILE *fopencookie(void *cookie, const char *mode, struct cookie_io_functions_t i
71
72 switch (mode[0]) {
73 case 'a':
74- case 'r': rd = 1; break;
75 case 'w': wr = 1; break;
76+ case 'r': rd = 1; break;
77 default:
78 errno = EINVAL;
79 return NULL;
80diff --git a/ext/solv_xfopen_fallback_fopencookie.h b/ext/solv_xfopen_fallback_fopencookie.h
81index 6a7bfee..7223e3f 100644
82--- a/ext/solv_xfopen_fallback_fopencookie.h
83+++ b/ext/solv_xfopen_fallback_fopencookie.h
84@@ -1,13 +1,13 @@
85-/*
86+/*
87 * Provides a very limited fopencookie() for environments with a libc
88 * that lacks it.
89- *
90- * Author: zhasha
91+ *
92+ * Authors: zhasha & nsz
93 * Modified for libsolv by Neal Gompa
94- *
95+ *
96 * This program is licensed under the BSD license, read LICENSE.BSD
97 * for further information.
98- *
99+ *
100 */
101
102 #ifndef SOLV_XFOPEN_FALLBACK_FOPENCOOKIE_H
103--
Brad Bishop316dfdd2018-06-25 12:45:53 -04001042.4.0
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500105