aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2002-11-27 05:04:07 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2002-11-27 05:04:07 +0000
commit2d459a804c0512bbceafe63a934770c2aa3f5edd (patch)
treec5f035ff1e834f8c487983bdf1f8af4a720eb21b /io.c
parent21a4b6cd1d79476721f4ed5d37eae394eddcb1cb (diff)
Version 0.3.0 from FTP
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@555 f38db490-d61c-443f-a65b-d21fe96a405b
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;
+}
+