From: Heng Li Date: Mon, 16 Jan 2012 02:49:51 +0000 (-0500) Subject: use fread() instead of fgetc() in example X-Git-Tag: spawn-final~72 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=4c51aae7d651466589be5fc23d19af0e9faa6745;p=klib.git use fread() instead of fgetc() in example --- diff --git a/kopen.c b/kopen.c index e228aa9..04b24b0 100644 --- a/kopen.c +++ b/kopen.c @@ -308,10 +308,12 @@ int kclose(void *a) } #ifdef _KO_MAIN +#define BUF_SIZE 0x10000 int main(int argc, char *argv[]) { void *x; - int fd, c; + int l, fd; + unsigned char buf[BUF_SIZE]; FILE *fp; if (argc == 1) { fprintf(stderr, "Usage: kopen \n"); @@ -323,11 +325,10 @@ int main(int argc, char *argv[]) fprintf(stderr, "ERROR: fail to open the input\n"); return 1; } - while (1) { - c = fgetc(fp); - if (feof(fp)) break; - putchar(c); - } + do { + if ((l = fread(buf, 1, BUF_SIZE, fp)) != 0) + fwrite(buf, 1, l, stdout); + } while (l == BUF_SIZE); fclose(fp); kclose(x); return 0;