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:
parent
3b447c3b43
commit
c1993d25d9
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,6 +4,7 @@
|
|||
/lib/
|
||||
/libwrk/
|
||||
/target/
|
||||
/test/ref/test_fgets.out
|
||||
/testwrk/
|
||||
/wrk/
|
||||
/cc65.zip
|
||||
|
|
57
test/ref/test_fgets.c
Normal file
57
test/ref/test_fgets.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user