mirror of https://github.com/cc65/cc65.git
add fgets/fgetc test
This commit is contained in:
parent
ebf43ddb05
commit
f7388cfb79
|
@ -86,6 +86,10 @@ extern FILE* stderr;
|
||||||
# define FILENAME_MAX (80+1)
|
# define FILENAME_MAX (80+1)
|
||||||
#elif defined(__TELESTRAT__)
|
#elif defined(__TELESTRAT__)
|
||||||
# define FILENAME_MAX (50+1)
|
# define FILENAME_MAX (50+1)
|
||||||
|
#elif defined(__SIM6502__)
|
||||||
|
# define FILENAME_MAX (1024+1)
|
||||||
|
#elif defined(__SIM65C02__)
|
||||||
|
# define FILENAME_MAX (1024+1)
|
||||||
#else
|
#else
|
||||||
# define FILENAME_MAX (16+1)
|
# define FILENAME_MAX (16+1)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
!!DESCRIPTION!! fgets test
|
||||||
|
!!LICENCE!! Public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
FILE *in, *out;
|
||||||
|
char buf[32];
|
||||||
|
|
||||||
|
#define INFILE "cf.in"
|
||||||
|
|
||||||
|
int main(int argc,char **argv)
|
||||||
|
{
|
||||||
|
static char outfile_path[FILENAME_MAX+1];
|
||||||
|
|
||||||
|
sprintf(outfile_path, "%s.test.out", argv[0]);
|
||||||
|
|
||||||
|
out = fopen(outfile_path, "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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!feof(in))
|
||||||
|
{
|
||||||
|
printf("We should have EOF!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(in);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue