summaryrefslogtreecommitdiffstats
path: root/source/ap/ash/patches/ash-memout.patch
blob: 1bfedadaa27f5ea8bb3c249b17f565bb1efe7da0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
diff -u ash-0.4.0/eval.c ash-0.4.0-/eval.c
--- ash-0.4.0/eval.c	Tue Apr 24 00:53:12 2001
+++ ash-0.4.0-/eval.c	Tue Apr 24 00:13:57 2001
@@ -879,9 +879,13 @@
 #endif
 		mode = (cmdentry.u.index == EXECCMD)? 0 : REDIR_PUSH;
 		if (flags == EV_BACKCMD) {
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+			openmemout();
+#else
 			memout.nleft = 0;
 			memout.nextc = memout.buf;
 			memout.bufsize = 64;
+#endif
 			mode |= REDIR_BACKQ;
 		}
 		redirect(cmd->ncmd.redirect, mode);
@@ -928,10 +932,18 @@
 		if (cmdentry.u.index != EXECCMD)
 			popredir();
 		if (flags == EV_BACKCMD) {
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+			closememout();
+#endif
 			backcmd->buf = memout.buf;
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+			backcmd->nleft = memout.bufsize;
+#else
 			backcmd->nleft = memout.nextc - memout.buf;
+#endif
 			memout.buf = NULL;
 		}
+		cmdenviron = NULL;
 	} else {
 #ifdef DEBUG
 		trputs("normal command:  ");  trargs(argv);
Common subdirectories: ash-0.4.0/funcs and ash-0.4.0-/funcs
diff -u ash-0.4.0/output.c ash-0.4.0-/output.c
--- ash-0.4.0/output.c	Fri Jan 12 17:50:39 2001
+++ ash-0.4.0-/output.c	Tue Apr 24 00:43:44 2001
@@ -65,6 +65,10 @@
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+#undef CEOF			/* get rid of the redefine warning */
+#include <fcntl.h>
+#endif
 
 #include "shell.h"
 #include "syntax.h"
@@ -79,9 +83,15 @@
 #define OUTPUT_ERR 01		/* error occurred on output */
 
 
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+struct output output = {NULL, NULL, 0, NULL, 0, 1, 0};
+struct output errout = {NULL, NULL, 0, NULL, 0, 2, 0};
+struct output memout = {NULL, NULL, 0, NULL, 0, MEM_OUT, 0};
+#else
 struct output output = {NULL, 0, NULL, OUTBUFSIZ, 1, 0};
 struct output errout = {NULL, 0, NULL, 100, 2, 0};
 struct output memout = {NULL, 0, NULL, 0, MEM_OUT, 0};
+#endif
 struct output *out1 = &output;
 struct output *out2 = &errout;
 
@@ -92,9 +102,19 @@
 INCLUDE "output.h"
 INCLUDE "memalloc.h"
 
+INIT {
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+	initstreams();
+#endif
+}
+
 RESET {
 	out1 = &output;
 	out2 = &errout;
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+	if (memout.stream != NULL)
+		closememout();
+#endif
 	if (memout.buf != NULL) {
 		ckfree(memout.buf);
 		memout.buf = NULL;
@@ -124,33 +144,22 @@
 
 
 void
-out1str(p)
-	const char *p;
-	{
-	outstr(p, out1);
-}
-
-
-void
-out2str(p)
-	const char *p;
-	{
-	outstr(p, out2);
-}
-
-
-void
 outstr(p, file)
 	const char *p;
 	struct output *file;
 	{
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+	fputs(p, file->stream);
+#else
 	while (*p)
 		outc(*p++, file);
+#endif
 	if (file == out2)
 		flushout(file);
 }
 
 
+#if !defined(_GNU_SOURCE) || defined(__UCLIBC__)
 char out_junk[16];
 
 
@@ -183,6 +192,7 @@
 	}
 	dest->nleft--;
 }
+#endif
 
 
 void
@@ -192,11 +202,11 @@
 }
 
 
+#if !defined(_GNU_SOURCE) || defined(__UCLIBC__)
 void
 flushout(dest)
 	struct output *dest;
 	{
-
 	if (dest->buf == NULL || dest->nextc == dest->buf || dest->fd < 0)
 		return;
 	if (xwrite(dest->fd, dest->buf, dest->nextc - dest->buf) < 0)
@@ -204,6 +214,7 @@
 	dest->nextc = dest->buf;
 	dest->nleft = dest->bufsize;
 }
+#endif
 
 
 void
@@ -264,6 +275,7 @@
 	va_end(ap);
 }
 
+#if !defined(__GLIBC__) && !defined(__UCLIBC__)
 void
 #ifdef __STDC__
 dprintf(const char *fmt, ...)
@@ -285,6 +297,7 @@
 	va_end(ap);
 	flushout(out2);
 }
+#endif
 
 void
 #ifdef __STDC__
@@ -295,7 +308,9 @@
 #endif
 {
 	va_list ap;
+#if !defined(_GNU_SOURCE) || defined(__UCLIBC__)
 	struct output strout;
+#endif
 #ifndef __STDC__
 	char *outbuf;
 	size_t length;
@@ -308,6 +323,9 @@
 #else
 	va_start(ap, fmt);
 #endif
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+	vsnprintf(outbuf, length, fmt, ap);
+#else
 	strout.nextc = outbuf;
 	strout.nleft = length;
 	strout.fd = BLOCK_OUT;
@@ -316,8 +334,10 @@
 	outc('\0', &strout);
 	if (strout.flags & OUTPUT_ERR)
 		outbuf[length - 1] = '\0';
+#endif
 }
 
+#if !defined(_GNU_SOURCE) || defined(__UCLIBC__)
 /*
  * Formatted output.  This routine handles a subset of the printf formats:
  * - Formats supported: d, u, o, p, X, s, and c.
@@ -534,7 +554,7 @@
 	}
 #endif	/* !HAVE_VASPRINTF */
 }
-
+#endif
 
 
 /*
@@ -544,7 +564,7 @@
 int
 xwrite(fd, buf, nbytes)
 	int fd;
-	char *buf;
+	const char *buf;
 	int nbytes;
 	{
 	int ntry;
@@ -570,6 +590,8 @@
 }
 
 
+
+#ifdef notdef
 /*
  * Version of ioctl that retries after a signal is caught.
  * XXX unused function
@@ -586,3 +608,27 @@
 	while ((i = ioctl(fd, request, arg)) == -1 && errno == EINTR);
 	return i;
 }
+#endif
+
+
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+void initstreams() {
+	output.stream = stdout;
+	errout.stream = stderr;
+}
+
+
+void
+openmemout() {
+	memout.stream = open_memstream(&memout.buf, &memout.bufsize);
+}
+
+
+void
+closememout() {
+	INTOFF;
+	fclose(memout.stream);
+	memout.stream = NULL;
+	INTON;
+}
+#endif
diff -u ash-0.4.0/output.h ash-0.4.0-/output.h
--- ash-0.4.0/output.h	Sat Jan 31 19:28:11 1998
+++ ash-0.4.0-/output.h	Tue Apr 24 00:13:57 2001
@@ -45,13 +45,19 @@
 #else
 #include <varargs.h>
 #endif
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+#include <stdio.h>
+#endif
 
 struct output {
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+	FILE *stream;
+#endif
 	char *nextc;
 	int nleft;
 	char *buf;
 	int bufsize;
-	short fd;
+	int fd;
 	short flags;
 };
 
@@ -61,29 +67,44 @@
 extern struct output *out1;
 extern struct output *out2;
 
-void open_mem __P((char *, int, struct output *));
-void out1str __P((const char *));
-void out2str __P((const char *));
 void outstr __P((const char *, struct output *));
+#ifndef _GNU_SOURCE
 void emptyoutbuf __P((struct output *));
+#endif
 void flushall __P((void));
+#ifndef _GNU_SOURCE
 void flushout __P((struct output *));
+#endif
 void freestdout __P((void));
 void outfmt __P((struct output *, const char *, ...))
     __attribute__((__format__(__printf__,2,3)));
 void out1fmt __P((const char *, ...))
     __attribute__((__format__(__printf__,1,2)));
+#if !defined(__GLIBC__) && !defined(__UCLIBC__)
 void dprintf __P((const char *, ...))
     __attribute__((__format__(__printf__,1,2)));
+#endif
 void fmtstr __P((char *, size_t, const char *, ...))
     __attribute__((__format__(__printf__,3,4)));
+#ifndef _GNU_SOURCE
 void doformat __P((struct output *, const char *, va_list));
-int xwrite __P((int, char *, int));
-int xioctl __P((int, unsigned long, char *));
+#endif
+int xwrite __P((int, const char *, int));
+#if defined(_GNU_SOURCE) && !defined(__UCLIBC__)
+void initstreams __P((void));
+void openmemout __P((void));
+void closememout __P((void));
 
+#define outc(c, o)	putc(c, (o)->stream)
+#define flushout(o)	fflush((o)->stream)
+#define doformat(d, f, a)	vfprintf((d)->stream, f, a)
+#else
 #define outc(c, file)	(--(file)->nleft < 0? (emptyoutbuf(file), *(file)->nextc++ = (c)) : (*(file)->nextc++ = (c)))
-#define out1c(c)	outc(c, out1);
-#define out2c(c)	outc(c, out2);
+#endif
+#define out1c(c)	outc(c, out1)
+#define out2c(c)	outc(c, out2)
+#define out1str(s)	outstr(s, out1)
+#define out2str(s)	outstr(s, out2)
 
 #define OUTPUT_INCL
 #endif