summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorMark Spencer <markster@digium.com>2002-11-27 05:04:07 +0000
committerMark Spencer <markster@digium.com>2002-11-27 05:04:07 +0000
commit55dc769bc3483555408f923e4291891b07a4ca72 (patch)
treec5f035ff1e834f8c487983bdf1f8af4a720eb21b /io.c
parent9bc09cd23cde028887e527d23391ca561d7757e8 (diff)
Version 0.3.0 from FTP
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@555 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'io.c')
-rwxr-xr-xio.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/io.c b/io.c
index 918104352..0c0eea47e 100755
--- a/io.c
+++ b/io.c
@@ -16,6 +16,8 @@
#include <unistd.h>
#include <stdlib.h>
#include <termios.h>
+#include <string.h> /* for memset */
+#include <sys/ioctl.h>
#include <asterisk/io.h>
#include <asterisk/logger.h>
@@ -76,12 +78,14 @@ struct io_context *io_context_create(void)
free(tmp);
tmp = NULL;
} else {
+ memset(tmp->fds, 0, (GROW_SHRINK_SIZE/2) * sizeof(struct pollfd));
tmp->ior = malloc((GROW_SHRINK_SIZE/2) * sizeof(struct io_rec));
if (!tmp->ior) {
free(tmp->fds);
free(tmp);
tmp = NULL;
- }
+ } else
+ memset(tmp->ior, 0, (GROW_SHRINK_SIZE/2) * sizeof(struct io_rec));
}
}
return tmp;
@@ -215,7 +219,7 @@ static int io_shrink(struct io_context *ioc)
int ast_io_remove(struct io_context *ioc, int *_id)
{
int x;
- if (!*_id) {
+ if (!_id) {
ast_log(LOG_WARNING, "Asked to remove NULL?\n");
return -1;
}
@@ -335,3 +339,22 @@ int ast_restore_tty(int fd, int oldstate)
return 0;
}
+int ast_get_termcols(int fd)
+{
+ struct winsize win;
+ int cols = 0;
+
+ if (!isatty(fd))
+ return -1;
+
+ if ( ioctl(fd, TIOCGWINSZ, &win) != -1 ) {
+ if ( !cols && win.ws_col > 0 )
+ cols = (int) win.ws_col;
+ } else {
+ /* assume 80 characters if the ioctl fails for some reason */
+ cols = 80;
+ }
+
+ return cols;
+}
+