From e735ad6710a82604a206ad29f6cbcdd7dc4b024c Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sun, 14 May 2023 21:43:02 -0400 Subject: refactor and add su --- lib/file.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/file.c') diff --git a/lib/file.c b/lib/file.c index f89b489..4af665d 100644 --- a/lib/file.c +++ b/lib/file.c @@ -1,6 +1,4 @@ -#include "file.h" -#include "error.h" -#include "convert.h" +#include "lslib.h" #include #include @@ -21,7 +19,7 @@ FILE* get_file_s(const char* path, const char* type) { if (lstat(path, &s) < 0) { if (type[0] != 'r') goto read; - error_s("failed to read %s: %s", path, strerror(errno)); + error_s("failed to read %s", path); return NULL; } @@ -35,7 +33,7 @@ read: file = fopen(path, type); if (file == NULL) { - error_s("failed to %s file %s: %s", type[0] == 'r' ? "read" : "write", path, strerror(errno)); + error_s("failed to %s file %s", type[0] == 'r' ? "read" : "write", path); } return file; @@ -48,8 +46,8 @@ FILE* get_file(const char* path, const char* type) { } int get_tty (void) { - int fd = open(_PATH_TTY, O_RDONLY); - if (fd < 0) error("failed to get tty: %s", strerror(errno)); + int fd = open(_PATH_TTY, O_RDONLY | O_NOCTTY | O_SYNC); + if (fd < 0) error("failed to get tty"); return fd; } @@ -57,7 +55,7 @@ FILE* get_tty_stream(char* type) { int fd = get_tty(); FILE* file = fdopen(fd, type); if (file == NULL) { - error("failed to open tty stream: %s", strerror(errno)); + error("failed to open tty stream"); } return file; } -- cgit v1.2.3-freya