Files
manticore/examples/linux/fclose.c
Brad Larsen 2527fa5c40 Add a native example program & test case for #1604 (#1606)
* Organize examples in Makefile

* .gitignore binaries created in examples/linux

* Add a new Linux example using fclose

* Add a test case for the fclose example binary

See also #1602 and #1604.

* Add a comment for the change from #1604

* Delete an obsolete comment

* Add type hints to native integration tests

* Do not squelch command output from test

* Use `--worksapce` for `test_logger_verbosity`

This should prevent extra mcore_* directories from hanging around after testing.

* Reformat test_integration_native.py via `black`
2020-02-04 09:22:53 -08:00

32 lines
782 B
C

// This example closes file descriptors 0, 1, and 2 (which correspond to stdin,
// stdout, and stderr in most environments).
//
// This serves as a reduced testcase for what most of the programs in GNU
// coreutils do. See #1602 and #1604 on GitHub.
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv) {
if (argc >= 2 && strcmp(argv[1], "--close") == 0) {
fprintf(stdout, "Closing file handles!\n");
int rc = 0;
if (fclose(stdin) != 0) {
rc += 1;
}
if (fclose(stdout) != 0) {
rc += 2;
}
if (fclose(stderr) != 0) {
rc += 4;
}
return rc;
} else {
fprintf(stdout, "Not doing anything.\n");
return 0;
}
}