1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-08 15:29:37 +00:00

add fgets test

This commit is contained in:
Colin Leroy-Mira 2024-01-11 18:30:13 +01:00
parent 3b447c3b43
commit c1993d25d9
2 changed files with 58 additions and 0 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@
/lib/
/libwrk/
/target/
/test/ref/test_fgets.out
/testwrk/
/wrk/
/cc65.zip

57
test/ref/test_fgets.c Normal file
View File

@ -0,0 +1,57 @@
/*
!!DESCRIPTION!! fgets test
!!LICENCE!! Public domain
*/
#include "common.h"
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
FILE *in, *out;
char buf[32];
#define INFILE "cf.in"
#define OUTFILE "test_fgets.out"
#ifdef NO_OLD_FUNC_DECL
int main(int argc,char **argv)
#else
main(argc, argv)
int argc;
char *argv[];
#endif
{
out = fopen(OUTFILE, "wb");
if (out == NULL) {
return EXIT_FAILURE;
}
if (fgets(buf, sizeof(buf), out) != NULL) {
printf("Error, could fgets with write-only file\n");
return 1;
}
if (!ferror(out)) {
printf("Error: file pointer should be in error state\n");
}
fclose(out);
in = fopen(INFILE, "rb");
if (in == NULL) {
return EXIT_FAILURE;
}
if (fgets(NULL, 0, in) != NULL) {
printf("Error, could fgets with zero size\n");
return 1;
}
while (fgets(buf, sizeof(buf), in) != NULL)
{
printf("%s",buf);
}
fclose(in);
return 0;
}