summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bar.c16
-rw-r--r--src/bfstd.c30
-rw-r--r--src/bfstd.h28
3 files changed, 40 insertions, 34 deletions
diff --git a/src/bar.c b/src/bar.c
index 3258df0..1b0691a 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -18,7 +18,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>
@@ -33,25 +32,14 @@ struct bfs_bar {
/** Get the terminal size, if possible. */
static int bfs_bar_getsize(struct bfs_bar *bar) {
-#if BFS_HAS_TCGETWINSIZE || defined(TIOCGWINSZ)
struct winsize ws;
-
-# if BFS_HAS_TCGETWINSIZE
- int ret = tcgetwinsize(bar->fd, &ws);
-# else
- int ret = ioctl(bar->fd, TIOCGWINSZ, &ws);
-# endif
- if (ret != 0) {
- return ret;
+ if (xtcgetwinsize(bar->fd, &ws) != 0) {
+ return -1;
}
store(&bar->width, ws.ws_col, relaxed);
store(&bar->height, ws.ws_row, relaxed);
return 0;
-#else
- errno = ENOTSUP;
- return -1;
-#endif
}
/** Write a string to the status bar (async-signal-safe). */
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);
diff --git a/src/bfstd.h b/src/bfstd.h
index 28f473e..a17ce95 100644
--- a/src/bfstd.h
+++ b/src/bfstd.h
@@ -158,16 +158,6 @@ FILE *xfopen(const char *path, int flags);
*/
char *xgetdelim(FILE *file, char delim);
-/**
- * Open the controlling terminal.
- *
- * @flags
- * The open() flags.
- * @return
- * An open file descriptor, or -1 on failure.
- */
-int open_cterm(int flags);
-
// #include <stdlib.h>
/**
@@ -342,6 +332,24 @@ int xminor(dev_t dev);
*/
pid_t xwaitpid(pid_t pid, int *status, int flags);
+#include <sys/ioctl.h> // May be necessary for struct winsize
+#include <termios.h>
+
+/**
+ * Open the controlling terminal.
+ *
+ * @flags
+ * The open() flags.
+ * @return
+ * An open file descriptor, or -1 on failure.
+ */
+int open_cterm(int flags);
+
+/**
+ * tcgetwinsize()/ioctl(TIOCGWINSZ) wrapper.
+ */
+int xtcgetwinsize(int fd, struct winsize *ws);
+
// #include <unistd.h>
/**