From owner-svn-src-head@FreeBSD.ORG Sun Nov 14 15:32:00 2010 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6B15A106564A; Sun, 14 Nov 2010 15:32:00 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3E4418FC15; Sun, 14 Nov 2010 15:32:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oAEFW0jm085943; Sun, 14 Nov 2010 15:32:00 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oAEFW0VK085939; Sun, 14 Nov 2010 15:32:00 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201011141532.oAEFW0VK085939@svn.freebsd.org> From: Jilles Tjoelker Date: Sun, 14 Nov 2010 15:32:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r215303 - in head/bin/sh: . bltin X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Nov 2010 15:32:00 -0000 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 +#include 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 *);