summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2010-11-14 15:31:59 +0000
committerjilles <jilles@FreeBSD.org>2010-11-14 15:31:59 +0000
commit808b93da2eb6ef8566357c705d038cf597718cd5 (patch)
tree960f01c2f76ed659f7b40abffbbabae8e71c6a34
parent3f7f99e32bfd4a62f3516eb46a43d84639f51f92 (diff)
downloadFreeBSD-src-808b93da2eb6ef8566357c705d038cf597718cd5.zip
FreeBSD-src-808b93da2eb6ef8566357c705d038cf597718cd5.tar.gz
sh: Add binary buffered output for use by the printf builtin.
-rw-r--r--bin/sh/bltin/bltin.h1
-rw-r--r--bin/sh/output.c23
-rw-r--r--bin/sh/output.h2
3 files changed, 16 insertions, 10 deletions
diff --git a/bin/sh/bltin/bltin.h b/bin/sh/bltin/bltin.h
index c4bf8b6..0fc8a28 100644
--- a/bin/sh/bltin/bltin.h
+++ b/bin/sh/bltin/bltin.h
@@ -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) { \
diff --git a/bin/sh/output.c b/bin/sh/output.c
index 9fd8478..d7fc534 100644
--- a/bin/sh/output.c
+++ b/bin/sh/output.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
diff --git a/bin/sh/output.h b/bin/sh/output.h
index 345fe53..a7c748e 100644
--- a/bin/sh/output.h
+++ b/bin/sh/output.h
@@ -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 *);
OpenPOWER on IntegriCloud