summaryrefslogtreecommitdiffstats
path: root/src/bfstd.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2025-04-15 10:36:12 -0400
committerTavian Barnes <tavianator@tavianator.com>2025-04-15 10:36:12 -0400
commit99ee1a95551cd869c56f5ee0a07047a35e8900d6 (patch)
tree8a01538c5f7f14910d479d47f96c55ae682db46f /src/bfstd.c
parenta81e98b3db4948cba6a597387f96d10c08e4d75c (diff)
downloadbfs-99ee1a95551cd869c56f5ee0a07047a35e8900d6.tar.xz
bfstd: Add a tcgetwinsize() polyfill
Diffstat (limited to 'src/bfstd.c')
-rw-r--r--src/bfstd.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/bfstd.c b/src/bfstd.c
index 82663eb..64cc605 100644
--- a/src/bfstd.c
+++ b/src/bfstd.c
@@ -23,10 +23,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <termios.h>
#include <unistd.h>
#include <wchar.h>
@@ -187,16 +189,6 @@ char *xgetdelim(FILE *file, char delim) {
}
}
-int open_cterm(int flags) {
- char path[L_ctermid];
- if (ctermid(path) == NULL || strlen(path) == 0) {
- errno = ENOTTY;
- return -1;
- }
-
- return open(path, flags);
-}
-
const char *xgetprogname(void) {
const char *cmd = NULL;
#if BFS_HAS_GETPROGNAME
@@ -558,6 +550,24 @@ pid_t xwaitpid(pid_t pid, int *status, int flags) {
return ret;
}
+int open_cterm(int flags) {
+ char path[L_ctermid];
+ if (ctermid(path) == NULL || strlen(path) == 0) {
+ errno = ENOTTY;
+ return -1;
+ }
+
+ return open(path, flags);
+}
+
+int xtcgetwinsize(int fd, struct winsize *ws) {
+#if BFS_HAS_TCGETWINSIZE
+ return tcgetwinsize(fd, ws);
+#else
+ return ioctl(fd, TIOCGWINSZ, ws);
+#endif
+}
+
int dup_cloexec(int fd) {
#ifdef F_DUPFD_CLOEXEC
return fcntl(fd, F_DUPFD_CLOEXEC, 0);