Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSTD: stdio.h: ungetc: prepare #298

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,28 @@ void test_sscanf()
is_streq(str, "Rudolph");
}

void test_ungetc()
{
FILE * fp;
int c;
char buffer [256];

fp = fopen ("./tests/stdio_ungetc.txt","r");
is_not_null(fp);

while(!feof(fp)) {
c = getc (fp);
/* replace ! with + */
if( c == '!' ) {
ungetc ('+', fp);
} else {
ungetc(c, fp);
}
fgets(buffer, 255, fp);
fputs(buffer, stdout);
}
}

void test_FILE()
{
FILE* p = stdout;
Expand Down Expand Up @@ -719,11 +741,13 @@ int main()
START_TEST(eof);
START_TEST(getline);
START_TEST(sscanf);

START_TEST(FILE);
START_TEST(vprintf);
START_TEST(vfprintf);
START_TEST(setbuf);
START_TEST(setvbuf);
START_TEST(ungetc);

// that test must be last test
START_TEST(perror);
Expand Down
3 changes: 3 additions & 0 deletions tests/stdio_ungetc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
this is tutorials point
!c standard library
!library functions and macros
4 changes: 3 additions & 1 deletion transpiler/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ func ResolveCgoType(p *program.Program, goType string, expr goast.Expr) (a goast

t := goType

if strings.HasPrefix(goType, "[][]") {
if t == "*noarch.File" {
return util.NewCallExpr("*C.struct__IO_FILE", expr), nil
} else if strings.HasPrefix(goType, "[][]") {
t = "interface{}"
} else if strings.HasPrefix(goType, "[") {
// []int -> * _Ctype_int
Expand Down