/* Work-alike for termcap, plus extra features.
Copyright (C) 1985, 1986, 1993, 1994, 1995, 2000, 2001, 2002, 2003,
- 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+ 2004, 2005, 2006, 2007, 2008, 2011 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
struct termcap_buffer
{
char *beg;
- int size;
+ ptrdiff_t size;
char *ptr;
int ateof;
- int full;
+ ptrdiff_t full;
};
/* Forward declarations of static functions. */
#ifdef MSDOS /* MW, May 1993 */
static int
-valid_filename_p (fn)
- char *fn;
+valid_filename_p (char *fn)
{
return *fn == '/' || fn[1] == ':';
}
register char *bp1;
char *tc_search_point;
char *term;
- int malloc_size = 0;
+ ptrdiff_t malloc_size = 0;
register int c;
char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */
char *indirect = NULL; /* Terminal type in :tc= in TERMCAP value. */
if (scan_file (term, fd, &buf) == 0)
{
close (fd);
- free (buf.beg);
+ xfree (buf.beg);
if (malloc_size)
- free (bp);
+ xfree (bp);
return 0;
}
/* Free old `term' if appropriate. */
if (term != name)
- free (term);
+ xfree (term);
/* If BP is malloc'd by us, make sure it is big enough. */
if (malloc_size)
}
close (fd);
- free (buf.beg);
+ xfree (buf.beg);
if (malloc_size)
bp = (char *) xrealloc (bp, bp1 - bp + 1);
{
if (bufp->full == bufp->size)
{
+ if ((PTRDIFF_MAX - 1) / 2 < bufp->size)
+ memory_full (SIZE_MAX);
bufp->size *= 2;
/* Add 1 to size to ensure room for terminating null. */
tem = (char *) xrealloc (buf, bufp->size + 1);
#include <stdio.h>
-main (argc, argv)
- int argc;
- char **argv;
+static void
+tprint (char *cap)
+{
+ char *x = tgetstr (cap, 0);
+ register char *y;
+
+ printf ("%s: ", cap);
+ if (x)
+ {
+ for (y = x; *y; y++)
+ if (*y <= ' ' || *y == 0177)
+ printf ("\\%0o", *y);
+ else
+ putchar (*y);
+ free (x);
+ }
+ else
+ printf ("none");
+ putchar ('\n');
+}
+
+int
+main (int argc, char **argv)
{
char *term;
char *buf;
printf ("co: %d\n", tgetnum ("co"));
printf ("am: %d\n", tgetflag ("am"));
-}
-
-tprint (cap)
- char *cap;
-{
- char *x = tgetstr (cap, 0);
- register char *y;
- printf ("%s: ", cap);
- if (x)
- {
- for (y = x; *y; y++)
- if (*y <= ' ' || *y == 0177)
- printf ("\\%0o", *y);
- else
- putchar (*y);
- free (x);
- }
- else
- printf ("none");
- putchar ('\n');
+ return 0;
}
#endif /* TEST */
-