From 2d459a804c0512bbceafe63a934770c2aa3f5edd Mon Sep 17 00:00:00 2001 From: markster Date: Wed, 27 Nov 2002 05:04:07 +0000 Subject: Version 0.3.0 from FTP git-svn-id: http://svn.digium.com/svn/asterisk/trunk@555 f38db490-d61c-443f-a65b-d21fe96a405b --- io.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 918104352..0c0eea47e 100755 --- a/io.c +++ b/io.c @@ -16,6 +16,8 @@ #include #include #include +#include /* for memset */ +#include #include #include @@ -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; +} + -- cgit v1.2.3