Is it possible to create a FILE * file in memory for a test?
Of course. To write:
char *buf;
size_t sz;
FILE *f = open_memstream(&buf, &sz);
// do stuff with `f`
fclose(f);
// here you can access the contents of `f` using `buf` and `sz`
free(buf); // when done
This is POSIX. Documents
For reading:
char buf[] = "Hello world! This is not a file, it just pretends to be one.";
FILE *f = fmemopen(buf, sizeof(buf), "r");
fclose(f);
This is also POSIX.
Sidenote:
I would like the test not to interact with the file system.
Why?
user529758
source
share