On Thu, 21 Jun 2018 00:56:04 +0200 Tomasz Rola <rto...@ceti.pl> wrote:
> On Thu, Jun 21, 2018 at 12:44:14AM +0200, Tomasz Rola wrote: > [...] > > => (591 60): cat nread > > #!/bin/sh > > > > # nread n - read up to n bytes from stdio, put them on to stdout > > > > N=$1 > > > > dd bs=512 count=$((N / 512)) iflag=fullblock 2>/dev/null > > dd bs=1 count=$((N % 512)) iflag=fullblock 2>/dev/null > > Craps. I have consulted OpenBSD's manpage for dd and there is no > mention of iflag. So this will not work on OpenBSD. I will have to > rethink this, sorry. > Untested... int main(int argc, char* argv[]){ long l = atod(argv[1]); while(l--){ if (c = getc(STDIN) != EOF) putc(c, STDOUT); else break; } return 0; } I haven't tested it so it might not be exactly right, and of course error handling would need to be added, but you know what I mean. IIRC getc() and putc() are very well buffered so it will be fast. In my youth I wrote similar functions using low level read() and write() and doing my own buffering, and those things were *really* fast, but I think that's overkill in this century. As far as finding command line tools that do it, if that's becoming hard to do, why not just write a 10 line program? -- SteveT Steve Litt June 2018 featured book: Twenty Eight Tales of Troubleshooting http://www.troubleshooters.com/28