zerotrunc: from Plan 9
R=rsc CC=plan9port.codebot http://codereview.appspot.com/4809089
This commit is contained in:
parent
f6d2cbfe47
commit
b6863de7e1
1 changed files with 26 additions and 0 deletions
26
src/cmd/zerotrunc.c
Normal file
26
src/cmd/zerotrunc.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* cat standard input until you get a zero byte
|
||||
*/
|
||||
|
||||
#include <u.h>
|
||||
#include <libc.h>
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
char buf[4096];
|
||||
char *p;
|
||||
int n;
|
||||
|
||||
while((n = read(0, buf, sizeof(buf))) > 0){
|
||||
p = memchr(buf, 0, n);
|
||||
if(p != nil)
|
||||
n = p-buf;
|
||||
if(n > 0)
|
||||
write(1, buf, n);
|
||||
if(p != nil)
|
||||
break;
|
||||
}
|
||||
exits(0);
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue