sh: Add binary buffered output for use by the printf builtin.
This commit is contained in:
parent
fb772a6c98
commit
c3f57269e6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=215303
@ -54,6 +54,7 @@
|
||||
#define putchar(c) out1c(c)
|
||||
#define fprintf outfmt
|
||||
#define fputs outstr
|
||||
#define fwrite(ptr, size, nmemb, file) outbin(ptr, (size) * (nmemb), file)
|
||||
#define fflush flushout
|
||||
#define INITARGS(argv)
|
||||
#define warnx1(a, b, c) { \
|
||||
|
@ -122,8 +122,7 @@ out2qstr(const char *p)
|
||||
void
|
||||
outstr(const char *p, struct output *file)
|
||||
{
|
||||
while (*p)
|
||||
outc(*p++, file);
|
||||
outbin(p, strlen(p), file);
|
||||
}
|
||||
|
||||
/* Like outstr(), but quote for re-input into the shell. */
|
||||
@ -165,6 +164,16 @@ outqstr(const char *p, struct output *file)
|
||||
outc('\'', file);
|
||||
}
|
||||
|
||||
void
|
||||
outbin(const void *data, size_t len, struct output *file)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
p = data;
|
||||
while (len-- > 0)
|
||||
outc(*p++, file);
|
||||
}
|
||||
|
||||
static char out_junk[16];
|
||||
|
||||
void
|
||||
@ -285,17 +294,11 @@ static int
|
||||
doformat_wr(void *cookie, const char *buf, int len)
|
||||
{
|
||||
struct output *o;
|
||||
int origlen;
|
||||
unsigned char c;
|
||||
|
||||
o = (struct output *)cookie;
|
||||
origlen = len;
|
||||
while (len-- != 0) {
|
||||
c = (unsigned char)*buf++;
|
||||
outc(c, o);
|
||||
}
|
||||
outbin(buf, len, o);
|
||||
|
||||
return (origlen);
|
||||
return (len);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -36,6 +36,7 @@
|
||||
#ifndef OUTPUT_INCL
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct output {
|
||||
char *nextc;
|
||||
@ -59,6 +60,7 @@ void out2str(const char *);
|
||||
void out2qstr(const char *);
|
||||
void outstr(const char *, struct output *);
|
||||
void outqstr(const char *, struct output *);
|
||||
void outbin(const void *, size_t, struct output *);
|
||||
void emptyoutbuf(struct output *);
|
||||
void flushall(void);
|
||||
void flushout(struct output *);
|
||||
|
Loading…
Reference in New Issue
Block a user