svn commit: r215303 - in head/bin/sh: . bltin
Jilles Tjoelker
jilles at FreeBSD.org
Sun Nov 14 15:32:00 UTC 2010
Author: jilles
Date: Sun Nov 14 15:31:59 2010
New Revision: 215303
URL: http://svn.freebsd.org/changeset/base/215303
Log:
sh: Add binary buffered output for use by the printf builtin.
Modified:
head/bin/sh/bltin/bltin.h
head/bin/sh/output.c
head/bin/sh/output.h
Modified: head/bin/sh/bltin/bltin.h
==============================================================================
--- head/bin/sh/bltin/bltin.h Sun Nov 14 15:15:22 2010 (r215302)
+++ head/bin/sh/bltin/bltin.h Sun Nov 14 15:31:59 2010 (r215303)
@@ -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) { \
Modified: head/bin/sh/output.c
==============================================================================
--- head/bin/sh/output.c Sun Nov 14 15:15:22 2010 (r215302)
+++ head/bin/sh/output.c Sun Nov 14 15:31:59 2010 (r215303)
@@ -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 *fi
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
Modified: head/bin/sh/output.h
==============================================================================
--- head/bin/sh/output.h Sun Nov 14 15:15:22 2010 (r215302)
+++ head/bin/sh/output.h Sun Nov 14 15:31:59 2010 (r215303)
@@ -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 *);
More information about the svn-src-head
mailing list