On Thu, Jun 21, 2018 at 10:57:40AM +0200, Maximilian Pichler wrote:
> > dd ibs=1 count=n
>
> Nice, this is about three time as fast as bs=1. Both are much slower
> than 'ghead -c'.
I think they meant dd and just didn't care about efficiency:
http://austingroupbugs.net/bug_view_page.php?bug_id=407
Does ghead -c beat a simple buffer loop?
Daniel
#include <stdio.h>
#include <stdlib.h>
#define BUFSIZE 65536
int main(int argc, char *argv[])
{
char buf[BUFSIZE];
size_t n, r;
if (argc != 2 || (n = atoi(argv[1])) < 1) {
fprintf(stderr, "usage: %s number\n", argv[0]);
return (1);
}
do {
r = fread(buf, 1, n > BUFSIZE ? BUFSIZE : n, stdin);
if (r > 0) {
fwrite(buf, 1, r, stdout);
n -= r;
}
} while (r > 0 && n > 0);
return (0);
}