Repository: Konstantin8105/c4go
Pull request #424 (2019-04-24 07:22:36)

CSTD: stdio.h: setbuf, setvbuf

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/424?src=pr&el=h1) Report
> Merging [#424](https://codecov.io/gh/Konstantin8105/c4go/pull/424?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/c229ad8e8d4de1dace072d2ff0cc0464a19469c3?src=pr&el=desc) will **increase** coverage by `0.03%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/424/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/424?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #424      +/-   ##
==========================================
+ Coverage   85.07%   85.11%   +0.03%     
==========================================
  Files         191      191              
  Lines       11637    11640       +3     
==========================================
+ Hits         9900     9907       +7     
+ Misses       1259     1256       -3     
+ Partials      478      477       -1
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/424?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/call.go](https://codecov.io/gh/Konstantin8105/c4go/pull/424/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9jYWxsLmdv) | `77.77% <100%> (+0.6%)` | :arrow_up: |
| [noarch/stdio.go](https://codecov.io/gh/Konstantin8105/c4go/pull/424/diff?src=pr&el=tree#diff-bm9hcmNoL3N0ZGlvLmdv) | `80.8% <0%> (+0.67%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/424?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/424?src=pr&el=footer). Last update [c229ad8...4786015](https://codecov.io/gh/Konstantin8105/c4go/pull/424?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index 2c373f0..7154aac 100644
--- a/README.md
+++ b/README.md
@@ -302,7 +302,7 @@ func c4goUnsafeConvert_int32(c4go_name *int32) []int32 {
             signal.h	       3/3	         100%
             stdarg.h	       4/4	         100%
             stddef.h	       3/4	          75%
-             stdio.h	     35/41	        85.4%
+             stdio.h	     37/41	        90.2%
             stdlib.h	     30/37	        81.1%
             string.h	     21/24	        87.5%
               time.h	     14/15	        93.3%
diff --git a/scripts/scripts.txt b/scripts/scripts.txt
index 1fea6b8..23793c1 100644
--- a/scripts/scripts.txt
+++ b/scripts/scripts.txt
@@ -12,7 +12,7 @@ Calculate warnings : ./testdata/9wm
 Calculate warnings : ./testdata/ed
 		After transpiling : 0 warnings.
 		Go build : 7 warnings
-		Unsafe   : 168
+		Unsafe   : 167
 
 Calculate warnings in file: ./testdata/kilo/kilo.go
 		After transpiling : 0 warnings.
@@ -72,7 +72,7 @@ Calculate warnings in file: ./testdata/progress/progress.go
 Calculate warnings in file: ./testdata/SQLITE/sqlite.go
 		After transpiling : 1 warnings.
 		Go build : 1 warnings
-		Unsafe   : 2405
+		Unsafe   : 2404
 
 Calculate warnings in file: ./testdata/tiny-web-server/tiny-web-server.go
 		After transpiling : 0 warnings.
diff --git a/transpiler/call.go b/transpiler/call.go
index 8075cf4..1c310d4 100644
--- a/transpiler/call.go
+++ b/transpiler/call.go
@@ -262,6 +262,12 @@ func transpileCallExpr(n *ast.CallExpr, p *program.Program) (
 		p.SetCalled(functionName)
 	}
 
+	if p.IncludeHeaderIsExists("stdio.h") &&
+		(functionName == "setbuf" || functionName == "setvbuf") {
+		// ignore function
+		return
+	}
+
 	// function "calloc" from stdlib.h
 	if p.IncludeHeaderIsExists("stdlib.h") {
 		if functionName == "calloc" && len(n.Children()) == 3 {


Test patch:
diff --git a/tests/stdio.c b/tests/stdio.c
index d90ac38..1bc30bd 100644
--- a/tests/stdio.c
+++ b/tests/stdio.c
@@ -638,50 +638,80 @@ void test_vfprintf()
    fclose (pFile);
 }
 
+void test_setbuf()
+{
+  char buffer[BUFSIZ];
+  FILE *pFile1, *pFile2;
+
+  pFile1=fopen ("./testdata/setbuf.txt","w");
+  pFile2=fopen ("./testdata/setbuf2.txt","a");
+
+  setbuf ( pFile1 , buffer );
+  fputs ("This is sent to a buffered stream",pFile1);
+  fflush (pFile1);
+
+  setbuf ( pFile2 , NULL );
+  fputs ("This is sent to an unbuffered stream",pFile2);
+
+  fclose (pFile1);
+  fclose (pFile2);
+  (void)(buffer);
+}
+
+void test_setvbuf()
+{
+  FILE *pFile;
+  pFile=fopen ("./testdata/detvbuf.txt","w");
+  setvbuf ( pFile , NULL , _IOFBF , 1024 );
+  fclose (pFile);
+}
+
 int main()
 {
     plan(71);
 
-    START_TEST(putchar)
-    START_TEST(puts)
-    START_TEST(printf)
-    START_TEST(remove)
-    START_TEST(rename)
-    START_TEST(fopen)
-    START_TEST(tmpfile)
-    START_TEST(tmpnam)
-    START_TEST(fclose)
-    START_TEST(fflush)
-    START_TEST(printf)
-    START_TEST(fprintf)
-    START_TEST(fscanf)
-    START_TEST(fgetc)
-    START_TEST(fgets)
-    START_TEST(fputc)
-    START_TEST(fputs)
-    START_TEST(getc)
-    START_TEST(putc)
-    START_TEST(fseek)
-    START_TEST(ftell)
-    START_TEST(fread)
-    START_TEST(fwrite)
-    START_TEST(fgetpos)
-    START_TEST(fsetpos)
-    START_TEST(rewind)
-    START_TEST(feof)
-    START_TEST(sprintf)
-    START_TEST(snprintf)
-    START_TEST(vsprintf)
-    START_TEST(vsnprintf)
-    START_TEST(eof)
-    START_TEST(getline)
-    START_TEST(sscanf)
-    START_TEST(FILE)
-    START_TEST(vprintf)
-    START_TEST(vfprintf)
+    START_TEST(putchar);
+    START_TEST(puts);
+    START_TEST(printf);
+    START_TEST(remove);
+    START_TEST(rename);
+    START_TEST(fopen);
+    START_TEST(tmpfile);
+    START_TEST(tmpnam);
+    START_TEST(fclose);
+    START_TEST(fflush);
+    START_TEST(printf);
+    START_TEST(fprintf);
+    START_TEST(fscanf);
+    START_TEST(fgetc);
+    START_TEST(fgets);
+    START_TEST(fputc);
+    START_TEST(fputs);
+    START_TEST(getc);
+    START_TEST(putc);
+    START_TEST(fseek);
+    START_TEST(ftell);
+    START_TEST(fread);
+    START_TEST(fwrite);
+    START_TEST(fgetpos);
+    START_TEST(fsetpos);
+    START_TEST(rewind);
+    START_TEST(feof);
+    START_TEST(sprintf);
+    START_TEST(snprintf);
+    START_TEST(vsprintf);
+    START_TEST(vsnprintf);
+    START_TEST(eof);
+    START_TEST(getline);
+    START_TEST(sscanf);
+    START_TEST(FILE);
+    START_TEST(vprintf);
+    START_TEST(vfprintf);
+    START_TEST(setbuf);
+    START_TEST(setvbuf);
 
     // that test must be last test
-    START_TEST(perror)
+    START_TEST(perror);
 
     done_testing();
 }