Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Nov 2010 15:32:00 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r215303 - in head/bin/sh: . bltin
Message-ID:  <201011141532.oAEFW0VK085939@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 *);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201011141532.oAEFW0VK085939>