diff options
author | ache <ache@FreeBSD.org> | 2003-08-31 18:29:38 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 2003-08-31 18:29:38 +0000 |
commit | 9294014b2a986205950322eb591206fe3b1bcc64 (patch) | |
tree | 1380d37e15244f9e913c90bc146a746ceee769c3 /contrib/libreadline/shell.c | |
parent | 5e1f4dd895b3cf48b9ebc43a4a53070ccfdf3a15 (diff) | |
download | FreeBSD-src-9294014b2a986205950322eb591206fe3b1bcc64.zip FreeBSD-src-9294014b2a986205950322eb591206fe3b1bcc64.tar.gz |
Merge local changes
Diffstat (limited to 'contrib/libreadline/shell.c')
-rw-r--r-- | contrib/libreadline/shell.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/contrib/libreadline/shell.c b/contrib/libreadline/shell.c index bbf4603..88b15c5 100644 --- a/contrib/libreadline/shell.c +++ b/contrib/libreadline/shell.c @@ -45,6 +45,10 @@ # include <strings.h> #endif /* !HAVE_STRING_H */ +#if defined (HAVE_LIMITS_H) +# include <limits.h> +#endif + #include <fcntl.h> #include <pwd.h> @@ -55,13 +59,29 @@ #include "xmalloc.h" #if !defined (HAVE_GETPW_DECLS) -extern struct passwd *getpwuid __P((uid_t)); +extern struct passwd *getpwuid PARAMS((uid_t)); #endif /* !HAVE_GETPW_DECLS */ #ifndef NULL # define NULL 0 #endif +#ifndef CHAR_BIT +# define CHAR_BIT 8 +#endif + +/* Nonzero if the integer type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + +/* Bound on length of the string representing an integer value of type T. + Subtract one for the sign bit if T is signed; + 302 / 1000 is log10 (2) rounded up; + add one for integer division truncation; + add one more for a minus sign if t is signed. */ +#define INT_STRLEN_BOUND(t) \ + ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 1000 \ + + 1 + TYPE_SIGNED (t)) + /* All of these functions are resolved from bash if we are linking readline as part of bash. */ @@ -104,18 +124,18 @@ sh_set_lines_and_columns (lines, cols) char *b; #if defined (HAVE_PUTENV) - b = xmalloc (24); + b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("LINES=") + 1); sprintf (b, "LINES=%d", lines); putenv (b); - b = xmalloc (24); + b = (char *)xmalloc (INT_STRLEN_BOUND (int) + sizeof ("COLUMNS=") + 1); sprintf (b, "COLUMNS=%d", cols); putenv (b); #else /* !HAVE_PUTENV */ # if defined (HAVE_SETENV) - b = xmalloc (8); + b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1); sprintf (b, "%d", lines); setenv ("LINES", b, 1); - b = xmalloc (8); + b = (char *)xmalloc (INT_STRLEN_BOUND (int) + 1); sprintf (b, "%d", cols); setenv ("COLUMNS", b, 1); # endif /* HAVE_SETENV */ |