Proper rewrite of function termsize (renamed getTerminalHeight): - add documentation - use constant instead of litteral integer value for the fd - handle ioctl failure - use better return type - clic - Clic is an command line interactive client for gopher written in Common LISP
HTML git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/clic/
DIR Log
DIR Files
DIR Refs
DIR Tags
DIR README
DIR LICENSE
---
DIR commit 40244f6eac457069e60611709cda1851aae1eb08
DIR parent 27321d7d6a66be5fd4f18a8acc515387e5bb1564
HTML Author: killruana <killruana@gmail.com>
Date: Sat, 11 Nov 2017 13:29:36 +0100
Proper rewrite of function termsize (renamed getTerminalHeight):
- add documentation
- use constant instead of litteral integer value for the fd
- handle ioctl failure
- use better return type
Diffstat:
M extension.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
---
DIR diff --git a/extension.c b/extension.c
@@ -1,8 +1,17 @@
+#include <limits.h>
#include <sys/ioctl.h>
+#include <unistd.h>
-int termsize()
+/**
+ * @brief Get the height of the terminal in term of visible lines
+ * @return the height of the terminal or UINT_MAX in case of error
+ */
+unsigned int getTerminalHeight()
{
- struct winsize w;
- ioctl(0,TIOCGWINSZ, &w);
- return(w.ws_row);
+ struct winsize w;
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) < 0) {
+ return UINT_MAX;
+ }
+
+ return w.ws_row;
}