mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-09 21:20:50 +02:00
Bash-5.3-alpha release
This commit is contained in:
+49
-144
@@ -9,7 +9,7 @@
|
||||
Unix snprintf implementation.
|
||||
derived from inetutils/libinetutils/snprintf.c Version 1.1
|
||||
|
||||
Copyright (C) 2001-2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 2001-2024 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash, the Bourne Again SHell.
|
||||
|
||||
@@ -77,7 +77,6 @@
|
||||
#endif
|
||||
#define HAVE_ISINF_IN_LIBC
|
||||
#define HAVE_ISNAN_IN_LIBC
|
||||
#define PREFER_STDARG
|
||||
#define HAVE_STRINGIZE
|
||||
#define HAVE_LIMITS_H
|
||||
#define HAVE_STDDEF_H
|
||||
@@ -89,19 +88,12 @@
|
||||
|
||||
#include <bashtypes.h>
|
||||
|
||||
#if defined(PREFER_STDARG)
|
||||
# include <stdarg.h>
|
||||
#else
|
||||
# include <varargs.h>
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
#endif
|
||||
#include <bashansi.h>
|
||||
#ifdef HAVE_STDDEF_H
|
||||
# include <stddef.h>
|
||||
#endif
|
||||
#include <chartypes.h>
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
@@ -129,8 +121,8 @@
|
||||
# define FL_ADDBASE 0x02 /* add base# prefix to converted value */
|
||||
# define FL_HEXUPPER 0x04 /* use uppercase when converting to hex */
|
||||
# define FL_UNSIGNED 0x08 /* don't add any sign */
|
||||
extern char *fmtulong PARAMS((unsigned long int, int, char *, size_t, int));
|
||||
extern char *fmtullong PARAMS((unsigned long long int, int, char *, size_t, int));
|
||||
extern char *fmtulong (unsigned long int, int, char *, size_t, int);
|
||||
extern char *fmtullong (unsigned long long int, int, char *, size_t, int);
|
||||
#endif
|
||||
|
||||
#ifndef FREE
|
||||
@@ -178,9 +170,6 @@ extern char *fmtullong PARAMS((unsigned long long int, int, char *, size_t, int)
|
||||
|
||||
#define ASBUFSIZE 128
|
||||
|
||||
#define x_digs "0123456789abcdef"
|
||||
#define X_digs "0123456789ABCDEF"
|
||||
|
||||
static char intbuf[INT_STRLEN_BOUND(unsigned long) + 1];
|
||||
|
||||
static int decpoint;
|
||||
@@ -271,38 +260,38 @@ struct DATA
|
||||
|
||||
/* the floating point stuff */
|
||||
#ifdef FLOATING_POINT
|
||||
static double pow_10 PARAMS((int));
|
||||
static int log_10 PARAMS((double));
|
||||
static double integral PARAMS((double, double *));
|
||||
static char *numtoa PARAMS((double, int, int, char **));
|
||||
static double pow_10 (int);
|
||||
static int log_10 (double);
|
||||
static double integral (double, double *);
|
||||
static char *numtoa (double, int, int, char **);
|
||||
#endif
|
||||
|
||||
static void init_data PARAMS((struct DATA *, char *, size_t, const char *, int));
|
||||
static void init_conv_flag PARAMS((struct DATA *));
|
||||
static void init_data (struct DATA *, char *, size_t, const char *, int);
|
||||
static void init_conv_flag (struct DATA *);
|
||||
|
||||
/* for the format */
|
||||
#ifdef FLOATING_POINT
|
||||
static void floating PARAMS((struct DATA *, double));
|
||||
static void exponent PARAMS((struct DATA *, double));
|
||||
static void floating (struct DATA *, double);
|
||||
static void exponent (struct DATA *, double);
|
||||
#endif
|
||||
static void number PARAMS((struct DATA *, unsigned long, int));
|
||||
static void number (struct DATA *, unsigned long, int);
|
||||
#ifdef HAVE_LONG_LONG_INT
|
||||
static void lnumber PARAMS((struct DATA *, unsigned long long, int));
|
||||
static void lnumber (struct DATA *, unsigned long long, int);
|
||||
#endif
|
||||
static void pointer PARAMS((struct DATA *, unsigned long));
|
||||
static void strings PARAMS((struct DATA *, char *));
|
||||
static void pointer (struct DATA *, unsigned long);
|
||||
static void strings (struct DATA *, char *);
|
||||
|
||||
#ifdef FLOATING_POINT
|
||||
# define FALLBACK_FMTSIZE 32
|
||||
# define FALLBACK_BASE 4096
|
||||
# define LFALLBACK_BASE 5120
|
||||
# ifdef HAVE_LONG_DOUBLE
|
||||
static void ldfallback PARAMS((struct DATA *, const char *, const char *, long double));
|
||||
static void ldfallback (struct DATA *, const char *, const char *, long double);
|
||||
# endif
|
||||
static void dfallback PARAMS((struct DATA *, const char *, const char *, double));
|
||||
static void dfallback (struct DATA *, const char *, const char *, double);
|
||||
#endif
|
||||
|
||||
static char *groupnum PARAMS((char *));
|
||||
static char *groupnum (char *);
|
||||
|
||||
#if defined (HAVE_LONG_DOUBLE)
|
||||
# define LONGDOUBLE long double
|
||||
@@ -331,10 +320,10 @@ static char *groupnum PARAMS((char *));
|
||||
#endif
|
||||
|
||||
#ifdef DRIVER
|
||||
static void memory_error_and_abort ();
|
||||
static void *xmalloc PARAMS((size_t));
|
||||
static void *xrealloc PARAMS((void *, size_t));
|
||||
static void xfree PARAMS((void *));
|
||||
static void memory_error_and_abort (void);
|
||||
static void *xmalloc (size_t);
|
||||
static void *xrealloc (void *, size_t);
|
||||
static void xfree (void *);
|
||||
#else
|
||||
# include <xmalloc.h>
|
||||
#endif
|
||||
@@ -470,8 +459,7 @@ static void xfree PARAMS((void *));
|
||||
* Find the nth power of 10
|
||||
*/
|
||||
static double
|
||||
pow_10(n)
|
||||
int n;
|
||||
pow_10(int n)
|
||||
{
|
||||
double P;
|
||||
|
||||
@@ -514,8 +502,7 @@ pow_10(n)
|
||||
* NOTE: do not call this with r == 0 -- an infinite loop results.
|
||||
*/
|
||||
static int
|
||||
log_10(r)
|
||||
double r;
|
||||
log_10(double r)
|
||||
{
|
||||
int i = 0;
|
||||
double result = 1.;
|
||||
@@ -549,9 +536,7 @@ log_10(r)
|
||||
* In many ways it resemble the modf() found on most Un*x
|
||||
*/
|
||||
static double
|
||||
integral(real, ip)
|
||||
double real;
|
||||
double *ip;
|
||||
integral(double real, double *ip)
|
||||
{
|
||||
int j;
|
||||
double i, s, p;
|
||||
@@ -598,10 +583,7 @@ integral(real, ip)
|
||||
* declare with fix size
|
||||
*/
|
||||
static char *
|
||||
numtoa(number, base, precision, fract)
|
||||
double number;
|
||||
int base, precision;
|
||||
char **fract;
|
||||
numtoa(double number, int base, int precision, char **fract)
|
||||
{
|
||||
register int i, j;
|
||||
double ip, fp; /* integer and fraction part */
|
||||
@@ -696,10 +678,7 @@ numtoa(number, base, precision, fract)
|
||||
* the representation with the right padding
|
||||
*/
|
||||
static void
|
||||
number(p, d, base)
|
||||
struct DATA *p;
|
||||
unsigned long d;
|
||||
int base;
|
||||
number(struct DATA *p, unsigned long d, int base)
|
||||
{
|
||||
char *tmp, *t;
|
||||
long sd;
|
||||
@@ -772,10 +751,7 @@ number(p, d, base)
|
||||
* identical to number() but works for `long long'
|
||||
*/
|
||||
static void
|
||||
lnumber(p, d, base)
|
||||
struct DATA *p;
|
||||
unsigned long long d;
|
||||
int base;
|
||||
lnumber(struct DATA *p, unsigned long long d, int base)
|
||||
{
|
||||
char *tmp, *t;
|
||||
long long sd;
|
||||
@@ -844,9 +820,7 @@ lnumber(p, d, base)
|
||||
#endif
|
||||
|
||||
static void
|
||||
pointer(p, d)
|
||||
struct DATA *p;
|
||||
unsigned long d;
|
||||
pointer(struct DATA *p, unsigned long d)
|
||||
{
|
||||
char *tmp;
|
||||
|
||||
@@ -869,9 +843,7 @@ pointer(p, d)
|
||||
|
||||
/* %s strings */
|
||||
static void
|
||||
strings(p, tmp)
|
||||
struct DATA *p;
|
||||
char *tmp;
|
||||
strings(struct DATA *p, char *tmp)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
@@ -886,9 +858,7 @@ strings(p, tmp)
|
||||
#if HANDLE_MULTIBYTE
|
||||
/* %ls wide-character strings */
|
||||
static void
|
||||
wstrings(p, tmp)
|
||||
struct DATA *p;
|
||||
wchar_t *tmp;
|
||||
wstrings(struct DATA *p, wchar_t *tmp)
|
||||
{
|
||||
size_t len;
|
||||
mbstate_t mbs;
|
||||
@@ -927,9 +897,7 @@ wstrings(p, tmp)
|
||||
}
|
||||
|
||||
static void
|
||||
wchars (p, wc)
|
||||
struct DATA *p;
|
||||
wint_t wc;
|
||||
wchars (struct DATA *p, wint_t wc)
|
||||
{
|
||||
char *lbuf, *l;
|
||||
mbstate_t mbs;
|
||||
@@ -956,10 +924,7 @@ wchars (p, wc)
|
||||
(mode == 2) we check for NaN. This does the necessary printing. Returns
|
||||
1 if Inf or Nan, 0 if not. */
|
||||
static int
|
||||
chkinfnan(p, d, mode)
|
||||
struct DATA *p;
|
||||
double d;
|
||||
int mode; /* == 1 for inf, == 2 for nan */
|
||||
chkinfnan(struct DATA *p, double d, int mode)
|
||||
{
|
||||
int i;
|
||||
char *tmp;
|
||||
@@ -987,9 +952,7 @@ chkinfnan(p, d, mode)
|
||||
|
||||
/* %f %F %g %G floating point representation */
|
||||
static void
|
||||
floating(p, d)
|
||||
struct DATA *p;
|
||||
double d;
|
||||
floating(struct DATA *p, double d)
|
||||
{
|
||||
char *tmp, *tmp2, *t;
|
||||
int i;
|
||||
@@ -1058,9 +1021,7 @@ floating(p, d)
|
||||
|
||||
/* %e %E %g %G exponent representation */
|
||||
static void
|
||||
exponent(p, d)
|
||||
struct DATA *p;
|
||||
double d;
|
||||
exponent(struct DATA *p, double d)
|
||||
{
|
||||
char *tmp, *tmp2;
|
||||
int j, i;
|
||||
@@ -1160,11 +1121,10 @@ exponent(p, d)
|
||||
grouping info and thousands separator. If no grouping should be performed,
|
||||
this returns NULL; the caller needs to check for it. */
|
||||
static char *
|
||||
groupnum (s)
|
||||
char *s;
|
||||
groupnum (char *s)
|
||||
{
|
||||
char *se, *ret, *re, *g;
|
||||
int len, slen;
|
||||
size_t len, slen;
|
||||
|
||||
if (grouping == 0 || *grouping <= 0 || *grouping == CHAR_MAX)
|
||||
return ((char *)NULL);
|
||||
@@ -1221,8 +1181,7 @@ groupnum (s)
|
||||
|
||||
/* initialize the conversion specifiers */
|
||||
static void
|
||||
init_conv_flag (p)
|
||||
struct DATA *p;
|
||||
init_conv_flag (struct DATA *p)
|
||||
{
|
||||
p->flags &= PF_ALLOCBUF; /* preserve PF_ALLOCBUF flag */
|
||||
p->precision = p->width = NOT_FOUND;
|
||||
@@ -1231,12 +1190,7 @@ init_conv_flag (p)
|
||||
}
|
||||
|
||||
static void
|
||||
init_data (p, string, length, format, mode)
|
||||
struct DATA *p;
|
||||
char *string;
|
||||
size_t length;
|
||||
const char *format;
|
||||
int mode;
|
||||
init_data (struct DATA *p, char *string, size_t length, const char *format, int mode)
|
||||
{
|
||||
p->length = length - 1; /* leave room for '\0' */
|
||||
p->holder = p->base = string;
|
||||
@@ -1246,16 +1200,7 @@ init_data (p, string, length, format, mode)
|
||||
}
|
||||
|
||||
static int
|
||||
#if defined (__STDC__)
|
||||
vsnprintf_internal(struct DATA *data, char *string, size_t length, const char *format, va_list args)
|
||||
#else
|
||||
vsnprintf_internal(data, string, length, format, args)
|
||||
struct DATA *data;
|
||||
char *string;
|
||||
size_t length;
|
||||
const char *format;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
double d; /* temporary holder */
|
||||
#ifdef HAVE_LONG_DOUBLE
|
||||
@@ -1639,10 +1584,7 @@ conv_break:
|
||||
* at it. Fall back to sprintf for long double formats.
|
||||
*/
|
||||
static void
|
||||
ldfallback (data, fs, fe, ld)
|
||||
struct DATA *data;
|
||||
const char *fs, *fe;
|
||||
long double ld;
|
||||
ldfallback (struct DATA *data, const char *fs, const char *fe, long double ld)
|
||||
{
|
||||
register char *x;
|
||||
char fmtbuf[FALLBACK_FMTSIZE], *obuf;
|
||||
@@ -1672,10 +1614,7 @@ ldfallback (data, fs, fe, ld)
|
||||
#ifdef FLOATING_POINT
|
||||
/* Used for %a, %A if the libc printf supports them. */
|
||||
static void
|
||||
dfallback (data, fs, fe, d)
|
||||
struct DATA *data;
|
||||
const char *fs, *fe;
|
||||
double d;
|
||||
dfallback (struct DATA *data, const char *fs, const char *fe, double d)
|
||||
{
|
||||
register char *x;
|
||||
char fmtbuf[FALLBACK_FMTSIZE], obuf[FALLBACK_BASE];
|
||||
@@ -1702,15 +1641,7 @@ dfallback (data, fs, fe, d)
|
||||
#if !HAVE_SNPRINTF
|
||||
|
||||
int
|
||||
#if defined (__STDC__)
|
||||
vsnprintf(char *string, size_t length, const char *format, va_list args)
|
||||
#else
|
||||
vsnprintf(string, length, format, args)
|
||||
char *string;
|
||||
size_t length;
|
||||
const char *format;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
struct DATA data;
|
||||
|
||||
@@ -1721,21 +1652,13 @@ vsnprintf(string, length, format, args)
|
||||
}
|
||||
|
||||
int
|
||||
#if defined(PREFER_STDARG)
|
||||
snprintf(char *string, size_t length, const char * format, ...)
|
||||
#else
|
||||
snprintf(string, length, format, va_alist)
|
||||
char *string;
|
||||
size_t length;
|
||||
const char *format;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
struct DATA data;
|
||||
int rval;
|
||||
va_list args;
|
||||
|
||||
SH_VA_START(args, format);
|
||||
va_start(args, format);
|
||||
|
||||
if (string == 0 && length != 0)
|
||||
return 0;
|
||||
@@ -1752,14 +1675,7 @@ snprintf(string, length, format, va_alist)
|
||||
#if !HAVE_ASPRINTF
|
||||
|
||||
int
|
||||
#if defined (__STDC__)
|
||||
vasprintf(char **stringp, const char *format, va_list args)
|
||||
#else
|
||||
vasprintf(stringp, format, args)
|
||||
char **stringp;
|
||||
const char *format;
|
||||
va_list args;
|
||||
#endif
|
||||
{
|
||||
struct DATA data;
|
||||
char *string;
|
||||
@@ -1773,19 +1689,12 @@ vasprintf(stringp, format, args)
|
||||
}
|
||||
|
||||
int
|
||||
#if defined(PREFER_STDARG)
|
||||
asprintf(char **stringp, const char * format, ...)
|
||||
#else
|
||||
asprintf(stringp, format, va_alist)
|
||||
char **stringp;
|
||||
const char *format;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
int rval;
|
||||
va_list args;
|
||||
|
||||
SH_VA_START(args, format);
|
||||
va_start(args, format);
|
||||
|
||||
rval = vasprintf (stringp, format, args);
|
||||
|
||||
@@ -1801,15 +1710,14 @@ asprintf(stringp, format, va_alist)
|
||||
#ifdef DRIVER
|
||||
|
||||
static void
|
||||
memory_error_and_abort ()
|
||||
memory_error_and_abort (void)
|
||||
{
|
||||
write (2, "out of virtual memory\n", 22);
|
||||
abort ();
|
||||
}
|
||||
|
||||
static void *
|
||||
xmalloc(bytes)
|
||||
size_t bytes;
|
||||
xmalloc(size_t bytes)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
@@ -1820,9 +1728,7 @@ xmalloc(bytes)
|
||||
}
|
||||
|
||||
static void *
|
||||
xrealloc (pointer, bytes)
|
||||
void *pointer;
|
||||
size_t bytes;
|
||||
xrealloc (void *pointer, size_t bytes)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
@@ -1833,15 +1739,14 @@ xrealloc (pointer, bytes)
|
||||
}
|
||||
|
||||
static void
|
||||
xfree(x)
|
||||
void *x;
|
||||
xfree(void *x)
|
||||
{
|
||||
if (x)
|
||||
free (x);
|
||||
}
|
||||
|
||||
/* set of small tests for snprintf() */
|
||||
main()
|
||||
main(int c, char **v)
|
||||
{
|
||||
char holder[100];
|
||||
char *h;
|
||||
|
||||
Reference in New Issue
Block a user