2017-10-21 23:40:19 +00:00
|
|
|
/* Conformance Test 17.7.0.2: Verification of fgets function, binary stream */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2022-10-17 22:50:42 +00:00
|
|
|
#include <string.h>
|
2017-10-21 23:40:19 +00:00
|
|
|
|
2022-10-17 22:50:42 +00:00
|
|
|
int main (void)
|
2017-10-21 23:40:19 +00:00
|
|
|
{
|
|
|
|
FILE *f1;
|
|
|
|
int i;
|
|
|
|
char string [80] = ""; /* initialize input string to null string */
|
|
|
|
char *strPtr;
|
|
|
|
|
|
|
|
|
|
|
|
f1 = fopen ("3/tmp", "w+b"); /* create binary file to work on */
|
|
|
|
if (f1 == NULL)
|
|
|
|
goto Fail1;
|
|
|
|
i = fputs ("Every good boy deserves favor\n", f1);
|
|
|
|
if (i)
|
|
|
|
goto Fail2;
|
|
|
|
|
|
|
|
rewind (f1); /* test reading until '\n' seen */
|
|
|
|
strPtr = fgets (string, 100, f1);
|
|
|
|
if (strPtr == NULL)
|
|
|
|
goto Fail;
|
|
|
|
if (strcmp ("Every good boy deserves favor\n", string))
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
fgetc(f1); /* force an EOF condition */
|
|
|
|
strPtr = fgets (string, 100, f1); /* test reading with EOF seen before */
|
|
|
|
if (strPtr != NULL) /* any other characters */
|
|
|
|
goto Fail;
|
|
|
|
if (! (feof (f1)) )
|
|
|
|
goto Fail;
|
|
|
|
if (strcmp ("Every good boy deserves favor\n", string))
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
rewind (f1); /* test reading until n-1 chars seen */
|
|
|
|
strPtr = fgets (string, 15, f1);
|
|
|
|
if (strPtr == NULL)
|
|
|
|
goto Fail;
|
|
|
|
if (strcmp ("Every good boy", string))
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
strPtr = fgets (string, 17, f1); /* ensure fgets moves internal file */
|
|
|
|
if (strPtr == NULL) /* pointer */
|
|
|
|
goto Fail;
|
|
|
|
if (strcmp (" deserves favor\n", string))
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
fgetc(f1); /* force an EOF condition */
|
|
|
|
strPtr = fgets (string, 100, f1); /* test reading with EOF seen before */
|
|
|
|
if (strPtr != NULL) /* any other characters */
|
|
|
|
goto Fail;
|
|
|
|
if (! (feof (f1)) )
|
|
|
|
goto Fail;
|
|
|
|
if (strcmp (" deserves favor\n", string))
|
|
|
|
goto Fail;
|
|
|
|
|
|
|
|
i = fclose (f1); /* close file and quit */
|
|
|
|
if (i)
|
|
|
|
goto Fail3;
|
|
|
|
|
|
|
|
printf ("Passed Conformance Test 17.7.0.2\n");
|
2022-10-17 22:50:42 +00:00
|
|
|
return 0;
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
Fail:
|
|
|
|
printf ("Failed Conformance Test 17.7.0.2\n");
|
2022-10-17 22:50:42 +00:00
|
|
|
return 0;
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
Fail1:
|
|
|
|
printf ("Unable to open temp file for Conformance Test 17.7.0.2\n");
|
2022-10-17 22:50:42 +00:00
|
|
|
return 0;
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
Fail2:
|
|
|
|
printf ("Unable to write to temp file for Conformance Test 17.7.0.2\n");
|
2022-10-17 22:50:42 +00:00
|
|
|
return 0;
|
2017-10-21 23:40:19 +00:00
|
|
|
|
|
|
|
Fail3:
|
|
|
|
printf ("Unable to close temp file for Conformance Test 17.7.0.2\n");
|
2022-10-17 22:50:42 +00:00
|
|
|
return 0;
|
2017-10-21 23:40:19 +00:00
|
|
|
}
|