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