MCPcopy Index your code
hub / github.com/GJDuck/e9patch / test_stdio

Function test_stdio

test/regtest/patch.cpp:758–875  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

756}
757
758void test_stdio(intptr_t arg)
759{
760 fprintf(stderr, "arg = 0x%llx\n", arg);
761
762 fprintf(stderr, "[0]\n");
763 FILE *stream = fopen("test.tmp", "w");
764 if (stream == NULL)
765 fprintf(stderr, "stream is NULL\n");
766 int n = fprintf(stream, "%s %10d %zd -%#lx %p\n%u\t%4hu\t \t%c 0%o\n",
767 "aaa", 101, arg, arg, (void *)arg, (unsigned)arg, (uint16_t)arg,
768 (char)arg, 0644);
769 fprintf(stderr, "pos = %zd vs %d\n", ftell(stream), n);
770 const char HELLO[] = "Hello World!";
771 int r = fwrite(HELLO, sizeof(char), sizeof(HELLO)-1, stream);
772 fprintf(stderr, "write = %d\n", r);
773 fseek(stream, 1, SEEK_SET);
774 fprintf(stderr, "getc() = %d\n", getc(stream));
775 fputs("bbb", stream);
776 fclose(stream);
777
778 fprintf(stderr, "[1]\n");
779 stream = fopen("test.tmp", "r");
780 if (stream == NULL)
781 fprintf(stderr, "stream is NULL\n");
782 fseek(stream, 4, SEEK_CUR);
783 fprintf(stderr, "pos = %zd\n", ftell(stream));
784 int i, j;
785 fscanf(stream, "%d", &i);
786 fprintf(stderr, "i = %d\n", i);
787 fseek(stream, 0, SEEK_SET);
788 getc(stream);
789 fprintf(stderr, "pos = %zd\n", ftell(stream));
790 ungetc('X', stream);
791 fprintf(stderr, "pos = %zd\n", ftell(stream));
792 char s[5];
793 fscanf(stream, " %5s", s);
794 fprintf(stderr, "s = \"%s\"\n", s);
795 char c1, c2, c3, c4;
796 s[2] = toupper(s[2]);
797 sscanf(s, "%c%c%c%c", &c1, &c2, &c3, &c4);
798 fprintf(stderr, "s = \"%c%c%c%c\"\n", c1, c2, c3, c4);
799 fclose(stream);
800
801 fprintf(stderr, "[2]\n");
802 stream = fopen("test.tmp", "r+");
803 if (stream == NULL)
804 fprintf(stderr, "stream is NULL\n");
805 char buf[5];
806 if (setvbuf(stream, buf, _IOLBF, sizeof(buf)) < 0)
807 fprintf(stderr, "setvbuf failed (%s)\n", strerror(errno));
808 fputs("cccc ", stream);
809 fprintf(stderr, "c = '%c'\n", getc(stream));
810 ungetc('7', stream);
811 intptr_t x, y;
812 void *p;
813 unsigned u;
814 uint16_t h;
815 char c;

Callers

nothing calls this directly

Calls 15

fopenFunction · 0.85
ftellFunction · 0.85
fwriteFunction · 0.85
fseekFunction · 0.85
getcFunction · 0.85
fputsFunction · 0.85
fcloseFunction · 0.85
fscanfFunction · 0.85
ungetcFunction · 0.85
toupperFunction · 0.85
sscanfFunction · 0.85
setvbufFunction · 0.85

Tested by

no test coverage detected