Mercurial > hg > Gears > Gears
changeset 967:64d713b3dba5
add setvbuf
author | ichikitakahiro <e165713@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 08 Apr 2021 20:49:46 +0900 |
parents | 9efaa40e56fa |
children | d082c861d5c2 |
files | src/parallel_execution/examples/wc/WcImpl.cbc |
diffstat | 1 files changed, 22 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/examples/wc/WcImpl.cbc Tue Apr 06 19:47:33 2021 +0900 +++ b/src/parallel_execution/examples/wc/WcImpl.cbc Thu Apr 08 20:49:46 2021 +0900 @@ -2,6 +2,8 @@ #include <stdio.h> #impl "Wc.h" as "WcImpl.h" #interface "WcResult.h" +#include <stdlib.h> +#define BUFFERING_MODE _IOLBF Wc* createWcImpl(struct Context* context, char* filename) { struct Wc* wc = new Wc(); @@ -21,7 +23,7 @@ printf("ファイルが開ませんでした\n"); exit(1); } else { - printf("file open"); + printf("file open\n"); } wc->file = (union Data*)file; goto countUp(wc, next); @@ -40,6 +42,7 @@ Count char TODO */ + /* int N = 256; char str[N]; int line = 0; @@ -49,4 +52,22 @@ } printf("line = %d\n", line); //goto countUp(wc, next); + */ + + static char stdinBuf[BUFSIZ]; + static char stdoutBuf[BUFSIZ]; + int LINE_SIZE = 1024; + char line[LINE_SIZE]; + + if( setvbuf( wc->file, stdinBuf, BUFFERING_MODE, sizeof(stdinBuf)) != 0 ){ + fputs("stdinのバッファリングを変更できませんでした。", stderr); + exit(EXIT_FAILURE); + } else { + printf("setvbuf\n"); + } + while(fgets(line, LINE_SIZE, wc->file)!=NULL){ + printf("%s", line); + } + + }