Clean up the code around isatty() a bit
This commit is contained in:
parent
dbf52344ae
commit
4bd21e0e17
3 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
||||||
#include "fio.hpp"
|
#include "fio.hpp"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
Result<String> read_fh(FILE* file) {
|
Result<String> read_fh(FILE* file) {
|
||||||
|
@ -37,3 +39,7 @@ Result<String> read_file(const char* filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<String> read_stdin() { return read_fh(stdin); }
|
Result<String> read_stdin() { return read_fh(stdin); }
|
||||||
|
|
||||||
|
// TODO: though unlikely, but isatty can possibly set an error. Need to check it
|
||||||
|
// someday.
|
||||||
|
bool stdin_isatty() { return isatty(STDIN_FILENO); }
|
||||||
|
|
|
@ -5,3 +5,4 @@
|
||||||
Result<String> read_file(const char* filename);
|
Result<String> read_file(const char* filename);
|
||||||
|
|
||||||
Result<String> read_stdin();
|
Result<String> read_stdin();
|
||||||
|
bool stdin_isatty();
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "arena.hpp"
|
#include "arena.hpp"
|
||||||
|
@ -17,7 +14,7 @@ StaticArena<64 * 1024 * 1024> arena;
|
||||||
Result<void> run(int argc, const char* argv[]) {
|
Result<void> run(int argc, const char* argv[]) {
|
||||||
String src = DIEX(String::create(""));
|
String src = DIEX(String::create(""));
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
if (isatty(STDIN_FILENO)) {
|
if (stdin_isatty()) {
|
||||||
die("Code expected at stdin, not a tty.\n");
|
die("Code expected at stdin, not a tty.\n");
|
||||||
}
|
}
|
||||||
src = TRY(read_stdin());
|
src = TRY(read_stdin());
|
||||||
|
|
Loading…
Reference in a new issue