Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
mailutils
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
48442c8f
...
48442c8f89b9de078fe91ac9d0a7495bcb7882f1
authored
2005-02-23 14:09:34 +0000
by
Sergey Poznyakoff
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Updated by gnulib-sync
1 parent
91cfb588
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
973 additions
and
745 deletions
lib/error.h
lib/fnmatch.c
lib/getpass.c
lib/malloc.c
lib/obstack.c
lib/obstack.h
lib/realloc.c
lib/error.h
View file @
48442c8
/* Declaration for error-reporting function
Copyright (C) 1995, 1996, 1997, 2000 Free Software Foundation, Inc.
Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
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 the
Free Software Foundation; either version 2, or (at your option) any
later version.
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
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA. */
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifndef _ERROR_H
#define _ERROR_H 1
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
|| __STRICT_ANSI__
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec)
/* empty */
# endif
/* The __-protected variants of `format' and `printf' attributes
...
...
@@ -40,17 +36,15 @@
extern
"C"
{
#endif
#if defined (__STDC__) && __STDC__
/* Print a message with `fprintf (stderr, FORMAT, ...)';
if ERRNUM is nonzero, follow it with ": " and strerror (ERRNUM).
If STATUS is nonzero, terminate the program with `exit (STATUS)'. */
extern
void
error
(
int
status
,
int
errnum
,
const
char
*
format
,
...)
extern
void
error
(
int
__status
,
int
__errnum
,
const
char
*
__
format
,
...)
__attribute__
((
__format__
(
__printf__
,
3
,
4
)));
extern
void
error_at_line
(
int
status
,
int
errnum
,
const
char
*
fname
,
unsigned
int
lineno
,
const
char
*
format
,
...)
extern
void
error_at_line
(
int
__status
,
int
__errnum
,
const
char
*
__
fname
,
unsigned
int
__lineno
,
const
char
*
__
format
,
...)
__attribute__
((
__format__
(
__printf__
,
5
,
6
)));
/* If NULL, error will flush stdout, then print on stderr the program
...
...
@@ -58,12 +52,6 @@ extern void error_at_line (int status, int errnum, const char *fname,
function without parameters instead. */
extern
void
(
*
error_print_progname
)
(
void
);
#else
void
error
();
void
error_at_line
();
extern
void
(
*
error_print_progname
)
();
#endif
/* This variable is incremented each time `error' is called. */
extern
unsigned
int
error_message_count
;
...
...
lib/fnmatch.c
View file @
48442c8
/* Copyright 1991, 1992, 1993, 1996, 1997, 2000 Free Software Foundation, Inc.
/* Copyright (C) 1991,1992,1993,1996,1997,1998,1999,2000,2001,2002,2003,2004
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
...
...
@@ -23,208 +24,363 @@
# define _GNU_SOURCE 1
#endif
#include <errno.h>
#if ! defined __builtin_expect && __GNUC__ < 3
# define __builtin_expect(expr, expected) (expr)
#endif
#include <fnmatch.h>
#include <ctype.h>
#if defined STDC_HEADERS || !defined isascii
# define IN_CTYPE_DOMAIN(c) 1
#else
# define IN_CTYPE_DOMAIN(c) isascii (c)
#include <alloca.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#define WIDE_CHAR_SUPPORT \
(HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC \
&& HAVE_WMEMCHR && (HAVE_WMEMCPY || HAVE_WMEMPCPY))
/* For platform which support the ISO C amendement 1 functionality we
support user defined character classes. */
#if defined _LIBC || WIDE_CHAR_SUPPORT
/* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */
# include <wchar.h>
# include <wctype.h>
#endif
#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
/* We need some of the locale data (the collation sequence information)
but there is no interface to get this information in general. Therefore
we support a correct implementation only in glibc. */
#ifdef _LIBC
# include "../locale/localeinfo.h"
# include "../locale/elem-hash.h"
# include "../locale/coll-lookup.h"
# include <shlib-compat.h>
# define CONCAT(a,b) __CONCAT(a,b)
# define mbsrtowcs __mbsrtowcs
# define fnmatch __fnmatch
extern
int
fnmatch
(
const
char
*
pattern
,
const
char
*
string
,
int
flags
);
#endif
#ifndef
errno
extern
int
errno
;
#ifndef
SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
/* Match STRING against the filename pattern PATTERN, returning zero if
it matches, nonzero if not. */
int
fnmatch
(
const
char
*
pattern
,
const
char
*
string
,
int
flags
)
{
register
const
char
*
p
=
pattern
,
*
n
=
string
;
register
char
c
;
/* We often have to test for FNM_FILE_NAME and FNM_PERIOD being both set. */
#define NO_LEADING_PERIOD(flags) \
((flags & (FNM_FILE_NAME | FNM_PERIOD)) == (FNM_FILE_NAME | FNM_PERIOD))
/* Comment out all this code if we are using the GNU C Library, and are not
actually compiling the library itself, and have not detected a bug
in the library. This code is part of the GNU C
Library, but also included in many other GNU distributions. Compiling
and linking in this code is a waste when using the GNU C library
(especially if it is a shared library). Rather than having every GNU
program understand `configure --with-gnu-libc' and omit the object files,
it is simpler to just do this in the source for each such file. */
#if defined _LIBC || !defined __GNU_LIBRARY__ || !HAVE_FNMATCH_GNU
# if defined STDC_HEADERS || !defined isascii
# define ISASCII(c) 1
# else
# define ISASCII(c) isascii(c)
# endif
# ifdef isblank
# define ISBLANK(c) (ISASCII (c) && isblank (c))
# else
# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
# endif
# ifdef isgraph
# define ISGRAPH(c) (ISASCII (c) && isgraph (c))
# else
# define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
# endif
# define ISPRINT(c) (ISASCII (c) && isprint (c))
# define ISDIGIT(c) (ISASCII (c) && isdigit (c))
# define ISALNUM(c) (ISASCII (c) && isalnum (c))
# define ISALPHA(c) (ISASCII (c) && isalpha (c))
# define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
# define ISLOWER(c) (ISASCII (c) && islower (c))
# define ISPUNCT(c) (ISASCII (c) && ispunct (c))
# define ISSPACE(c) (ISASCII (c) && isspace (c))
# define ISUPPER(c) (ISASCII (c) && isupper (c))
# define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
# define STREQ(s1, s2) ((strcmp (s1, s2) == 0))
# if defined _LIBC || WIDE_CHAR_SUPPORT
/* The GNU C library provides support for user-defined character classes
and the functions from ISO C amendement 1. */
# ifdef CHARCLASS_NAME_MAX
# define CHAR_CLASS_MAX_LENGTH CHARCLASS_NAME_MAX
# else
/* This shouldn't happen but some implementation might still have this
problem. Use a reasonable default value. */
# define CHAR_CLASS_MAX_LENGTH 256
# endif
# ifdef _LIBC
# define IS_CHAR_CLASS(string) __wctype (string)
# else
# define IS_CHAR_CLASS(string) wctype (string)
# endif
# ifdef _LIBC
# define ISWCTYPE(WC, WT) __iswctype (WC, WT)
# else
# define ISWCTYPE(WC, WT) iswctype (WC, WT)
# endif
# if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC
/* In this case we are implementing the multibyte character handling. */
# define HANDLE_MULTIBYTE 1
# endif
# else
# define CHAR_CLASS_MAX_LENGTH 6
/* Namely, `xdigit'. */
# define IS_CHAR_CLASS(string) \
(STREQ (string, "alpha") || STREQ (string, "upper") \
|| STREQ (string, "lower") || STREQ (string, "digit") \
|| STREQ (string, "alnum") || STREQ (string, "xdigit") \
|| STREQ (string, "space") || STREQ (string, "print") \
|| STREQ (string, "punct") || STREQ (string, "graph") \
|| STREQ (string, "cntrl") || STREQ (string, "blank"))
# endif
/* Avoid depending on library functions or files
whose names are inconsistent. */
/* Global variable. */
static
int
posixly_correct
;
# ifndef internal_function
/* Inside GNU libc we mark some function in a special way. In other
environments simply ignore the marking. */
# define internal_function
# endif
/* Note that this evaluates C many times. */
#define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER ((unsigned char) (c)) \
? tolower ((unsigned char) (c)) \
: (c))
# ifdef _LIBC
# define FOLD(c) ((flags & FNM_CASEFOLD) ? tolower (c) : (c))
# else
# define FOLD(c) ((flags & FNM_CASEFOLD) && ISUPPER (c) ? tolower (c) : (c))
# endif
# define CHAR char
# define UCHAR unsigned char
# define INT int
# define FCT internal_fnmatch
# define EXT ext_match
# define END end_pattern
# define L(CS) CS
# ifdef _LIBC
# define BTOWC(C) __btowc (C)
# else
# define BTOWC(C) btowc (C)
# endif
# define STRLEN(S) strlen (S)
# define STRCAT(D, S) strcat (D, S)
# ifdef _LIBC
# define MEMPCPY(D, S, N) __mempcpy (D, S, N)
# else
# if HAVE_MEMPCPY
# define MEMPCPY(D, S, N) mempcpy (D, S, N)
# else
# define MEMPCPY(D, S, N) ((void *) ((char *) memcpy (D, S, N) + (N)))
# endif
# endif
# define MEMCHR(S, C, N) memchr (S, C, N)
# define STRCOLL(S1, S2) strcoll (S1, S2)
# include "fnmatch_loop.c"
# if HANDLE_MULTIBYTE
# define FOLD(c) ((flags & FNM_CASEFOLD) ? towlower (c) : (c))
# define CHAR wchar_t
# define UCHAR wint_t
# define INT wint_t
# define FCT internal_fnwmatch
# define EXT ext_wmatch
# define END end_wpattern
# define L(CS) L##CS
# define BTOWC(C) (C)
# ifdef _LIBC
# define STRLEN(S) __wcslen (S)
# define STRCAT(D, S) __wcscat (D, S)
# define MEMPCPY(D, S, N) __wmempcpy (D, S, N)
# else
# define STRLEN(S) wcslen (S)
# define STRCAT(D, S) wcscat (D, S)
# if HAVE_WMEMPCPY
# define MEMPCPY(D, S, N) wmempcpy (D, S, N)
# else
# define MEMPCPY(D, S, N) (wmemcpy (D, S, N) + (N))
# endif
# endif
# define MEMCHR(S, C, N) wmemchr (S, C, N)
# define STRCOLL(S1, S2) wcscoll (S1, S2)
# define WIDE_CHAR_VERSION 1
# undef IS_CHAR_CLASS
/* We have to convert the wide character string in a multibyte string. But
we know that the character class names consist of alphanumeric characters
from the portable character set, and since the wide character encoding
for a member of the portable character set is the same code point as
its single-byte encoding, we can use a simplified method to convert the
string to a multibyte character string. */
static
wctype_t
is_char_class
(
const
wchar_t
*
wcs
)
{
char
s
[
CHAR_CLASS_MAX_LENGTH
+
1
];
char
*
cp
=
s
;
while
((
c
=
*
p
++
)
!=
'\0'
)
do
{
c
=
FOLD
(
c
);
switch
(
c
)
/* Test for a printable character from the portable character set. */
# ifdef _LIBC
if
(
*
wcs
<
0x20
||
*
wcs
>
0x7e
||
*
wcs
==
0x24
||
*
wcs
==
0x40
||
*
wcs
==
0x60
)
return
(
wctype_t
)
0
;
# else
switch
(
*
wcs
)
{
case
'?'
:
if
(
*
n
==
'\0'
)
return
FNM_NOMATCH
;
else
if
((
flags
&
FNM_FILE_NAME
)
&&
*
n
==
'/'
)
return
FNM_NOMATCH
;
else
if
((
flags
&
FNM_PERIOD
)
&&
*
n
==
'.'
&&
(
n
==
string
||
((
flags
&
FNM_FILE_NAME
)
&&
n
[
-
1
]
==
'/'
)))
return
FNM_NOMATCH
;
case
L' '
:
case
L'!'
:
case
L'"'
:
case
L'#'
:
case
L'%'
:
case
L'&'
:
case
L'\''
:
case
L'('
:
case
L')'
:
case
L'*'
:
case
L'+'
:
case
L','
:
case
L'-'
:
case
L'.'
:
case
L'/'
:
case
L'0'
:
case
L'1'
:
case
L'2'
:
case
L'3'
:
case
L'4'
:
case
L'5'
:
case
L'6'
:
case
L'7'
:
case
L'8'
:
case
L'9'
:
case
L':'
:
case
L';'
:
case
L'<'
:
case
L'='
:
case
L'>'
:
case
L'?'
:
case
L'A'
:
case
L'B'
:
case
L'C'
:
case
L'D'
:
case
L'E'
:
case
L'F'
:
case
L'G'
:
case
L'H'
:
case
L'I'
:
case
L'J'
:
case
L'K'
:
case
L'L'
:
case
L'M'
:
case
L'N'
:
case
L'O'
:
case
L'P'
:
case
L'Q'
:
case
L'R'
:
case
L'S'
:
case
L'T'
:
case
L'U'
:
case
L'V'
:
case
L'W'
:
case
L'X'
:
case
L'Y'
:
case
L'Z'
:
case
L'['
:
case
L'\\'
:
case
L']'
:
case
L'^'
:
case
L'_'
:
case
L'a'
:
case
L'b'
:
case
L'c'
:
case
L'd'
:
case
L'e'
:
case
L'f'
:
case
L'g'
:
case
L'h'
:
case
L'i'
:
case
L'j'
:
case
L'k'
:
case
L'l'
:
case
L'm'
:
case
L'n'
:
case
L'o'
:
case
L'p'
:
case
L'q'
:
case
L'r'
:
case
L's'
:
case
L't'
:
case
L'u'
:
case
L'v'
:
case
L'w'
:
case
L'x'
:
case
L'y'
:
case
L'z'
:
case
L'{'
:
case
L'|'
:
case
L'}'
:
case
L'~'
:
break
;
case
'\\'
:
if
(
!
(
flags
&
FNM_NOESCAPE
))
{
c
=
*
p
++
;
if
(
c
==
'\0'
)
/* Trailing \ loses. */
return
FNM_NOMATCH
;
c
=
FOLD
(
c
);
}
if
(
FOLD
(
*
n
)
!=
c
)
return
FNM_NOMATCH
;
break
;
case
'*'
:
if
((
flags
&
FNM_PERIOD
)
&&
*
n
==
'.'
&&
(
n
==
string
||
((
flags
&
FNM_FILE_NAME
)
&&
n
[
-
1
]
==
'/'
)))
return
FNM_NOMATCH
;
for
(
c
=
*
p
++
;
c
==
'?'
||
c
==
'*'
;
c
=
*
p
++
)
{
if
(
c
==
'?'
)
{
/* A ? needs to match one character. */
if
(
*
n
==
'\0'
||
(
*
n
==
'/'
&&
(
flags
&
FNM_FILE_NAME
)))
/* There isn't another character; no match. */
return
FNM_NOMATCH
;
else
/* One character of the string is consumed in matching
this ? wildcard, so *??? won't match if there are
less than three characters. */
++
n
;
}
default:
return
(
wctype_t
)
0
;
}
# endif
if
(
c
==
'\0'
)
{
if
((
flags
&
(
FNM_FILE_NAME
|
FNM_LEADING_DIR
))
==
FNM_FILE_NAME
)
for
(;
*
n
!=
'\0'
;
n
++
)
if
(
*
n
==
'/'
)
return
FNM_NOMATCH
;
return
0
;
}
/* Avoid overrunning the buffer. */
if
(
cp
==
s
+
CHAR_CLASS_MAX_LENGTH
)
return
(
wctype_t
)
0
;
{
char
c1
=
(
!
(
flags
&
FNM_NOESCAPE
)
&&
c
==
'\\'
)
?
*
p
:
c
;
c1
=
FOLD
(
c1
);
for
(
--
p
;
*
n
!=
'\0'
;
++
n
)
if
((
c
==
'['
||
FOLD
(
*
n
)
==
c1
)
&&
fnmatch
(
p
,
n
,
flags
&
~
FNM_PERIOD
)
==
0
)
return
0
;
else
if
(
*
n
==
'/'
&&
(
flags
&
FNM_FILE_NAME
))
break
;
return
FNM_NOMATCH
;
*
cp
++
=
(
char
)
*
wcs
++
;
}
while
(
*
wcs
!=
L'\0'
);
case
'['
:
{
/* Nonzero if the sense of the character class is inverted. */
register
int
not
;
*
cp
=
'\0'
;
if
(
*
n
==
'\0'
)
return
FNM_NOMATCH
;
if
((
flags
&
FNM_PERIOD
)
&&
*
n
==
'.'
&&
(
n
==
string
||
((
flags
&
FNM_FILE_NAME
)
&&
n
[
-
1
]
==
'/'
)))
return
FNM_NOMATCH
;
# ifdef _LIBC
return
__wctype
(
s
);
# else
return
wctype
(
s
);
# endif
}
# define IS_CHAR_CLASS(string) is_char_class (string)
not
=
(
*
p
==
'!'
||
*
p
==
'^'
);
if
(
not
)
++
p
;
# include "fnmatch_loop.c"
# endif
c
=
*
p
++
;
for
(;;)
{
register
char
cstart
=
c
,
cend
=
c
;
if
(
!
(
flags
&
FNM_NOESCAPE
)
&&
c
==
'\\'
)
int
fnmatch
(
const
char
*
pattern
,
const
char
*
string
,
int
flags
)
{
# if HANDLE_MULTIBYTE
# define ALLOCA_LIMIT 2000
if
(
__builtin_expect
(
MB_CUR_MAX
,
1
)
!=
1
)
{
if
(
*
p
==
'\0'
)
return
FNM_NOMATCH
;
cstart
=
cend
=
*
p
++
;
}
cstart
=
cend
=
FOLD
(
cstart
);
if
(
c
==
'\0'
)
/* [ (unterminated) loses. */
return
FNM_NOMATCH
;
c
=
*
p
++
;
c
=
FOLD
(
c
);
if
((
flags
&
FNM_FILE_NAME
)
&&
c
==
'/'
)
/* [/] can never match. */
return
FNM_NOMATCH
;
if
(
c
==
'-'
&&
*
p
!=
']'
)
mbstate_t
ps
;
size_t
patsize
;
size_t
strsize
;
size_t
totsize
;
wchar_t
*
wpattern
;
wchar_t
*
wstring
;
int
res
;
/* Calculate the size needed to convert the strings to
wide characters. */
memset
(
&
ps
,
'\0'
,
sizeof
(
ps
));
patsize
=
mbsrtowcs
(
NULL
,
&
pattern
,
0
,
&
ps
)
+
1
;
if
(
__builtin_expect
(
patsize
==
0
,
0
))
/* Something wrong.
XXX Do we have to set `errno' to something which mbsrtows hasn't
already done? */
return
-
1
;
assert
(
mbsinit
(
&
ps
));
strsize
=
mbsrtowcs
(
NULL
,
&
string
,
0
,
&
ps
)
+
1
;
if
(
__builtin_expect
(
strsize
==
0
,
0
))
/* Something wrong.
XXX Do we have to set `errno' to something which mbsrtows hasn't
already done? */
return
-
1
;
assert
(
mbsinit
(
&
ps
));
totsize
=
patsize
+
strsize
;
if
(
__builtin_expect
(
!
(
patsize
<=
totsize
&&
totsize
<=
SIZE_MAX
/
sizeof
(
wchar_t
)),
0
))
{
cend
=
*
p
++
;
if
(
!
(
flags
&
FNM_NOESCAPE
)
&&
cend
==
'\\'
)
cend
=
*
p
++
;
if
(
cend
==
'\0'
)
return
FNM_NOMATCH
;
cend
=
FOLD
(
cend
);
c
=
*
p
++
;
}
if
(
FOLD
(
*
n
)
>=
cstart
&&
FOLD
(
*
n
)
<=
cend
)
goto
matched
;
if
(
c
==
']'
)
break
;
errno
=
ENOMEM
;
return
-
1
;
}
if
(
!
not
)
return
FNM_NOMATCH
;
break
;
matched:
;
/* Skip the rest of the [...] that already matched. */
while
(
c
!=
']'
)
/* Allocate room for the wide characters. */
if
(
__builtin_expect
(
totsize
<
ALLOCA_LIMIT
,
1
))
wpattern
=
(
wchar_t
*
)
alloca
(
totsize
*
sizeof
(
wchar_t
));
else
{
if
(
c
==
'\0'
)
/* [... (unterminated) loses. */
return
FNM_NOMATCH
;
c
=
*
p
++
;
if
(
!
(
flags
&
FNM_NOESCAPE
)
&&
c
==
'\\'
)
wpattern
=
malloc
(
totsize
*
sizeof
(
wchar_t
));
if
(
__builtin_expect
(
!
wpattern
,
0
))
{
if
(
*
p
==
'\0'
)
return
FNM_NOMATCH
;
/* XXX 1003.2d11 is unclear if this is right. */
++
p
;
}
}
if
(
not
)
return
FNM_NOMATCH
;
errno
=
ENOMEM
;
return
-
1
;
}
break
;
default:
if
(
c
!=
FOLD
(
*
n
))
return
FNM_NOMATCH
;
}
wstring
=
wpattern
+
patsize
;
++
n
;
}
/* Convert the strings into wide characters. */
mbsrtowcs
(
wpattern
,
&
pattern
,
patsize
,
&
ps
);
assert
(
mbsinit
(
&
ps
));
mbsrtowcs
(
wstring
,
&
string
,
strsize
,
&
ps
);
if
(
*
n
==
'\0'
)
return
0
;
res
=
internal_fnwmatch
(
wpattern
,
wstring
,
wstring
+
strsize
-
1
,
flags
&
FNM_PERIOD
,
flags
)
;
if
((
flags
&
FNM_LEADING_DIR
)
&&
*
n
==
'/'
)
/* The FNM_LEADING_DIR flag says that "foo*" matches "foobar/frobozz". */
return
0
;
return
FNM_NOMATCH
;
if
(
__builtin_expect
(
!
(
totsize
<
ALLOCA_LIMIT
),
0
)
)
free
(
wpattern
);
return
res
;
}
# endif
/* HANDLE_MULTIBYTE */
#undef FOLD
return
internal_fnmatch
(
pattern
,
string
,
string
+
strlen
(
string
),
flags
&
FNM_PERIOD
,
flags
);
}
# ifdef _LIBC
# undef fnmatch
versioned_symbol
(
libc
,
__fnmatch
,
fnmatch
,
GLIBC_2_2_3
);
# if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_2_3)
strong_alias
(
__fnmatch
,
__fnmatch_old
)
compat_symbol
(
libc
,
__fnmatch_old
,
fnmatch
,
GLIBC_2_0
);
# endif
libc_hidden_ver
(
__fnmatch
,
fnmatch
)
# endif
#endif
/* _LIBC or not __GNU_LIBRARY__. */
...
...
lib/getpass.c
View file @
48442c8
/*
GNU Mailutils -- a suite of utilities for electronic mail
Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc
.
/*
Copyright (C) 1992-2001, 2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library
.
This
library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option)
any later version.
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
the Free Software Foundation; either version 2, or (at your option)
any later version.
This
library
is distributed in the hope that it will be useful,
This
program
is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU
Lesser
General Public License for more details.
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#if !_LIBC
# include "getpass.h"
#endif
#if _LIBC
# define HAVE_STDIO_EXT_H 1
#endif
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#if HAVE_STDIO_EXT_H
# include <stdio_ext.h>
#else
# define __fsetlocking(stream, type)
/* empty */
#endif
#if !_LIBC
# include "getline.h"
#endif
#include <termios.h>
#include <unistd.h>
/* Alain: Parts originally from GNU Lib C. */
#if _LIBC
# include <wchar.h>
#endif
static
void
echo_off
(
int
fd
,
struct
termios
*
stored_settings
)
{
struct
termios
new_settings
;
tcgetattr
(
fd
,
stored_settings
);
new_settings
=
*
stored_settings
;
new_settings
.
c_lflag
&=
(
~
ECHO
);
tcsetattr
(
fd
,
TCSANOW
,
&
new_settings
);
}
#if _LIBC
# define NOTCANCEL_MODE "c"
#else
# define NOTCANCEL_MODE
#endif
#if _LIBC
# define flockfile(s) _IO_flockfile (s)
# define funlockfile(s) _IO_funlockfile (s)
#elif USE_UNLOCKED_IO
# include "unlocked-io.h"
#else
# if !HAVE_DECL_FFLUSH_UNLOCKED
# undef fflush_unlocked
# define fflush_unlocked(x) fflush (x)
# endif
# if !HAVE_DECL_FLOCKFILE
# undef flockfile
# define flockfile(x) ((void) 0)
# endif
# if !HAVE_DECL_FUNLOCKFILE
# undef funlockfile
# define funlockfile(x) ((void) 0)
# endif
# if !HAVE_DECL_FPUTS_UNLOCKED
# undef fputs_unlocked
# define fputs_unlocked(str,stream) fputs (str, stream)
# endif
# if !HAVE_DECL_PUTC_UNLOCKED
# undef putc_unlocked
# define putc_unlocked(c,stream) putc (c, stream)
# endif
#endif
#if _LIBC
# include <bits/libc-lock.h>
#else
# define __libc_cleanup_push(function, arg)
/* empty */
# define __libc_cleanup_pop(execute)
/* empty */
#endif
#if !_LIBC
# define __getline getline
# define __tcgetattr tcgetattr
#endif
/* It is desirable to use this bit on systems that have it.
The only bit of terminal state we want to twiddle is echoing, which is
done in software; there is no need to change the state of the terminal
hardware. */
#ifndef TCSASOFT
# define TCSASOFT 0
#endif
static
void
echo_on
(
int
fd
,
struct
termios
*
stored_settings
)
call_fclose
(
void
*
arg
)
{
tcsetattr
(
fd
,
TCSANOW
,
stored_settings
);
if
(
arg
!=
NULL
)
fclose
(
arg
);
}
char
*
getpass
(
const
char
*
prompt
)
getpass
(
const
char
*
prompt
)
{
FILE
*
tty
;
FILE
*
in
,
*
out
;
struct
termios
stored_settings
;
struct
termios
s
,
t
;
bool
tty_changed
;
static
char
*
buf
;
static
size_t
buf_size
;
char
*
pbuf
;
static
size_t
bufsize
;
ssize_t
nread
;
/* Try to write to and read from the terminal if we can.
If we can't open the terminal, use stderr and stdin. */
/* First pass initialize the buffer. */
if
(
buf_size
==
0
)
tty
=
fopen
(
"/dev/tty"
,
"w+"
NOTCANCEL_MODE
);
if
(
tty
==
NULL
)
{
buf_size
=
256
;
buf
=
calloc
(
1
,
buf_size
);
if
(
buf
==
NULL
)
return
NULL
;
in
=
stdin
;
out
=
stderr
;
}
else
memset
(
buf
,
'\0'
,
buf_size
);
{
/* We do the locking ourselves. */
__fsetlocking
(
tty
,
FSETLOCKING_BYCALLER
);
out
=
in
=
tty
;
}
/* Make sure the stream we opened is closed even if the thread is
canceled. */
__libc_cleanup_push
(
call_fclose
,
tty
);
flockfile
(
out
);
/* Turn echoing off if it is on now. */
echo_off
(
fileno
(
stdin
),
&
stored_settings
);
if
(
__tcgetattr
(
fileno
(
in
),
&
t
)
==
0
)
{
/* Save the old one. */
s
=
t
;
/* Tricky, tricky. */
t
.
c_lflag
&=
~
(
ECHO
|
ISIG
);
tty_changed
=
(
tcsetattr
(
fileno
(
in
),
TCSAFLUSH
|
TCSASOFT
,
&
t
)
==
0
);
}
else
tty_changed
=
false
;
/* Write the prompt. */
fputs
(
prompt
,
stdout
);
fflush
(
stdout
);
#ifdef USE_IN_LIBIO
if
(
_IO_fwide
(
out
,
0
)
>
0
)
__fwprintf
(
out
,
L"%s"
,
prompt
);
else
#endif
fputs_unlocked
(
prompt
,
out
);
fflush_unlocked
(
out
);
/* Read the password. */
pbuf
=
fgets
(
buf
,
buf_size
,
stdin
);
if
(
pbuf
)
nread
=
__getline
(
&
buf
,
&
bufsize
,
in
);
#if !_LIBC
/* As far as is known, glibc doesn't need this no-op fseek. */
/* According to the C standard, input may not be followed by output
on the same stream without an intervening call to a file
positioning function. Suppose in == out; then without this fseek
call, on Solaris, HP-UX, AIX, OSF/1, the previous input gets
echoed, whereas on IRIX, the following newline is not output as
it should be. POSIX imposes similar restrictions if fileno (in)
== fileno (out). The POSIX restrictions are tricky and change
from POSIX version to POSIX version, so play it safe and invoke
fseek even if in != out. */
fseek
(
out
,
0
,
SEEK_CUR
);
#endif
if
(
buf
!=
NULL
)
{
size_t
nread
=
strlen
(
pbuf
);
if
(
nread
&&
pbuf
[
nread
-
1
]
==
'\n'
)
if
(
nread
<
0
)
buf
[
0
]
=
'\0'
;
else
if
(
buf
[
nread
-
1
]
==
'\n'
)
{
/* Remove the newline. */
pbuf
[
nread
-
1
]
=
'\0'
;
buf
[
nread
-
1
]
=
'\0'
;
if
(
tty_changed
)
{
/* Write the newline that was not echoed. */
putc
(
'\n'
,
stdout
);
#ifdef USE_IN_LIBIO
if
(
_IO_fwide
(
out
,
0
)
>
0
)
putwc_unlocked
(
L'\n'
,
out
);
else
#endif
putc_unlocked
(
'\n'
,
out
);
}
}
}
/* Restore the original setting. */
echo_on
(
fileno
(
stdin
),
&
stored_settings
);
if
(
tty_changed
)
(
void
)
tcsetattr
(
fileno
(
in
),
TCSAFLUSH
|
TCSASOFT
,
&
s
);
return
pbuf
;
}
funlockfile
(
out
);
#ifdef _GETPASS_STANDALONE_TEST
__libc_cleanup_pop
(
0
);
int
main
()
{
char
*
p
;
p
=
getpass
(
"my prompt: "
);
if
(
p
)
printf
(
"Passwd: %s
\n
"
,
p
);
return
0
;
call_fclose
(
tty
);
return
buf
;
}
#endif
...
...
lib/malloc.c
View file @
48442c8
/*
rpl_malloc.c -- a replacement for malloc that don't accept 0 size
Copyright (C)
2001
Free Software Foundation, Inc.
/*
malloc() function that is glibc compatible.
Copyright (C)
1997, 1998
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
...
...
@@ -15,12 +15,22 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* written by Jim Meyering */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#undef malloc
#include <stdlib.h>
/* Allocate an N-byte block of memory from the heap.
If N is zero, allocate a 1-byte block. */
void
*
rpl_malloc
(
size_t
size
)
rpl_malloc
(
size_t
n
)
{
if
(
!
size
)
size
++
;
return
malloc
(
size
);
if
(
n
==
0
)
n
=
1
;
return
malloc
(
n
);
}
...
...
lib/obstack.c
View file @
48442c8
/* obstack.c - subroutines used implicitly by object stack macros
Copyright (C) 1988, 89, 90, 91, 92, 93, 94 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 the
Free Software Foundation; either version 2, or (at your option) any
later version.
Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1996, 1997,
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation,
Inc.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details
.
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
the Free Software Foundation; either version 2, or (at your option)
any later version
.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
#include "obstack.h"
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#ifdef _LIBC
# include <obstack.h>
# include <shlib-compat.h>
#else
# include "obstack.h"
#endif
/* NOTE BEFORE MODIFYING THIS FILE: This version number must be
incremented whenever callers compiled using an old obstack.h can no
...
...
@@ -32,45 +44,86 @@ Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
files, it is simpler to just do this in the source for each such file. */
#include <stdio.h>
/* Random thing to get __GNU_LIBRARY__. */
#if !defined (_LIBC) && defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1
#include <gnu-versions.h>
#if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
#define ELIDE_CODE
#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
# include <gnu-versions.h>
# if _GNU_OBSTACK_INTERFACE_VERSION == OBSTACK_INTERFACE_VERSION
# define ELIDE_CODE
# endif
#endif
#if defined _LIBC && defined USE_IN_LIBIO
# include <wchar.h>
#endif
#include <stddef.h>
#ifndef ELIDE_CODE
#if defined (__STDC__) && __STDC__
#define POINTER void *
#else
#define POINTER char *
#endif
# if HAVE_INTTYPES_H
# include <inttypes.h>
# endif
# if HAVE_STDINT_H || defined _LIBC
# include <stdint.h>
# endif
/* Determine default alignment. */
struct
fooalign
{
char
x
;
double
d
;};
#define DEFAULT_ALIGNMENT \
((PTR_INT_TYPE) ((char *)&((struct fooalign *) 0)->d - (char *)0))
union
fooround
{
uintmax_t
i
;
long
double
d
;
void
*
p
;
};
struct
fooalign
{
char
c
;
union
fooround
u
;
};
/* If malloc were really smart, it would round addresses to DEFAULT_ALIGNMENT.
But in fact it might be less smart and round addresses to as much as
DEFAULT_ROUNDING. So we prepare for it to do that. */
union
fooround
{
long
x
;
double
d
;};
#define DEFAULT_ROUNDING (sizeof (union fooround))
enum
{
DEFAULT_ALIGNMENT
=
offsetof
(
struct
fooalign
,
u
),
DEFAULT_ROUNDING
=
sizeof
(
union
fooround
)
};
/* When we copy a long block of data, this is the unit to do it with.
On some machines, copying successive ints does not work;
in such a case, redefine COPYING_UNIT to `long' (if that works)
or `char' as a last resort. */
#ifndef COPYING_UNIT
#define COPYING_UNIT int
#endif
/* The non-GNU-C macros copy the obstack into this global variable
to avoid multiple evaluation. */
struct
obstack
*
_obstack
;
# ifndef COPYING_UNIT
# define COPYING_UNIT int
# endif
/* The functions allocating more room by calling `obstack_chunk_alloc'
jump to the handler pointed to by `obstack_alloc_failed_handler'.
This can be set to a user defined function which should either
abort gracefully or use longjump - but shouldn't return. This
variable by default points to the internal function
`print_and_abort'. */
static
void
print_and_abort
(
void
);
void
(
*
obstack_alloc_failed_handler
)
(
void
)
=
print_and_abort
;
/* Exit value used when `print_and_abort' is used. */
# include <stdlib.h>
# ifdef _LIBC
int
obstack_exit_failure
=
EXIT_FAILURE
;
# else
# include "exitfail.h"
# define obstack_exit_failure exit_failure
# endif
# ifdef _LIBC
# if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_3_4)
/* A looong time ago (before 1994, anyway; we're not sure) this global variable
was used by non-GNU-C macros to avoid multiple evaluation. The GNU C
library still exports it because somebody might use it. */
struct
obstack
*
_obstack_compat
;
compat_symbol
(
libc
,
_obstack_compat
,
_obstack
,
GLIBC_2_0
);
# endif
# endif
/* Define a macro that either calls functions with the traditional malloc/free
calling interface, or calls functions with the mmalloc/mfree interface
...
...
@@ -78,17 +131,17 @@ struct obstack *_obstack;
For free, do not use ?:, since some compilers, like the MIPS compilers,
do not allow (expr) ? void : void. */
#define CALL_CHUNKFUN(h, size) \
#
define CALL_CHUNKFUN(h, size) \
(((h) -> use_extra_arg) \
? (*(h)->chunkfun) ((h)->extra_arg, (size)) \
: (*(h)->chunkfun) ((size)))
: (*(
struct _obstack_chunk *(*) (long)) (
h)->chunkfun) ((size)))
#define CALL_FREEFUN(h, old_chunk) \
#
define CALL_FREEFUN(h, old_chunk) \
do { \
if ((h) -> use_extra_arg) \
(*(h)->freefun) ((h)->extra_arg, (old_chunk)); \
else \
(*(h)->freefun) ((old_chunk)); \
(*(
void (*) (void *)) (
h)->freefun) ((old_chunk)); \
} while (0)
...
...
@@ -97,19 +150,16 @@ struct obstack *_obstack;
CHUNKFUN is the function to use to allocate chunks,
and FREEFUN the function to free them.
Return nonzero if successful, zero if out of memory.
To recover from an out of memory error,
free up some memory, then call this again. */
Return nonzero if successful, calls obstack_alloc_failed_handler if
allocation fails. */
int
_obstack_begin
(
h
,
size
,
alignment
,
chunkfun
,
freefun
)
struct
obstack
*
h
;
int
size
;
int
alignment
;
POINTER
(
*
chunkfun
)
();
void
(
*
freefun
)
();
_obstack_begin
(
struct
obstack
*
h
,
int
size
,
int
alignment
,
void
*
(
*
chunkfun
)
(
long
),
void
(
*
freefun
)
(
void
*
))
{
register
struct
_obstack_chunk
*
chunk
;
/* points to new chunk */
register
struct
_obstack_chunk
*
chunk
;
/* points to new chunk */
if
(
alignment
==
0
)
alignment
=
DEFAULT_ALIGNMENT
;
...
...
@@ -130,38 +180,33 @@ _obstack_begin (h, size, alignment, chunkfun, freefun)
size
=
4096
-
extra
;
}
h
->
chunkfun
=
(
struct
_obstack_chunk
*
(
*
)())
chunkfun
;
h
->
freefun
=
freefun
;
h
->
chunkfun
=
(
struct
_obstack_chunk
*
(
*
)(
void
*
,
long
))
chunkfun
;
h
->
freefun
=
(
void
(
*
)
(
void
*
,
struct
_obstack_chunk
*
))
freefun
;
h
->
chunk_size
=
size
;
h
->
alignment_mask
=
alignment
-
1
;
h
->
use_extra_arg
=
0
;
chunk
=
h
->
chunk
=
CALL_CHUNKFUN
(
h
,
h
->
chunk_size
);
if
(
!
chunk
)
{
h
->
alloc_failed
=
1
;
return
0
;
}
h
->
alloc_failed
=
0
;
h
->
next_free
=
h
->
object_base
=
chunk
->
contents
;
(
*
obstack_alloc_failed_handler
)
();
h
->
next_free
=
h
->
object_base
=
__PTR_ALIGN
((
char
*
)
chunk
,
chunk
->
contents
,
alignment
-
1
);
h
->
chunk_limit
=
chunk
->
limit
=
(
char
*
)
chunk
+
h
->
chunk_size
;
chunk
->
prev
=
0
;
/* The initial chunk now contains no empty object. */
h
->
maybe_empty_object
=
0
;
h
->
alloc_failed
=
0
;
return
1
;
}
int
_obstack_begin_1
(
h
,
size
,
alignment
,
chunkfun
,
freefun
,
arg
)
struct
obstack
*
h
;
int
size
;
int
alignment
;
POINTER
(
*
chunkfun
)
();
void
(
*
freefun
)
();
POINTER
arg
;
_obstack_begin_1
(
struct
obstack
*
h
,
int
size
,
int
alignment
,
void
*
(
*
chunkfun
)
(
void
*
,
long
),
void
(
*
freefun
)
(
void
*
,
void
*
),
void
*
arg
)
{
register
struct
_obstack_chunk
*
chunk
;
/* points to new chunk */
register
struct
_obstack_chunk
*
chunk
;
/* points to new chunk */
if
(
alignment
==
0
)
alignment
=
DEFAULT_ALIGNMENT
;
...
...
@@ -182,8 +227,8 @@ _obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg)
size
=
4096
-
extra
;
}
h
->
chunkfun
=
(
struct
_obstack_chunk
*
(
*
)())
chunkfun
;
h
->
freefun
=
freefun
;
h
->
chunkfun
=
(
struct
_obstack_chunk
*
(
*
)(
void
*
,
long
))
chunkfun
;
h
->
freefun
=
(
void
(
*
)
(
void
*
,
struct
_obstack_chunk
*
))
freefun
;
h
->
chunk_size
=
size
;
h
->
alignment_mask
=
alignment
-
1
;
h
->
extra_arg
=
arg
;
...
...
@@ -191,17 +236,15 @@ _obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg)
chunk
=
h
->
chunk
=
CALL_CHUNKFUN
(
h
,
h
->
chunk_size
);
if
(
!
chunk
)
{
h
->
alloc_failed
=
1
;
return
0
;
}
h
->
alloc_failed
=
0
;
h
->
next_free
=
h
->
object_base
=
chunk
->
contents
;
(
*
obstack_alloc_failed_handler
)
();
h
->
next_free
=
h
->
object_base
=
__PTR_ALIGN
((
char
*
)
chunk
,
chunk
->
contents
,
alignment
-
1
);
h
->
chunk_limit
=
chunk
->
limit
=
(
char
*
)
chunk
+
h
->
chunk_size
;
chunk
->
prev
=
0
;
/* The initial chunk now contains no empty object. */
h
->
maybe_empty_object
=
0
;
h
->
alloc_failed
=
0
;
return
1
;
}
...
...
@@ -212,34 +255,33 @@ _obstack_begin_1 (h, size, alignment, chunkfun, freefun, arg)
to the beginning of the new one. */
void
_obstack_newchunk
(
h
,
length
)
struct
obstack
*
h
;
int
length
;
_obstack_newchunk
(
struct
obstack
*
h
,
int
length
)
{
register
struct
_obstack_chunk
*
old_chunk
=
h
->
chunk
;
register
struct
_obstack_chunk
*
new_chunk
;
register
struct
_obstack_chunk
*
old_chunk
=
h
->
chunk
;
register
struct
_obstack_chunk
*
new_chunk
;
register
long
new_size
;
register
int
obj_size
=
h
->
next_free
-
h
->
object_base
;
register
int
i
;
int
already
;
register
long
obj_size
=
h
->
next_free
-
h
->
object_base
;
register
long
i
;
long
already
;
char
*
object_base
;
/* Compute size for new chunk. */
new_size
=
(
obj_size
+
length
)
+
(
obj_size
>>
3
)
+
100
;
new_size
=
(
obj_size
+
length
)
+
(
obj_size
>>
3
)
+
h
->
alignment_mask
+
100
;
if
(
new_size
<
h
->
chunk_size
)
new_size
=
h
->
chunk_size
;
/* Allocate and initialize the new chunk. */
new_chunk
=
CALL_CHUNKFUN
(
h
,
new_size
);
if
(
!
new_chunk
)
{
h
->
alloc_failed
=
1
;
return
;
}
h
->
alloc_failed
=
0
;
(
*
obstack_alloc_failed_handler
)
();
h
->
chunk
=
new_chunk
;
new_chunk
->
prev
=
old_chunk
;
new_chunk
->
limit
=
h
->
chunk_limit
=
(
char
*
)
new_chunk
+
new_size
;
/* Compute an aligned object_base in the new chunk */
object_base
=
__PTR_ALIGN
((
char
*
)
new_chunk
,
new_chunk
->
contents
,
h
->
alignment_mask
);
/* Move the existing object to the new chunk.
Word at a time is fast and is safe if the object
is sufficiently aligned. */
...
...
@@ -247,7 +289,7 @@ _obstack_newchunk (h, length)
{
for
(
i
=
obj_size
/
sizeof
(
COPYING_UNIT
)
-
1
;
i
>=
0
;
i
--
)
((
COPYING_UNIT
*
)
new_chunk
->
contents
)[
i
]
((
COPYING_UNIT
*
)
object_base
)[
i
]
=
((
COPYING_UNIT
*
)
h
->
object_base
)[
i
];
/* We used to copy the odd few remaining bytes as one extra COPYING_UNIT,
but that can cross a page boundary on a machine
...
...
@@ -258,46 +300,48 @@ _obstack_newchunk (h, length)
already
=
0
;
/* Copy remaining bytes one by one. */
for
(
i
=
already
;
i
<
obj_size
;
i
++
)
new_chunk
->
contents
[
i
]
=
h
->
object_base
[
i
];
object_base
[
i
]
=
h
->
object_base
[
i
];
/* If the object just copied was the only data in OLD_CHUNK,
free that chunk and remove it from the chain.
But not if that chunk might contain an empty object. */
if
(
h
->
object_base
==
old_chunk
->
contents
&&
!
h
->
maybe_empty_object
)
if
(
!
h
->
maybe_empty_object
&&
(
h
->
object_base
==
__PTR_ALIGN
((
char
*
)
old_chunk
,
old_chunk
->
contents
,
h
->
alignment_mask
)))
{
new_chunk
->
prev
=
old_chunk
->
prev
;
CALL_FREEFUN
(
h
,
old_chunk
);
}
h
->
object_base
=
new_chunk
->
contents
;
h
->
object_base
=
object_base
;
h
->
next_free
=
h
->
object_base
+
obj_size
;
/* The new chunk certainly contains no empty object yet. */
h
->
maybe_empty_object
=
0
;
}
# ifdef _LIBC
libc_hidden_def
(
_obstack_newchunk
)
# endif
/* Return nonzero if object OBJ has been allocated from obstack H.
This is here for debugging.
If you use it in a program, you are probably losing. */
#if defined (__STDC__) && __STDC__
/* Suppress -Wmissing-prototypes warning. We don't want to declare this in
obstack.h because it is just for debugging. */
int
_obstack_allocated_p
(
struct
obstack
*
h
,
POINTER
obj
);
#endif
int
_obstack_allocated_p
(
struct
obstack
*
h
,
void
*
obj
);
int
_obstack_allocated_p
(
h
,
obj
)
struct
obstack
*
h
;
POINTER
obj
;
_obstack_allocated_p
(
struct
obstack
*
h
,
void
*
obj
)
{
register
struct
_obstack_chunk
*
lp
;
/* below addr of any objects in this chunk */
register
struct
_obstack_chunk
*
plp
;
/* point to previous chunk if any */
register
struct
_obstack_chunk
*
lp
;
/* below addr of any objects in this chunk */
register
struct
_obstack_chunk
*
plp
;
/* point to previous chunk if any */
lp
=
(
h
)
->
chunk
;
/* We use >= rather than > since the object cannot be exactly at
the beginning of the chunk but might be an empty object exactly
at the end of an adjacent chunk. */
while
(
lp
!=
0
&&
((
POINTER
)
lp
>=
obj
||
(
POINTER
)
(
lp
)
->
limit
<
obj
))
while
(
lp
!=
0
&&
((
void
*
)
lp
>=
obj
||
(
void
*
)
(
lp
)
->
limit
<
obj
))
{
plp
=
lp
->
prev
;
lp
=
plp
;
...
...
@@ -308,24 +352,19 @@ _obstack_allocated_p (h, obj)
/* Free objects in obstack H, including OBJ and everything allocate
more recently than OBJ. If OBJ is zero, free everything in H. */
#undef obstack_free
/* This function has two names with identical definitions.
This is the first one, called from non-ANSI code. */
# undef obstack_free
void
_obstack_free
(
h
,
obj
)
struct
obstack
*
h
;
POINTER
obj
;
obstack_free
(
struct
obstack
*
h
,
void
*
obj
)
{
register
struct
_obstack_chunk
*
lp
;
/* below addr of any objects in this chunk */
register
struct
_obstack_chunk
*
plp
;
/* point to previous chunk if any */
register
struct
_obstack_chunk
*
lp
;
/* below addr of any objects in this chunk */
register
struct
_obstack_chunk
*
plp
;
/* point to previous chunk if any */
lp
=
h
->
chunk
;
/* We use >= because there cannot be an object at the beginning of a chunk.
But there can be an empty object at that address
at the end of another chunk. */
while
(
lp
!=
0
&&
((
POINTER
)
lp
>=
obj
||
(
POINTER
)
(
lp
)
->
limit
<
obj
))
while
(
lp
!=
0
&&
((
void
*
)
lp
>=
obj
||
(
void
*
)
(
lp
)
->
limit
<
obj
))
{
plp
=
lp
->
prev
;
CALL_FREEFUN
(
h
,
lp
);
...
...
@@ -336,7 +375,7 @@ _obstack_free (h, obj)
}
if
(
lp
)
{
h
->
object_base
=
h
->
next_free
=
(
char
*
)(
obj
);
h
->
object_base
=
h
->
next_free
=
(
char
*
)
(
obj
);
h
->
chunk_limit
=
lp
->
limit
;
h
->
chunk
=
lp
;
}
...
...
@@ -345,153 +384,62 @@ _obstack_free (h, obj)
abort
();
}
/* This function is used from ANSI code. */
# ifdef _LIBC
/* Older versions of libc used a function _obstack_free intended to be
called by non-GCC compilers. */
strong_alias
(
obstack_free
,
_obstack_free
)
# endif
void
obstack_free
(
h
,
obj
)
struct
obstack
*
h
;
POINTER
obj
;
int
_obstack_memory_used
(
struct
obstack
*
h
)
{
register
struct
_obstack_chunk
*
lp
;
/* below addr of any objects in this chunk */
register
struct
_obstack_chunk
*
plp
;
/* point to previous chunk if any */
register
struct
_obstack_chunk
*
lp
;
register
int
nbytes
=
0
;
lp
=
h
->
chunk
;
/* We use >= because there cannot be an object at the beginning of a chunk.
But there can be an empty object at that address
at the end of another chunk. */
while
(
lp
!=
0
&&
((
POINTER
)
lp
>=
obj
||
(
POINTER
)(
lp
)
->
limit
<
obj
))
for
(
lp
=
h
->
chunk
;
lp
!=
0
;
lp
=
lp
->
prev
)
{
plp
=
lp
->
prev
;
CALL_FREEFUN
(
h
,
lp
);
lp
=
plp
;
/* If we switch chunks, we can't tell whether the new current
chunk contains an empty object, so assume that it may. */
h
->
maybe_empty_object
=
1
;
nbytes
+=
lp
->
limit
-
(
char
*
)
lp
;
}
if
(
lp
)
{
h
->
object_base
=
h
->
next_free
=
(
char
*
)(
obj
);
h
->
chunk_limit
=
lp
->
limit
;
h
->
chunk
=
lp
;
}
else
if
(
obj
!=
0
)
/* obj is not in any of the chunks! */
abort
();
}
#if 0
/* These are now turned off because the applications do not use it
and it uses bcopy via obstack_grow, which causes trouble on sysV. */
/* Now define the functional versions of the obstack macros.
Define them to simply use the corresponding macros to do the job. */
#if defined (__STDC__) && __STDC__
/* These function definitions do not work with non-ANSI preprocessors;
they won't pass through the macro names in parentheses. */
/* The function names appear in parentheses in order to prevent
the macro-definitions of the names from being expanded there. */
POINTER (obstack_base) (obstack)
struct obstack *obstack;
{
return obstack_base (obstack);
}
POINTER (obstack_next_free) (obstack)
struct obstack *obstack;
{
return obstack_next_free (obstack);
}
int (obstack_object_size) (obstack)
struct obstack *obstack;
{
return obstack_object_size (obstack);
}
int (obstack_room) (obstack)
struct obstack *obstack;
{
return obstack_room (obstack);
}
void (obstack_grow) (obstack, pointer, length)
struct obstack *obstack;
POINTER pointer;
int length;
{
obstack_grow (obstack, pointer, length);
}
void (obstack_grow0) (obstack, pointer, length)
struct obstack *obstack;
POINTER pointer;
int length;
{
obstack_grow0 (obstack, pointer, length);
return
nbytes
;
}
void (obstack_1grow) (obstack, character)
struct obstack *obstack;
int character;
/* Define the error handler. */
# ifdef _LIBC
# include <libintl.h>
# else
# include "gettext.h"
# endif
# ifndef _
# define _(msgid) gettext (msgid)
# endif
# ifdef _LIBC
# include <libio/iolibio.h>
# endif
# ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
# define __attribute__(Spec)
/* empty */
# endif
# endif
static
void
__attribute__
((
noreturn
))
print_and_abort
(
void
)
{
obstack_1grow (obstack, character);
}
void (obstack_blank) (obstack, length)
struct obstack *obstack;
int length;
{
obstack_blank (obstack, length);
}
void (obstack_1grow_fast) (obstack, character)
struct obstack *obstack;
int character;
{
obstack_1grow_fast (obstack, character);
}
void (obstack_blank_fast) (obstack, length)
struct obstack *obstack;
int length;
{
obstack_blank_fast (obstack, length);
}
POINTER (obstack_finish) (obstack)
struct obstack *obstack;
{
return obstack_finish (obstack);
}
POINTER (obstack_alloc) (obstack, length)
struct obstack *obstack;
int length;
{
return obstack_alloc (obstack, length);
}
POINTER (obstack_copy) (obstack, pointer, length)
struct obstack *obstack;
POINTER pointer;
int length;
{
return obstack_copy (obstack, pointer, length);
}
POINTER (obstack_copy0) (obstack, pointer, length)
struct obstack *obstack;
POINTER pointer;
int length;
{
return obstack_copy0 (obstack, pointer, length);
/* Don't change any of these strings. Yes, it would be possible to add
the newline to the string and use fputs or so. But this must not
happen because the "memory exhausted" message appears in other places
like this and the translation should be reused instead of creating
a very similar string which requires a separate translation. */
# if defined _LIBC && defined USE_IN_LIBIO
if
(
_IO_fwide
(
stderr
,
0
)
>
0
)
__fwprintf
(
stderr
,
L"%s
\n
"
,
_
(
"memory exhausted"
));
else
# endif
fprintf
(
stderr
,
"%s
\n
"
,
_
(
"memory exhausted"
));
exit
(
obstack_exit_failure
);
}
#endif /* __STDC__ */
#endif /* 0 */
#endif
/* !ELIDE_CODE */
...
...
lib/obstack.h
View file @
48442c8
/* obstack.h - object stack macros
Copyright (C) 1988
, 89, 90, 91, 92, 93, 94, 95, 96
Free Software Foundation, Inc.
Copyright (C) 1988
-1994,1996-1999,2003,2004
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This file is part of the GNU C Library. Its master source is NOT part of
the C library, however. The master source lives in /gd/gnu/lib.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
NOTE: The canonical source of this file is maintained with the GNU C Library.
Bugs can be reported to bug-glibc@gnu.org.
You should have received a copy of the GNU Library General Public License
along with this program; if not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
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
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* Summary:
...
...
@@ -100,43 +106,43 @@ Summary:
/* Don't do the contents of this file more than once. */
#ifndef _
_OBSTACK_H__
#define _
_OBSTACK_H__
#ifndef _
OBSTACK_H
#define _
OBSTACK_H 1
/* We use subtraction of (char *)0 instead of casting to int
because on word-addressable machines a simple cast to int
may ignore the byte-within-word field of the pointer. */
#ifndef __PTR_TO_INT
#define __PTR_TO_INT(P) ((P) - (char *)0)
#ifdef __cplusplus
extern
"C"
{
#endif
#ifndef __INT_TO_PTR
#define __INT_TO_PTR(P) ((P) + (char *)0)
#endif
/* We need the type of a pointer subtraction. If __PTRDIFF_TYPE__ is
defined, as with GNU C, use that; that way we don't pollute the
namespace with <stddef.h>'s symbols. Otherwise, include <stddef.h>
and use ptrdiff_t. */
/* We need the type of the resulting object. In ANSI C it is ptrdiff_t
but in traditional C it is usually long. If we are in ANSI C and
don't already have ptrdiff_t get it. */
#if defined (__STDC__) && ! defined (offsetof)
#if defined (__GNUC__) && defined (IN_GCC)
/* On Next machine, the system's stddef.h screws up if included
after we have defined just ptrdiff_t, so include all of stddef.h.
Otherwise, define just ptrdiff_t, which is all we need. */
#ifndef __NeXT__
#define __need_ptrdiff_t
#endif
#ifdef __PTRDIFF_TYPE__
# define PTR_INT_TYPE __PTRDIFF_TYPE__
#else
# include <stddef.h>
# define PTR_INT_TYPE ptrdiff_t
#endif
#include <stddef.h>
#endif
/* If B is the base of an object addressed by P, return the result of
aligning P to the next multiple of A + 1. B and P must be of type
char *. A + 1 must be a power of 2. */
#ifdef __STDC__
#define PTR_INT_TYPE ptrdiff_t
#else
#define PTR_INT_TYPE long
#endif
#define __BPTR_ALIGN(B, P, A) ((B) + (((P) - (B) + (A)) & ~(A)))
/* Similiar to _BPTR_ALIGN (B, P, A), except optimize the common case
where pointers can be converted to integers, aligned as integers,
and converted back again. If PTR_INT_TYPE is narrower than a
pointer (e.g., the AS/400), play it safe and compute the alignment
relative to B. Otherwise, use the faster strategy of computing the
alignment relative to 0. */
#define __PTR_ALIGN(B, P, A) \
__BPTR_ALIGN (sizeof (PTR_INT_TYPE) < sizeof (void *) ? (B) : (char *) 0, \
P, A)
#include <string.h>
struct
_obstack_chunk
/* Lives at front of each chunk. */
{
...
...
@@ -148,90 +154,59 @@ struct _obstack_chunk /* Lives at front of each chunk. */
struct
obstack
/* control current object in current chunk */
{
long
chunk_size
;
/* preferred size to allocate chunks in */
struct
_obstack_chunk
*
chunk
;
/* address of current struct obstack_chunk */
struct
_obstack_chunk
*
chunk
;
/* address of current struct obstack_chunk */
char
*
object_base
;
/* address of object we are building */
char
*
next_free
;
/* where to add next char to current object */
char
*
chunk_limit
;
/* address of char after current chunk */
PTR_INT_TYPE
temp
;
/* Temporary for some macros. */
union
{
PTR_INT_TYPE
tempint
;
void
*
tempptr
;
}
temp
;
/* Temporary for some macros. */
int
alignment_mask
;
/* Mask of alignment for each object. */
struct
_obstack_chunk
*
(
*
chunkfun
)
();
/* User's fcn to allocate a chunk. */
void
(
*
freefun
)
();
/* User's function to free a chunk. */
char
*
extra_arg
;
/* first arg for chunk alloc/dealloc funcs */
/* These prototypes vary based on `use_extra_arg', and we use
casts to the prototypeless function type in all assignments,
but having prototypes here quiets -Wstrict-prototypes. */
struct
_obstack_chunk
*
(
*
chunkfun
)
(
void
*
,
long
);
void
(
*
freefun
)
(
void
*
,
struct
_obstack_chunk
*
);
void
*
extra_arg
;
/* first arg for chunk alloc/dealloc funcs */
unsigned
use_extra_arg
:
1
;
/* chunk alloc/dealloc funcs take extra arg */
unsigned
maybe_empty_object
:
1
;
/* There is a possibility that the current
chunk contains a zero-length object. This
prevents freeing the chunk if we allocate
a bigger chunk to replace it. */
unsigned
alloc_failed
:
1
;
/* chunk alloc func returned 0 */
unsigned
alloc_failed
:
1
;
/* No longer used, as we now call the failed
handler on error, but retained for binary
compatibility. */
};
/* Declare the external functions we use; they are in obstack.c. */
#ifdef __STDC__
extern
void
_obstack_newchunk
(
struct
obstack
*
,
int
);
extern
void
_obstack_free
(
struct
obstack
*
,
void
*
);
extern
int
_obstack_begin
(
struct
obstack
*
,
int
,
int
,
void
*
(
*
)
(
),
void
(
*
)
(
));
void
*
(
*
)
(
long
),
void
(
*
)
(
void
*
));
extern
int
_obstack_begin_1
(
struct
obstack
*
,
int
,
int
,
void
*
(
*
)
(),
void
(
*
)
(),
void
*
);
void
*
(
*
)
(
void
*
,
long
),
void
(
*
)
(
void
*
,
void
*
),
void
*
);
extern
int
_obstack_memory_used
(
struct
obstack
*
);
#else
extern
void
_obstack_newchunk
();
extern
void
_obstack_free
();
extern
int
_obstack_begin
();
extern
int
_obstack_begin_1
();
extern
int
_obstack_memory_used
();
#endif
#ifdef __STDC__
/* Do the function-declarations after the structs
but before defining the macros. */
void
obstack_init
(
struct
obstack
*
obstack
);
void
*
obstack_alloc
(
struct
obstack
*
obstack
,
int
size
);
void
*
obstack_copy
(
struct
obstack
*
obstack
,
void
*
address
,
int
size
);
void
*
obstack_copy0
(
struct
obstack
*
obstack
,
void
*
address
,
int
size
);
void
obstack_free
(
struct
obstack
*
obstack
,
void
*
block
);
void
obstack_blank
(
struct
obstack
*
obstack
,
int
size
);
void
obstack_grow
(
struct
obstack
*
obstack
,
void
*
data
,
int
size
);
void
obstack_grow0
(
struct
obstack
*
obstack
,
void
*
data
,
int
size
);
void
obstack_1grow
(
struct
obstack
*
obstack
,
int
data_char
);
void
obstack_ptr_grow
(
struct
obstack
*
obstack
,
void
*
data
);
void
obstack_int_grow
(
struct
obstack
*
obstack
,
int
data
);
void
*
obstack_finish
(
struct
obstack
*
obstack
);
int
obstack_object_size
(
struct
obstack
*
obstack
);
int
obstack_room
(
struct
obstack
*
obstack
);
void
obstack_1grow_fast
(
struct
obstack
*
obstack
,
int
data_char
);
void
obstack_ptr_grow_fast
(
struct
obstack
*
obstack
,
void
*
data
);
void
obstack_int_grow_fast
(
struct
obstack
*
obstack
,
int
data
);
void
obstack_blank_fast
(
struct
obstack
*
obstack
,
int
size
);
void
*
obstack_base
(
struct
obstack
*
obstack
);
void
*
obstack_next_free
(
struct
obstack
*
obstack
);
int
obstack_alignment_mask
(
struct
obstack
*
obstack
);
int
obstack_chunk_size
(
struct
obstack
*
obstack
);
int
obstack_memory_used
(
struct
obstack
*
obstack
);
#endif
/* __STDC__ */
/* Error handler called when `obstack_chunk_alloc' failed to allocate
more memory. This can be set to a user defined function which
should either abort gracefully or use longjump - but shouldn't
return. The default action is to print a message and abort. */
extern
void
(
*
obstack_alloc_failed_handler
)
(
void
);
/*
Non-ANSI C cannot really support alternative functions for these macros,
so we do not declare them. */
/*
Exit value used when `print_and_abort' is used. */
extern
int
obstack_exit_failure
;
/* Pointer to beginning of object being allocated or to be allocated next.
Note that this might not be the final address of the object
because a new chunk might be needed to hold the final size. */
#define obstack_base(h) ((
h)->alloc_failed ? 0 :
(h)->object_base)
#define obstack_base(h) ((
void *)
(h)->object_base)
/* Size for allocating ordinary chunks. */
...
...
@@ -239,145 +214,167 @@ int obstack_memory_used (struct obstack *obstack);
/* Pointer to next byte not yet allocated in current chunk. */
#define obstack_next_free(h) ((h)->
alloc_failed ? 0 : (h)->
next_free)
#define obstack_next_free(h) ((h)->next_free)
/* Mask specifying low bits that should be clear in address of an object. */
#define obstack_alignment_mask(h) ((h)->alignment_mask)
/* To prevent prototype warnings provide complete argument list. */
#define obstack_init(h) \
_obstack_begin ((h), 0, 0, \
(void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free)
(void *(*) (long)) obstack_chunk_alloc, \
(void (*) (void *)) obstack_chunk_free)
#define obstack_begin(h, size) \
_obstack_begin ((h), (size), 0, \
(void *(*) ()) obstack_chunk_alloc, (void (*) ()) obstack_chunk_free)
(void *(*) (long)) obstack_chunk_alloc, \
(void (*) (void *)) obstack_chunk_free)
#define obstack_specify_allocation(h, size, alignment, chunkfun, freefun) \
_obstack_begin ((h), (size), (alignment), \
(void *(*) ()) (chunkfun), (void (*) ()) (freefun))
(void *(*) (long)) (chunkfun), \
(void (*) (void *)) (freefun))
#define obstack_specify_allocation_with_arg(h, size, alignment, chunkfun, freefun, arg) \
_obstack_begin_1 ((h), (size), (alignment), \
(void *(*) ()) (chunkfun), (void (*) ()) (freefun), (arg))
(void *(*) (void *, long)) (chunkfun), \
(void (*) (void *, void *)) (freefun), (arg))
#define obstack_chunkfun(h, newchunkfun) \
((h) -> chunkfun = (struct _obstack_chunk *(*)()) (newchunkfun))
((h) -> chunkfun = (struct _obstack_chunk *(*)(
void *, long
)) (newchunkfun))
#define obstack_freefun(h, newfreefun) \
((h) -> freefun = (void (*)()) (newfreefun))
((h) -> freefun = (void (*)(
void *, struct _obstack_chunk *
)) (newfreefun))
#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ =
achar
)
#define obstack_1grow_fast(h,achar) (*((h)->next_free)++ =
(achar)
)
#define obstack_blank_fast(h,n) ((h)->next_free += (n))
#define obstack_memory_used(h) _obstack_memory_used (h)
#if defined (__GNUC__) && defined (__STDC__)
#if __GNUC__ < 2
#define __extension__
#endif
#if defined __GNUC__ && defined __STDC__ && __STDC__
/* NextStep 2.0 cc is really gcc 1.93 but it defines __GNUC__ = 2 and
does not implement __extension__. But that compiler doesn't define
__GNUC_MINOR__. */
# if __GNUC__ < 2 || (__NeXT__ && !__GNUC_MINOR__)
# define __extension__
# endif
/* For GNU C, if not -traditional,
we can define these macros to compute all args only once
without using a global variable.
Also, we can avoid using the `temp' slot, to make faster code. */
#define obstack_object_size(OBSTACK) \
#
define obstack_object_size(OBSTACK) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
__o->alloc_failed ? 0 : \
({ struct obstack const *__o = (OBSTACK); \
(unsigned) (__o->next_free - __o->object_base); })
#define obstack_room(OBSTACK) \
#
define obstack_room(OBSTACK) \
__extension__ \
({ struct obstack
*__o = (OBSTACK);
\
({ struct obstack
const *__o = (OBSTACK);
\
(unsigned) (__o->chunk_limit - __o->next_free); })
#define obstack_grow(OBSTACK,where,length) \
# define obstack_make_room(OBSTACK,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
int __len = (length); \
if (__o->chunk_limit - __o->next_free < __len) \
_obstack_newchunk (__o, __len); \
(void) 0; })
# define obstack_empty_p(OBSTACK) \
__extension__ \
({ struct obstack const *__o = (OBSTACK); \
(__o->chunk->prev == 0 \
&& __o->next_free == __PTR_ALIGN ((char *) __o->chunk, \
__o->chunk->contents, \
__o->alignment_mask)); })
# define obstack_grow(OBSTACK,where,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
int __len = (length); \
if (__o->next_free + __len > __o->chunk_limit) \
_obstack_newchunk (__o, __len); \
if (!__o->alloc_failed) \
{ \
bcopy (where, __o->next_free, __len); \
memcpy (__o->next_free, where, __len); \
__o->next_free += __len; \
} \
(void) 0; })
#define obstack_grow0(OBSTACK,where,length) \
#
define obstack_grow0(OBSTACK,where,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
int __len = (length); \
if (__o->next_free + __len + 1 > __o->chunk_limit) \
_obstack_newchunk (__o, __len + 1); \
if (!__o->alloc_failed) \
{ \
bcopy (where, __o->next_free, __len); \
memcpy (__o->next_free, where, __len); \
__o->next_free += __len; \
*(__o->next_free)++ = 0; \
} \
(void) 0; })
#define obstack_1grow(OBSTACK,datum) \
#
define obstack_1grow(OBSTACK,datum) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + 1 > __o->chunk_limit) \
_obstack_newchunk (__o, 1); \
if (!__o->alloc_failed) \
*(__o->next_free)++ = (datum); \
obstack_1grow_fast (__o, datum); \
(void) 0; })
/* These assume that the obstack alignment is good enough for pointers
or ints,
and that the data added so far to the current object
/* These assume that the obstack alignment is good enough for pointers
or ints,
and that the data added so far to the current object
shares that much alignment. */
#
define obstack_ptr_grow(OBSTACK,datum)
\
#
define obstack_ptr_grow(OBSTACK,datum)
\
__extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (void *) > __o->chunk_limit) \
_obstack_newchunk (__o, sizeof (void *)); \
if (!__o->alloc_failed) \
*((void **)__o->next_free)++ = ((void *)datum); \
(void) 0; })
obstack_ptr_grow_fast (__o, datum); }) \
#
define obstack_int_grow(OBSTACK,datum)
\
#
define obstack_int_grow(OBSTACK,datum)
\
__extension__ \
({ struct obstack *__o = (OBSTACK); \
if (__o->next_free + sizeof (int) > __o->chunk_limit) \
_obstack_newchunk (__o, sizeof (int)); \
if (!__o->alloc_failed) \
*((int *)__o->next_free)++ = ((int)datum); \
obstack_int_grow_fast (__o, datum); })
# define obstack_ptr_grow_fast(OBSTACK,aptr) \
__extension__ \
({ struct obstack *__o1 = (OBSTACK); \
*(const void **) __o1->next_free = (aptr); \
__o1->next_free += sizeof (const void *); \
(void) 0; })
#define obstack_ptr_grow_fast(h,aptr) (*((void **)(h)->next_free)++ = (void *)aptr)
#define obstack_int_grow_fast(h,aint) (*((int *)(h)->next_free)++ = (int)aint)
# define obstack_int_grow_fast(OBSTACK,aint) \
__extension__ \
({ struct obstack *__o1 = (OBSTACK); \
*(int *) __o1->next_free = (aint); \
__o1->next_free += sizeof (int); \
(void) 0; })
#define obstack_blank(OBSTACK,length) \
#
define obstack_blank(OBSTACK,length) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
int __len = (length); \
if (__o->chunk_limit - __o->next_free < __len) \
_obstack_newchunk (__o, __len); \
if (!__o->alloc_failed) \
__o->next_free += __len; \
obstack_blank_fast (__o, __len); \
(void) 0; })
#define obstack_alloc(OBSTACK,length) \
#
define obstack_alloc(OBSTACK,length) \
__extension__ \
({ struct obstack *__h = (OBSTACK); \
obstack_blank (__h, (length)); \
obstack_finish (__h); })
#define obstack_copy(OBSTACK,where,length) \
#
define obstack_copy(OBSTACK,where,length) \
__extension__ \
({ struct obstack *__h = (OBSTACK); \
obstack_grow (__h, (where), (length)); \
obstack_finish (__h); })
#define obstack_copy0(OBSTACK,where,length) \
#
define obstack_copy0(OBSTACK,where,length) \
__extension__ \
({ struct obstack *__h = (OBSTACK); \
obstack_grow0 (__h, (where), (length)); \
...
...
@@ -385,134 +382,131 @@ __extension__ \
/* The local variable is named __o1 to avoid a name conflict
when obstack_blank is called. */
#
define obstack_finish(OBSTACK)
\
#
define obstack_finish(OBSTACK)
\
__extension__ \
({ struct obstack *__o1 = (OBSTACK); \
void *value; \
if (__o1->alloc_failed) \
value = 0; \
else \
{ \
value = (void *) __o1->object_base; \
if (__o1->next_free == value) \
void *__value = (void *) __o1->object_base; \
if (__o1->next_free == __value) \
__o1->maybe_empty_object = 1; \
__o1->next_free \
= __INT_TO_PTR ((__PTR_TO_INT (__o1->next_free)+__o1->alignment_mask)
\
& ~ (__o1->alignment_mask));
\
= __PTR_ALIGN (__o1->object_base, __o1->next_free,
\
__o1->alignment_mask);
\
if (__o1->next_free - (char *)__o1->chunk \
> __o1->chunk_limit - (char *)__o1->chunk) \
__o1->next_free = __o1->chunk_limit; \
__o1->object_base = __o1->next_free; \
} \
value; })
__value; })
#define obstack_free(OBSTACK, OBJ) \
#
define obstack_free(OBSTACK, OBJ) \
__extension__ \
({ struct obstack *__o = (OBSTACK); \
void *__obj = (OBJ); \
if (__obj > (void *)__o->chunk && __obj < (void *)__o->chunk_limit) \
__o->next_free = __o->object_base =
__obj;
\
__o->next_free = __o->object_base =
(char *)__obj;
\
else (obstack_free) (__o, __obj); })
#else
/* not __GNUC__ or not __STDC__ */
#define obstack_object_size(h) \
(unsigned) ((h)->
alloc_failed ? 0 : (h)->
next_free - (h)->object_base)
#
define obstack_object_size(h) \
(unsigned) ((h)->next_free - (h)->object_base)
#define obstack_room(h) \
#
define obstack_room(h) \
(unsigned) ((h)->chunk_limit - (h)->next_free)
# define obstack_empty_p(h) \
((h)->chunk->prev == 0 \
&& (h)->next_free == __PTR_ALIGN ((char *) (h)->chunk, \
(h)->chunk->contents, \
(h)->alignment_mask))
/* Note that the call to _obstack_newchunk is enclosed in (..., 0)
so that we can avoid having void expressions
in the arms of the conditional expression.
Casting the third operand to void was tried before,
but some compilers won't accept it. */
#define obstack_grow(h,where,length) \
( (h)->temp = (length), \
(((h)->next_free + (h)->temp > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
((h)->alloc_failed ? 0 : \
(bcopy (where, (h)->next_free, (h)->temp), \
(h)->next_free += (h)->temp)))
#define obstack_grow0(h,where,length) \
( (h)->temp = (length), \
(((h)->next_free + (h)->temp + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp + 1), 0) : 0), \
((h)->alloc_failed ? 0 : \
(bcopy (where, (h)->next_free, (h)->temp), \
(h)->next_free += (h)->temp, \
*((h)->next_free)++ = 0)))
#define obstack_1grow(h,datum) \
# define obstack_make_room(h,length) \
( (h)->temp.tempint = (length), \
(((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0))
# define obstack_grow(h,where,length) \
( (h)->temp.tempint = (length), \
(((h)->next_free + (h)->temp.tempint > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
memcpy ((h)->next_free, where, (h)->temp.tempint), \
(h)->next_free += (h)->temp.tempint)
# define obstack_grow0(h,where,length) \
( (h)->temp.tempint = (length), \
(((h)->next_free + (h)->temp.tempint + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), (h)->temp.tempint + 1), 0) : 0), \
memcpy ((h)->next_free, where, (h)->temp.tempint), \
(h)->next_free += (h)->temp.tempint, \
*((h)->next_free)++ = 0)
# define obstack_1grow(h,datum) \
( (((h)->next_free + 1 > (h)->chunk_limit) \
? (_obstack_newchunk ((h), 1), 0) : 0), \
((h)->alloc_failed ? 0 : \
(*((h)->next_free)++ = (datum))))
obstack_1grow_fast (h, datum))
#define obstack_ptr_grow(h,datum) \
#
define obstack_ptr_grow(h,datum) \
( (((h)->next_free + sizeof (char *) > (h)->chunk_limit) \
? (_obstack_newchunk ((h), sizeof (char *)), 0) : 0), \
((h)->alloc_failed ? 0 : \
(*((char **)(((h)->next_free+=sizeof(char *))-sizeof(char *))) = ((char *)datum))))
obstack_ptr_grow_fast (h, datum))
#define obstack_int_grow(h,datum) \
#
define obstack_int_grow(h,datum) \
( (((h)->next_free + sizeof (int) > (h)->chunk_limit) \
? (_obstack_newchunk ((h), sizeof (int)), 0) : 0), \
((h)->alloc_failed ? 0 : \
(*((int *)(((h)->next_free+=sizeof(int))-sizeof(int))) = ((int)datum))))
obstack_int_grow_fast (h, datum))
#
define obstack_ptr_grow_fast(h,aptr) (*((char **)(h)->next_free)++ = (char *)aptr)
#define obstack_int_grow_fast(h,aint) (*((int *)(h)->next_free)++ = (int)aint
)
#
define obstack_ptr_grow_fast(h,aptr) \
(((const void **) ((h)->next_free += sizeof (void *)))[-1] = (aptr)
)
#define obstack_blank(h,length) \
( (h)->temp = (length), \
(((h)->chunk_limit - (h)->next_free < (h)->temp) \
? (_obstack_newchunk ((h), (h)->temp), 0) : 0), \
((h)->alloc_failed ? 0 : \
((h)->next_free += (h)->temp)))
# define obstack_int_grow_fast(h,aint) \
(((int *) ((h)->next_free += sizeof (int)))[-1] = (aptr))
#define obstack_alloc(h,length) \
# define obstack_blank(h,length) \
( (h)->temp.tempint = (length), \
(((h)->chunk_limit - (h)->next_free < (h)->temp.tempint) \
? (_obstack_newchunk ((h), (h)->temp.tempint), 0) : 0), \
obstack_blank_fast (h, (h)->temp.tempint))
# define obstack_alloc(h,length) \
(obstack_blank ((h), (length)), obstack_finish ((h)))
#define obstack_copy(h,where,length) \
#
define obstack_copy(h,where,length) \
(obstack_grow ((h), (where), (length)), obstack_finish ((h)))
#define obstack_copy0(h,where,length) \
#
define obstack_copy0(h,where,length) \
(obstack_grow0 ((h), (where), (length)), obstack_finish ((h)))
#define obstack_finish(h) \
( (h)->alloc_failed ? 0 : \
(((h)->next_free == (h)->object_base \
# define obstack_finish(h) \
( ((h)->next_free == (h)->object_base \
? (((h)->maybe_empty_object = 1), 0) \
: 0), \
(h)->temp
= __PTR_TO_INT ((h)->object_base),
\
(h)->temp
.tempptr = (h)->object_base,
\
(h)->next_free \
= __
INT_TO_PTR ((__PTR_TO_INT ((h)->next_free)+(h)->alignment_mask)
\
& ~ ((h)->alignment_mask)
), \
(((h)->next_free - (char *)
(h)->chunk
\
> (h)->chunk_limit - (char *)(h)->chunk) \
= __
PTR_ALIGN ((h)->object_base, (h)->next_free,
\
(h)->alignment_mask
), \
(((h)->next_free - (char *)
(h)->chunk
\
> (h)->chunk_limit - (char *)
(h)->chunk) \
? ((h)->next_free = (h)->chunk_limit) : 0), \
(h)->object_base = (h)->next_free, \
__INT_TO_PTR ((h)->temp))
)
(h)->temp.tempptr
)
#ifdef __STDC__
#define obstack_free(h,obj) \
( (h)->temp = (char *)(obj) - (char *) (h)->chunk, \
(((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\
? (int) ((h)->next_free = (h)->object_base \
= (h)->temp + (char *) (h)->chunk) \
: (((obstack_free) ((h), (h)->temp + (char *) (h)->chunk), 0), 0)))
#else
#define obstack_free(h,obj) \
( (h)->temp = (char *)(obj) - (char *) (h)->chunk, \
(((h)->temp > 0 && (h)->temp < (h)->chunk_limit - (char *) (h)->chunk)\
# define obstack_free(h,obj) \
( (h)->temp.tempint = (char *) (obj) - (char *) (h)->chunk, \
((((h)->temp.tempint > 0 \
&& (h)->temp.tempint < (h)->chunk_limit - (char *) (h)->chunk)) \
? (int) ((h)->next_free = (h)->object_base \
= (h)->temp + (char *) (h)->chunk) \
: (_obstack_free ((h), (h)->temp + (char *) (h)->chunk), 0)))
#endif
= (h)->temp.tempint + (char *) (h)->chunk) \
: (((obstack_free) ((h), (h)->temp.tempint + (char *) (h)->chunk), 0), 0)))
#endif
/* not __GNUC__ or not __STDC__ */
#endif
/* not __OBSTACK_H__ */
#ifdef __cplusplus
}
/* C++ */
#endif
#endif
/* obstack.h */
...
...
lib/realloc.c
View file @
48442c8
/* r
pl_realloc.c -- a replacement for broken realloc implementations
Copyright (C)
2001
Free Software Foundation, Inc.
/* r
ealloc() function that is glibc compatible.
Copyright (C)
1997, 2003, 2004
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
...
...
@@ -15,18 +15,32 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/* written by Jim Meyering */
#if HAVE_CONFIG_H
# include <config.h>
#endif
#undef realloc
#include <stdlib.h>
/* Change the size of an allocated block of memory P to N bytes,
with error checking. If N is zero, change it to 1. If P is NULL,
use malloc. */
void
*
rpl_realloc
(
void
*
ptr
,
size_t
size
)
rpl_realloc
(
void
*
p
,
size_t
n
)
{
if
(
!
ptr
)
return
malloc
(
size
);
if
(
!
size
)
if
(
n
==
0
)
{
if
(
ptr
)
free
(
ptr
);
return
malloc
(
size
);
n
=
1
;
/* In theory realloc might fail, so don't rely on it to free. */
free
(
p
);
p
=
NULL
;
}
return
realloc
(
ptr
,
size
);
if
(
p
==
NULL
)
return
malloc
(
n
);
return
realloc
(
p
,
n
);
}
...
...
Please
register
or
sign in
to post a comment