make .gnulib a submodule

This makes it so we record (via a git submodule)
a snapshot of whatever version of gnulib we're using,
and none of gnulib sources are in the libvirt repository.
The result is that we have as much reproducibility as when
we version-controlled imported copies of the gnulib sources,
but without the hassle of the manual process we used when
syncing with upstream.

Note that when you clone libvirt, you get only the libvirt
repository, but when you first run ./bootstrap, it clones
gnulib (at the SHA1 recorded via the submodule), creating
the .gnulib/ hierarchy.  Then, the bootstrap script runs
gnulib-tool to populate gnulib/ with the files that make
up the selected modules.

Put the following in your ~/.gitconfig file.
[alias]
  syncsub = submodule foreach git pull origin master

The update procedure is simple:
  git syncsub
  ...build & test...
  git commit -m 'gnulib: sync submodule to latest' .gnulib

* .gitmodules: New file.
* .gnulib: Initialize.
* bootstrap: Set up to use the new submodule.
Stop using --no-vc-files.
Don't remove .gitignore files.
Don't use or create .cvsignore.
Diagnose an invalid --gnulib-srcdir=DIR argument.
* build-aux/vc-list-files: Delete file, now pulled from gnulib.
* build-aux/useless-if-before-free: Likewise.
* po/POTFILES.in: Remove gnulib/lib/gai_strerror.c, since
it no longer contains translatable strings.
* gnulib/*: Remove gnulib/ hierarchy.
This commit is contained in:
Jim Meyering 2009-07-07 11:22:52 +02:00
parent 360194bfb5
commit 7bb22f58b8
241 changed files with 26 additions and 33807 deletions

1
.gitignore vendored
View File

@ -34,3 +34,4 @@ stamp-h
stamp-h.in
stamp-h1
update.log
tests/*.log

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "gnulib"]
path = .gnulib
url = git://git.sv.gnu.org/gnulib.git

1
.gnulib Submodule

@ -0,0 +1 @@
Subproject commit 1203e8d1f62dec3d2436dffadd5c20793cf84366

View File

@ -40,25 +40,31 @@ do
esac
done
cleanup_gnulib() {
st=$?
rm -fr .gnulib
exit $st
}
# Get gnulib files.
case ${GNULIB_SRCDIR--} in
-)
if [ ! -d .gnulib ]; then
echo "$0: getting gnulib files..."
trap cleanup_gnulib 1 2 13 15
git clone --depth 1 git://git.sv.gnu.org/gnulib .gnulib ||
cleanup_gnulib
trap - 1 2 13 15
fi
echo "$0: getting gnulib files..."
git submodule init || exit $?
git submodule update || exit $?
GNULIB_SRCDIR=.gnulib
;;
*)
# Redirect the gnulib submodule to the directory on the command line
# if possible.
if test -d "$GNULIB_SRCDIR"/.git && \
git config --file .gitmodules submodule.gnulib.url >/dev/null; then
git submodule init
GNULIB_SRCDIR=`cd $GNULIB_SRCDIR && pwd`
git config --replace-all submodule.gnulib.url $GNULIB_SRCDIR
echo "$0: getting gnulib files..."
git submodule update || exit $?
GNULIB_SRCDIR=.gnulib
else
echo >&2 "$0: invalid gnulib srcdir: $GNULIB_SRCDIR"
exit 1
fi
;;
esac
gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
@ -103,20 +109,9 @@ vc-list-files
# put *.[ch] files in new gnulib/lib/ dir.
$gnulib_tool \
--no-vc-files \
--lgpl=2 \
--with-tests \
--m4-base=gnulib/m4 \
--source-base=gnulib/lib \
--tests-base=gnulib/tests \
--import $modules
rm -f \
.gitignore \
gnulib/lib/.gitignore \
gnulib/m4/.gitignore \
gnulib/tests/.gitignore
(cd gnulib/lib &&
(cat .cvsignore; \
ls -1 *.in.h|sed 's/\.in\.h/.h/') | sort -u > .t; mv .t .cvsignore)

View File

@ -1,180 +0,0 @@
#!/usr/bin/perl -T
# Detect instances of "if (p) free (p);".
# Likewise for "if (p != NULL) free (p);". And with braces.
my $VERSION = '2008-05-25 17:36'; # UTC
# The definition above must lie within the first 8 lines in order
# for the Emacs time-stamp write hook (at end) to update it.
# If you change this file with Emacs, please let the write hook
# do its job. Otherwise, update this string manually.
# Copyright (C) 2008 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
# Written by Jim Meyering
use strict;
use warnings;
use Getopt::Long;
(my $ME = $0) =~ s|.*/||;
# use File::Coda; # http://meyering.net/code/Coda/
END {
defined fileno STDOUT or return;
close STDOUT and return;
warn "$ME: failed to close standard output: $!\n";
$? ||= 1;
}
sub usage ($)
{
my ($exit_code) = @_;
my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
if ($exit_code != 0)
{
print $STREAM "Try `$ME --help' for more information.\n";
}
else
{
print $STREAM <<EOF;
Usage: $ME [OPTIONS] FILE...
Detect any instance in FILE of a useless "if" test before a free call, e.g.,
"if (p) free (p);". Any such test may be safely removed without affecting
the semantics of the C code in FILE. Use --name=FOO --name=BAR to also
detect free-like functions named FOO and BAR.
OPTIONS:
--list print only the name of each matching FILE (\0-terminated)
--name=N add name N to the list of `free'-like functions to detect;
may be repeated
--help display this help and exit
--version output version information and exit
Exit status:
0 one or more matches
1 no match
2 an error
EXAMPLE:
For example, this command prints all removable "if" tests before "free"
and "kfree" calls in the linux kernel sources:
git ls-files -z |xargs -0 $ME --name=kfree
EOF
}
exit $exit_code;
}
{
sub EXIT_MATCH {0}
sub EXIT_NO_MATCH {1}
sub EXIT_ERROR {2}
my $err = EXIT_NO_MATCH;
my $list;
my @name = qw(free);
GetOptions
(
help => sub { usage 0 },
version => sub { print "$ME version $VERSION\n"; exit },
list => \$list,
'name=s@' => \@name,
) or usage 1;
# Make sure we have the right number of non-option arguments.
# Always tell the user why we fail.
@ARGV < 1
and (warn "$ME: missing FILE argument\n"), usage EXIT_ERROR;
my $or = join '|', @name;
my $regexp = qr/(?:$or)/;
# Set the input record separator.
# Note: this makes it impractical to print line numbers.
$/ = '"';
my $found_match = 0;
FILE:
foreach my $file (@ARGV)
{
open FH, '<', $file
or (warn "$ME: can't open `$file' for reading: $!\n"),
$err = EXIT_ERROR, next;
while (defined (my $line = <FH>))
{
while ($line =~
/\b(if\s*\(\s*([^)]+?)(?:\s*!=\s*NULL)?\s*\)
(?: \s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)|
\s*\{\s*$regexp\s*\((?:\s*\([^)]+\))?\s*([^)]+)\)\s*;\s*\}))/sxg)
{
# Compare "if" expression and free'd expression,
# without regard to white space.
(my $e1 = $2) =~ tr/ \t//d;
my $e2 = defined $3 ? $3 : $4;
$e2 =~ tr/ \t//d;
if ($e1 eq $e2)
{
$found_match = 1;
$list
and (print "$file\0"), next FILE;
print "$file: $1\n";
}
}
}
}
continue
{
close FH;
}
$found_match && $err == EXIT_NO_MATCH
and $err = EXIT_MATCH;
exit $err;
}
my $foo = <<'EOF';
# The above is to *find* them.
# This adjusts them, removing the unnecessary "if (p)" part.
# FIXME: do something like this as an option (doesn't do braces):
useless-if-before-free -l $(lid -knone free) | xargs -0 \
perl -0x3b -pi -e \
's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+(free\s*\((?:\s*\([^)]+\))?\s*\1\s*\))/$2/s'
# Or, with git:
git ls-files -z |xargs -0 perl -0x3b -pi -e '...'
Be careful that the result of the above transformation is valid.
If the matched string is followed by "else", then obviously, it won't be.
When modifying files, refuse to process anything other than a regular file.
EOF
## Local Variables:
## indent-tabs-mode: nil
## eval: (add-hook 'write-file-hooks 'time-stamp)
## time-stamp-start: "my $VERSION = '"
## time-stamp-format: "%:y-%02m-%02d %02H:%02M"
## time-stamp-time-zone: "UTC"
## time-stamp-end: "'; # UTC"
## End:

View File

@ -1,107 +0,0 @@
#!/bin/sh
# List version-controlled file names.
# Print a version string.
scriptversion=2008-07-11.19
# Copyright (C) 2006-2008 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
# List the specified version-controlled files.
# With no argument, list them all. With a single DIRECTORY argument,
# list the version-controlled files in that directory.
# If there's an argument, it must be a single, "."-relative directory name.
# cvsu is part of the cvsutils package: http://www.red-bean.com/cvsutils/
postprocess=
case $1 in
--help) cat <<EOF
Usage: $0 [-C SRCDIR] [DIR]
Output a list of version-controlled files in DIR (default .), relative to
SRCDIR (default .). SRCDIR must be the top directory of a checkout.
Options:
--help print this help, then exit
--version print version number, then exit
-C SRCDIR change directory to SRCDIR before generating list
Report bugs and patches to <bug-gnulib@gnu.org>.
EOF
exit ;;
--version)
year=`echo "$scriptversion" | sed 's/[^0-9].*//'`
cat <<EOF
vc-list-files $scriptversion
Copyright (C) $year Free Software Foundation, Inc,
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
EOF
exit ;;
-C)
test "$2" = . || postprocess="| sed 's|^|$2/|'"
cd "$2" || exit 1
shift; shift ;;
esac
dir=
case $# in
0) ;;
1) dir=$1 ;;
*) echo "$0: too many arguments" 1>&2
echo "Usage: $0 [-C srcdir] [DIR]" 1>&2; exit 1;;
esac
test "x$dir" = x && dir=.
if test -d .git; then
eval exec git ls-files '"$dir"' $postprocess
elif test -d .hg; then
eval exec hg locate '"$dir/*"' $postprocess
elif test -d .bzr; then
test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
eval exec bzr ls --versioned '"$dir"' $postprocess
elif test -d CVS; then
test "$postprocess" = '' && postprocess="| sed 's|^\./||'"
if test -x build-aux/cvsu; then
eval build-aux/cvsu --find --types=AFGM '"$dir"' $postprocess
elif (cvsu --help) >/dev/null 2>&1; then
eval cvsu --find --types=AFGM '"$dir"' $postprocess
else
eval awk -F/ \''{ \
if (!$1 && $3 !~ /^-/) { \
f=FILENAME; \
if (f ~ /CVS\/Entries$/) \
f = substr(f, 0, length(f)-11); \
print f $2; \
}}'\'' \
`find "$dir" -name Entries -print` /dev/null' $postprocess
fi
else
echo "$0: Failed to determine type of version control used in `pwd`" 1>&2
exit 1
fi
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View File

@ -1,26 +0,0 @@
*.la
*.lo
.deps
.libs
Makefile
Makefile.in
alloca.h
arpa_inet.h
errno.h
float.h
netdb.h
netinet_in.h
poll.h
stdbool.h
stdint.h
stdio.h
stdlib.h
string.h
sys_ioctl.h
sys_select.h
sys_socket.h
sys_stat.h
sys_time.h
time.h
unistd.h
wchar.h

26
gnulib/lib/.gitignore vendored
View File

@ -1,26 +0,0 @@
*.la
*.lo
.deps
.libs
Makefile
Makefile.in
alloca.h
arpa_inet.h
errno.h
float.h
netdb.h
netinet_in.h
poll.h
stdbool.h
stdint.h
stdio.h
stdlib.h
string.h
sys_ioctl.h
sys_select.h
sys_socket.h
sys_stat.h
sys_time.h
time.h
unistd.h
wchar.h

File diff suppressed because it is too large Load Diff

View File

@ -1,489 +0,0 @@
/* alloca.c -- allocate automatically reclaimed memory
(Mostly) portable public-domain implementation -- D A Gwyn
This implementation of the PWB library alloca function,
which is used to allocate space off the run-time stack so
that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
J.Otto Tennant <jot@cray.com> contributed the Cray support.
There are some preprocessor constants that can
be defined when compiling for your specific system, for
improved efficiency; however, the defaults should be okay.
The general concept of this implementation is to keep
track of all alloca-allocated blocks, and reclaim any
that are found to be deeper in the stack than the current
invocation. This heuristic does not reclaim storage as
soon as it becomes invalid, but it will do so eventually.
As a special case, alloca(0) reclaims storage without
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
#include <config.h>
#include <alloca.h>
#include <string.h>
#include <stdlib.h>
#ifdef emacs
# include "lisp.h"
# include "blockinput.h"
# ifdef EMACS_FREE
# undef free
# define free EMACS_FREE
# endif
#else
# define memory_full() abort ()
#endif
/* If compiling with GCC 2, this file's not needed. */
#if !defined (__GNUC__) || __GNUC__ < 2
/* If someone has defined alloca as a macro,
there must be some other way alloca is supposed to work. */
# ifndef alloca
# ifdef emacs
# ifdef static
/* actually, only want this if static is defined as ""
-- this is for usg, in which emacs must undefine static
in order to make unexec workable
*/
# ifndef STACK_DIRECTION
you
lose
-- must know STACK_DIRECTION at compile-time
/* Using #error here is not wise since this file should work for
old and obscure compilers. */
# endif /* STACK_DIRECTION undefined */
# endif /* static */
# endif /* emacs */
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
# if defined (CRAY) && defined (CRAY_STACKSEG_END)
long i00afunc ();
# define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
# else
# define ADDRESS_FUNCTION(arg) &(arg)
# endif
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
deduced at run-time.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
# ifndef STACK_DIRECTION
# define STACK_DIRECTION 0 /* Direction unknown. */
# endif
# if STACK_DIRECTION != 0
# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
# else /* STACK_DIRECTION == 0; need run-time code. */
static int stack_dir; /* 1 or -1 once known. */
# define STACK_DIR stack_dir
static void
find_stack_direction (void)
{
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
if (addr == NULL)
{ /* Initial entry. */
addr = ADDRESS_FUNCTION (dummy);
find_stack_direction (); /* Recurse once. */
}
else
{
/* Second entry. */
if (ADDRESS_FUNCTION (dummy) > addr)
stack_dir = 1; /* Stack grew upward. */
else
stack_dir = -1; /* Stack grew downward. */
}
}
# endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
(b) keep track of stack depth.
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
# ifndef ALIGN_SIZE
# define ALIGN_SIZE sizeof(double)
# endif
typedef union hdr
{
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
} header;
static header *last_alloca_header = NULL; /* -> last alloca header. */
/* Return a pointer to at least SIZE bytes of storage,
which will be automatically reclaimed upon exit from
the procedure that called alloca. Originally, this space
was supposed to be taken from the current stack frame of the
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
void *
alloca (size_t size)
{
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
# if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
# endif
/* Reclaim garbage, defined as all alloca'd storage that
was allocated from deeper in the stack than currently. */
{
register header *hp; /* Traverses linked list. */
# ifdef emacs
BLOCK_INPUT;
# endif
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
register header *np = hp->h.next;
free (hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
last_alloca_header = hp; /* -> last valid storage. */
# ifdef emacs
UNBLOCK_INPUT;
# endif
}
if (size == 0)
return NULL; /* No allocation required. */
/* Allocate combined header + user data storage. */
{
/* Address of header. */
register header *new;
size_t combined_size = sizeof (header) + size;
if (combined_size < sizeof (header))
memory_full ();
new = malloc (combined_size);
if (! new)
memory_full ();
new->h.next = last_alloca_header;
new->h.deep = depth;
last_alloca_header = new;
/* User storage begins just after header. */
return (void *) (new + 1);
}
}
# if defined (CRAY) && defined (CRAY_STACKSEG_END)
# ifdef DEBUG_I00AFUNC
# include <stdio.h>
# endif
# ifndef CRAY_STACK
# define CRAY_STACK
# ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header
{
long shgrow:32; /* Number of times stack has grown. */
long shaseg:32; /* Size of increments to stack. */
long shhwm:32; /* High water mark of stack. */
long shsize:32; /* Current size of stack (all segments). */
};
/* The stack segment linkage control information occurs at
the high-address end of a stack segment. (The stack
grows from low addresses to high addresses.) The initial
part of the stack segment linkage control information is
0200 (octal) words. This provides for register storage
for the routine which overflows the stack. */
struct stack_segment_linkage
{
long ss[0200]; /* 0200 overflow words. */
long sssize:32; /* Number of words in this segment. */
long ssbase:32; /* Offset to stack base. */
long:32;
long sspseg:32; /* Offset to linkage control of previous
segment of stack. */
long:32;
long sstcpt:32; /* Pointer to task common address block. */
long sscsnm; /* Private control structure number for
microtasking. */
long ssusr1; /* Reserved for user. */
long ssusr2; /* Reserved for user. */
long sstpid; /* Process ID for pid based multi-tasking. */
long ssgvup; /* Pointer to multitasking thread giveup. */
long sscray[7]; /* Reserved for Cray Research. */
long ssa0;
long ssa1;
long ssa2;
long ssa3;
long ssa4;
long ssa5;
long ssa6;
long ssa7;
long sss0;
long sss1;
long sss2;
long sss3;
long sss4;
long sss5;
long sss6;
long sss7;
};
# else /* CRAY2 */
/* The following structure defines the vector of words
returned by the STKSTAT library routine. */
struct stk_stat
{
long now; /* Current total stack size. */
long maxc; /* Amount of contiguous space which would
be required to satisfy the maximum
stack demand to date. */
long high_water; /* Stack high-water mark. */
long overflows; /* Number of stack overflow ($STKOFEN) calls. */
long hits; /* Number of internal buffer hits. */
long extends; /* Number of block extensions. */
long stko_mallocs; /* Block allocations by $STKOFEN. */
long underflows; /* Number of stack underflow calls ($STKRETN). */
long stko_free; /* Number of deallocations by $STKRETN. */
long stkm_free; /* Number of deallocations by $STKMRET. */
long segments; /* Current number of stack segments. */
long maxs; /* Maximum number of stack segments so far. */
long pad_size; /* Stack pad size. */
long current_address; /* Current stack segment address. */
long current_size; /* Current stack segment size. This
number is actually corrupted by STKSTAT to
include the fifteen word trailer area. */
long initial_address; /* Address of initial segment. */
long initial_size; /* Size of initial segment. */
};
/* The following structure describes the data structure which trails
any stack segment. I think that the description in 'asdef' is
out of date. I only describe the parts that I am sure about. */
struct stk_trailer
{
long this_address; /* Address of this block. */
long this_size; /* Size of this block (does not include
this trailer). */
long unknown2;
long unknown3;
long link; /* Address of trailer block of previous
segment. */
long unknown5;
long unknown6;
long unknown7;
long unknown8;
long unknown9;
long unknown10;
long unknown11;
long unknown12;
long unknown13;
long unknown14;
};
# endif /* CRAY2 */
# endif /* not CRAY_STACK */
# ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS.
I doubt that "lint" will like this much. */
static long
i00afunc (long *address)
{
struct stk_stat status;
struct stk_trailer *trailer;
long *block, size;
long result = 0;
/* We want to iterate through all of the segments. The first
step is to get the stack status structure. We could do this
more quickly and more directly, perhaps, by referencing the
$LM00 common block, but I know that this works. */
STKSTAT (&status);
/* Set up the iteration. */
trailer = (struct stk_trailer *) (status.current_address
+ status.current_size
- 15);
/* There must be at least one stack segment. Therefore it is
a fatal error if "trailer" is null. */
if (trailer == 0)
abort ();
/* Discard segments that do not contain our argument address. */
while (trailer != 0)
{
block = (long *) trailer->this_address;
size = trailer->this_size;
if (block == 0 || size == 0)
abort ();
trailer = (struct stk_trailer *) trailer->link;
if ((block <= address) && (address < (block + size)))
break;
}
/* Set the result to the offset in this segment and add the sizes
of all predecessor segments. */
result = address - block;
if (trailer == 0)
{
return result;
}
do
{
if (trailer->this_size <= 0)
abort ();
result += trailer->this_size;
trailer = (struct stk_trailer *) trailer->link;
}
while (trailer != 0);
/* We are done. Note that if you present a bogus address (one
not in any segment), you will get a different number back, formed
from subtracting the address of the first block. This is probably
not what you want. */
return (result);
}
# else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
routine is to linearize, in some sense, stack addresses
for alloca. */
static long
i00afunc (long address)
{
long stkl = 0;
long size, pseg, this_segment, stack;
long result = 0;
struct stack_segment_linkage *ssptr;
/* Register B67 contains the address of the end of the
current stack segment. If you (as a subprogram) store
your registers on the stack and find that you are past
the contents of B67, you have overflowed the segment.
B67 also points to the stack segment linkage control
area, which is what we are really interested in. */
stkl = CRAY_STACKSEG_END ();
ssptr = (struct stack_segment_linkage *) stkl;
/* If one subtracts 'size' from the end of the segment,
one has the address of the first word of the segment.
If this is not the first segment, 'pseg' will be
nonzero. */
pseg = ssptr->sspseg;
size = ssptr->sssize;
this_segment = stkl - size;
/* It is possible that calling this routine itself caused
a stack overflow. Discard stack segments which do not
contain the target address. */
while (!(this_segment <= address && address <= stkl))
{
# ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
# endif
if (pseg == 0)
break;
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
this_segment = stkl - size;
}
result = address - this_segment;
/* If you subtract pseg from the current end of the stack,
you get the address of the previous stack segment's end.
This seems a little convoluted to me, but I'll bet you save
a cycle somewhere. */
while (pseg != 0)
{
# ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size);
# endif
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
pseg = ssptr->sspseg;
result += size;
}
return (result);
}
# endif /* not CRAY2 */
# endif /* CRAY */
# endif /* no alloca */
#endif /* not GCC version 2.1 */

View File

@ -1,56 +0,0 @@
/* Memory allocation on the stack.
Copyright (C) 1995, 1999, 2001-2004, 2006-2008 Free Software
Foundation, Inc.
This program 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.1, 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 Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
USA. */
/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
means there is a real alloca function. */
#ifndef _GL_ALLOCA_H
#define _GL_ALLOCA_H
/* alloca (N) returns a pointer to N bytes of memory
allocated on the stack, which will last until the function returns.
Use of alloca should be avoided:
- inside arguments of function calls - undefined behaviour,
- in inline functions - the allocation may actually last until the
calling function returns,
- for huge N (say, N >= 65536) - you never know how large (or small)
the stack is, and when the stack cannot fulfill the memory allocation
request, the program just crashes.
*/
#ifndef alloca
# ifdef __GNUC__
# define alloca __builtin_alloca
# elif defined _AIX
# define alloca __alloca
# elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
# elif defined __DECC && defined __VMS
# define alloca __ALLOCA
# else
# include <stddef.h>
# ifdef __cplusplus
extern "C"
# endif
void *alloca (size_t);
# endif
#endif
#endif /* _GL_ALLOCA_H */

View File

@ -1 +0,0 @@
inet.h

View File

@ -1 +0,0 @@
inet.h

View File

@ -1,90 +0,0 @@
/* A GNU-like <arpa/inet.h>.
Copyright (C) 2005-2006, 2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_ARPA_INET_H
/* Gnulib's sys/socket.h is responsible for pulling in winsock2.h etc
under MinGW. */
#include <sys/socket.h>
#if @HAVE_ARPA_INET_H@
# if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
# endif
/* The include_next requires a split double-inclusion guard. */
# @INCLUDE_NEXT@ @NEXT_ARPA_INET_H@
#endif
#ifndef _GL_ARPA_INET_H
#define _GL_ARPA_INET_H
/* The definition of GL_LINK_WARNING is copied here. */
#ifdef __cplusplus
extern "C" {
#endif
#if @GNULIB_INET_NTOP@
# if !@HAVE_DECL_INET_NTOP@
/* Converts an internet address from internal format to a printable,
presentable format.
AF is an internet address family, such as AF_INET or AF_INET6.
SRC points to a 'struct in_addr' (for AF_INET) or 'struct in6_addr'
(for AF_INET6).
DST points to a buffer having room for CNT bytes.
The printable representation of the address (in numeric form, not
surrounded by [...], no reverse DNS is done) is placed in DST, and
DST is returned. If an error occurs, the return value is NULL and
errno is set. If CNT bytes are not sufficient to hold the result,
the return value is NULL and errno is set to ENOSPC. A good value
for CNT is 46.
For more details, see the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/inet_ntop.html>. */
extern const char *inet_ntop (int af, const void *restrict src,
char *restrict dst, socklen_t cnt);
# endif
#elif defined GNULIB_POSIXCHECK
# undef inet_ntop
# define inet_ntop(af,src,dst,cnt) \
(GL_LINK_WARNING ("inet_ntop is unportable - " \
"use gnulib module inet_ntop for portability"), \
inet_ntop (af, src, dst, cnt))
#endif
#if @GNULIB_INET_PTON@
# if !@HAVE_DECL_INET_PTON@
extern int inet_pton (int af, const char *restrict src, void *restrict dst);
# endif
#elif defined GNULIB_POSIXCHECK
# undef inet_pton
# define inet_pton(af,src,dst) \
(GL_LINK_WARNING ("inet_pton is unportable - " \
"use gnulib module inet_pton for portability"), \
inet_pton (af, src, dst))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_ARPA_INET_H */
#endif /* _GL_ARPA_INET_H */

View File

@ -1,35 +0,0 @@
/* Formatted output to strings.
Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#include "vasnprintf.h"
#include <stdarg.h>
char *
asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
{
va_list args;
char *result;
va_start (args, format);
result = vasnprintf (resultbuf, lengthp, format, args);
va_end (args);
return result;
}

View File

@ -1,39 +0,0 @@
/* Formatted output to strings.
Copyright (C) 1999, 2002, 2006-2007 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#ifdef IN_LIBASPRINTF
# include "vasprintf.h"
#else
# include <stdio.h>
#endif
#include <stdarg.h>
int
asprintf (char **resultp, const char *format, ...)
{
va_list args;
int result;
va_start (args, format);
result = vasprintf (resultp, format, args);
va_end (args);
return result;
}

View File

@ -1,396 +0,0 @@
/* Character handling in C locale.
Copyright 2000-2003, 2006 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#define NO_C_CTYPE_MACROS
#include "c-ctype.h"
/* The function isascii is not locale dependent. Its use in EBCDIC is
questionable. */
bool
c_isascii (int c)
{
return (c >= 0x00 && c <= 0x7f);
}
bool
c_isalnum (int c)
{
#if C_CTYPE_CONSECUTIVE_DIGITS \
&& C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
#if C_CTYPE_ASCII
return ((c >= '0' && c <= '9')
|| ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z'));
#else
return ((c >= '0' && c <= '9')
|| (c >= 'A' && c <= 'Z')
|| (c >= 'a' && c <= 'z'));
#endif
#else
switch (c)
{
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
return 1;
default:
return 0;
}
#endif
}
bool
c_isalpha (int c)
{
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
#if C_CTYPE_ASCII
return ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z');
#else
return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'));
#endif
#else
switch (c)
{
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
return 1;
default:
return 0;
}
#endif
}
bool
c_isblank (int c)
{
return (c == ' ' || c == '\t');
}
bool
c_iscntrl (int c)
{
#if C_CTYPE_ASCII
return ((c & ~0x1f) == 0 || c == 0x7f);
#else
switch (c)
{
case ' ': case '!': case '"': case '#': case '$': case '%':
case '&': case '\'': case '(': case ')': case '*': case '+':
case ',': case '-': case '.': case '/':
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
case ':': case ';': case '<': case '=': case '>': case '?':
case '@':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case '[': case '\\': case ']': case '^': case '_': case '`':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case '{': case '|': case '}': case '~':
return 0;
default:
return 1;
}
#endif
}
bool
c_isdigit (int c)
{
#if C_CTYPE_CONSECUTIVE_DIGITS
return (c >= '0' && c <= '9');
#else
switch (c)
{
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
return 1;
default:
return 0;
}
#endif
}
bool
c_islower (int c)
{
#if C_CTYPE_CONSECUTIVE_LOWERCASE
return (c >= 'a' && c <= 'z');
#else
switch (c)
{
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
return 1;
default:
return 0;
}
#endif
}
bool
c_isgraph (int c)
{
#if C_CTYPE_ASCII
return (c >= '!' && c <= '~');
#else
switch (c)
{
case '!': case '"': case '#': case '$': case '%': case '&':
case '\'': case '(': case ')': case '*': case '+': case ',':
case '-': case '.': case '/':
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
case ':': case ';': case '<': case '=': case '>': case '?':
case '@':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case '[': case '\\': case ']': case '^': case '_': case '`':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case '{': case '|': case '}': case '~':
return 1;
default:
return 0;
}
#endif
}
bool
c_isprint (int c)
{
#if C_CTYPE_ASCII
return (c >= ' ' && c <= '~');
#else
switch (c)
{
case ' ': case '!': case '"': case '#': case '$': case '%':
case '&': case '\'': case '(': case ')': case '*': case '+':
case ',': case '-': case '.': case '/':
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
case ':': case ';': case '<': case '=': case '>': case '?':
case '@':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
case '[': case '\\': case ']': case '^': case '_': case '`':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
case 's': case 't': case 'u': case 'v': case 'w': case 'x':
case 'y': case 'z':
case '{': case '|': case '}': case '~':
return 1;
default:
return 0;
}
#endif
}
bool
c_ispunct (int c)
{
#if C_CTYPE_ASCII
return ((c >= '!' && c <= '~')
&& !((c >= '0' && c <= '9')
|| ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'Z')));
#else
switch (c)
{
case '!': case '"': case '#': case '$': case '%': case '&':
case '\'': case '(': case ')': case '*': case '+': case ',':
case '-': case '.': case '/':
case ':': case ';': case '<': case '=': case '>': case '?':
case '@':
case '[': case '\\': case ']': case '^': case '_': case '`':
case '{': case '|': case '}': case '~':
return 1;
default:
return 0;
}
#endif
}
bool
c_isspace (int c)
{
return (c == ' ' || c == '\t'
|| c == '\n' || c == '\v' || c == '\f' || c == '\r');
}
bool
c_isupper (int c)
{
#if C_CTYPE_CONSECUTIVE_UPPERCASE
return (c >= 'A' && c <= 'Z');
#else
switch (c)
{
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
case 'Y': case 'Z':
return 1;
default:
return 0;
}
#endif
}
bool
c_isxdigit (int c)
{
#if C_CTYPE_CONSECUTIVE_DIGITS \
&& C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
#if C_CTYPE_ASCII
return ((c >= '0' && c <= '9')
|| ((c & ~0x20) >= 'A' && (c & ~0x20) <= 'F'));
#else
return ((c >= '0' && c <= '9')
|| (c >= 'A' && c <= 'F')
|| (c >= 'a' && c <= 'f'));
#endif
#else
switch (c)
{
case '0': case '1': case '2': case '3': case '4': case '5':
case '6': case '7': case '8': case '9':
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
return 1;
default:
return 0;
}
#endif
}
int
c_tolower (int c)
{
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
return (c >= 'A' && c <= 'Z' ? c - 'A' + 'a' : c);
#else
switch (c)
{
case 'A': return 'a';
case 'B': return 'b';
case 'C': return 'c';
case 'D': return 'd';
case 'E': return 'e';
case 'F': return 'f';
case 'G': return 'g';
case 'H': return 'h';
case 'I': return 'i';
case 'J': return 'j';
case 'K': return 'k';
case 'L': return 'l';
case 'M': return 'm';
case 'N': return 'n';
case 'O': return 'o';
case 'P': return 'p';
case 'Q': return 'q';
case 'R': return 'r';
case 'S': return 's';
case 'T': return 't';
case 'U': return 'u';
case 'V': return 'v';
case 'W': return 'w';
case 'X': return 'x';
case 'Y': return 'y';
case 'Z': return 'z';
default: return c;
}
#endif
}
int
c_toupper (int c)
{
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
return (c >= 'a' && c <= 'z' ? c - 'a' + 'A' : c);
#else
switch (c)
{
case 'a': return 'A';
case 'b': return 'B';
case 'c': return 'C';
case 'd': return 'D';
case 'e': return 'E';
case 'f': return 'F';
case 'g': return 'G';
case 'h': return 'H';
case 'i': return 'I';
case 'j': return 'J';
case 'k': return 'K';
case 'l': return 'L';
case 'm': return 'M';
case 'n': return 'N';
case 'o': return 'O';
case 'p': return 'P';
case 'q': return 'Q';
case 'r': return 'R';
case 's': return 'S';
case 't': return 'T';
case 'u': return 'U';
case 'v': return 'V';
case 'w': return 'W';
case 'x': return 'X';
case 'y': return 'Y';
case 'z': return 'Z';
default: return c;
}
#endif
}

View File

@ -1,295 +0,0 @@
/* Character handling in C locale.
These functions work like the corresponding functions in <ctype.h>,
except that they have the C (POSIX) locale hardwired, whereas the
<ctype.h> functions' behaviour depends on the current locale set via
setlocale.
Copyright (C) 2000-2003, 2006, 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef C_CTYPE_H
#define C_CTYPE_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/* The functions defined in this file assume the "C" locale and a character
set without diacritics (ASCII-US or EBCDIC-US or something like that).
Even if the "C" locale on a particular system is an extension of the ASCII
character set (like on BeOS, where it is UTF-8, or on AmigaOS, where it
is ISO-8859-1), the functions in this file recognize only the ASCII
characters. */
/* Check whether the ASCII optimizations apply. */
/* ANSI C89 (and ISO C99 5.2.1.3 too) already guarantees that
'0', '1', ..., '9' have consecutive integer values. */
#define C_CTYPE_CONSECUTIVE_DIGITS 1
#if ('A' <= 'Z') \
&& ('A' + 1 == 'B') && ('B' + 1 == 'C') && ('C' + 1 == 'D') \
&& ('D' + 1 == 'E') && ('E' + 1 == 'F') && ('F' + 1 == 'G') \
&& ('G' + 1 == 'H') && ('H' + 1 == 'I') && ('I' + 1 == 'J') \
&& ('J' + 1 == 'K') && ('K' + 1 == 'L') && ('L' + 1 == 'M') \
&& ('M' + 1 == 'N') && ('N' + 1 == 'O') && ('O' + 1 == 'P') \
&& ('P' + 1 == 'Q') && ('Q' + 1 == 'R') && ('R' + 1 == 'S') \
&& ('S' + 1 == 'T') && ('T' + 1 == 'U') && ('U' + 1 == 'V') \
&& ('V' + 1 == 'W') && ('W' + 1 == 'X') && ('X' + 1 == 'Y') \
&& ('Y' + 1 == 'Z')
#define C_CTYPE_CONSECUTIVE_UPPERCASE 1
#endif
#if ('a' <= 'z') \
&& ('a' + 1 == 'b') && ('b' + 1 == 'c') && ('c' + 1 == 'd') \
&& ('d' + 1 == 'e') && ('e' + 1 == 'f') && ('f' + 1 == 'g') \
&& ('g' + 1 == 'h') && ('h' + 1 == 'i') && ('i' + 1 == 'j') \
&& ('j' + 1 == 'k') && ('k' + 1 == 'l') && ('l' + 1 == 'm') \
&& ('m' + 1 == 'n') && ('n' + 1 == 'o') && ('o' + 1 == 'p') \
&& ('p' + 1 == 'q') && ('q' + 1 == 'r') && ('r' + 1 == 's') \
&& ('s' + 1 == 't') && ('t' + 1 == 'u') && ('u' + 1 == 'v') \
&& ('v' + 1 == 'w') && ('w' + 1 == 'x') && ('x' + 1 == 'y') \
&& ('y' + 1 == 'z')
#define C_CTYPE_CONSECUTIVE_LOWERCASE 1
#endif
#if (' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126)
/* The character set is ASCII or one of its variants or extensions, not EBCDIC.
Testing the value of '\n' and '\r' is not relevant. */
#define C_CTYPE_ASCII 1
#endif
/* Function declarations. */
/* Unlike the functions in <ctype.h>, which require an argument in the range
of the 'unsigned char' type, the functions here operate on values that are
in the 'unsigned char' range or in the 'char' range. In other words,
when you have a 'char' value, you need to cast it before using it as
argument to a <ctype.h> function:
const char *s = ...;
if (isalpha ((unsigned char) *s)) ...
but you don't need to cast it for the functions defined in this file:
const char *s = ...;
if (c_isalpha (*s)) ...
*/
extern bool c_isascii (int c); /* not locale dependent */
extern bool c_isalnum (int c);
extern bool c_isalpha (int c);
extern bool c_isblank (int c);
extern bool c_iscntrl (int c);
extern bool c_isdigit (int c);
extern bool c_islower (int c);
extern bool c_isgraph (int c);
extern bool c_isprint (int c);
extern bool c_ispunct (int c);
extern bool c_isspace (int c);
extern bool c_isupper (int c);
extern bool c_isxdigit (int c);
extern int c_tolower (int c);
extern int c_toupper (int c);
#if defined __GNUC__ && defined __OPTIMIZE__ && !defined __OPTIMIZE_SIZE__ && !defined NO_C_CTYPE_MACROS
/* ASCII optimizations. */
#undef c_isascii
#define c_isascii(c) \
({ int __c = (c); \
(__c >= 0x00 && __c <= 0x7f); \
})
#if C_CTYPE_CONSECUTIVE_DIGITS \
&& C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
#if C_CTYPE_ASCII
#undef c_isalnum
#define c_isalnum(c) \
({ int __c = (c); \
((__c >= '0' && __c <= '9') \
|| ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z')); \
})
#else
#undef c_isalnum
#define c_isalnum(c) \
({ int __c = (c); \
((__c >= '0' && __c <= '9') \
|| (__c >= 'A' && __c <= 'Z') \
|| (__c >= 'a' && __c <= 'z')); \
})
#endif
#endif
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
#if C_CTYPE_ASCII
#undef c_isalpha
#define c_isalpha(c) \
({ int __c = (c); \
((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'Z'); \
})
#else
#undef c_isalpha
#define c_isalpha(c) \
({ int __c = (c); \
((__c >= 'A' && __c <= 'Z') || (__c >= 'a' && __c <= 'z')); \
})
#endif
#endif
#undef c_isblank
#define c_isblank(c) \
({ int __c = (c); \
(__c == ' ' || __c == '\t'); \
})
#if C_CTYPE_ASCII
#undef c_iscntrl
#define c_iscntrl(c) \
({ int __c = (c); \
((__c & ~0x1f) == 0 || __c == 0x7f); \
})
#endif
#if C_CTYPE_CONSECUTIVE_DIGITS
#undef c_isdigit
#define c_isdigit(c) \
({ int __c = (c); \
(__c >= '0' && __c <= '9'); \
})
#endif
#if C_CTYPE_CONSECUTIVE_LOWERCASE
#undef c_islower
#define c_islower(c) \
({ int __c = (c); \
(__c >= 'a' && __c <= 'z'); \
})
#endif
#if C_CTYPE_ASCII
#undef c_isgraph
#define c_isgraph(c) \
({ int __c = (c); \
(__c >= '!' && __c <= '~'); \
})
#endif
#if C_CTYPE_ASCII
#undef c_isprint
#define c_isprint(c) \
({ int __c = (c); \
(__c >= ' ' && __c <= '~'); \
})
#endif
#if C_CTYPE_ASCII
#undef c_ispunct
#define c_ispunct(c) \
({ int _c = (c); \
(c_isgraph (_c) && ! c_isalnum (_c)); \
})
#endif
#undef c_isspace
#define c_isspace(c) \
({ int __c = (c); \
(__c == ' ' || __c == '\t' \
|| __c == '\n' || __c == '\v' || __c == '\f' || __c == '\r'); \
})
#if C_CTYPE_CONSECUTIVE_UPPERCASE
#undef c_isupper
#define c_isupper(c) \
({ int __c = (c); \
(__c >= 'A' && __c <= 'Z'); \
})
#endif
#if C_CTYPE_CONSECUTIVE_DIGITS \
&& C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
#if C_CTYPE_ASCII
#undef c_isxdigit
#define c_isxdigit(c) \
({ int __c = (c); \
((__c >= '0' && __c <= '9') \
|| ((__c & ~0x20) >= 'A' && (__c & ~0x20) <= 'F')); \
})
#else
#undef c_isxdigit
#define c_isxdigit(c) \
({ int __c = (c); \
((__c >= '0' && __c <= '9') \
|| (__c >= 'A' && __c <= 'F') \
|| (__c >= 'a' && __c <= 'f')); \
})
#endif
#endif
#if C_CTYPE_CONSECUTIVE_UPPERCASE && C_CTYPE_CONSECUTIVE_LOWERCASE
#undef c_tolower
#define c_tolower(c) \
({ int __c = (c); \
(__c >= 'A' && __c <= 'Z' ? __c - 'A' + 'a' : __c); \
})
#undef c_toupper
#define c_toupper(c) \
({ int __c = (c); \
(__c >= 'a' && __c <= 'z' ? __c - 'a' + 'A' : __c); \
})
#endif
#endif /* optimizing for speed */
#ifdef __cplusplus
}
#endif
#endif /* C_CTYPE_H */

View File

@ -1,82 +0,0 @@
/* close replacement.
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <unistd.h>
#if GNULIB_SYS_SOCKET
# define WIN32_LEAN_AND_MEAN
# include <sys/socket.h>
#endif
#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
static int
_gl_close_fd_maybe_socket (int fd)
{
SOCKET sock = FD_TO_SOCKET (fd);
WSANETWORKEVENTS ev;
ev.lNetworkEvents = 0xDEADBEEF;
WSAEnumNetworkEvents (sock, NULL, &ev);
if (ev.lNetworkEvents != 0xDEADBEEF)
{
/* FIXME: other applications, like squid, use an undocumented
_free_osfhnd free function. But this is not enough: The 'osfile'
flags for fd also needs to be cleared, but it is hard to access it.
Instead, here we just close twice the file descriptor. */
if (closesocket (sock))
{
set_winsock_errno ();
return -1;
}
else
{
/* This call frees the file descriptor and does a
CloseHandle ((HANDLE) _get_osfhandle (fd)), which fails. */
_close (fd);
return 0;
}
}
else
return _close (fd);
}
#endif
/* Override close() to call into other gnulib modules. */
int
rpl_close (int fd)
#undef close
{
#if HAVE__GL_CLOSE_FD_MAYBE_SOCKET
int retval = _gl_close_fd_maybe_socket (fd);
#else
int retval = close (fd);
#endif
#ifdef FCHDIR_REPLACEMENT
if (retval >= 0)
_gl_unregister_fd (fd);
#endif
return retval;
}

View File

@ -1,47 +0,0 @@
/* connect.c --- wrappers for Windows connect function
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paolo Bonzini */
#include <config.h>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef connect
int
rpl_connect (int fd, struct sockaddr *sockaddr, int len)
{
SOCKET sock = FD_TO_SOCKET (fd);
int r = connect (sock, sockaddr, len);
if (r < 0)
{
/* EINPROGRESS is not returned by WinSock 2.0; for backwards
compatibility, connect(2) uses EWOULDBLOCK. */
if (WSAGetLastError () == WSAEWOULDBLOCK)
WSASetLastError (WSAEINPROGRESS);
set_winsock_errno ();
}
return r;
}

View File

@ -1,155 +0,0 @@
/* A POSIX-like <errno.h>.
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_ERRNO_H
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
/* The include_next requires a split double-inclusion guard. */
#@INCLUDE_NEXT@ @NEXT_ERRNO_H@
#ifndef _GL_ERRNO_H
#define _GL_ERRNO_H
/* On native Windows platforms, many macros are not defined. */
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* POSIX says that EAGAIN and EWOULDBLOCK may have the same value. */
# define EWOULDBLOCK EAGAIN
/* Values >= 100 seem safe to use. */
# define ETXTBSY 100
# define GNULIB_defined_ETXTBSY 1
/* These are intentionally the same values as the WSA* error numbers, defined
in <winsock2.h>. */
# define EINPROGRESS 10036
# define EALREADY 10037
# define ENOTSOCK 10038
# define EDESTADDRREQ 10039
# define EMSGSIZE 10040
# define EPROTOTYPE 10041
# define ENOPROTOOPT 10042
# define EPROTONOSUPPORT 10043
# define ESOCKTNOSUPPORT 10044 /* not required by POSIX */
# define EOPNOTSUPP 10045
# define EPFNOSUPPORT 10046 /* not required by POSIX */
# define EAFNOSUPPORT 10047
# define EADDRINUSE 10048
# define EADDRNOTAVAIL 10049
# define ENETDOWN 10050
# define ENETUNREACH 10051
# define ENETRESET 10052
# define ECONNABORTED 10053
# define ECONNRESET 10054
# define ENOBUFS 10055
# define EISCONN 10056
# define ENOTCONN 10057
# define ESHUTDOWN 10058 /* not required by POSIX */
# define ETOOMANYREFS 10059 /* not required by POSIX */
# define ETIMEDOUT 10060
# define ECONNREFUSED 10061
# define ELOOP 10062
# define EHOSTDOWN 10064 /* not required by POSIX */
# define EHOSTUNREACH 10065
# define EPROCLIM 10067 /* not required by POSIX */
# define EUSERS 10068 /* not required by POSIX */
# define EDQUOT 10069
# define ESTALE 10070
# define EREMOTE 10071 /* not required by POSIX */
# define GNULIB_defined_ESOCK 1
# endif
/* On OSF/1 5.1, when _XOPEN_SOURCE_EXTENDED is not defined, the macros
EMULTIHOP, ENOLINK, EOVERFLOW are not defined. */
# if @EMULTIHOP_HIDDEN@
# define EMULTIHOP @EMULTIHOP_VALUE@
# define GNULIB_defined_EMULTIHOP 1
# endif
# if @ENOLINK_HIDDEN@
# define ENOLINK @ENOLINK_VALUE@
# define GNULIB_defined_ENOLINK 1
# endif
# if @EOVERFLOW_HIDDEN@
# define EOVERFLOW @EOVERFLOW_VALUE@
# define GNULIB_defined_EOVERFLOW 1
# endif
/* On OpenBSD 4.0 and on native Windows, the macros ENOMSG, EIDRM, ENOLINK,
EPROTO, EMULTIHOP, EBADMSG, EOVERFLOW, ENOTSUP, ECANCELED are not defined.
Define them here. Values >= 2000 seem safe to use: Solaris ESTALE = 151,
HP-UX EWOULDBLOCK = 246, IRIX EDQUOT = 1133.
Note: When one of these systems defines some of these macros some day,
binaries will have to be recompiled so that they recognizes the new
errno values from the system. */
# ifndef ENOMSG
# define ENOMSG 2000
# define GNULIB_defined_ENOMSG 1
# endif
# ifndef EIDRM
# define EIDRM 2001
# define GNULIB_defined_EIDRM 1
# endif
# ifndef ENOLINK
# define ENOLINK 2002
# define GNULIB_defined_ENOLINK 1
# endif
# ifndef EPROTO
# define EPROTO 2003
# define GNULIB_defined_EPROTO 1
# endif
# ifndef EMULTIHOP
# define EMULTIHOP 2004
# define GNULIB_defined_EMULTIHOP 1
# endif
# ifndef EBADMSG
# define EBADMSG 2005
# define GNULIB_defined_EBADMSG 1
# endif
# ifndef EOVERFLOW
# define EOVERFLOW 2006
# define GNULIB_defined_EOVERFLOW 1
# endif
# ifndef ENOTSUP
# define ENOTSUP 2007
# define GNULIB_defined_ENOTSUP 1
# endif
# ifndef ECANCELED
# define ECANCELED 2008
# define GNULIB_defined_ECANCELED 1
# endif
#endif /* _GL_ERRNO_H */
#endif /* _GL_ERRNO_H */

View File

@ -1,47 +0,0 @@
/* fclose replacement.
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
/* Override fclose() to call the overridden close(). */
int
rpl_fclose (FILE *fp)
#undef fclose
{
int saved_errno = 0;
if (fflush (fp))
saved_errno = errno;
if (close (fileno (fp)) < 0 && saved_errno == 0)
saved_errno = errno;
fclose (fp); /* will fail with errno = EBADF */
if (saved_errno != 0)
{
errno = saved_errno;
return EOF;
}
return 0;
}

View File

@ -1,148 +0,0 @@
/* Supplemental information about the floating-point formats.
Copyright (C) 2007 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2007.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _FLOATPLUS_H
#define _FLOATPLUS_H
#include <float.h>
#include <limits.h>
/* Number of bits in the mantissa of a floating-point number, including the
"hidden bit". */
#if FLT_RADIX == 2
# define FLT_MANT_BIT FLT_MANT_DIG
# define DBL_MANT_BIT DBL_MANT_DIG
# define LDBL_MANT_BIT LDBL_MANT_DIG
#elif FLT_RADIX == 4
# define FLT_MANT_BIT (FLT_MANT_DIG * 2)
# define DBL_MANT_BIT (DBL_MANT_DIG * 2)
# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2)
#elif FLT_RADIX == 16
# define FLT_MANT_BIT (FLT_MANT_DIG * 4)
# define DBL_MANT_BIT (DBL_MANT_DIG * 4)
# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4)
#endif
/* Bit mask that can be used to mask the exponent, as an unsigned number. */
#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7)
#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7)
/* Number of bits used for the exponent of a floating-point number, including
the exponent's sign. */
#define FLT_EXP_BIT \
(FLT_EXP_MASK < 0x100 ? 8 : \
FLT_EXP_MASK < 0x200 ? 9 : \
FLT_EXP_MASK < 0x400 ? 10 : \
FLT_EXP_MASK < 0x800 ? 11 : \
FLT_EXP_MASK < 0x1000 ? 12 : \
FLT_EXP_MASK < 0x2000 ? 13 : \
FLT_EXP_MASK < 0x4000 ? 14 : \
FLT_EXP_MASK < 0x8000 ? 15 : \
FLT_EXP_MASK < 0x10000 ? 16 : \
FLT_EXP_MASK < 0x20000 ? 17 : \
FLT_EXP_MASK < 0x40000 ? 18 : \
FLT_EXP_MASK < 0x80000 ? 19 : \
FLT_EXP_MASK < 0x100000 ? 20 : \
FLT_EXP_MASK < 0x200000 ? 21 : \
FLT_EXP_MASK < 0x400000 ? 22 : \
FLT_EXP_MASK < 0x800000 ? 23 : \
FLT_EXP_MASK < 0x1000000 ? 24 : \
FLT_EXP_MASK < 0x2000000 ? 25 : \
FLT_EXP_MASK < 0x4000000 ? 26 : \
FLT_EXP_MASK < 0x8000000 ? 27 : \
FLT_EXP_MASK < 0x10000000 ? 28 : \
FLT_EXP_MASK < 0x20000000 ? 29 : \
FLT_EXP_MASK < 0x40000000 ? 30 : \
FLT_EXP_MASK <= 0x7fffffff ? 31 : \
32)
#define DBL_EXP_BIT \
(DBL_EXP_MASK < 0x100 ? 8 : \
DBL_EXP_MASK < 0x200 ? 9 : \
DBL_EXP_MASK < 0x400 ? 10 : \
DBL_EXP_MASK < 0x800 ? 11 : \
DBL_EXP_MASK < 0x1000 ? 12 : \
DBL_EXP_MASK < 0x2000 ? 13 : \
DBL_EXP_MASK < 0x4000 ? 14 : \
DBL_EXP_MASK < 0x8000 ? 15 : \
DBL_EXP_MASK < 0x10000 ? 16 : \
DBL_EXP_MASK < 0x20000 ? 17 : \
DBL_EXP_MASK < 0x40000 ? 18 : \
DBL_EXP_MASK < 0x80000 ? 19 : \
DBL_EXP_MASK < 0x100000 ? 20 : \
DBL_EXP_MASK < 0x200000 ? 21 : \
DBL_EXP_MASK < 0x400000 ? 22 : \
DBL_EXP_MASK < 0x800000 ? 23 : \
DBL_EXP_MASK < 0x1000000 ? 24 : \
DBL_EXP_MASK < 0x2000000 ? 25 : \
DBL_EXP_MASK < 0x4000000 ? 26 : \
DBL_EXP_MASK < 0x8000000 ? 27 : \
DBL_EXP_MASK < 0x10000000 ? 28 : \
DBL_EXP_MASK < 0x20000000 ? 29 : \
DBL_EXP_MASK < 0x40000000 ? 30 : \
DBL_EXP_MASK <= 0x7fffffff ? 31 : \
32)
#define LDBL_EXP_BIT \
(LDBL_EXP_MASK < 0x100 ? 8 : \
LDBL_EXP_MASK < 0x200 ? 9 : \
LDBL_EXP_MASK < 0x400 ? 10 : \
LDBL_EXP_MASK < 0x800 ? 11 : \
LDBL_EXP_MASK < 0x1000 ? 12 : \
LDBL_EXP_MASK < 0x2000 ? 13 : \
LDBL_EXP_MASK < 0x4000 ? 14 : \
LDBL_EXP_MASK < 0x8000 ? 15 : \
LDBL_EXP_MASK < 0x10000 ? 16 : \
LDBL_EXP_MASK < 0x20000 ? 17 : \
LDBL_EXP_MASK < 0x40000 ? 18 : \
LDBL_EXP_MASK < 0x80000 ? 19 : \
LDBL_EXP_MASK < 0x100000 ? 20 : \
LDBL_EXP_MASK < 0x200000 ? 21 : \
LDBL_EXP_MASK < 0x400000 ? 22 : \
LDBL_EXP_MASK < 0x800000 ? 23 : \
LDBL_EXP_MASK < 0x1000000 ? 24 : \
LDBL_EXP_MASK < 0x2000000 ? 25 : \
LDBL_EXP_MASK < 0x4000000 ? 26 : \
LDBL_EXP_MASK < 0x8000000 ? 27 : \
LDBL_EXP_MASK < 0x10000000 ? 28 : \
LDBL_EXP_MASK < 0x20000000 ? 29 : \
LDBL_EXP_MASK < 0x40000000 ? 30 : \
LDBL_EXP_MASK <= 0x7fffffff ? 31 : \
32)
/* Number of bits used for a floating-point number: the mantissa (not
counting the "hidden bit", since it may or may not be explicit), the
exponent, and the sign. */
#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1)
#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1)
#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1)
/* Number of bytes used for a floating-point number.
This can be smaller than the 'sizeof'. For example, on i386 systems,
'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence
LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but
sizeof (long double) = 12 or = 16. */
#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
/* Verify that SIZEOF_FLT <= sizeof (float) etc. */
typedef int verify_sizeof_flt[2 * (SIZEOF_FLT <= sizeof (float)) - 1];
typedef int verify_sizeof_dbl[2 * (SIZEOF_DBL <= sizeof (double)) - 1];
typedef int verify_sizeof_ldbl[2 * (SIZEOF_LDBL <= sizeof (long double)) - 1];
#endif /* _FLOATPLUS_H */

View File

@ -1,62 +0,0 @@
/* A correct <float.h>.
Copyright (C) 2007-2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#ifndef _GL_FLOAT_H
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
/* The include_next requires a split double-inclusion guard. */
#@INCLUDE_NEXT@ @NEXT_FLOAT_H@
#ifndef _GL_FLOAT_H
#define _GL_FLOAT_H
/* 'long double' properties. */
#if defined __i386__ && (defined __BEOS__ || defined __OpenBSD__)
/* Number of mantissa units, in base FLT_RADIX. */
# undef LDBL_MANT_DIG
# define LDBL_MANT_DIG 64
/* Number of decimal digits that is sufficient for representing a number. */
# undef LDBL_DIG
# define LDBL_DIG 18
/* x-1 where x is the smallest representable number > 1. */
# undef LDBL_EPSILON
# define LDBL_EPSILON 1.0842021724855044340E-19L
/* Minimum e such that FLT_RADIX^(e-1) is a normalized number. */
# undef LDBL_MIN_EXP
# define LDBL_MIN_EXP (-16381)
/* Maximum e such that FLT_RADIX^(e-1) is a representable finite number. */
# undef LDBL_MAX_EXP
# define LDBL_MAX_EXP 16384
/* Minimum positive normalized number. */
# undef LDBL_MIN
# define LDBL_MIN 3.3621031431120935063E-4932L
/* Maximum representable finite number. */
# undef LDBL_MAX
# define LDBL_MAX 1.1897314953572317650E+4932L
/* Minimum e such that 10^e is in the range of normalized numbers. */
# undef LDBL_MIN_10_EXP
# define LDBL_MIN_10_EXP (-4931)
/* Maximum e such that 10^e is in the range of representable finite numbers. */
# undef LDBL_MAX_10_EXP
# define LDBL_MAX_10_EXP 4932
#endif
#endif /* _GL_FLOAT_H */
#endif /* _GL_FLOAT_H */

View File

@ -1,122 +0,0 @@
/* An fseeko() function that, together with fflush(), is POSIX compliant.
Copyright (C) 2007-2009 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#include <stdio.h>
/* Get off_t and lseek. */
#include <unistd.h>
#include "stdio-impl.h"
#undef fseeko
#if !HAVE_FSEEKO
# undef fseek
# define fseeko fseek
#endif
int
rpl_fseeko (FILE *fp, off_t offset, int whence)
{
#if LSEEK_PIPE_BROKEN
/* mingw gives bogus answers rather than failure on non-seekable files. */
if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
return EOF;
#endif
/* These tests are based on fpurge.c. */
#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
if (fp->_IO_read_end == fp->_IO_read_ptr
&& fp->_IO_write_ptr == fp->_IO_write_base
&& fp->_IO_save_base == NULL)
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
# if defined __SL64 && defined __SCLE /* Cygwin */
if ((fp->_flags & __SL64) == 0)
{
/* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
mode; but has an fseeko that requires 64-bit mode. */
FILE *tmp = fopen ("/dev/null", "r");
if (!tmp)
return -1;
fp->_flags |= __SL64;
fp->_seek64 = tmp->_seek64;
fclose (tmp);
}
# endif
if (fp_->_p == fp_->_bf._base
&& fp_->_r == 0
&& fp_->_w == ((fp_->_flags & (__SLBF | __SNBF | __SRD)) == 0 /* fully buffered and not currently reading? */
? fp_->_bf._size
: 0)
&& fp_ub._base == NULL)
#elif defined __EMX__ /* emx+gcc */
if (fp->_ptr == fp->_buffer
&& fp->_rcount == 0
&& fp->_wcount == 0
&& fp->_ungetc_count == 0)
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
if (fp_->_ptr == fp_->_base
&& (fp_->_ptr == NULL || fp_->_cnt == 0))
#elif defined __UCLIBC__ /* uClibc */
if (((fp->__modeflags & __FLAG_WRITING) == 0
|| fp->__bufpos == fp->__bufstart)
&& ((fp->__modeflags & (__FLAG_READONLY | __FLAG_READING)) == 0
|| fp->__bufpos == fp->__bufread))
#elif defined __QNX__ /* QNX */
if ((fp->_Mode & _MWRITE ? fp->_Next == fp->_Buf : fp->_Next == fp->_Rend)
&& fp->_Rback == fp->_Back + sizeof (fp->_Back)
&& fp->_Rsave == NULL)
#else
#error "Please port gnulib fseeko.c to your platform! Look at the code in fpurge.c, then report this to bug-gnulib."
#endif
{
/* We get here when an fflush() call immediately preceded this one. We
know there are no buffers.
POSIX requires us to modify the file descriptor's position.
But we cannot position beyond end of file here. */
off_t pos =
lseek (fileno (fp),
whence == SEEK_END && offset > 0 ? 0 : offset,
whence);
if (pos == -1)
{
#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
fp_->_flags &= ~__SOFF;
#endif
return -1;
}
#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
fp->_flags &= ~_IO_EOF_SEEN;
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
fp_->_offset = pos;
fp_->_flags |= __SOFF;
fp_->_flags &= ~__SEOF;
#elif defined __EMX__ /* emx+gcc */
fp->_flags &= ~_IOEOF;
#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */
fp->_flag &= ~_IOEOF;
#endif
/* If we were not requested to position beyond end of file, we're
done. */
if (!(whence == SEEK_END && offset > 0))
return 0;
}
return fseeko (fp, offset, whence);
}

View File

@ -1,75 +0,0 @@
/* Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _LIBC
# include <config.h>
#endif
#include <stdio.h>
#include <netdb.h>
#ifdef _LIBC
# include <libintl.h>
#else
# include "gettext.h"
# define _(String) gettext (String)
# define N_(String) String
#endif
static struct
{
int code;
const char *msg;
}
values[] =
{
{ EAI_ADDRFAMILY, N_("Address family for hostname not supported") },
{ EAI_AGAIN, N_("Temporary failure in name resolution") },
{ EAI_BADFLAGS, N_("Bad value for ai_flags") },
{ EAI_FAIL, N_("Non-recoverable failure in name resolution") },
{ EAI_FAMILY, N_("ai_family not supported") },
{ EAI_MEMORY, N_("Memory allocation failure") },
{ EAI_NODATA, N_("No address associated with hostname") },
{ EAI_NONAME, N_("Name or service not known") },
{ EAI_SERVICE, N_("Servname not supported for ai_socktype") },
{ EAI_SOCKTYPE, N_("ai_socktype not supported") },
{ EAI_SYSTEM, N_("System error") },
{ EAI_OVERFLOW, N_("Argument buffer too small") },
#ifdef __USE_GNU
{ EAI_INPROGRESS, N_("Processing request in progress") },
{ EAI_CANCELED, N_("Request canceled") },
{ EAI_NOTCANCELED, N_("Request not canceled") },
{ EAI_ALLDONE, N_("All requests done") },
{ EAI_INTR, N_("Interrupted by a signal") },
{ EAI_IDN_ENCODE, N_("Parameter string not correctly encoded") }
#endif
};
const char *
gai_strerror (int code)
{
size_t i;
for (i = 0; i < sizeof (values) / sizeof (values[0]); ++i)
if (values[i].code == code)
return _(values[i].msg);
return _("Unknown error");
}
#ifdef _LIBC
libc_hidden_def (gai_strerror)
#endif

View File

@ -1,435 +0,0 @@
/* Get address information (partial implementation).
Copyright (C) 1997, 2001, 2002, 2004, 2005, 2006, 2007, 2008 Free Software
Foundation, Inc.
Contributed by Simon Josefsson <simon@josefsson.org>.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
#include <netdb.h>
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
/* Get inet_ntop. */
#include <arpa/inet.h>
/* Get calloc. */
#include <stdlib.h>
/* Get memcpy, strdup. */
#include <string.h>
/* Get snprintf. */
#include <stdio.h>
#include <stdbool.h>
#include "gettext.h"
#define _(String) gettext (String)
#define N_(String) String
/* BeOS has AF_INET, but not PF_INET. */
#ifndef PF_INET
# define PF_INET AF_INET
#endif
/* BeOS also lacks PF_UNSPEC. */
#ifndef PF_UNSPEC
# define PF_UNSPEC 0
#endif
#if defined _WIN32 || defined __WIN32__
# define WIN32_NATIVE
#endif
#ifdef WIN32_NATIVE
typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*,
const struct addrinfo*,
struct addrinfo**);
typedef void (WSAAPI *freeaddrinfo_func) (struct addrinfo*);
typedef int (WSAAPI *getnameinfo_func) (const struct sockaddr*,
socklen_t, char*, DWORD,
char*, DWORD, int);
static getaddrinfo_func getaddrinfo_ptr = NULL;
static freeaddrinfo_func freeaddrinfo_ptr = NULL;
static getnameinfo_func getnameinfo_ptr = NULL;
static int
use_win32_p (void)
{
static int done = 0;
HMODULE h;
if (done)
return getaddrinfo_ptr ? 1 : 0;
done = 1;
h = GetModuleHandle ("ws2_32.dll");
if (h)
{
getaddrinfo_ptr = (getaddrinfo_func) GetProcAddress (h, "getaddrinfo");
freeaddrinfo_ptr = (freeaddrinfo_func) GetProcAddress (h, "freeaddrinfo");
getnameinfo_ptr = (getnameinfo_func) GetProcAddress (h, "getnameinfo");
}
/* If either is missing, something is odd. */
if (!getaddrinfo_ptr || !freeaddrinfo_ptr || !getnameinfo_ptr)
{
getaddrinfo_ptr = NULL;
freeaddrinfo_ptr = NULL;
getnameinfo_ptr = NULL;
return 0;
}
return 1;
}
#endif
static inline bool
validate_family (int family)
{
/* FIXME: Support more families. */
#if HAVE_IPV4
if (family == PF_INET)
return true;
#endif
#if HAVE_IPV6
if (family == PF_INET6)
return true;
#endif
if (family == PF_UNSPEC)
return true;
return false;
}
/* Translate name of a service location and/or a service name to set of
socket addresses. */
int
getaddrinfo (const char *restrict nodename,
const char *restrict servname,
const struct addrinfo *restrict hints,
struct addrinfo **restrict res)
{
struct addrinfo *tmp;
int port = 0;
struct hostent *he;
void *storage;
size_t size;
#if HAVE_IPV6
struct v6_pair {
struct addrinfo addrinfo;
struct sockaddr_in6 sockaddr_in6;
};
#endif
#if HAVE_IPV4
struct v4_pair {
struct addrinfo addrinfo;
struct sockaddr_in sockaddr_in;
};
#endif
#ifdef WIN32_NATIVE
if (use_win32_p ())
return getaddrinfo_ptr (nodename, servname, hints, res);
#endif
if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE)))
/* FIXME: Support more flags. */
return EAI_BADFLAGS;
if (hints && !validate_family (hints->ai_family))
return EAI_FAMILY;
if (hints &&
hints->ai_socktype != SOCK_STREAM && hints->ai_socktype != SOCK_DGRAM)
/* FIXME: Support other socktype. */
return EAI_SOCKTYPE; /* FIXME: Better return code? */
if (!nodename)
{
if (!(hints->ai_flags & AI_PASSIVE))
return EAI_NONAME;
#ifdef HAVE_IPV6
nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0";
#else
nodename = "0.0.0.0";
#endif
}
if (servname)
{
struct servent *se = NULL;
const char *proto =
(hints && hints->ai_socktype == SOCK_DGRAM) ? "udp" : "tcp";
if (hints == NULL || !(hints->ai_flags & AI_NUMERICSERV))
/* FIXME: Use getservbyname_r if available. */
se = getservbyname (servname, proto);
if (!se)
{
char *c;
if (!(*servname >= '0' && *servname <= '9'))
return EAI_NONAME;
port = strtoul (servname, &c, 10);
if (*c || port > 0xffff)
return EAI_NONAME;
port = htons (port);
}
else
port = se->s_port;
}
/* FIXME: Use gethostbyname_r if available. */
he = gethostbyname (nodename);
if (!he || he->h_addr_list[0] == NULL)
return EAI_NONAME;
switch (he->h_addrtype)
{
#if HAVE_IPV6
case PF_INET6:
size = sizeof (struct v6_pair);
break;
#endif
#if HAVE_IPV4
case PF_INET:
size = sizeof (struct v4_pair);
break;
#endif
default:
return EAI_NODATA;
}
storage = calloc (1, size);
if (!storage)
return EAI_MEMORY;
switch (he->h_addrtype)
{
#if HAVE_IPV6
case PF_INET6:
{
struct v6_pair *p = storage;
struct sockaddr_in6 *sinp = &p->sockaddr_in6;
tmp = &p->addrinfo;
if (port)
sinp->sin6_port = port;
if (he->h_length != sizeof (sinp->sin6_addr))
{
free (storage);
return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */
}
memcpy (&sinp->sin6_addr, he->h_addr_list[0], sizeof sinp->sin6_addr);
tmp->ai_addr = (struct sockaddr *) sinp;
tmp->ai_addrlen = sizeof *sinp;
}
break;
#endif
#if HAVE_IPV4
case PF_INET:
{
struct v4_pair *p = storage;
struct sockaddr_in *sinp = &p->sockaddr_in;
tmp = &p->addrinfo;
if (port)
sinp->sin_port = port;
if (he->h_length != sizeof (sinp->sin_addr))
{
free (storage);
return EAI_SYSTEM; /* FIXME: Better return code? Set errno? */
}
memcpy (&sinp->sin_addr, he->h_addr_list[0], sizeof sinp->sin_addr);
tmp->ai_addr = (struct sockaddr *) sinp;
tmp->ai_addrlen = sizeof *sinp;
}
break;
#endif
default:
free (storage);
return EAI_NODATA;
}
if (hints && hints->ai_flags & AI_CANONNAME)
{
const char *cn;
if (he->h_name)
cn = he->h_name;
else
cn = nodename;
tmp->ai_canonname = strdup (cn);
if (!tmp->ai_canonname)
{
free (storage);
return EAI_MEMORY;
}
}
tmp->ai_protocol = (hints) ? hints->ai_protocol : 0;
tmp->ai_socktype = (hints) ? hints->ai_socktype : 0;
tmp->ai_addr->sa_family = he->h_addrtype;
tmp->ai_family = he->h_addrtype;
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
switch (he->h_addrtype)
{
#if HAVE_IPV4
case AF_INET:
tmp->ai_addr->sa_len = sizeof (struct sockaddr_in);
break;
#endif
#if HAVE_IPV6
case AF_INET6:
tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6);
break;
#endif
}
#endif
/* FIXME: If more than one address, create linked list of addrinfo's. */
*res = tmp;
return 0;
}
/* Free `addrinfo' structure AI including associated storage. */
void
freeaddrinfo (struct addrinfo *ai)
{
#ifdef WIN32_NATIVE
if (use_win32_p ())
{
freeaddrinfo_ptr (ai);
return;
}
#endif
while (ai)
{
struct addrinfo *cur;
cur = ai;
ai = ai->ai_next;
free (cur->ai_canonname);
free (cur);
}
}
int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
char *restrict node, socklen_t nodelen,
char *restrict service, socklen_t servicelen,
int flags)
{
#ifdef WIN32_NATIVE
if (use_win32_p ())
return getnameinfo_ptr (sa, salen, node, nodelen,
service, servicelen, flags);
#endif
/* FIXME: Support other flags. */
if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) ||
(service && servicelen > 0 && !(flags & NI_NUMERICHOST)) ||
(flags & ~(NI_NUMERICHOST|NI_NUMERICSERV)))
return EAI_BADFLAGS;
if (sa == NULL || salen < sizeof (sa->sa_family))
return EAI_FAMILY;
switch (sa->sa_family)
{
#if HAVE_IPV4
case AF_INET:
if (salen < sizeof (struct sockaddr_in))
return EAI_FAMILY;
break;
#endif
#if HAVE_IPV6
case AF_INET6:
if (salen < sizeof (struct sockaddr_in6))
return EAI_FAMILY;
break;
#endif
default:
return EAI_FAMILY;
}
if (node && nodelen > 0 && flags & NI_NUMERICHOST)
{
switch (sa->sa_family)
{
#if HAVE_IPV4
case AF_INET:
if (!inet_ntop (AF_INET,
&(((const struct sockaddr_in *) sa)->sin_addr),
node, nodelen))
return EAI_SYSTEM;
break;
#endif
#if HAVE_IPV6
case AF_INET6:
if (!inet_ntop (AF_INET6,
&(((const struct sockaddr_in6 *) sa)->sin6_addr),
node, nodelen))
return EAI_SYSTEM;
break;
#endif
default:
return EAI_FAMILY;
}
}
if (service && servicelen > 0 && flags & NI_NUMERICSERV)
switch (sa->sa_family)
{
#if HAVE_IPV4
case AF_INET:
#endif
#if HAVE_IPV6
case AF_INET6:
#endif
{
unsigned short int port
= ntohs (((const struct sockaddr_in *) sa)->sin_port);
if (servicelen <= snprintf (service, servicelen, "%u", port))
return EAI_OVERFLOW;
}
break;
}
return 0;
}

View File

@ -1,135 +0,0 @@
/* getdelim.c --- Implementation of replacement getdelim function.
Copyright (C) 1994, 1996, 1997, 1998, 2001, 2003, 2005, 2006, 2007, 2008 Free
Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA. */
/* Ported from glibc by Simon Josefsson. */
#include <config.h>
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <errno.h>
#ifndef SIZE_MAX
# define SIZE_MAX ((size_t) -1)
#endif
#ifndef SSIZE_MAX
# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
#endif
#if USE_UNLOCKED_IO
# include "unlocked-io.h"
# define getc_maybe_unlocked(fp) getc(fp)
#elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED
# undef flockfile
# undef funlockfile
# define flockfile(x) ((void) 0)
# define funlockfile(x) ((void) 0)
# define getc_maybe_unlocked(fp) getc(fp)
#else
# define getc_maybe_unlocked(fp) getc_unlocked(fp)
#endif
/* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
NULL), pointing to *N characters of space. It is realloc'ed as
necessary. Returns the number of characters read (not including
the null terminator), or -1 on error or EOF. */
ssize_t
getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
{
ssize_t result;
size_t cur_len = 0;
if (lineptr == NULL || n == NULL || fp == NULL)
{
errno = EINVAL;
return -1;
}
flockfile (fp);
if (*lineptr == NULL || *n == 0)
{
char *new_lineptr;
*n = 120;
new_lineptr = (char *) realloc (*lineptr, *n);
if (new_lineptr == NULL)
{
result = -1;
goto unlock_return;
}
*lineptr = new_lineptr;
}
for (;;)
{
int i;
i = getc_maybe_unlocked (fp);
if (i == EOF)
{
result = -1;
break;
}
/* Make enough space for len+1 (for final NUL) bytes. */
if (cur_len + 1 >= *n)
{
size_t needed_max =
SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
size_t needed = 2 * *n + 1; /* Be generous. */
char *new_lineptr;
if (needed_max < needed)
needed = needed_max;
if (cur_len + 1 >= needed)
{
result = -1;
errno = EOVERFLOW;
goto unlock_return;
}
new_lineptr = (char *) realloc (*lineptr, needed);
if (new_lineptr == NULL)
{
result = -1;
goto unlock_return;
}
*lineptr = new_lineptr;
*n = needed;
}
(*lineptr)[cur_len] = i;
cur_len++;
if (i == delimiter)
break;
}
(*lineptr)[cur_len] = '\0';
result = cur_len ? cur_len : result;
unlock_return:
funlockfile (fp); /* doesn't set errno */
return result;
}

View File

@ -1,56 +0,0 @@
/* gethostname emulation for SysV and POSIX.1.
Copyright (C) 1992, 2003, 2006, 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* David MacKenzie <djm@gnu.ai.mit.edu> */
#include <config.h>
/* Specification. */
#include <unistd.h>
#ifdef HAVE_UNAME
# include <sys/utsname.h>
#endif
#include <string.h>
/* Put up to LEN chars of the host name into NAME.
Null terminate it if the name is shorter than LEN.
Return 0 if ok, -1 if error. */
#include <stddef.h>
int
gethostname (char *name, size_t len)
{
#ifdef HAVE_UNAME
struct utsname uts;
if (uname (&uts) == -1)
return -1;
if (len > sizeof (uts.nodename))
{
/* More space than we need is available. */
name[sizeof (uts.nodename)] = '\0';
len = sizeof (uts.nodename);
}
strncpy (name, uts.nodename, len);
#else
strcpy (name, ""); /* Hardcode your system name if you want. */
#endif
return 0;
}

View File

@ -1,29 +0,0 @@
/* getline.c --- Implementation of replacement getline function.
Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA. */
/* Written by Simon Josefsson. */
#include <config.h>
#include <stdio.h>
ssize_t
getline (char **lineptr, size_t *n, FILE *stream)
{
return getdelim (lineptr, n, '\n', stream);
}

View File

@ -1,231 +0,0 @@
/* Copyright (C) 1992-2001, 2003, 2004, 2005, 2006, 2007 Free Software
Foundation, Inc.
This file is part of the GNU C Library.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _LIBC
# include <config.h>
#endif
#include "getpass.h"
#include <stdio.h>
#if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__)
#include <stdbool.h>
#if HAVE_DECL___FSETLOCKING && HAVE___FSETLOCKING
# if HAVE_STDIO_EXT_H
# include <stdio_ext.h>
# endif
#else
# define __fsetlocking(stream, type) /* empty */
#endif
#if HAVE_TERMIOS_H
# include <termios.h>
#endif
#if 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
/* 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
call_fclose (void *arg)
{
if (arg != NULL)
fclose (arg);
}
char *
getpass (const char *prompt)
{
FILE *tty;
FILE *in, *out;
struct termios s, t;
bool tty_changed = false;
static char *buf;
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. */
tty = fopen ("/dev/tty", "w+");
if (tty == NULL)
{
in = stdin;
out = stderr;
}
else
{
/* We do the locking ourselves. */
__fsetlocking (tty, FSETLOCKING_BYCALLER);
out = in = tty;
}
flockfile (out);
/* Turn echoing off if it is on now. */
#if HAVE_TCGETATTR
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);
}
#endif
/* Write the prompt. */
fputs_unlocked (prompt, out);
fflush_unlocked (out);
/* Read the password. */
nread = getline (&buf, &bufsize, in);
/* 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. */
fseeko (out, 0, SEEK_CUR);
if (buf != NULL)
{
if (nread < 0)
buf[0] = '\0';
else if (buf[nread - 1] == '\n')
{
/* Remove the newline. */
buf[nread - 1] = '\0';
if (tty_changed)
{
/* Write the newline that was not echoed. */
putc_unlocked ('\n', out);
}
}
}
/* Restore the original setting. */
#if HAVE_TCSETATTR
if (tty_changed)
tcsetattr (fileno (in), TCSAFLUSH | TCSASOFT, &s);
#endif
funlockfile (out);
call_fclose (tty);
return buf;
}
#else /* W32 native */
/* Windows implementation by Martin Lambers <marlam@marlam.de>,
improved by Simon Josefsson. */
/* For PASS_MAX. */
#include <limits.h>
/* For _getch(). */
#include <conio.h>
/* For strdup(). */
#include <string.h>
#ifndef PASS_MAX
# define PASS_MAX 512
#endif
char *
getpass (const char *prompt)
{
char getpassbuf[PASS_MAX + 1];
size_t i = 0;
int c;
if (prompt)
{
fputs (prompt, stderr);
fflush (stderr);
}
for (;;)
{
c = _getch ();
if (c == '\r')
{
getpassbuf[i] = '\0';
break;
}
else if (i < PASS_MAX)
{
getpassbuf[i++] = c;
}
if (i >= PASS_MAX)
{
getpassbuf[i] = '\0';
break;
}
}
if (prompt)
{
fputs ("\r\n", stderr);
fflush (stderr);
}
return strdup (getpassbuf);
}
#endif

View File

@ -1,31 +0,0 @@
/* getpass.h -- Read a password of arbitrary length from /dev/tty or stdin.
Copyright (C) 2004 Free Software Foundation, Inc.
Contributed by Simon Josefsson <jas@extundo.com>, 2004.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef GETPASS_H
# define GETPASS_H
/* Get getpass declaration, if available. */
# include <unistd.h>
# if defined HAVE_DECL_GETPASS && !HAVE_DECL_GETPASS
/* Read a password of arbitrary length from /dev/tty or stdin. */
char *getpass (const char *prompt);
# endif
#endif /* GETPASS_H */

View File

@ -1,270 +0,0 @@
/* Convenience header for conditional use of GNU <libintl.h>.
Copyright (C) 1995-1998, 2000-2002, 2004-2006 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _LIBGETTEXT_H
#define _LIBGETTEXT_H 1
/* NLS can be disabled through the configure --disable-nls option. */
#if ENABLE_NLS
/* Get declarations of GNU message catalog functions. */
# include <libintl.h>
/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
the gettext() and ngettext() macros. This is an alternative to calling
textdomain(), and is useful for libraries. */
# ifdef DEFAULT_TEXT_DOMAIN
# undef gettext
# define gettext(Msgid) \
dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
# undef ngettext
# define ngettext(Msgid1, Msgid2, N) \
dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
# endif
#else
/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
chokes if dcgettext is defined as a macro. So include it now, to make
later inclusions of <locale.h> a NOP. We don't include <libintl.h>
as well because people using "gettext.h" will not include <libintl.h>,
and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
is OK. */
#if defined(__sun)
# include <locale.h>
#endif
/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
<libintl.h>, which chokes if dcgettext is defined as a macro. So include
it now, to make later inclusions of <libintl.h> a NOP. */
#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
# include <cstdlib>
# if (__GLIBC__ >= 2) || _GLIBCXX_HAVE_LIBINTL_H
# include <libintl.h>
# endif
#endif
/* Disabled NLS.
The casts to 'const char *' serve the purpose of producing warnings
for invalid uses of the value returned from these functions.
On pre-ANSI systems without 'const', the config.h file is supposed to
contain "#define const". */
# define gettext(Msgid) ((const char *) (Msgid))
# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
# define dcgettext(Domainname, Msgid, Category) \
((void) (Category), dgettext (Domainname, Msgid))
# define ngettext(Msgid1, Msgid2, N) \
((N) == 1 \
? ((void) (Msgid2), (const char *) (Msgid1)) \
: ((void) (Msgid1), (const char *) (Msgid2)))
# define dngettext(Domainname, Msgid1, Msgid2, N) \
((void) (Domainname), ngettext (Msgid1, Msgid2, N))
# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
((void) (Category), dngettext(Domainname, Msgid1, Msgid2, N))
# define textdomain(Domainname) ((const char *) (Domainname))
# define bindtextdomain(Domainname, Dirname) \
((void) (Domainname), (const char *) (Dirname))
# define bind_textdomain_codeset(Domainname, Codeset) \
((void) (Domainname), (const char *) (Codeset))
#endif
/* A pseudo function call that serves as a marker for the automated
extraction of messages, but does not call gettext(). The run-time
translation is done at a different place in the code.
The argument, String, should be a literal string. Concatenated strings
and other string expressions won't work.
The macro's expansion is not parenthesized, so that it is suitable as
initializer for static 'char[]' or 'const char[]' variables. */
#define gettext_noop(String) String
/* The separator between msgctxt and msgid in a .mo file. */
#define GETTEXT_CONTEXT_GLUE "\004"
/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
short and rarely need to change.
The letter 'p' stands for 'particular' or 'special'. */
#ifdef DEFAULT_TEXT_DOMAIN
# define pgettext(Msgctxt, Msgid) \
pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#else
# define pgettext(Msgctxt, Msgid) \
pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#endif
#define dpgettext(Domainname, Msgctxt, Msgid) \
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
#ifdef DEFAULT_TEXT_DOMAIN
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#else
# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#endif
#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
pgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
int category)
{
const char *translation = dcgettext (domain, msg_ctxt_id, category);
if (translation == msg_ctxt_id)
return msgid;
else
return translation;
}
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
npgettext_aux (const char *domain,
const char *msg_ctxt_id, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
const char *translation =
dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
if (translation == msg_ctxt_id || translation == msgid_plural)
return (n == 1 ? msgid : msgid_plural);
else
return translation;
}
/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
can be arbitrary expressions. But for string literals these macros are
less efficient than those above. */
#include <string.h>
#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
(((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
/* || __STDC_VERSION__ >= 199901L */ )
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
#include <stdlib.h>
#endif
#define pgettext_expr(Msgctxt, Msgid) \
dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
dcpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
const char *translation;
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
char msg_ctxt_id[msgctxt_len + msgid_len];
#else
char buf[1024];
char *msg_ctxt_id =
(msgctxt_len + msgid_len <= sizeof (buf)
? buf
: (char *) malloc (msgctxt_len + msgid_len));
if (msg_ctxt_id != NULL)
#endif
{
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcgettext (domain, msg_ctxt_id, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
if (translation != msg_ctxt_id)
return translation;
}
return msgid;
}
#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
#ifdef __GNUC__
__inline
#else
#ifdef __cplusplus
inline
#endif
#endif
static const char *
dcnpgettext_expr (const char *domain,
const char *msgctxt, const char *msgid,
const char *msgid_plural, unsigned long int n,
int category)
{
size_t msgctxt_len = strlen (msgctxt) + 1;
size_t msgid_len = strlen (msgid) + 1;
const char *translation;
#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
char msg_ctxt_id[msgctxt_len + msgid_len];
#else
char buf[1024];
char *msg_ctxt_id =
(msgctxt_len + msgid_len <= sizeof (buf)
? buf
: (char *) malloc (msgctxt_len + msgid_len));
if (msg_ctxt_id != NULL)
#endif
{
memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
msg_ctxt_id[msgctxt_len - 1] = '\004';
memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
if (msg_ctxt_id != buf)
free (msg_ctxt_id);
#endif
if (!(translation == msg_ctxt_id || translation == msgid_plural))
return translation;
}
return (n == 1 ? msgid : msgid_plural);
}
#endif /* _LIBGETTEXT_H */

View File

@ -1,145 +0,0 @@
/* Provide gettimeofday for systems that don't have it or for which it's broken.
Copyright (C) 2001, 2002, 2003, 2005, 2006, 2007 Free Software
Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* written by Jim Meyering */
#include <config.h>
/* Specification. */
#include <sys/time.h>
#include <time.h>
#if HAVE_SYS_TIMEB_H
# include <sys/timeb.h>
#endif
#if GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME
/* Work around the bug in some systems whereby gettimeofday clobbers
the static buffer that localtime uses for its return value. The
gettimeofday function from Mac OS X 10.0.4 (i.e., Darwin 1.3.7) has
this problem. The tzset replacement is necessary for at least
Solaris 2.5, 2.5.1, and 2.6. */
static struct tm tm_zero_buffer;
static struct tm *localtime_buffer_addr = &tm_zero_buffer;
#undef localtime
extern struct tm *localtime (time_t const *);
#undef gmtime
extern struct tm *gmtime (time_t const *);
/* This is a wrapper for localtime. It is used only on systems for which
gettimeofday clobbers the static buffer used for localtime's result.
On the first call, record the address of the static buffer that
localtime uses for its result. */
struct tm *
rpl_localtime (time_t const *timep)
{
struct tm *tm = localtime (timep);
if (localtime_buffer_addr == &tm_zero_buffer)
localtime_buffer_addr = tm;
return tm;
}
/* Same as above, since gmtime and localtime use the same buffer. */
struct tm *
rpl_gmtime (time_t const *timep)
{
struct tm *tm = gmtime (timep);
if (localtime_buffer_addr == &tm_zero_buffer)
localtime_buffer_addr = tm;
return tm;
}
#endif /* GETTIMEOFDAY_CLOBBERS_LOCALTIME || TZSET_CLOBBERS_LOCALTIME */
#if TZSET_CLOBBERS_LOCALTIME
#undef tzset
extern void tzset (void);
/* This is a wrapper for tzset, for systems on which tzset may clobber
the static buffer used for localtime's result. */
void
rpl_tzset (void)
{
/* Save and restore the contents of the buffer used for localtime's
result around the call to tzset. */
struct tm save = *localtime_buffer_addr;
tzset ();
*localtime_buffer_addr = save;
}
#endif
/* This is a wrapper for gettimeofday. It is used only on systems
that lack this function, or whose implementation of this function
causes problems. */
int
rpl_gettimeofday (struct timeval *restrict tv, void *restrict tz)
{
#undef gettimeofday
#if HAVE_GETTIMEOFDAY
# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
/* Save and restore the contents of the buffer used for localtime's
result around the call to gettimeofday. */
struct tm save = *localtime_buffer_addr;
# endif
int result = gettimeofday (tv, tz);
# if GETTIMEOFDAY_CLOBBERS_LOCALTIME
*localtime_buffer_addr = save;
# endif
return result;
#else
# if HAVE__FTIME
struct _timeb timebuf;
_ftime (&timebuf);
tv->tv_sec = timebuf.time;
tv->tv_usec = timebuf.millitm * 1000;
# else
# if !defined OK_TO_USE_1S_CLOCK
# error "Only 1-second nominal clock resolution found. Is that intended?" \
"If so, compile with the -DOK_TO_USE_1S_CLOCK option."
# endif
tv->tv_sec = time (NULL);
tv->tv_usec = 0;
# endif
return 0;
#endif
}

View File

@ -1,238 +0,0 @@
/* inet_ntop.c -- convert IPv4 and IPv6 addresses from binary to text form
Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/*
* Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
/* Specification. */
#include <arpa/inet.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#ifndef EAFNOSUPPORT
# define EAFNOSUPPORT EINVAL
#endif
#define NS_IN6ADDRSZ 16
#define NS_INT16SZ 2
/*
* WARNING: Don't even consider trying to compile this on a system where
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
typedef int verify_int_size[2 * sizeof (int) - 7];
static const char *inet_ntop4 (const unsigned char *src, char *dst, socklen_t size);
#if HAVE_IPV6
static const char *inet_ntop6 (const unsigned char *src, char *dst, socklen_t size);
#endif
/* char *
* inet_ntop(af, src, dst, size)
* convert a network format address to presentation format.
* return:
* pointer to presentation format address (`dst'), or NULL (see errno).
* author:
* Paul Vixie, 1996.
*/
const char *
inet_ntop (int af, const void *restrict src,
char *restrict dst, socklen_t cnt)
{
switch (af)
{
#if HAVE_IPV4
case AF_INET:
return (inet_ntop4 (src, dst, cnt));
#endif
#if HAVE_IPV6
case AF_INET6:
return (inet_ntop6 (src, dst, cnt));
#endif
default:
errno = EAFNOSUPPORT;
return (NULL);
}
/* NOTREACHED */
}
/* const char *
* inet_ntop4(src, dst, size)
* format an IPv4 address
* return:
* `dst' (as a const)
* notes:
* (1) uses no statics
* (2) takes a u_char* not an in_addr as input
* author:
* Paul Vixie, 1996.
*/
static const char *
inet_ntop4 (const unsigned char *src, char *dst, socklen_t size)
{
char tmp[sizeof "255.255.255.255"];
int len;
len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
if (len < 0)
return NULL;
if (len > size)
{
errno = ENOSPC;
return NULL;
}
return strcpy (dst, tmp);
}
#if HAVE_IPV6
/* const char *
* inet_ntop6(src, dst, size)
* convert IPv6 binary address into presentation (printable) format
* author:
* Paul Vixie, 1996.
*/
static const char *
inet_ntop6 (const unsigned char *src, char *dst, socklen_t size)
{
/*
* Note that int32_t and int16_t need only be "at least" large enough
* to contain a value of the specified size. On some systems, like
* Crays, there is no such thing as an integer variable with 16 bits.
* Keep this in mind if you think this function should have been coded
* to use pointer overlays. All the world's not a VAX.
*/
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
struct
{
int base, len;
} best, cur;
unsigned int words[NS_IN6ADDRSZ / NS_INT16SZ];
int i;
/*
* Preprocess:
* Copy the input (bytewise) array into a wordwise array.
* Find the longest run of 0x00's in src[] for :: shorthanding.
*/
memset (words, '\0', sizeof words);
for (i = 0; i < NS_IN6ADDRSZ; i += 2)
words[i / 2] = (src[i] << 8) | src[i + 1];
best.base = -1;
cur.base = -1;
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
{
if (words[i] == 0)
{
if (cur.base == -1)
cur.base = i, cur.len = 1;
else
cur.len++;
}
else
{
if (cur.base != -1)
{
if (best.base == -1 || cur.len > best.len)
best = cur;
cur.base = -1;
}
}
}
if (cur.base != -1)
{
if (best.base == -1 || cur.len > best.len)
best = cur;
}
if (best.base != -1 && best.len < 2)
best.base = -1;
/*
* Format the result.
*/
tp = tmp;
for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++)
{
/* Are we inside the best run of 0x00's? */
if (best.base != -1 && i >= best.base && i < (best.base + best.len))
{
if (i == best.base)
*tp++ = ':';
continue;
}
/* Are we following an initial run of 0x00s or any real hex? */
if (i != 0)
*tp++ = ':';
/* Is this address an encapsulated IPv4? */
if (i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff)))
{
if (!inet_ntop4 (src + 12, tp, sizeof tmp - (tp - tmp)))
return (NULL);
tp += strlen (tp);
break;
}
{
int len = sprintf (tp, "%x", words[i]);
if (len < 0)
return NULL;
tp += len;
}
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) ==
(NS_IN6ADDRSZ / NS_INT16SZ))
*tp++ = ':';
*tp++ = '\0';
/*
* Check for overflow, copy, and we're done.
*/
if ((socklen_t) (tp - tmp) > size)
{
errno = ENOSPC;
return NULL;
}
return strcpy (dst, tmp);
}
#endif

View File

@ -1,257 +0,0 @@
/* inet_pton.c -- convert IPv4 and IPv6 addresses from text to binary form
Copyright (C) 2006, 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/*
* Copyright (c) 1996,1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#include <config.h>
/* Specification. */
#include <arpa/inet.h>
#include <c-ctype.h>
#include <string.h>
#include <errno.h>
#ifndef EAFNOSUPPORT
# define EAFNOSUPPORT EINVAL
#endif
#define NS_INADDRSZ 4
#define NS_IN6ADDRSZ 16
#define NS_INT16SZ 2
/*
* WARNING: Don't even consider trying to compile this on a system where
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
*/
static int inet_pton4 (const char *src, unsigned char *dst);
#if HAVE_IPV6
static int inet_pton6 (const char *src, unsigned char *dst);
#endif
/* int
* inet_pton(af, src, dst)
* convert from presentation format (which usually means ASCII printable)
* to network format (which is usually some kind of binary format).
* return:
* 1 if the address was valid for the specified address family
* 0 if the address wasn't valid (`dst' is untouched in this case)
* -1 if some other error occurred (`dst' is untouched in this case, too)
* author:
* Paul Vixie, 1996.
*/
int
inet_pton (int af, const char *restrict src, void *restrict dst)
{
switch (af)
{
case AF_INET:
return (inet_pton4 (src, dst));
#if HAVE_IPV6
case AF_INET6:
return (inet_pton6 (src, dst));
#endif
default:
errno = EAFNOSUPPORT;
return (-1);
}
/* NOTREACHED */
}
/* int
* inet_pton4(src, dst)
* like inet_aton() but without all the hexadecimal, octal (with the
* exception of 0) and shorthand.
* return:
* 1 if `src' is a valid dotted quad, else 0.
* notice:
* does not touch `dst' unless it's returning 1.
* author:
* Paul Vixie, 1996.
*/
static int
inet_pton4 (const char *restrict src, unsigned char *restrict dst)
{
int saw_digit, octets, ch;
unsigned char tmp[NS_INADDRSZ], *tp;
saw_digit = 0;
octets = 0;
*(tp = tmp) = 0;
while ((ch = *src++) != '\0')
{
if (ch >= '0' && ch <= '9')
{
unsigned new = *tp * 10 + (ch - '0');
if (saw_digit && *tp == 0)
return (0);
if (new > 255)
return (0);
*tp = new;
if (!saw_digit)
{
if (++octets > 4)
return (0);
saw_digit = 1;
}
}
else if (ch == '.' && saw_digit)
{
if (octets == 4)
return (0);
*++tp = 0;
saw_digit = 0;
}
else
return (0);
}
if (octets < 4)
return (0);
memcpy (dst, tmp, NS_INADDRSZ);
return (1);
}
#if HAVE_IPV6
/* int
* inet_pton6(src, dst)
* convert presentation level address to network order binary form.
* return:
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
* notice:
* (1) does not touch `dst' unless it's returning 1.
* (2) :: in a full address is silently ignored.
* credit:
* inspired by Mark Andrews.
* author:
* Paul Vixie, 1996.
*/
static int
inet_pton6 (const char *restrict src, unsigned char *restrict dst)
{
static const char xdigits[] = "0123456789abcdef";
unsigned char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
const char *curtok;
int ch, saw_xdigit;
unsigned val;
tp = memset (tmp, '\0', NS_IN6ADDRSZ);
endp = tp + NS_IN6ADDRSZ;
colonp = NULL;
/* Leading :: requires some special handling. */
if (*src == ':')
if (*++src != ':')
return (0);
curtok = src;
saw_xdigit = 0;
val = 0;
while ((ch = c_tolower (*src++)) != '\0')
{
const char *pch;
pch = strchr (xdigits, ch);
if (pch != NULL)
{
val <<= 4;
val |= (pch - xdigits);
if (val > 0xffff)
return (0);
saw_xdigit = 1;
continue;
}
if (ch == ':')
{
curtok = src;
if (!saw_xdigit)
{
if (colonp)
return (0);
colonp = tp;
continue;
}
else if (*src == '\0')
{
return (0);
}
if (tp + NS_INT16SZ > endp)
return (0);
*tp++ = (u_char) (val >> 8) & 0xff;
*tp++ = (u_char) val & 0xff;
saw_xdigit = 0;
val = 0;
continue;
}
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
inet_pton4 (curtok, tp) > 0)
{
tp += NS_INADDRSZ;
saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */
}
return (0);
}
if (saw_xdigit)
{
if (tp + NS_INT16SZ > endp)
return (0);
*tp++ = (u_char) (val >> 8) & 0xff;
*tp++ = (u_char) val & 0xff;
}
if (colonp != NULL)
{
/*
* Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand.
*/
const int n = tp - colonp;
int i;
if (tp == endp)
return (0);
for (i = 1; i <= n; i++)
{
endp[-i] = colonp[n - i];
colonp[n - i] = 0;
}
tp = endp;
}
if (tp != endp)
return (0);
memcpy (dst, tmp, NS_IN6ADDRSZ);
return (1);
}
#endif

View File

@ -1,77 +0,0 @@
/* intprops.h -- properties of integer types
Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert. */
#include <limits.h>
/* The extra casts in the following macros work around compiler bugs,
e.g., in Cray C 5.0.3.0. */
/* True if the arithmetic type T is an integer type. bool counts as
an integer. */
#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1)
/* True if negative values of the signed integer type T use two's
complement, ones' complement, or signed magnitude representation,
respectively. Much GNU code assumes two's complement, but some
people like to be portable to all possible C hosts. */
#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1)
#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0)
#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1)
/* True if the arithmetic type T is signed. */
#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
/* The maximum and minimum values for the integer type T. These
macros have undefined behavior if T is signed and has padding bits.
If this is a problem for you, please let us know how to fix it for
your host. */
#define TYPE_MINIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) 0 \
: TYPE_SIGNED_MAGNITUDE (t) \
? ~ (t) 0 \
: ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))
#define TYPE_MAXIMUM(t) \
((t) (! TYPE_SIGNED (t) \
? (t) -1 \
: ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))))
/* Return zero if T can be determined to be an unsigned type.
Otherwise, return 1.
When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a
tighter bound. Otherwise, it overestimates the true bound by one byte
when applied to unsigned types of size 2, 4, 16, ... bytes.
The symbol signed_type_or_expr__ is private to this header file. */
#if __GNUC__ >= 2
# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t))
#else
# define signed_type_or_expr__(t) 1
#endif
/* Bound on length of the string representing an integer type or expression T.
Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485;
add 1 for integer division truncation; add 1 more for a minus sign
if needed. */
#define INT_STRLEN_BOUND(t) \
((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \
+ signed_type_or_expr__ (t) + 1)
/* Bound on buffer size needed to represent an integer type or expression T,
including the terminating null. */
#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1)

View File

@ -1,51 +0,0 @@
/* ioctl.c --- wrappers for Windows ioctl function
Copyright (C) 2008, 2009 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paolo Bonzini */
#include <config.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
int
rpl_ioctl (int fd, int req, ...)
{
void *buf;
va_list args;
SOCKET sock;
int r;
va_start (args, req);
buf = va_arg (args, void *);
va_end (args);
sock = FD_TO_SOCKET (fd);
r = ioctlsocket (sock, req, buf);
if (r < 0)
set_winsock_errno ();
return r;
}

View File

@ -1,62 +0,0 @@
/* An lseek() function that detects pipes.
Copyright (C) 2007 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#include <unistd.h>
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* Windows platforms. */
/* Get GetFileType. */
# include <windows.h>
#else
# include <sys/stat.h>
#endif
#include <errno.h>
#undef lseek
off_t
rpl_lseek (int fd, off_t offset, int whence)
{
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* mingw lseek mistakenly succeeds on pipes, sockets, and terminals. */
HANDLE h = (HANDLE) _get_osfhandle (fd);
if (h == INVALID_HANDLE_VALUE)
{
errno = EBADF;
return -1;
}
if (GetFileType (h) != FILE_TYPE_DISK)
{
errno = ESPIPE;
return -1;
}
#else
/* BeOS lseek mistakenly succeeds on pipes... */
struct stat statbuf;
if (fstat (fd, &statbuf) < 0)
return -1;
if (!S_ISREG (statbuf.st_mode))
{
errno = ESPIPE;
return -1;
}
#endif
return lseek (fd, offset, whence);
}

View File

@ -1,82 +0,0 @@
/* Work around a bug of lstat on some systems
Copyright (C) 1997-1999, 2000-2006, 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* written by Jim Meyering */
#include <config.h>
/* Get the original definition of open. It might be defined as a macro. */
#define __need_system_sys_stat_h
#include <sys/types.h>
#include <sys/stat.h>
#undef __need_system_sys_stat_h
static inline int
orig_lstat (const char *filename, struct stat *buf)
{
return lstat (filename, buf);
}
/* Specification. */
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
/* lstat works differently on Linux and Solaris systems. POSIX (see
`pathname resolution' in the glossary) requires that programs like
`ls' take into consideration the fact that FILE has a trailing slash
when FILE is a symbolic link. On Linux and Solaris 10 systems, the
lstat function already has the desired semantics (in treating
`lstat ("symlink/", sbuf)' just like `lstat ("symlink/.", sbuf)',
but on Solaris 9 and earlier it does not.
If FILE has a trailing slash and specifies a symbolic link,
then use stat() to get more info on the referent of FILE.
If the referent is a non-directory, then set errno to ENOTDIR
and return -1. Otherwise, return stat's result. */
int
rpl_lstat (const char *file, struct stat *sbuf)
{
size_t len;
int lstat_result = orig_lstat (file, sbuf);
if (lstat_result != 0 || !S_ISLNK (sbuf->st_mode))
return lstat_result;
len = strlen (file);
if (len == 0 || file[len - 1] != '/')
return 0;
/* FILE refers to a symbolic link and the name ends with a slash.
Call stat() to get info about the link's referent. */
/* If stat fails, then we do the same. */
if (stat (file, sbuf) != 0)
return -1;
/* If FILE references a directory, return 0. */
if (S_ISDIR (sbuf->st_mode))
return 0;
/* Here, we know stat succeeded and FILE references a non-directory.
But it was specified via a name including a trailing slash.
Fail with errno set to ENOTDIR to indicate the contradiction. */
errno = ENOTDIR;
return -1;
}

View File

@ -1,57 +0,0 @@
/* malloc() function that is glibc compatible.
Copyright (C) 1997, 1998, 2006, 2007 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* written by Jim Meyering and Bruno Haible */
#include <config.h>
/* Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
#ifdef malloc
# define NEED_MALLOC_GNU
# undef malloc
#endif
/* Specification. */
#include <stdlib.h>
#include <errno.h>
/* Call the system's malloc below. */
#undef malloc
/* Allocate an N-byte block of memory from the heap.
If N is zero, allocate a 1-byte block. */
void *
rpl_malloc (size_t n)
{
void *result;
#ifdef NEED_MALLOC_GNU
if (n == 0)
n = 1;
#endif
result = malloc (n);
#if !HAVE_MALLOC_POSIX
if (result == NULL)
errno = ENOMEM;
#endif
return result;
}

View File

@ -1,44 +0,0 @@
/* Copyright (C) 1998, 1999, 2001, 2005, 2006, 2007 Free Software Foundation, Inc.
This file is derived from the one in the GNU C Library.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#if !_LIBC
# include <config.h>
#endif
#include <stdlib.h>
#if !_LIBC
# include "tempname.h"
# define __gen_tempname gen_tempname
# define __GT_FILE GT_FILE
#endif
#include <stdio.h>
#ifndef __GT_FILE
# define __GT_FILE 0
#endif
/* Generate a unique temporary file name from TEMPLATE.
The last six characters of TEMPLATE must be "XXXXXX";
they are replaced with a string that makes the file name unique.
Then open the file and return a fd. */
int
mkstemp (template)
char *template;
{
return __gen_tempname (template, __GT_FILE);
}

View File

@ -1,182 +0,0 @@
/* Provide a netdb.h header file for systems lacking it (read: MinGW).
Copyright (C) 2008 Free Software Foundation, Inc.
Written by Simon Josefsson.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* This file is supposed to be used on platforms that lack <netdb.h>.
It is intended to provide definitions and prototypes needed by an
application. */
#ifndef _GL_NETDB_H
#if @HAVE_NETDB_H@
# if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
# endif
/* The include_next requires a split double-inclusion guard. */
# @INCLUDE_NEXT@ @NEXT_NETDB_H@
#endif
#ifndef _GL_NETDB_H
#define _GL_NETDB_H
/* Get netdb.h definitions such as struct hostent for MinGW. */
#include <sys/socket.h>
/* Declarations for a platform that lacks <netdb.h>, or where it is
incomplete. */
#if @GNULIB_GETADDRINFO@
# if !@HAVE_STRUCT_ADDRINFO@
/* Structure to contain information about address of a service provider. */
struct addrinfo
{
int ai_flags; /* Input flags. */
int ai_family; /* Protocol family for socket. */
int ai_socktype; /* Socket type. */
int ai_protocol; /* Protocol for socket. */
socklen_t ai_addrlen; /* Length of socket address. */
struct sockaddr *ai_addr; /* Socket address for socket. */
char *ai_canonname; /* Canonical name for service location. */
struct addrinfo *ai_next; /* Pointer to next in list. */
};
# endif
/* Possible values for `ai_flags' field in `addrinfo' structure. */
# ifndef AI_PASSIVE
# define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
# endif
# ifndef AI_CANONNAME
# define AI_CANONNAME 0x0002 /* Request for canonical name. */
# endif
# ifndef AI_NUMERICSERV
# define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
# endif
# if 0
/* The commented out definitions below are not yet implemented in the
GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact,
cause conflicts on systems with a getaddrinfo() function which does not
define them.
If they are restored, be sure to protect the definitions with #ifndef. */
# define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
# define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
# define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
# define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
returned address type.. */
# endif /* 0 */
/* Error values for `getaddrinfo' function. */
# ifndef EAI_BADFLAGS
# define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
# define EAI_AGAIN -3 /* Temporary failure in name resolution. */
# define EAI_FAIL -4 /* Non-recoverable failure in name res. */
# define EAI_NODATA -5 /* No address associated with NAME. */
# define EAI_FAMILY -6 /* `ai_family' not supported. */
# define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
# define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
# define EAI_MEMORY -10 /* Memory allocation failure. */
# endif
/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
FreeBSD, which does define EAI_BADFLAGS) have removed the definition
in favor of EAI_NONAME. */
# if !defined EAI_NODATA && defined EAI_NONAME
# define EAI_NODATA EAI_NONAME
# endif
# ifndef EAI_OVERFLOW
/* Not defined on mingw32 and Haiku. */
# define EAI_OVERFLOW -12 /* Argument buffer overflow. */
# endif
# ifndef EAI_ADDRFAMILY
/* Not defined on mingw32. */
# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
# endif
# ifndef EAI_SYSTEM
/* Not defined on mingw32. */
# define EAI_SYSTEM -11 /* System error returned in `errno'. */
# endif
# if 0
/* The commented out definitions below are not yet implemented in the
GNULIB getaddrinfo() replacement, so are not yet needed.
If they are restored, be sure to protect the definitions with #ifndef. */
# ifndef EAI_INPROGRESS
# define EAI_INPROGRESS -100 /* Processing request in progress. */
# define EAI_CANCELED -101 /* Request canceled. */
# define EAI_NOTCANCELED -102 /* Request not canceled. */
# define EAI_ALLDONE -103 /* All requests done. */
# define EAI_INTR -104 /* Interrupted by a signal. */
# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
# endif
# endif
# if !@HAVE_DECL_GETADDRINFO@
/* Translate name of a service location and/or a service name to set of
socket addresses.
For more details, see the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
extern int getaddrinfo (const char *restrict nodename,
const char *restrict servname,
const struct addrinfo *restrict hints,
struct addrinfo **restrict res);
# endif
# if !@HAVE_DECL_FREEADDRINFO@
/* Free `addrinfo' structure AI including associated storage.
For more details, see the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
extern void freeaddrinfo (struct addrinfo *ai);
# endif
# if !@HAVE_DECL_GAI_STRERROR@
/* Convert error return from getaddrinfo() to a string.
For more details, see the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/gai_strerror.html>. */
extern const char *gai_strerror (int ecode);
# endif
# if !@HAVE_DECL_GETNAMEINFO@
/* Convert socket address to printable node and service names.
For more details, see the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/getnameinfo.html>. */
extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
char *restrict node, socklen_t nodelen,
char *restrict service, socklen_t servicelen,
int flags);
# endif
/* Possible flags for getnameinfo. */
# ifndef NI_NUMERICHOST
# define NI_NUMERICHOST 1
# endif
# ifndef NI_NUMERICSERV
# define NI_NUMERICSERV 2
# endif
#endif /* @GNULIB_GETADDRINFO@ */
#endif /* _GL_NETDB_H */
#endif /* _GL_NETDB_H */

View File

@ -1 +0,0 @@
in.h

View File

@ -1 +0,0 @@
in.h

View File

@ -1,47 +0,0 @@
/* Substitute for <netinet/in.h>.
Copyright (C) 2007-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_NETINET_IN_H
#if @HAVE_NETINET_IN_H@
# if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
# endif
/* On many platforms, <netinet/in.h> assumes prior inclusion of
<sys/types.h>. */
# include <sys/types.h>
/* The include_next requires a split double-inclusion guard. */
# @INCLUDE_NEXT@ @NEXT_NETINET_IN_H@
#endif
#ifndef _GL_NETINET_IN_H
#define _GL_NETINET_IN_H
#if !@HAVE_NETINET_IN_H@
/* A platform that lacks <netinet/in.h>. */
# include <sys/socket.h>
#endif
#endif /* _GL_NETINET_IN_H */
#endif /* _GL_NETINET_IN_H */

View File

@ -1,35 +0,0 @@
/* Print a message describing error code.
Copyright (C) 2008 Free Software Foundation, Inc.
Written by Bruno Haible and Simon Josefsson.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <stdio.h>
#include <errno.h>
#include <string.h>
void
perror (const char *string)
{
const char *errno_description = strerror (errno);
if (string != NULL && *string != '\0')
fprintf (stderr, "%s: %s\n", string, errno_description);
else
fprintf (stderr, "%s\n", errno_description);
}

View File

@ -1,304 +0,0 @@
/* Calculate the size of physical memory.
Copyright (C) 2000, 2001, 2003, 2005, 2006 Free Software
Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert. */
#include <config.h>
#include "physmem.h"
#include <unistd.h>
#if HAVE_SYS_PSTAT_H
# include <sys/pstat.h>
#endif
#if HAVE_SYS_SYSMP_H
# include <sys/sysmp.h>
#endif
#if HAVE_SYS_SYSINFO_H && HAVE_MACHINE_HAL_SYSINFO_H
# include <sys/sysinfo.h>
# include <machine/hal_sysinfo.h>
#endif
#if HAVE_SYS_TABLE_H
# include <sys/table.h>
#endif
#include <sys/types.h>
#if HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#if HAVE_SYS_SYSCTL_H
# include <sys/sysctl.h>
#endif
#if HAVE_SYS_SYSTEMCFG_H
# include <sys/systemcfg.h>
#endif
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
/* MEMORYSTATUSEX is missing from older windows headers, so define
a local replacement. */
typedef struct
{
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} lMEMORYSTATUSEX;
typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*);
#endif
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
/* Return the total amount of physical memory. */
double
physmem_total (void)
{
#if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE
{ /* This works on linux-gnu, solaris2 and cygwin. */
double pages = sysconf (_SC_PHYS_PAGES);
double pagesize = sysconf (_SC_PAGESIZE);
if (0 <= pages && 0 <= pagesize)
return pages * pagesize;
}
#endif
#if HAVE_PSTAT_GETSTATIC
{ /* This works on hpux11. */
struct pst_static pss;
if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0))
{
double pages = pss.physical_memory;
double pagesize = pss.page_size;
if (0 <= pages && 0 <= pagesize)
return pages * pagesize;
}
}
#endif
#if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
{ /* This works on irix6. */
struct rminfo realmem;
if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0)
{
double pagesize = sysconf (_SC_PAGESIZE);
double pages = realmem.physmem;
if (0 <= pages && 0 <= pagesize)
return pages * pagesize;
}
}
#endif
#if HAVE_GETSYSINFO && defined GSI_PHYSMEM
{ /* This works on Tru64 UNIX V4/5. */
int physmem;
if (getsysinfo (GSI_PHYSMEM, (caddr_t) &physmem, sizeof (physmem),
NULL, NULL, NULL) == 1)
{
double kbytes = physmem;
if (0 <= kbytes)
return kbytes * 1024.0;
}
}
#endif
#if HAVE_SYSCTL && defined HW_PHYSMEM
{ /* This works on *bsd and darwin. */
unsigned int physmem;
size_t len = sizeof physmem;
static int mib[2] = { CTL_HW, HW_PHYSMEM };
if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0
&& len == sizeof (physmem))
return (double) physmem;
}
#endif
#if HAVE__SYSTEM_CONFIGURATION
/* This works on AIX. */
return _system_configuration.physmem;
#endif
#if defined _WIN32
{ /* this works on windows */
PFN_MS_EX pfnex;
HMODULE h = GetModuleHandle ("kernel32.dll");
if (!h)
return 0.0;
/* Use GlobalMemoryStatusEx if available. */
if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx")))
{
lMEMORYSTATUSEX lms_ex;
lms_ex.dwLength = sizeof lms_ex;
if (!pfnex (&lms_ex))
return 0.0;
return (double) lms_ex.ullTotalPhys;
}
/* Fall back to GlobalMemoryStatus which is always available.
but returns wrong results for physical memory > 4GB. */
else
{
MEMORYSTATUS ms;
GlobalMemoryStatus (&ms);
return (double) ms.dwTotalPhys;
}
}
#endif
/* Guess 64 MB. It's probably an older host, so guess small. */
return 64 * 1024 * 1024;
}
/* Return the amount of physical memory available. */
double
physmem_available (void)
{
#if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE
{ /* This works on linux-gnu, solaris2 and cygwin. */
double pages = sysconf (_SC_AVPHYS_PAGES);
double pagesize = sysconf (_SC_PAGESIZE);
if (0 <= pages && 0 <= pagesize)
return pages * pagesize;
}
#endif
#if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC
{ /* This works on hpux11. */
struct pst_static pss;
struct pst_dynamic psd;
if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0)
&& 0 <= pstat_getdynamic (&psd, sizeof psd, 1, 0))
{
double pages = psd.psd_free;
double pagesize = pss.page_size;
if (0 <= pages && 0 <= pagesize)
return pages * pagesize;
}
}
#endif
#if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
{ /* This works on irix6. */
struct rminfo realmem;
if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0)
{
double pagesize = sysconf (_SC_PAGESIZE);
double pages = realmem.availrmem;
if (0 <= pages && 0 <= pagesize)
return pages * pagesize;
}
}
#endif
#if HAVE_TABLE && defined TBL_VMSTATS
{ /* This works on Tru64 UNIX V4/5. */
struct tbl_vmstats vmstats;
if (table (TBL_VMSTATS, 0, &vmstats, 1, sizeof (vmstats)) == 1)
{
double pages = vmstats.free_count;
double pagesize = vmstats.pagesize;
if (0 <= pages && 0 <= pagesize)
return pages * pagesize;
}
}
#endif
#if HAVE_SYSCTL && defined HW_USERMEM
{ /* This works on *bsd and darwin. */
unsigned int usermem;
size_t len = sizeof usermem;
static int mib[2] = { CTL_HW, HW_USERMEM };
if (sysctl (mib, ARRAY_SIZE (mib), &usermem, &len, NULL, 0) == 0
&& len == sizeof (usermem))
return (double) usermem;
}
#endif
#if defined _WIN32
{ /* this works on windows */
PFN_MS_EX pfnex;
HMODULE h = GetModuleHandle ("kernel32.dll");
if (!h)
return 0.0;
/* Use GlobalMemoryStatusEx if available. */
if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx")))
{
lMEMORYSTATUSEX lms_ex;
lms_ex.dwLength = sizeof lms_ex;
if (!pfnex (&lms_ex))
return 0.0;
return (double) lms_ex.ullAvailPhys;
}
/* Fall back to GlobalMemoryStatus which is always available.
but returns wrong results for physical memory > 4GB */
else
{
MEMORYSTATUS ms;
GlobalMemoryStatus (&ms);
return (double) ms.dwAvailPhys;
}
}
#endif
/* Guess 25% of physical memory. */
return physmem_total () / 4;
}
#if DEBUG
# include <stdio.h>
# include <stdlib.h>
int
main (void)
{
printf ("%12.f %12.f\n", physmem_total (), physmem_available ());
exit (0);
}
#endif /* DEBUG */
/*
Local Variables:
compile-command: "gcc -DDEBUG -g -O -Wall -W physmem.c"
End:
*/

View File

@ -1,26 +0,0 @@
/* Calculate the size of physical memory.
Copyright (C) 2000, 2003 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert. */
#ifndef PHYSMEM_H_
# define PHYSMEM_H_ 1
double physmem_total (void);
double physmem_available (void);
#endif /* PHYSMEM_H_ */

View File

@ -1,566 +0,0 @@
/* Emulation for poll(2)
Contributed by Paolo Bonzini.
Copyright 2001-2003, 2006-2009 Free Software Foundation, Inc.
This file is part of gnulib.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Tell gcc not to warn about the (nfd < 0) tests, below. */
#if (__GNUC__ == 4 && 3 <= __GNUC_MINOR__) || 4 < __GNUC__
# pragma GCC diagnostic ignored "-Wtype-limits"
#endif
#include <config.h>
#include <alloca.h>
#include <sys/types.h>
#include "poll.h"
#include <errno.h>
#include <limits.h>
#include <assert.h>
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
# define WIN32_NATIVE
# include <winsock2.h>
# include <windows.h>
# include <io.h>
# include <stdio.h>
# include <conio.h>
#else
# include <sys/time.h>
# include <sys/socket.h>
# include <sys/select.h>
# include <unistd.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_SYS_FILIO_H
# include <sys/filio.h>
#endif
#include <time.h>
#ifndef INFTIM
# define INFTIM (-1)
#endif
/* BeOS does not have MSG_PEEK. */
#ifndef MSG_PEEK
# define MSG_PEEK 0
#endif
#ifdef WIN32_NATIVE
/* Declare data structures for ntdll functions. */
typedef struct _FILE_PIPE_LOCAL_INFORMATION {
ULONG NamedPipeType;
ULONG NamedPipeConfiguration;
ULONG MaximumInstances;
ULONG CurrentInstances;
ULONG InboundQuota;
ULONG ReadDataAvailable;
ULONG OutboundQuota;
ULONG WriteQuotaAvailable;
ULONG NamedPipeState;
ULONG NamedPipeEnd;
} FILE_PIPE_LOCAL_INFORMATION, *PFILE_PIPE_LOCAL_INFORMATION;
typedef struct _IO_STATUS_BLOCK
{
union {
DWORD Status;
PVOID Pointer;
} u;
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef enum _FILE_INFORMATION_CLASS {
FilePipeLocalInformation = 24
} FILE_INFORMATION_CLASS, *PFILE_INFORMATION_CLASS;
typedef DWORD (WINAPI *PNtQueryInformationFile)
(HANDLE, IO_STATUS_BLOCK *, VOID *, ULONG, FILE_INFORMATION_CLASS);
# ifndef PIPE_BUF
# define PIPE_BUF 512
# endif
/* Compute revents values for file handle H. */
static int
win32_compute_revents (HANDLE h, int sought)
{
int i, ret, happened;
INPUT_RECORD *irbuffer;
DWORD avail, nbuffer;
BOOL bRet;
IO_STATUS_BLOCK iosb;
FILE_PIPE_LOCAL_INFORMATION fpli;
static PNtQueryInformationFile NtQueryInformationFile;
static BOOL once_only;
switch (GetFileType (h))
{
case FILE_TYPE_PIPE:
if (!once_only)
{
NtQueryInformationFile = (PNtQueryInformationFile)
GetProcAddress (GetModuleHandle ("ntdll.dll"),
"NtQueryInformationFile");
once_only = TRUE;
}
happened = 0;
if (PeekNamedPipe (h, NULL, 0, NULL, &avail, NULL) != 0)
{
if (avail)
happened |= sought & (POLLIN | POLLRDNORM);
}
else
{
/* It was the write-end of the pipe. Check if it is writable.
If NtQueryInformationFile fails, optimistically assume the pipe is
writable. This could happen on Win9x, where NtQueryInformationFile
is not available, or if we inherit a pipe that doesn't permit
FILE_READ_ATTRIBUTES access on the write end (I think this should
not happen since WinXP SP2; WINE seems fine too). Otherwise,
ensure that enough space is available for atomic writes. */
memset (&iosb, 0, sizeof (iosb));
memset (&fpli, 0, sizeof (fpli));
if (!NtQueryInformationFile
|| NtQueryInformationFile (h, &iosb, &fpli, sizeof (fpli),
FilePipeLocalInformation)
|| fpli.WriteQuotaAvailable >= PIPE_BUF
|| (fpli.OutboundQuota < PIPE_BUF &&
fpli.WriteQuotaAvailable == fpli.OutboundQuota))
happened |= sought & (POLLOUT | POLLWRNORM | POLLWRBAND);
}
return happened;
case FILE_TYPE_CHAR:
ret = WaitForSingleObject (h, 0);
if (ret == WAIT_OBJECT_0)
{
nbuffer = avail = 0;
bRet = GetNumberOfConsoleInputEvents (h, &nbuffer);
if (!bRet || nbuffer == 0)
return POLLHUP;
irbuffer = (INPUT_RECORD *) alloca (nbuffer * sizeof (INPUT_RECORD));
bRet = PeekConsoleInput (h, irbuffer, nbuffer, &avail);
if (!bRet || avail == 0)
return POLLHUP;
for (i = 0; i < avail; i++)
if (irbuffer[i].EventType == KEY_EVENT)
return sought & ~(POLLPRI | POLLRDBAND);
}
break;
default:
ret = WaitForSingleObject (h, 0);
if (ret == WAIT_OBJECT_0)
return sought & ~(POLLPRI | POLLRDBAND);
break;
}
return sought & (POLLOUT | POLLWRNORM | POLLWRBAND);
}
/* Convert fd_sets returned by select into revents values. */
static int
win32_compute_revents_socket (SOCKET h, int sought, long lNetworkEvents)
{
int happened = 0;
if ((lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)) == FD_ACCEPT)
happened |= (POLLIN | POLLRDNORM) & sought;
else if (lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE))
{
int r, error;
char data[64];
WSASetLastError (0);
r = recv (h, data, sizeof (data), MSG_PEEK);
error = WSAGetLastError ();
WSASetLastError (0);
if (r > 0 || error == WSAENOTCONN)
happened |= (POLLIN | POLLRDNORM) & sought;
/* Distinguish hung-up sockets from other errors. */
else if (r == 0 || error == WSAESHUTDOWN || error == WSAECONNRESET
|| error == WSAECONNABORTED || error == WSAENETRESET)
happened |= POLLHUP;
else
happened |= POLLERR;
}
if (lNetworkEvents & (FD_WRITE | FD_CONNECT))
happened |= (POLLOUT | POLLWRNORM | POLLWRBAND) & sought;
if (lNetworkEvents & FD_OOB)
happened |= (POLLPRI | POLLRDBAND) & sought;
return happened;
}
#else /* !MinGW */
/* Convert select(2) returned fd_sets into poll(2) revents values. */
static int
compute_revents (int fd, int sought, fd_set *rfds, fd_set *wfds, fd_set *efds)
{
int happened = 0;
if (FD_ISSET (fd, rfds))
{
int r;
int socket_errno;
# if defined __MACH__ && defined __APPLE__
/* There is a bug in Mac OS X that causes it to ignore MSG_PEEK
for some kinds of descriptors. Detect if this descriptor is a
connected socket, a server socket, or something else using a
0-byte recv, and use ioctl(2) to detect POLLHUP. */
r = recv (fd, NULL, 0, MSG_PEEK);
socket_errno = (r < 0) ? errno : 0;
if (r == 0 || socket_errno == ENOTSOCK)
ioctl (fd, FIONREAD, &r);
# else
char data[64];
r = recv (fd, data, sizeof (data), MSG_PEEK);
socket_errno = (r < 0) ? errno : 0;
# endif
if (r == 0)
happened |= POLLHUP;
/* If the event happened on an unconnected server socket,
that's fine. */
else if (r > 0 || ( /* (r == -1) && */ socket_errno == ENOTCONN))
happened |= (POLLIN | POLLRDNORM) & sought;
/* Distinguish hung-up sockets from other errors. */
else if (socket_errno == ESHUTDOWN || socket_errno == ECONNRESET
|| socket_errno == ECONNABORTED || socket_errno == ENETRESET)
happened |= POLLHUP;
else
happened |= POLLERR;
}
if (FD_ISSET (fd, wfds))
happened |= (POLLOUT | POLLWRNORM | POLLWRBAND) & sought;
if (FD_ISSET (fd, efds))
happened |= (POLLPRI | POLLRDBAND) & sought;
return happened;
}
#endif /* !MinGW */
int
poll (pfd, nfd, timeout)
struct pollfd *pfd;
nfds_t nfd;
int timeout;
{
#ifndef WIN32_NATIVE
fd_set rfds, wfds, efds;
struct timeval tv;
struct timeval *ptv;
int maxfd, rc;
nfds_t i;
# ifdef _SC_OPEN_MAX
static int sc_open_max = -1;
if (nfd < 0
|| (nfd > sc_open_max
&& (sc_open_max != -1
|| nfd > (sc_open_max = sysconf (_SC_OPEN_MAX)))))
{
errno = EINVAL;
return -1;
}
# else /* !_SC_OPEN_MAX */
# ifdef OPEN_MAX
if (nfd < 0 || nfd > OPEN_MAX)
{
errno = EINVAL;
return -1;
}
# endif /* OPEN_MAX -- else, no check is needed */
# endif /* !_SC_OPEN_MAX */
/* EFAULT is not necessary to implement, but let's do it in the
simplest case. */
if (!pfd)
{
errno = EFAULT;
return -1;
}
/* convert timeout number into a timeval structure */
if (timeout == 0)
{
ptv = &tv;
ptv->tv_sec = 0;
ptv->tv_usec = 0;
}
else if (timeout > 0)
{
ptv = &tv;
ptv->tv_sec = timeout / 1000;
ptv->tv_usec = (timeout % 1000) * 1000;
}
else if (timeout == INFTIM)
/* wait forever */
ptv = NULL;
else
{
errno = EINVAL;
return -1;
}
/* create fd sets and determine max fd */
maxfd = -1;
FD_ZERO (&rfds);
FD_ZERO (&wfds);
FD_ZERO (&efds);
for (i = 0; i < nfd; i++)
{
if (pfd[i].fd < 0)
continue;
if (pfd[i].events & (POLLIN | POLLRDNORM))
FD_SET (pfd[i].fd, &rfds);
/* see select(2): "the only exceptional condition detectable
is out-of-band data received on a socket", hence we push
POLLWRBAND events onto wfds instead of efds. */
if (pfd[i].events & (POLLOUT | POLLWRNORM | POLLWRBAND))
FD_SET (pfd[i].fd, &wfds);
if (pfd[i].events & (POLLPRI | POLLRDBAND))
FD_SET (pfd[i].fd, &efds);
if (pfd[i].fd >= maxfd
&& (pfd[i].events & (POLLIN | POLLOUT | POLLPRI
| POLLRDNORM | POLLRDBAND
| POLLWRNORM | POLLWRBAND)))
{
maxfd = pfd[i].fd;
if (maxfd > FD_SETSIZE)
{
errno = EOVERFLOW;
return -1;
}
}
}
/* examine fd sets */
rc = select (maxfd + 1, &rfds, &wfds, &efds, ptv);
if (rc < 0)
return rc;
/* establish results */
rc = 0;
for (i = 0; i < nfd; i++)
if (pfd[i].fd < 0)
pfd[i].revents = 0;
else
{
int happened = compute_revents (pfd[i].fd, pfd[i].events,
&rfds, &wfds, &efds);
if (happened)
{
pfd[i].revents = happened;
rc++;
}
}
return rc;
#else
static struct timeval tv0;
static HANDLE hEvent;
WSANETWORKEVENTS ev;
HANDLE h, handle_array[FD_SETSIZE + 2];
DWORD ret, wait_timeout, nhandles;
fd_set rfds, wfds, xfds;
BOOL poll_again;
MSG msg;
int rc = 0;
nfds_t i;
if (nfd < 0 || timeout < -1)
{
errno = EINVAL;
return -1;
}
if (!hEvent)
hEvent = CreateEvent (NULL, FALSE, FALSE, NULL);
handle_array[0] = hEvent;
nhandles = 1;
FD_ZERO (&rfds);
FD_ZERO (&wfds);
FD_ZERO (&xfds);
/* Classify socket handles and create fd sets. */
for (i = 0; i < nfd; i++)
{
pfd[i].revents = 0;
if (pfd[i].fd < 0)
continue;
if (!(pfd[i].events & (POLLIN | POLLRDNORM |
POLLOUT | POLLWRNORM | POLLWRBAND)))
continue;
h = (HANDLE) _get_osfhandle (pfd[i].fd);
assert (h != NULL);
/* Under Wine, it seems that getsockopt returns 0 for pipes too.
WSAEnumNetworkEvents instead distinguishes the two correctly. */
ev.lNetworkEvents = 0xDEADBEEF;
WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
if (ev.lNetworkEvents != 0xDEADBEEF)
{
int requested = FD_CLOSE;
/* see above; socket handles are mapped onto select. */
if (pfd[i].events & (POLLIN | POLLRDNORM))
{
requested |= FD_READ | FD_ACCEPT;
FD_SET ((SOCKET) h, &rfds);
}
if (pfd[i].events & (POLLOUT | POLLWRNORM | POLLWRBAND))
{
requested |= FD_WRITE | FD_CONNECT;
FD_SET ((SOCKET) h, &wfds);
}
if (pfd[i].events & (POLLPRI | POLLRDBAND))
{
requested |= FD_OOB;
FD_SET ((SOCKET) h, &xfds);
}
if (requested)
WSAEventSelect ((SOCKET) h, hEvent, requested);
}
else
{
handle_array[nhandles++] = h;
/* Poll now. If we get an event, do not poll again. */
pfd[i].revents = win32_compute_revents (h, pfd[i].events);
if (pfd[i].revents)
wait_timeout = 0;
}
}
if (select (0, &rfds, &wfds, &xfds, &tv0) > 0)
{
/* Do MsgWaitForMultipleObjects anyway to dispatch messages, but
no need to call select again. */
poll_again = FALSE;
wait_timeout = 0;
}
else
{
poll_again = TRUE;
if (timeout == INFTIM)
wait_timeout = INFINITE;
else
wait_timeout = timeout;
}
for (;;)
{
ret = MsgWaitForMultipleObjects (nhandles, handle_array, FALSE,
wait_timeout, QS_ALLINPUT);
if (ret == WAIT_OBJECT_0 + nhandles)
{
/* new input of some other kind */
BOOL bRet;
while ((bRet = PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) != 0)
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
break;
}
if (poll_again)
select (0, &rfds, &wfds, &xfds, &tv0);
/* Place a sentinel at the end of the array. */
handle_array[nhandles] = NULL;
nhandles = 1;
for (i = 0; i < nfd; i++)
{
int happened;
if (pfd[i].fd < 0)
continue;
if (!(pfd[i].events & (POLLIN | POLLRDNORM |
POLLOUT | POLLWRNORM | POLLWRBAND)))
continue;
h = (HANDLE) _get_osfhandle (pfd[i].fd);
if (h != handle_array[nhandles])
{
/* It's a socket. */
WSAEnumNetworkEvents ((SOCKET) h, NULL, &ev);
WSAEventSelect ((SOCKET) h, 0, 0);
/* If we're lucky, WSAEnumNetworkEvents already provided a way
to distinguish FD_READ and FD_ACCEPT; this saves a recv later. */
if (FD_ISSET ((SOCKET) h, &rfds)
&& !(ev.lNetworkEvents & (FD_READ | FD_ACCEPT)))
ev.lNetworkEvents |= FD_READ | FD_ACCEPT;
if (FD_ISSET ((SOCKET) h, &wfds))
ev.lNetworkEvents |= FD_WRITE | FD_CONNECT;
if (FD_ISSET ((SOCKET) h, &xfds))
ev.lNetworkEvents |= FD_OOB;
happened = win32_compute_revents_socket ((SOCKET) h, pfd[i].events,
ev.lNetworkEvents);
}
else
{
/* Not a socket. */
nhandles++;
happened = win32_compute_revents (h, pfd[i].events);
}
if ((pfd[i].revents |= happened) != 0)
rc++;
}
return rc;
#endif
}

View File

@ -1,53 +0,0 @@
/* Header for poll(2) emulation
Contributed by Paolo Bonzini.
Copyright 2001, 2002, 2003, 2007 Free Software Foundation, Inc.
This file is part of gnulib.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_POLL_H
#define _GL_POLL_H
/* fake a poll(2) environment */
#define POLLIN 0x0001 /* any readable data available */
#define POLLPRI 0x0002 /* OOB/Urgent readable data */
#define POLLOUT 0x0004 /* file descriptor is writeable */
#define POLLERR 0x0008 /* some poll error occurred */
#define POLLHUP 0x0010 /* file descriptor was "hung up" */
#define POLLNVAL 0x0020 /* requested events "invalid" */
#define POLLRDNORM 0x0040
#define POLLRDBAND 0x0080
#define POLLWRNORM 0x0100
#define POLLWRBAND 0x0200
struct pollfd
{
int fd; /* which file descriptor to poll */
short events; /* events we are interested in */
short revents; /* events found on return */
};
typedef unsigned long nfds_t;
extern int poll (struct pollfd *pfd, nfds_t nfd, int timeout);
/* Define INFTIM only if doing so conforms to POSIX. */
#if !defined (_POSIX_C_SOURCE) && !defined (_XOPEN_SOURCE)
#define INFTIM (-1)
#endif
#endif /* _GL_POLL_H */

View File

@ -1,187 +0,0 @@
/* Decomposed printf argument list.
Copyright (C) 1999, 2002-2003, 2005-2007 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* This file can be parametrized with the following macros:
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
PRINTF_FETCHARGS Name of the function to be defined.
STATIC Set to 'static' to declare the function static. */
#ifndef PRINTF_FETCHARGS
# include <config.h>
#endif
/* Specification. */
#ifndef PRINTF_FETCHARGS
# include "printf-args.h"
#endif
#ifdef STATIC
STATIC
#endif
int
PRINTF_FETCHARGS (va_list args, arguments *a)
{
size_t i;
argument *ap;
for (i = 0, ap = &a->arg[0]; i < a->count; i++, ap++)
switch (ap->type)
{
case TYPE_SCHAR:
ap->a.a_schar = va_arg (args, /*signed char*/ int);
break;
case TYPE_UCHAR:
ap->a.a_uchar = va_arg (args, /*unsigned char*/ int);
break;
case TYPE_SHORT:
ap->a.a_short = va_arg (args, /*short*/ int);
break;
case TYPE_USHORT:
ap->a.a_ushort = va_arg (args, /*unsigned short*/ int);
break;
case TYPE_INT:
ap->a.a_int = va_arg (args, int);
break;
case TYPE_UINT:
ap->a.a_uint = va_arg (args, unsigned int);
break;
case TYPE_LONGINT:
ap->a.a_longint = va_arg (args, long int);
break;
case TYPE_ULONGINT:
ap->a.a_ulongint = va_arg (args, unsigned long int);
break;
#if HAVE_LONG_LONG_INT
case TYPE_LONGLONGINT:
ap->a.a_longlongint = va_arg (args, long long int);
break;
case TYPE_ULONGLONGINT:
ap->a.a_ulonglongint = va_arg (args, unsigned long long int);
break;
#endif
case TYPE_DOUBLE:
ap->a.a_double = va_arg (args, double);
break;
case TYPE_LONGDOUBLE:
ap->a.a_longdouble = va_arg (args, long double);
break;
case TYPE_CHAR:
ap->a.a_char = va_arg (args, int);
break;
#if HAVE_WINT_T
case TYPE_WIDE_CHAR:
/* Although ISO C 99 7.24.1.(2) says that wint_t is "unchanged by
default argument promotions", this is not the case in mingw32,
where wint_t is 'unsigned short'. */
ap->a.a_wide_char =
(sizeof (wint_t) < sizeof (int)
? va_arg (args, int)
: va_arg (args, wint_t));
break;
#endif
case TYPE_STRING:
ap->a.a_string = va_arg (args, const char *);
/* A null pointer is an invalid argument for "%s", but in practice
it occurs quite frequently in printf statements that produce
debug output. Use a fallback in this case. */
if (ap->a.a_string == NULL)
ap->a.a_string = "(NULL)";
break;
#if HAVE_WCHAR_T
case TYPE_WIDE_STRING:
ap->a.a_wide_string = va_arg (args, const wchar_t *);
/* A null pointer is an invalid argument for "%ls", but in practice
it occurs quite frequently in printf statements that produce
debug output. Use a fallback in this case. */
if (ap->a.a_wide_string == NULL)
{
static const wchar_t wide_null_string[] =
{
(wchar_t)'(',
(wchar_t)'N', (wchar_t)'U', (wchar_t)'L', (wchar_t)'L',
(wchar_t)')',
(wchar_t)0
};
ap->a.a_wide_string = wide_null_string;
}
break;
#endif
case TYPE_POINTER:
ap->a.a_pointer = va_arg (args, void *);
break;
case TYPE_COUNT_SCHAR_POINTER:
ap->a.a_count_schar_pointer = va_arg (args, signed char *);
break;
case TYPE_COUNT_SHORT_POINTER:
ap->a.a_count_short_pointer = va_arg (args, short *);
break;
case TYPE_COUNT_INT_POINTER:
ap->a.a_count_int_pointer = va_arg (args, int *);
break;
case TYPE_COUNT_LONGINT_POINTER:
ap->a.a_count_longint_pointer = va_arg (args, long int *);
break;
#if HAVE_LONG_LONG_INT
case TYPE_COUNT_LONGLONGINT_POINTER:
ap->a.a_count_longlongint_pointer = va_arg (args, long long int *);
break;
#endif
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
case TYPE_U8_STRING:
ap->a.a_u8_string = va_arg (args, const uint8_t *);
/* A null pointer is an invalid argument for "%U", but in practice
it occurs quite frequently in printf statements that produce
debug output. Use a fallback in this case. */
if (ap->a.a_u8_string == NULL)
{
static const uint8_t u8_null_string[] =
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
ap->a.a_u8_string = u8_null_string;
}
break;
case TYPE_U16_STRING:
ap->a.a_u16_string = va_arg (args, const uint16_t *);
/* A null pointer is an invalid argument for "%lU", but in practice
it occurs quite frequently in printf statements that produce
debug output. Use a fallback in this case. */
if (ap->a.a_u16_string == NULL)
{
static const uint16_t u16_null_string[] =
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
ap->a.a_u16_string = u16_null_string;
}
break;
case TYPE_U32_STRING:
ap->a.a_u32_string = va_arg (args, const uint32_t *);
/* A null pointer is an invalid argument for "%llU", but in practice
it occurs quite frequently in printf statements that produce
debug output. Use a fallback in this case. */
if (ap->a.a_u32_string == NULL)
{
static const uint32_t u32_null_string[] =
{ '(', 'N', 'U', 'L', 'L', ')', 0 };
ap->a.a_u32_string = u32_null_string;
}
break;
#endif
default:
/* Unknown type. */
return -1;
}
return 0;
}

View File

@ -1,154 +0,0 @@
/* Decomposed printf argument list.
Copyright (C) 1999, 2002-2003, 2006-2007 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _PRINTF_ARGS_H
#define _PRINTF_ARGS_H
/* This file can be parametrized with the following macros:
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
PRINTF_FETCHARGS Name of the function to be declared.
STATIC Set to 'static' to declare the function static. */
/* Default parameters. */
#ifndef PRINTF_FETCHARGS
# define PRINTF_FETCHARGS printf_fetchargs
#endif
/* Get size_t. */
#include <stddef.h>
/* Get wchar_t. */
#if HAVE_WCHAR_T
# include <stddef.h>
#endif
/* Get wint_t. */
#if HAVE_WINT_T
# include <wchar.h>
#endif
/* Get va_list. */
#include <stdarg.h>
/* Argument types */
typedef enum
{
TYPE_NONE,
TYPE_SCHAR,
TYPE_UCHAR,
TYPE_SHORT,
TYPE_USHORT,
TYPE_INT,
TYPE_UINT,
TYPE_LONGINT,
TYPE_ULONGINT,
#if HAVE_LONG_LONG_INT
TYPE_LONGLONGINT,
TYPE_ULONGLONGINT,
#endif
TYPE_DOUBLE,
TYPE_LONGDOUBLE,
TYPE_CHAR,
#if HAVE_WINT_T
TYPE_WIDE_CHAR,
#endif
TYPE_STRING,
#if HAVE_WCHAR_T
TYPE_WIDE_STRING,
#endif
TYPE_POINTER,
TYPE_COUNT_SCHAR_POINTER,
TYPE_COUNT_SHORT_POINTER,
TYPE_COUNT_INT_POINTER,
TYPE_COUNT_LONGINT_POINTER
#if HAVE_LONG_LONG_INT
, TYPE_COUNT_LONGLONGINT_POINTER
#endif
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
, TYPE_U8_STRING
, TYPE_U16_STRING
, TYPE_U32_STRING
#endif
} arg_type;
/* Polymorphic argument */
typedef struct
{
arg_type type;
union
{
signed char a_schar;
unsigned char a_uchar;
short a_short;
unsigned short a_ushort;
int a_int;
unsigned int a_uint;
long int a_longint;
unsigned long int a_ulongint;
#if HAVE_LONG_LONG_INT
long long int a_longlongint;
unsigned long long int a_ulonglongint;
#endif
float a_float;
double a_double;
long double a_longdouble;
int a_char;
#if HAVE_WINT_T
wint_t a_wide_char;
#endif
const char* a_string;
#if HAVE_WCHAR_T
const wchar_t* a_wide_string;
#endif
void* a_pointer;
signed char * a_count_schar_pointer;
short * a_count_short_pointer;
int * a_count_int_pointer;
long int * a_count_longint_pointer;
#if HAVE_LONG_LONG_INT
long long int * a_count_longlongint_pointer;
#endif
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
const uint8_t * a_u8_string;
const uint16_t * a_u16_string;
const uint32_t * a_u32_string;
#endif
}
a;
}
argument;
typedef struct
{
size_t count;
argument *arg;
}
arguments;
/* Fetch the arguments, putting them into a. */
#ifdef STATIC
STATIC
#else
extern
#endif
int PRINTF_FETCHARGS (va_list args, arguments *a);
#endif /* _PRINTF_ARGS_H */

View File

@ -1,627 +0,0 @@
/* Formatted output to strings.
Copyright (C) 1999-2000, 2002-2003, 2006-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* This file can be parametrized with the following macros:
CHAR_T The element type of the format string.
CHAR_T_ONLY_ASCII Set to 1 to enable verification that all characters
in the format string are ASCII.
DIRECTIVE Structure denoting a format directive.
Depends on CHAR_T.
DIRECTIVES Structure denoting the set of format directives of a
format string. Depends on CHAR_T.
PRINTF_PARSE Function that parses a format string.
Depends on CHAR_T.
STATIC Set to 'static' to declare the function static.
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions. */
#ifndef PRINTF_PARSE
# include <config.h>
#endif
/* Specification. */
#ifndef PRINTF_PARSE
# include "printf-parse.h"
#endif
/* Default parameters. */
#ifndef PRINTF_PARSE
# define PRINTF_PARSE printf_parse
# define CHAR_T char
# define DIRECTIVE char_directive
# define DIRECTIVES char_directives
#endif
/* Get size_t, NULL. */
#include <stddef.h>
/* Get intmax_t. */
#if defined IN_LIBINTL || defined IN_LIBASPRINTF
# if HAVE_STDINT_H_WITH_UINTMAX
# include <stdint.h>
# endif
# if HAVE_INTTYPES_H_WITH_UINTMAX
# include <inttypes.h>
# endif
#else
# include <stdint.h>
#endif
/* malloc(), realloc(), free(). */
#include <stdlib.h>
/* errno. */
#include <errno.h>
/* Checked size_t computations. */
#include "xsize.h"
#if CHAR_T_ONLY_ASCII
/* c_isascii(). */
# include "c-ctype.h"
#endif
#ifdef STATIC
STATIC
#endif
int
PRINTF_PARSE (const CHAR_T *format, DIRECTIVES *d, arguments *a)
{
const CHAR_T *cp = format; /* pointer into format */
size_t arg_posn = 0; /* number of regular arguments consumed */
size_t d_allocated; /* allocated elements of d->dir */
size_t a_allocated; /* allocated elements of a->arg */
size_t max_width_length = 0;
size_t max_precision_length = 0;
d->count = 0;
d_allocated = 1;
d->dir = (DIRECTIVE *) malloc (d_allocated * sizeof (DIRECTIVE));
if (d->dir == NULL)
/* Out of memory. */
goto out_of_memory_1;
a->count = 0;
a_allocated = 0;
a->arg = NULL;
#define REGISTER_ARG(_index_,_type_) \
{ \
size_t n = (_index_); \
if (n >= a_allocated) \
{ \
size_t memory_size; \
argument *memory; \
\
a_allocated = xtimes (a_allocated, 2); \
if (a_allocated <= n) \
a_allocated = xsum (n, 1); \
memory_size = xtimes (a_allocated, sizeof (argument)); \
if (size_overflow_p (memory_size)) \
/* Overflow, would lead to out of memory. */ \
goto out_of_memory; \
memory = (argument *) (a->arg \
? realloc (a->arg, memory_size) \
: malloc (memory_size)); \
if (memory == NULL) \
/* Out of memory. */ \
goto out_of_memory; \
a->arg = memory; \
} \
while (a->count <= n) \
a->arg[a->count++].type = TYPE_NONE; \
if (a->arg[n].type == TYPE_NONE) \
a->arg[n].type = (_type_); \
else if (a->arg[n].type != (_type_)) \
/* Ambiguous type for positional argument. */ \
goto error; \
}
while (*cp != '\0')
{
CHAR_T c = *cp++;
if (c == '%')
{
size_t arg_index = ARG_NONE;
DIRECTIVE *dp = &d->dir[d->count]; /* pointer to next directive */
/* Initialize the next directive. */
dp->dir_start = cp - 1;
dp->flags = 0;
dp->width_start = NULL;
dp->width_end = NULL;
dp->width_arg_index = ARG_NONE;
dp->precision_start = NULL;
dp->precision_end = NULL;
dp->precision_arg_index = ARG_NONE;
dp->arg_index = ARG_NONE;
/* Test for positional argument. */
if (*cp >= '0' && *cp <= '9')
{
const CHAR_T *np;
for (np = cp; *np >= '0' && *np <= '9'; np++)
;
if (*np == '$')
{
size_t n = 0;
for (np = cp; *np >= '0' && *np <= '9'; np++)
n = xsum (xtimes (n, 10), *np - '0');
if (n == 0)
/* Positional argument 0. */
goto error;
if (size_overflow_p (n))
/* n too large, would lead to out of memory later. */
goto error;
arg_index = n - 1;
cp = np + 1;
}
}
/* Read the flags. */
for (;;)
{
if (*cp == '\'')
{
dp->flags |= FLAG_GROUP;
cp++;
}
else if (*cp == '-')
{
dp->flags |= FLAG_LEFT;
cp++;
}
else if (*cp == '+')
{
dp->flags |= FLAG_SHOWSIGN;
cp++;
}
else if (*cp == ' ')
{
dp->flags |= FLAG_SPACE;
cp++;
}
else if (*cp == '#')
{
dp->flags |= FLAG_ALT;
cp++;
}
else if (*cp == '0')
{
dp->flags |= FLAG_ZERO;
cp++;
}
else
break;
}
/* Parse the field width. */
if (*cp == '*')
{
dp->width_start = cp;
cp++;
dp->width_end = cp;
if (max_width_length < 1)
max_width_length = 1;
/* Test for positional argument. */
if (*cp >= '0' && *cp <= '9')
{
const CHAR_T *np;
for (np = cp; *np >= '0' && *np <= '9'; np++)
;
if (*np == '$')
{
size_t n = 0;
for (np = cp; *np >= '0' && *np <= '9'; np++)
n = xsum (xtimes (n, 10), *np - '0');
if (n == 0)
/* Positional argument 0. */
goto error;
if (size_overflow_p (n))
/* n too large, would lead to out of memory later. */
goto error;
dp->width_arg_index = n - 1;
cp = np + 1;
}
}
if (dp->width_arg_index == ARG_NONE)
{
dp->width_arg_index = arg_posn++;
if (dp->width_arg_index == ARG_NONE)
/* arg_posn wrapped around. */
goto error;
}
REGISTER_ARG (dp->width_arg_index, TYPE_INT);
}
else if (*cp >= '0' && *cp <= '9')
{
size_t width_length;
dp->width_start = cp;
for (; *cp >= '0' && *cp <= '9'; cp++)
;
dp->width_end = cp;
width_length = dp->width_end - dp->width_start;
if (max_width_length < width_length)
max_width_length = width_length;
}
/* Parse the precision. */
if (*cp == '.')
{
cp++;
if (*cp == '*')
{
dp->precision_start = cp - 1;
cp++;
dp->precision_end = cp;
if (max_precision_length < 2)
max_precision_length = 2;
/* Test for positional argument. */
if (*cp >= '0' && *cp <= '9')
{
const CHAR_T *np;
for (np = cp; *np >= '0' && *np <= '9'; np++)
;
if (*np == '$')
{
size_t n = 0;
for (np = cp; *np >= '0' && *np <= '9'; np++)
n = xsum (xtimes (n, 10), *np - '0');
if (n == 0)
/* Positional argument 0. */
goto error;
if (size_overflow_p (n))
/* n too large, would lead to out of memory
later. */
goto error;
dp->precision_arg_index = n - 1;
cp = np + 1;
}
}
if (dp->precision_arg_index == ARG_NONE)
{
dp->precision_arg_index = arg_posn++;
if (dp->precision_arg_index == ARG_NONE)
/* arg_posn wrapped around. */
goto error;
}
REGISTER_ARG (dp->precision_arg_index, TYPE_INT);
}
else
{
size_t precision_length;
dp->precision_start = cp - 1;
for (; *cp >= '0' && *cp <= '9'; cp++)
;
dp->precision_end = cp;
precision_length = dp->precision_end - dp->precision_start;
if (max_precision_length < precision_length)
max_precision_length = precision_length;
}
}
{
arg_type type;
/* Parse argument type/size specifiers. */
{
int flags = 0;
for (;;)
{
if (*cp == 'h')
{
flags |= (1 << (flags & 1));
cp++;
}
else if (*cp == 'L')
{
flags |= 4;
cp++;
}
else if (*cp == 'l')
{
flags += 8;
cp++;
}
else if (*cp == 'j')
{
if (sizeof (intmax_t) > sizeof (long))
{
/* intmax_t = long long */
flags += 16;
}
else if (sizeof (intmax_t) > sizeof (int))
{
/* intmax_t = long */
flags += 8;
}
cp++;
}
else if (*cp == 'z' || *cp == 'Z')
{
/* 'z' is standardized in ISO C 99, but glibc uses 'Z'
because the warning facility in gcc-2.95.2 understands
only 'Z' (see gcc-2.95.2/gcc/c-common.c:1784). */
if (sizeof (size_t) > sizeof (long))
{
/* size_t = long long */
flags += 16;
}
else if (sizeof (size_t) > sizeof (int))
{
/* size_t = long */
flags += 8;
}
cp++;
}
else if (*cp == 't')
{
if (sizeof (ptrdiff_t) > sizeof (long))
{
/* ptrdiff_t = long long */
flags += 16;
}
else if (sizeof (ptrdiff_t) > sizeof (int))
{
/* ptrdiff_t = long */
flags += 8;
}
cp++;
}
#if defined __APPLE__ && defined __MACH__
/* On MacOS X 10.3, PRIdMAX is defined as "qd".
We cannot change it to "lld" because PRIdMAX must also
be understood by the system's printf routines. */
else if (*cp == 'q')
{
if (64 / 8 > sizeof (long))
{
/* int64_t = long long */
flags += 16;
}
else
{
/* int64_t = long */
flags += 8;
}
cp++;
}
#endif
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
/* On native Win32, PRIdMAX is defined as "I64d".
We cannot change it to "lld" because PRIdMAX must also
be understood by the system's printf routines. */
else if (*cp == 'I' && cp[1] == '6' && cp[2] == '4')
{
if (64 / 8 > sizeof (long))
{
/* __int64 = long long */
flags += 16;
}
else
{
/* __int64 = long */
flags += 8;
}
cp += 3;
}
#endif
else
break;
}
/* Read the conversion character. */
c = *cp++;
switch (c)
{
case 'd': case 'i':
#if HAVE_LONG_LONG_INT
/* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_LONGLONGINT;
else
#endif
/* If 'long long' exists and is the same as 'long', we parse
"lld" into TYPE_LONGINT. */
if (flags >= 8)
type = TYPE_LONGINT;
else if (flags & 2)
type = TYPE_SCHAR;
else if (flags & 1)
type = TYPE_SHORT;
else
type = TYPE_INT;
break;
case 'o': case 'u': case 'x': case 'X':
#if HAVE_LONG_LONG_INT
/* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_ULONGLONGINT;
else
#endif
/* If 'unsigned long long' exists and is the same as
'unsigned long', we parse "llu" into TYPE_ULONGINT. */
if (flags >= 8)
type = TYPE_ULONGINT;
else if (flags & 2)
type = TYPE_UCHAR;
else if (flags & 1)
type = TYPE_USHORT;
else
type = TYPE_UINT;
break;
case 'f': case 'F': case 'e': case 'E': case 'g': case 'G':
case 'a': case 'A':
if (flags >= 16 || (flags & 4))
type = TYPE_LONGDOUBLE;
else
type = TYPE_DOUBLE;
break;
case 'c':
if (flags >= 8)
#if HAVE_WINT_T
type = TYPE_WIDE_CHAR;
#else
goto error;
#endif
else
type = TYPE_CHAR;
break;
#if HAVE_WINT_T
case 'C':
type = TYPE_WIDE_CHAR;
c = 'c';
break;
#endif
case 's':
if (flags >= 8)
#if HAVE_WCHAR_T
type = TYPE_WIDE_STRING;
#else
goto error;
#endif
else
type = TYPE_STRING;
break;
#if HAVE_WCHAR_T
case 'S':
type = TYPE_WIDE_STRING;
c = 's';
break;
#endif
case 'p':
type = TYPE_POINTER;
break;
case 'n':
#if HAVE_LONG_LONG_INT
/* If 'long long' exists and is larger than 'long': */
if (flags >= 16 || (flags & 4))
type = TYPE_COUNT_LONGLONGINT_POINTER;
else
#endif
/* If 'long long' exists and is the same as 'long', we parse
"lln" into TYPE_COUNT_LONGINT_POINTER. */
if (flags >= 8)
type = TYPE_COUNT_LONGINT_POINTER;
else if (flags & 2)
type = TYPE_COUNT_SCHAR_POINTER;
else if (flags & 1)
type = TYPE_COUNT_SHORT_POINTER;
else
type = TYPE_COUNT_INT_POINTER;
break;
#if ENABLE_UNISTDIO
/* The unistdio extensions. */
case 'U':
if (flags >= 16)
type = TYPE_U32_STRING;
else if (flags >= 8)
type = TYPE_U16_STRING;
else
type = TYPE_U8_STRING;
break;
#endif
case '%':
type = TYPE_NONE;
break;
default:
/* Unknown conversion character. */
goto error;
}
}
if (type != TYPE_NONE)
{
dp->arg_index = arg_index;
if (dp->arg_index == ARG_NONE)
{
dp->arg_index = arg_posn++;
if (dp->arg_index == ARG_NONE)
/* arg_posn wrapped around. */
goto error;
}
REGISTER_ARG (dp->arg_index, type);
}
dp->conversion = c;
dp->dir_end = cp;
}
d->count++;
if (d->count >= d_allocated)
{
size_t memory_size;
DIRECTIVE *memory;
d_allocated = xtimes (d_allocated, 2);
memory_size = xtimes (d_allocated, sizeof (DIRECTIVE));
if (size_overflow_p (memory_size))
/* Overflow, would lead to out of memory. */
goto out_of_memory;
memory = (DIRECTIVE *) realloc (d->dir, memory_size);
if (memory == NULL)
/* Out of memory. */
goto out_of_memory;
d->dir = memory;
}
}
#if CHAR_T_ONLY_ASCII
else if (!c_isascii (c))
{
/* Non-ASCII character. Not supported. */
goto error;
}
#endif
}
d->dir[d->count].dir_start = cp;
d->max_width_length = max_width_length;
d->max_precision_length = max_precision_length;
return 0;
error:
if (a->arg)
free (a->arg);
if (d->dir)
free (d->dir);
errno = EINVAL;
return -1;
out_of_memory:
if (a->arg)
free (a->arg);
if (d->dir)
free (d->dir);
out_of_memory_1:
errno = ENOMEM;
return -1;
}
#undef PRINTF_PARSE
#undef DIRECTIVES
#undef DIRECTIVE
#undef CHAR_T_ONLY_ASCII
#undef CHAR_T

View File

@ -1,179 +0,0 @@
/* Parse printf format string.
Copyright (C) 1999, 2002-2003, 2005, 2007 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _PRINTF_PARSE_H
#define _PRINTF_PARSE_H
/* This file can be parametrized with the following macros:
ENABLE_UNISTDIO Set to 1 to enable the unistdio extensions.
STATIC Set to 'static' to declare the function static. */
#include "printf-args.h"
/* Flags */
#define FLAG_GROUP 1 /* ' flag */
#define FLAG_LEFT 2 /* - flag */
#define FLAG_SHOWSIGN 4 /* + flag */
#define FLAG_SPACE 8 /* space flag */
#define FLAG_ALT 16 /* # flag */
#define FLAG_ZERO 32
/* arg_index value indicating that no argument is consumed. */
#define ARG_NONE (~(size_t)0)
/* xxx_directive: A parsed directive.
xxx_directives: A parsed format string. */
/* A parsed directive. */
typedef struct
{
const char* dir_start;
const char* dir_end;
int flags;
const char* width_start;
const char* width_end;
size_t width_arg_index;
const char* precision_start;
const char* precision_end;
size_t precision_arg_index;
char conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
size_t arg_index;
}
char_directive;
/* A parsed format string. */
typedef struct
{
size_t count;
char_directive *dir;
size_t max_width_length;
size_t max_precision_length;
}
char_directives;
#if ENABLE_UNISTDIO
/* A parsed directive. */
typedef struct
{
const uint8_t* dir_start;
const uint8_t* dir_end;
int flags;
const uint8_t* width_start;
const uint8_t* width_end;
size_t width_arg_index;
const uint8_t* precision_start;
const uint8_t* precision_end;
size_t precision_arg_index;
uint8_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
size_t arg_index;
}
u8_directive;
/* A parsed format string. */
typedef struct
{
size_t count;
u8_directive *dir;
size_t max_width_length;
size_t max_precision_length;
}
u8_directives;
/* A parsed directive. */
typedef struct
{
const uint16_t* dir_start;
const uint16_t* dir_end;
int flags;
const uint16_t* width_start;
const uint16_t* width_end;
size_t width_arg_index;
const uint16_t* precision_start;
const uint16_t* precision_end;
size_t precision_arg_index;
uint16_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
size_t arg_index;
}
u16_directive;
/* A parsed format string. */
typedef struct
{
size_t count;
u16_directive *dir;
size_t max_width_length;
size_t max_precision_length;
}
u16_directives;
/* A parsed directive. */
typedef struct
{
const uint32_t* dir_start;
const uint32_t* dir_end;
int flags;
const uint32_t* width_start;
const uint32_t* width_end;
size_t width_arg_index;
const uint32_t* precision_start;
const uint32_t* precision_end;
size_t precision_arg_index;
uint32_t conversion; /* d i o u x X f F e E g G a A c s p n U % but not C S */
size_t arg_index;
}
u32_directive;
/* A parsed format string. */
typedef struct
{
size_t count;
u32_directive *dir;
size_t max_width_length;
size_t max_precision_length;
}
u32_directives;
#endif
/* Parses the format string. Fills in the number N of directives, and fills
in directives[0], ..., directives[N-1], and sets directives[N].dir_start
to the end of the format string. Also fills in the arg_type fields of the
arguments and the needed count of arguments. */
#if ENABLE_UNISTDIO
extern int
ulc_printf_parse (const char *format, char_directives *d, arguments *a);
extern int
u8_printf_parse (const uint8_t *format, u8_directives *d, arguments *a);
extern int
u16_printf_parse (const uint16_t *format, u16_directives *d,
arguments *a);
extern int
u32_printf_parse (const uint32_t *format, u32_directives *d,
arguments *a);
#else
# ifdef STATIC
STATIC
# else
extern
# endif
int printf_parse (const char *format, char_directives *d, arguments *a);
#endif
#endif /* _PRINTF_PARSE_H */

View File

@ -1,420 +0,0 @@
/*
Copyright (C) 1995, 2005, 2008 Free Software Foundation
The GNU C 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.1 of the License, or (at your option) any later version.
The GNU C Library 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.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
/*
Copyright (C) 1983 Regents of the University of California.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
4. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.*/
/*
* This is derived from the Berkeley source:
* @(#)random.c 5.5 (Berkeley) 7/6/88
* It was reworked for the GNU C Library by Roland McGrath.
* Rewritten to be reentrant by Ulrich Drepper, 1995
*/
#include <config.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
#include <inttypes.h>
/* An improved random number generation package. In addition to the standard
rand()/srand() like interface, this package also has a special state info
interface. The initstate() routine is called with a seed, an array of
bytes, and a count of how many bytes are being passed in; this array is
then initialized to contain information for random number generation with
that much state information. Good sizes for the amount of state
information are 32, 64, 128, and 256 bytes. The state can be switched by
calling the setstate() function with the same array as was initialized
with initstate(). By default, the package runs with 128 bytes of state
information and generates far better random numbers than a linear
congruential generator. If the amount of state information is less than
32 bytes, a simple linear congruential R.N.G. is used. Internally, the
state information is treated as an array of longs; the zeroth element of
the array is the type of R.N.G. being used (small integer); the remainder
of the array is the state information for the R.N.G. Thus, 32 bytes of
state information will give 7 longs worth of state information, which will
allow a degree seven polynomial. (Note: The zeroth word of state
information also has some other information stored in it; see setstate
for details). The random number generation technique is a linear feedback
shift register approach, employing trinomials (since there are fewer terms
to sum up that way). In this approach, the least significant bit of all
the numbers in the state table will act as a linear feedback shift register,
and will have period 2^deg - 1 (where deg is the degree of the polynomial
being used, assuming that the polynomial is irreducible and primitive).
The higher order bits will have longer periods, since their values are
also influenced by pseudo-random carries out of the lower bits. The
total period of the generator is approximately deg*(2**deg - 1); thus
doubling the amount of state information has a vast influence on the
period of the generator. Note: The deg*(2**deg - 1) is an approximation
only good for large deg, when the period of the shift register is the
dominant factor. With deg equal to seven, the period is actually much
longer than the 7*(2**7 - 1) predicted by this formula. */
/* For each of the currently supported random number generators, we have a
break value on the amount of state information (you need at least this many
bytes of state info to support this random number generator), a degree for
the polynomial (actually a trinomial) that the R.N.G. is based on, and
separation between the two lower order coefficients of the trinomial. */
/* Linear congruential. */
#define TYPE_0 0
#define BREAK_0 8
#define DEG_0 0
#define SEP_0 0
/* x**7 + x**3 + 1. */
#define TYPE_1 1
#define BREAK_1 32
#define DEG_1 7
#define SEP_1 3
/* x**15 + x + 1. */
#define TYPE_2 2
#define BREAK_2 64
#define DEG_2 15
#define SEP_2 1
/* x**31 + x**3 + 1. */
#define TYPE_3 3
#define BREAK_3 128
#define DEG_3 31
#define SEP_3 3
/* x**63 + x + 1. */
#define TYPE_4 4
#define BREAK_4 256
#define DEG_4 63
#define SEP_4 1
/* Array versions of the above information to make code run faster.
Relies on fact that TYPE_i == i. */
#define MAX_TYPES 5 /* Max number of types above. */
struct random_poly_info
{
int seps[MAX_TYPES];
int degrees[MAX_TYPES];
};
static const struct random_poly_info random_poly_info =
{
{ SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 },
{ DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }
};
#ifndef _LIBC
# define weak_alias(local, symbol)
# define __set_errno(e) errno = (e)
# define __srandom_r srandom_r
# define __initstate_r initstate_r
# define __setstate_r setstate_r
# define __random_r random_r
#endif
/* Initialize the random number generator based on the given seed. If the
type is the trivial no-state-information type, just remember the seed.
Otherwise, initializes state[] based on the given "seed" via a linear
congruential generator. Then, the pointers are set to known locations
that are exactly rand_sep places apart. Lastly, it cycles the state
information a given number of times to get rid of any initial dependencies
introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
for default usage relies on values produced by this routine. */
int
__srandom_r (unsigned int seed, struct random_data *buf)
{
int type;
int32_t *state;
long int i;
long int word;
int32_t *dst;
int kc;
if (buf == NULL)
goto fail;
type = buf->rand_type;
if ((unsigned int) type >= MAX_TYPES)
goto fail;
state = buf->state;
/* We must make sure the seed is not 0. Take arbitrarily 1 in this case. */
if (seed == 0)
seed = 1;
state[0] = seed;
if (type == TYPE_0)
goto done;
dst = state;
word = seed;
kc = buf->rand_deg;
for (i = 1; i < kc; ++i)
{
/* This does:
state[i] = (16807 * state[i - 1]) % 2147483647;
but avoids overflowing 31 bits. */
long int hi = word / 127773;
long int lo = word % 127773;
word = 16807 * lo - 2836 * hi;
if (word < 0)
word += 2147483647;
*++dst = word;
}
buf->fptr = &state[buf->rand_sep];
buf->rptr = &state[0];
kc *= 10;
while (--kc >= 0)
{
int32_t discard;
(void) __random_r (buf, &discard);
}
done:
return 0;
fail:
return -1;
}
weak_alias (__srandom_r, srandom_r)
/* Initialize the state information in the given array of N bytes for
future random number generation. Based on the number of bytes we
are given, and the break values for the different R.N.G.'s, we choose
the best (largest) one we can and set things up for it. srandom is
then called to initialize the state information. Note that on return
from srandom, we set state[-1] to be the type multiplexed with the current
value of the rear pointer; this is so successive calls to initstate won't
lose this information and will be able to restart with setstate.
Note: The first thing we do is save the current state, if any, just like
setstate so that it doesn't matter when initstate is called.
Returns a pointer to the old state. */
int
__initstate_r (unsigned int seed, char *arg_state, size_t n,
struct random_data *buf)
{
int32_t *old_state;
int32_t *state;
int type;
int degree;
int separation;
if (buf == NULL)
goto fail;
old_state = buf->state;
if (old_state != NULL)
{
int old_type = buf->rand_type;
if (old_type == TYPE_0)
old_state[-1] = TYPE_0;
else
old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
}
if (n >= BREAK_3)
type = n < BREAK_4 ? TYPE_3 : TYPE_4;
else if (n < BREAK_1)
{
if (n < BREAK_0)
{
__set_errno (EINVAL);
goto fail;
}
type = TYPE_0;
}
else
type = n < BREAK_2 ? TYPE_1 : TYPE_2;
degree = random_poly_info.degrees[type];
separation = random_poly_info.seps[type];
buf->rand_type = type;
buf->rand_sep = separation;
buf->rand_deg = degree;
state = &((int32_t *) arg_state)[1]; /* First location. */
/* Must set END_PTR before srandom. */
buf->end_ptr = &state[degree];
buf->state = state;
__srandom_r (seed, buf);
state[-1] = TYPE_0;
if (type != TYPE_0)
state[-1] = (buf->rptr - state) * MAX_TYPES + type;
return 0;
fail:
__set_errno (EINVAL);
return -1;
}
weak_alias (__initstate_r, initstate_r)
/* Restore the state from the given state array.
Note: It is important that we also remember the locations of the pointers
in the current state information, and restore the locations of the pointers
from the old state information. This is done by multiplexing the pointer
location into the zeroth word of the state information. Note that due
to the order in which things are done, it is OK to call setstate with the
same state as the current state
Returns a pointer to the old state information. */
int
__setstate_r (char *arg_state, struct random_data *buf)
{
int32_t *new_state = 1 + (int32_t *) arg_state;
int type;
int old_type;
int32_t *old_state;
int degree;
int separation;
if (arg_state == NULL || buf == NULL)
goto fail;
old_type = buf->rand_type;
old_state = buf->state;
if (old_type == TYPE_0)
old_state[-1] = TYPE_0;
else
old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
type = new_state[-1] % MAX_TYPES;
if (type < TYPE_0 || type > TYPE_4)
goto fail;
buf->rand_deg = degree = random_poly_info.degrees[type];
buf->rand_sep = separation = random_poly_info.seps[type];
buf->rand_type = type;
if (type != TYPE_0)
{
int rear = new_state[-1] / MAX_TYPES;
buf->rptr = &new_state[rear];
buf->fptr = &new_state[(rear + separation) % degree];
}
buf->state = new_state;
/* Set end_ptr too. */
buf->end_ptr = &new_state[degree];
return 0;
fail:
__set_errno (EINVAL);
return -1;
}
weak_alias (__setstate_r, setstate_r)
/* If we are using the trivial TYPE_0 R.N.G., just do the old linear
congruential bit. Otherwise, we do our fancy trinomial stuff, which is the
same in all the other cases due to all the global variables that have been
set up. The basic operation is to add the number at the rear pointer into
the one at the front pointer. Then both pointers are advanced to the next
location cyclically in the table. The value returned is the sum generated,
reduced to 31 bits by throwing away the "least random" low bit.
Note: The code takes advantage of the fact that both the front and
rear pointers can't wrap on the same call by not testing the rear
pointer if the front one has wrapped. Returns a 31-bit random number. */
int
__random_r (struct random_data *buf, int32_t *result)
{
int32_t *state;
if (buf == NULL || result == NULL)
goto fail;
state = buf->state;
if (buf->rand_type == TYPE_0)
{
int32_t val = state[0];
val = ((state[0] * 1103515245) + 12345) & 0x7fffffff;
state[0] = val;
*result = val;
}
else
{
int32_t *fptr = buf->fptr;
int32_t *rptr = buf->rptr;
int32_t *end_ptr = buf->end_ptr;
int32_t val;
val = *fptr += *rptr;
/* Chucking least random bit. */
*result = (val >> 1) & 0x7fffffff;
++fptr;
if (fptr >= end_ptr)
{
fptr = state;
++rptr;
}
else
{
++rptr;
if (rptr >= end_ptr)
rptr = state;
}
buf->fptr = fptr;
buf->rptr = rptr;
}
return 0;
fail:
__set_errno (EINVAL);
return -1;
}
weak_alias (__random_r, random_r)

View File

@ -1,87 +0,0 @@
/* realloc() function that is glibc compatible.
Copyright (C) 1997, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* written by Jim Meyering and Bruno Haible */
#include <config.h>
/* Only the AC_FUNC_REALLOC macro defines 'realloc' already in config.h. */
#ifdef realloc
# define NEED_REALLOC_GNU 1
#endif
/* Infer the properties of the system's malloc function.
Only the AC_FUNC_MALLOC macro defines 'malloc' already in config.h. */
#if GNULIB_MALLOC_GNU && !defined malloc
# define SYSTEM_MALLOC_GLIBC_COMPATIBLE 1
#endif
/* Below we want to call the system's malloc and realloc.
Undefine the symbols here so that including <stdlib.h> provides a
declaration of malloc(), not of rpl_malloc(), and likewise for realloc. */
#undef malloc
#undef realloc
/* Specification. */
#include <stdlib.h>
#include <errno.h>
/* Below we want to call the system's malloc and realloc.
Undefine the symbols, if they were defined by gnulib's <stdlib.h>
replacement. */
#undef malloc
#undef realloc
/* 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 *p, size_t n)
{
void *result;
#if NEED_REALLOC_GNU
if (n == 0)
{
n = 1;
/* In theory realloc might fail, so don't rely on it to free. */
free (p);
p = NULL;
}
#endif
if (p == NULL)
{
#if GNULIB_REALLOC_GNU && !NEED_REALLOC_GNU && !SYSTEM_MALLOC_GLIBC_COMPATIBLE
if (n == 0)
n = 1;
#endif
result = malloc (n);
}
else
result = realloc (p, n);
#if !HAVE_REALLOC_POSIX
if (result == NULL)
errno = ENOMEM;
#endif
return result;
}

View File

@ -1,40 +0,0 @@
/* recv.c --- wrappers for Windows recv function
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paolo Bonzini */
#include <config.h>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef recv
int
rpl_recv (int fd, void *buf, int len, int flags)
{
SOCKET sock = FD_TO_SOCKET (fd);
int r = recv (sock, buf, len, flags);
if (r < 0)
set_winsock_errno ();
return r;
}

View File

@ -1,40 +0,0 @@
/* send.c --- wrappers for Windows send function
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paolo Bonzini */
#include <config.h>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef send
int
rpl_send (int fd, const void *buf, int len, int flags)
{
SOCKET sock = FD_TO_SOCKET (fd);
int r = send (sock, buf, len, flags);
if (r < 0)
set_winsock_errno ();
return r;
}

View File

@ -1,40 +0,0 @@
/* setsockopt.c --- wrappers for Windows setsockopt function
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paolo Bonzini */
#include <config.h>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
#undef setsockopt
int
rpl_setsockopt (int fd, int level, int optname, const void *optval, int optlen)
{
SOCKET sock = FD_TO_SOCKET (fd);
int r = setsockopt (sock, level, optname, optval, optlen);
if (r < 0)
set_winsock_errno ();
return r;
}

View File

@ -1,31 +0,0 @@
/* size_max.h -- declare SIZE_MAX through system headers
Copyright (C) 2005-2006 Free Software Foundation, Inc.
Written by Simon Josefsson.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef GNULIB_SIZE_MAX_H
#define GNULIB_SIZE_MAX_H
/* Get SIZE_MAX declaration on systems like Solaris 7/8/9. */
# include <limits.h>
/* Get SIZE_MAX declaration on systems like glibc 2. */
# if HAVE_STDINT_H
# include <stdint.h>
# endif
/* On systems where these include files don't define it, SIZE_MAX is defined
in config.h. */
#endif /* GNULIB_SIZE_MAX_H */

View File

@ -1,72 +0,0 @@
/* Formatted output to strings.
Copyright (C) 2004, 2006-2008 Free Software Foundation, Inc.
Written by Simon Josefsson and Paul Eggert.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include "vasnprintf.h"
/* Print formatted output to string STR. Similar to sprintf, but
additional length SIZE limit how much is written into STR. Returns
string length of formatted string (which may be larger than SIZE).
STR may be NULL, in which case nothing will be written. On error,
return a negative value. */
int
snprintf (char *str, size_t size, const char *format, ...)
{
char *output;
size_t len;
size_t lenbuf = size;
va_list args;
va_start (args, format);
output = vasnprintf (str, &lenbuf, format, args);
len = lenbuf;
va_end (args);
if (!output)
return -1;
if (output != str)
{
if (size)
{
size_t pruned_len = (len < size ? len : size - 1);
memcpy (str, output, pruned_len);
str[pruned_len] = '\0';
}
free (output);
}
if (INT_MAX < len)
{
errno = EOVERFLOW;
return -1;
}
return len;
}

View File

@ -1,43 +0,0 @@
/* socket.c --- wrappers for Windows socket function
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paolo Bonzini */
#include <config.h>
#define WIN32_LEAN_AND_MEAN
/* Get winsock2.h. */
#include <sys/socket.h>
/* Get set_winsock_errno, FD_TO_SOCKET etc. */
#include "w32sock.h"
int
rpl_socket (int domain, int type, int protocol)
{
/* We have to use WSASocket() to create non-overlapped IO sockets.
Overlapped IO sockets cannot be used with read/write. */
SOCKET fh = WSASocket (domain, type, protocol, NULL, 0, 0);
if (fh == INVALID_SOCKET)
{
set_winsock_errno ();
return -1;
}
else
return SOCKET_TO_FD (fh);
}

View File

@ -1,119 +0,0 @@
/* Copyright (C) 2001-2003, 2006-2008 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_STDBOOL_H
#define _GL_STDBOOL_H
/* ISO C 99 <stdbool.h> for platforms that lack it. */
/* Usage suggestions:
Programs that use <stdbool.h> should be aware of some limitations
and standards compliance issues.
Standards compliance:
- <stdbool.h> must be #included before 'bool', 'false', 'true'
can be used.
- You cannot assume that sizeof (bool) == 1.
- Programs should not undefine the macros bool, true, and false,
as C99 lists that as an "obsolescent feature".
Limitations of this substitute, when used in a C89 environment:
- <stdbool.h> must be #included before the '_Bool' type can be used.
- You cannot assume that _Bool is a typedef; it might be a macro.
- Bit-fields of type 'bool' are not supported. Portable code
should use 'unsigned int foo : 1;' rather than 'bool foo : 1;'.
- In C99, casts and automatic conversions to '_Bool' or 'bool' are
performed in such a way that every nonzero value gets converted
to 'true', and zero gets converted to 'false'. This doesn't work
with this substitute. With this substitute, only the values 0 and 1
give the expected result when converted to _Bool' or 'bool'.
Also, it is suggested that programs use 'bool' rather than '_Bool';
this isn't required, but 'bool' is more common. */
/* 7.16. Boolean type and values */
/* BeOS <sys/socket.h> already #defines false 0, true 1. We use the same
definitions below, but temporarily we have to #undef them. */
#if defined __BEOS__ && !defined __HAIKU__
# include <OS.h> /* defines bool but not _Bool */
# undef false
# undef true
#endif
/* For the sake of symbolic names in gdb, we define true and false as
enum constants, not only as macros.
It is tempting to write
typedef enum { false = 0, true = 1 } _Bool;
so that gdb prints values of type 'bool' symbolically. But if we do
this, values of type '_Bool' may promote to 'int' or 'unsigned int'
(see ISO C 99 6.7.2.2.(4)); however, '_Bool' must promote to 'int'
(see ISO C 99 6.3.1.1.(2)). So we add a negative value to the
enum; this ensures that '_Bool' promotes to 'int'. */
#if defined __cplusplus || (defined __BEOS__ && !defined __HAIKU__)
/* A compiler known to have 'bool'. */
/* If the compiler already has both 'bool' and '_Bool', we can assume they
are the same types. */
# if !@HAVE__BOOL@
typedef bool _Bool;
# endif
#else
# if !defined __GNUC__
/* If @HAVE__BOOL@:
Some HP-UX cc and AIX IBM C compiler versions have compiler bugs when
the built-in _Bool type is used. See
http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
Similar bugs are likely with other compilers as well; this file
wouldn't be used if <stdbool.h> was working.
So we override the _Bool type.
If !@HAVE__BOOL@:
Need to define _Bool ourselves. As 'signed char' or as an enum type?
Use of a typedef, with SunPRO C, leads to a stupid
"warning: _Bool is a keyword in ISO C99".
Use of an enum type, with IRIX cc, leads to a stupid
"warning(1185): enumerated type mixed with another type".
Even the existence of an enum type, without a typedef,
"Invalid enumerator. (badenum)" with HP-UX cc on Tru64.
The only benefit of the enum, debuggability, is not important
with these compilers. So use 'signed char' and no enum. */
# define _Bool signed char
# else
/* With this compiler, trust the _Bool type if the compiler has it. */
# if !@HAVE__BOOL@
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
# endif
# endif
#endif
#define bool _Bool
/* The other macros must be usable in preprocessor directives. */
#define false 0
#define true 1
#define __bool_true_false_are_defined 1
#endif /* _GL_STDBOOL_H */

View File

@ -1,567 +0,0 @@
/* Copyright (C) 2001-2002, 2004-2009 Free Software Foundation, Inc.
Written by Paul Eggert, Bruno Haible, Sam Steingold, Peter Burwood.
This file is part of gnulib.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/*
* ISO C 99 <stdint.h> for platforms that lack it.
* <http://www.opengroup.org/susv3xbd/stdint.h.html>
*/
#ifndef _GL_STDINT_H
/* When including a system file that in turn includes <inttypes.h>,
use the system <inttypes.h>, not our substitute. This avoids
problems with (for example) VMS, whose <sys/bitypes.h> includes
<inttypes.h>. */
#define _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
/* Get those types that are already defined in other system include
files, so that we can "#define int8_t signed char" below without
worrying about a later system include file containing a "typedef
signed char int8_t;" that will get messed up by our macro. Our
macros should all be consistent with the system versions, except
for the "fast" types and macros, which we recommend against using
in public interfaces due to compiler differences. */
#if @HAVE_STDINT_H@
# if defined __sgi && ! defined __c99
/* Bypass IRIX's <stdint.h> if in C89 mode, since it merely annoys users
with "This header file is to be used only for c99 mode compilations"
diagnostics. */
# define __STDINT_H__
# endif
/* Other systems may have an incomplete or buggy <stdint.h>.
Include it before <inttypes.h>, since any "#include <stdint.h>"
in <inttypes.h> would reinclude us, skipping our contents because
_GL_STDINT_H is defined.
The include_next requires a split double-inclusion guard. */
# if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
# endif
# @INCLUDE_NEXT@ @NEXT_STDINT_H@
#endif
#if ! defined _GL_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
#define _GL_STDINT_H
/* <sys/types.h> defines some of the stdint.h types as well, on glibc,
IRIX 6.5, and OpenBSD 3.8 (via <machine/types.h>).
AIX 5.2 <sys/types.h> isn't needed and causes troubles.
MacOS X 10.4.6 <sys/types.h> includes <stdint.h> (which is us), but
relies on the system <stdint.h> definitions, so include
<sys/types.h> after @NEXT_STDINT_H@. */
#if @HAVE_SYS_TYPES_H@ && ! defined _AIX
# include <sys/types.h>
#endif
/* Get LONG_MIN, LONG_MAX, ULONG_MAX. */
#include <limits.h>
#if @HAVE_INTTYPES_H@
/* In OpenBSD 3.8, <inttypes.h> includes <machine/types.h>, which defines
int{8,16,32,64}_t, uint{8,16,32,64}_t and __BIT_TYPES_DEFINED__.
<inttypes.h> also defines intptr_t and uintptr_t. */
# include <inttypes.h>
#elif @HAVE_SYS_INTTYPES_H@
/* Solaris 7 <sys/inttypes.h> has the types except the *_fast*_t types, and
the macros except for *_FAST*_*, INTPTR_MIN, PTRDIFF_MIN, PTRDIFF_MAX. */
# include <sys/inttypes.h>
#endif
#if @HAVE_SYS_BITYPES_H@ && ! defined __BIT_TYPES_DEFINED__
/* Linux libc4 >= 4.6.7 and libc5 have a <sys/bitypes.h> that defines
int{8,16,32,64}_t and __BIT_TYPES_DEFINED__. In libc5 >= 5.2.2 it is
included by <sys/types.h>. */
# include <sys/bitypes.h>
#endif
#undef _GL_JUST_INCLUDE_SYSTEM_INTTYPES_H
/* Minimum and maximum values for a integer type under the usual assumption.
Return an unspecified value if BITS == 0, adding a check to pacify
picky compilers. */
#define _STDINT_MIN(signed, bits, zero) \
((signed) ? (- ((zero) + 1) << ((bits) ? (bits) - 1 : 0)) : (zero))
#define _STDINT_MAX(signed, bits, zero) \
((signed) \
? ~ _STDINT_MIN (signed, bits, zero) \
: /* The expression for the unsigned case. The subtraction of (signed) \
is a nop in the unsigned case and avoids "signed integer overflow" \
warnings in the signed case. */ \
((((zero) + 1) << ((bits) ? (bits) - 1 - (signed) : 0)) - 1) * 2 + 1)
/* 7.18.1.1. Exact-width integer types */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. */
#undef int8_t
#undef uint8_t
typedef signed char gl_int8_t;
typedef unsigned char gl_uint8_t;
#define int8_t gl_int8_t
#define uint8_t gl_uint8_t
#undef int16_t
#undef uint16_t
typedef short int gl_int16_t;
typedef unsigned short int gl_uint16_t;
#define int16_t gl_int16_t
#define uint16_t gl_uint16_t
#undef int32_t
#undef uint32_t
typedef int gl_int32_t;
typedef unsigned int gl_uint32_t;
#define int32_t gl_int32_t
#define uint32_t gl_uint32_t
/* Do not undefine int64_t if gnulib is not being used with 64-bit
types, since otherwise it breaks platforms like Tandem/NSK. */
#if LONG_MAX >> 31 >> 31 == 1
# undef int64_t
typedef long int gl_int64_t;
# define int64_t gl_int64_t
# define GL_INT64_T
#elif defined _MSC_VER
# undef int64_t
typedef __int64 gl_int64_t;
# define int64_t gl_int64_t
# define GL_INT64_T
#elif @HAVE_LONG_LONG_INT@
# undef int64_t
typedef long long int gl_int64_t;
# define int64_t gl_int64_t
# define GL_INT64_T
#endif
#if ULONG_MAX >> 31 >> 31 >> 1 == 1
# undef uint64_t
typedef unsigned long int gl_uint64_t;
# define uint64_t gl_uint64_t
# define GL_UINT64_T
#elif defined _MSC_VER
# undef uint64_t
typedef unsigned __int64 gl_uint64_t;
# define uint64_t gl_uint64_t
# define GL_UINT64_T
#elif @HAVE_UNSIGNED_LONG_LONG_INT@
# undef uint64_t
typedef unsigned long long int gl_uint64_t;
# define uint64_t gl_uint64_t
# define GL_UINT64_T
#endif
/* Avoid collision with Solaris 2.5.1 <pthread.h> etc. */
#define _UINT8_T
#define _UINT32_T
#define _UINT64_T
/* 7.18.1.2. Minimum-width integer types */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
are the same as the corresponding N_t types. */
#undef int_least8_t
#undef uint_least8_t
#undef int_least16_t
#undef uint_least16_t
#undef int_least32_t
#undef uint_least32_t
#undef int_least64_t
#undef uint_least64_t
#define int_least8_t int8_t
#define uint_least8_t uint8_t
#define int_least16_t int16_t
#define uint_least16_t uint16_t
#define int_least32_t int32_t
#define uint_least32_t uint32_t
#ifdef GL_INT64_T
# define int_least64_t int64_t
#endif
#ifdef GL_UINT64_T
# define uint_least64_t uint64_t
#endif
/* 7.18.1.3. Fastest minimum-width integer types */
/* Note: Other <stdint.h> substitutes may define these types differently.
It is not recommended to use these types in public header files. */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
are taken from the same list of types. Assume that 'long int'
is fast enough for all narrower integers. */
#undef int_fast8_t
#undef uint_fast8_t
#undef int_fast16_t
#undef uint_fast16_t
#undef int_fast32_t
#undef uint_fast32_t
#undef int_fast64_t
#undef uint_fast64_t
typedef long int gl_int_fast8_t;
typedef unsigned long int gl_uint_fast8_t;
typedef long int gl_int_fast16_t;
typedef unsigned long int gl_uint_fast16_t;
typedef long int gl_int_fast32_t;
typedef unsigned long int gl_uint_fast32_t;
#define int_fast8_t gl_int_fast8_t
#define uint_fast8_t gl_uint_fast8_t
#define int_fast16_t gl_int_fast16_t
#define uint_fast16_t gl_uint_fast16_t
#define int_fast32_t gl_int_fast32_t
#define uint_fast32_t gl_uint_fast32_t
#ifdef GL_INT64_T
# define int_fast64_t int64_t
#endif
#ifdef GL_UINT64_T
# define uint_fast64_t uint64_t
#endif
/* 7.18.1.4. Integer types capable of holding object pointers */
#undef intptr_t
#undef uintptr_t
typedef long int gl_intptr_t;
typedef unsigned long int gl_uintptr_t;
#define intptr_t gl_intptr_t
#define uintptr_t gl_uintptr_t
/* 7.18.1.5. Greatest-width integer types */
/* Note: These types are compiler dependent. It may be unwise to use them in
public header files. */
#undef intmax_t
#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
typedef long long int gl_intmax_t;
# define intmax_t gl_intmax_t
#elif defined GL_INT64_T
# define intmax_t int64_t
#else
typedef long int gl_intmax_t;
# define intmax_t gl_intmax_t
#endif
#undef uintmax_t
#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
typedef unsigned long long int gl_uintmax_t;
# define uintmax_t gl_uintmax_t
#elif defined GL_UINT64_T
# define uintmax_t uint64_t
#else
typedef unsigned long int gl_uintmax_t;
# define uintmax_t gl_uintmax_t
#endif
/* Verify that intmax_t and uintmax_t have the same size. Too much code
breaks if this is not the case. If this check fails, the reason is likely
to be found in the autoconf macros. */
typedef int _verify_intmax_size[2 * (sizeof (intmax_t) == sizeof (uintmax_t)) - 1];
/* 7.18.2. Limits of specified-width integer types */
#if ! defined __cplusplus || defined __STDC_LIMIT_MACROS
/* 7.18.2.1. Limits of exact-width integer types */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. */
#undef INT8_MIN
#undef INT8_MAX
#undef UINT8_MAX
#define INT8_MIN (~ INT8_MAX)
#define INT8_MAX 127
#define UINT8_MAX 255
#undef INT16_MIN
#undef INT16_MAX
#undef UINT16_MAX
#define INT16_MIN (~ INT16_MAX)
#define INT16_MAX 32767
#define UINT16_MAX 65535
#undef INT32_MIN
#undef INT32_MAX
#undef UINT32_MAX
#define INT32_MIN (~ INT32_MAX)
#define INT32_MAX 2147483647
#define UINT32_MAX 4294967295U
#undef INT64_MIN
#undef INT64_MAX
#ifdef GL_INT64_T
/* Prefer (- INTMAX_C (1) << 63) over (~ INT64_MAX) because SunPRO C 5.0
evaluates the latter incorrectly in preprocessor expressions. */
# define INT64_MIN (- INTMAX_C (1) << 63)
# define INT64_MAX INTMAX_C (9223372036854775807)
#endif
#undef UINT64_MAX
#ifdef GL_UINT64_T
# define UINT64_MAX UINTMAX_C (18446744073709551615)
#endif
/* 7.18.2.2. Limits of minimum-width integer types */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. Therefore the leastN_t types
are the same as the corresponding N_t types. */
#undef INT_LEAST8_MIN
#undef INT_LEAST8_MAX
#undef UINT_LEAST8_MAX
#define INT_LEAST8_MIN INT8_MIN
#define INT_LEAST8_MAX INT8_MAX
#define UINT_LEAST8_MAX UINT8_MAX
#undef INT_LEAST16_MIN
#undef INT_LEAST16_MAX
#undef UINT_LEAST16_MAX
#define INT_LEAST16_MIN INT16_MIN
#define INT_LEAST16_MAX INT16_MAX
#define UINT_LEAST16_MAX UINT16_MAX
#undef INT_LEAST32_MIN
#undef INT_LEAST32_MAX
#undef UINT_LEAST32_MAX
#define INT_LEAST32_MIN INT32_MIN
#define INT_LEAST32_MAX INT32_MAX
#define UINT_LEAST32_MAX UINT32_MAX
#undef INT_LEAST64_MIN
#undef INT_LEAST64_MAX
#ifdef GL_INT64_T
# define INT_LEAST64_MIN INT64_MIN
# define INT_LEAST64_MAX INT64_MAX
#endif
#undef UINT_LEAST64_MAX
#ifdef GL_UINT64_T
# define UINT_LEAST64_MAX UINT64_MAX
#endif
/* 7.18.2.3. Limits of fastest minimum-width integer types */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits. Therefore the fastN_t types
are taken from the same list of types. */
#undef INT_FAST8_MIN
#undef INT_FAST8_MAX
#undef UINT_FAST8_MAX
#define INT_FAST8_MIN LONG_MIN
#define INT_FAST8_MAX LONG_MAX
#define UINT_FAST8_MAX ULONG_MAX
#undef INT_FAST16_MIN
#undef INT_FAST16_MAX
#undef UINT_FAST16_MAX
#define INT_FAST16_MIN LONG_MIN
#define INT_FAST16_MAX LONG_MAX
#define UINT_FAST16_MAX ULONG_MAX
#undef INT_FAST32_MIN
#undef INT_FAST32_MAX
#undef UINT_FAST32_MAX
#define INT_FAST32_MIN LONG_MIN
#define INT_FAST32_MAX LONG_MAX
#define UINT_FAST32_MAX ULONG_MAX
#undef INT_FAST64_MIN
#undef INT_FAST64_MAX
#ifdef GL_INT64_T
# define INT_FAST64_MIN INT64_MIN
# define INT_FAST64_MAX INT64_MAX
#endif
#undef UINT_FAST64_MAX
#ifdef GL_UINT64_T
# define UINT_FAST64_MAX UINT64_MAX
#endif
/* 7.18.2.4. Limits of integer types capable of holding object pointers */
#undef INTPTR_MIN
#undef INTPTR_MAX
#undef UINTPTR_MAX
#define INTPTR_MIN LONG_MIN
#define INTPTR_MAX LONG_MAX
#define UINTPTR_MAX ULONG_MAX
/* 7.18.2.5. Limits of greatest-width integer types */
#undef INTMAX_MIN
#undef INTMAX_MAX
#ifdef INT64_MAX
# define INTMAX_MIN INT64_MIN
# define INTMAX_MAX INT64_MAX
#else
# define INTMAX_MIN INT32_MIN
# define INTMAX_MAX INT32_MAX
#endif
#undef UINTMAX_MAX
#ifdef UINT64_MAX
# define UINTMAX_MAX UINT64_MAX
#else
# define UINTMAX_MAX UINT32_MAX
#endif
/* 7.18.3. Limits of other integer types */
/* ptrdiff_t limits */
#undef PTRDIFF_MIN
#undef PTRDIFF_MAX
#if @APPLE_UNIVERSAL_BUILD@
# if _LP64
# define PTRDIFF_MIN _STDINT_MIN (1, 64, 0l)
# define PTRDIFF_MAX _STDINT_MAX (1, 64, 0l)
# else
# define PTRDIFF_MIN _STDINT_MIN (1, 32, 0)
# define PTRDIFF_MAX _STDINT_MAX (1, 32, 0)
# endif
#else
# define PTRDIFF_MIN \
_STDINT_MIN (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
# define PTRDIFF_MAX \
_STDINT_MAX (1, @BITSIZEOF_PTRDIFF_T@, 0@PTRDIFF_T_SUFFIX@)
#endif
/* sig_atomic_t limits */
#undef SIG_ATOMIC_MIN
#undef SIG_ATOMIC_MAX
#define SIG_ATOMIC_MIN \
_STDINT_MIN (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
0@SIG_ATOMIC_T_SUFFIX@)
#define SIG_ATOMIC_MAX \
_STDINT_MAX (@HAVE_SIGNED_SIG_ATOMIC_T@, @BITSIZEOF_SIG_ATOMIC_T@, \
0@SIG_ATOMIC_T_SUFFIX@)
/* size_t limit */
#undef SIZE_MAX
#if @APPLE_UNIVERSAL_BUILD@
# if _LP64
# define SIZE_MAX _STDINT_MAX (0, 64, 0ul)
# else
# define SIZE_MAX _STDINT_MAX (0, 32, 0ul)
# endif
#else
# define SIZE_MAX _STDINT_MAX (0, @BITSIZEOF_SIZE_T@, 0@SIZE_T_SUFFIX@)
#endif
/* wchar_t limits */
/* Get WCHAR_MIN, WCHAR_MAX.
This include is not on the top, above, because on OSF/1 4.0 we have a sequence of nested
includes <wchar.h> -> <stdio.h> -> <getopt.h> -> <stdlib.h>, and the latter includes
<stdint.h> and assumes its types are already defined. */
#if ! (defined WCHAR_MIN && defined WCHAR_MAX)
# define _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
# include <wchar.h>
# undef _GL_JUST_INCLUDE_SYSTEM_WCHAR_H
#endif
#undef WCHAR_MIN
#undef WCHAR_MAX
#define WCHAR_MIN \
_STDINT_MIN (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
#define WCHAR_MAX \
_STDINT_MAX (@HAVE_SIGNED_WCHAR_T@, @BITSIZEOF_WCHAR_T@, 0@WCHAR_T_SUFFIX@)
/* wint_t limits */
#undef WINT_MIN
#undef WINT_MAX
#define WINT_MIN \
_STDINT_MIN (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
#define WINT_MAX \
_STDINT_MAX (@HAVE_SIGNED_WINT_T@, @BITSIZEOF_WINT_T@, 0@WINT_T_SUFFIX@)
#endif /* !defined __cplusplus || defined __STDC_LIMIT_MACROS */
/* 7.18.4. Macros for integer constants */
#if ! defined __cplusplus || defined __STDC_CONSTANT_MACROS
/* 7.18.4.1. Macros for minimum-width integer constants */
/* According to ISO C 99 Technical Corrigendum 1 */
/* Here we assume a standard architecture where the hardware integer
types have 8, 16, 32, optionally 64 bits, and int is 32 bits. */
#undef INT8_C
#undef UINT8_C
#define INT8_C(x) x
#define UINT8_C(x) x
#undef INT16_C
#undef UINT16_C
#define INT16_C(x) x
#define UINT16_C(x) x
#undef INT32_C
#undef UINT32_C
#define INT32_C(x) x
#define UINT32_C(x) x ## U
#undef INT64_C
#undef UINT64_C
#if LONG_MAX >> 31 >> 31 == 1
# define INT64_C(x) x##L
#elif defined _MSC_VER
# define INT64_C(x) x##i64
#elif @HAVE_LONG_LONG_INT@
# define INT64_C(x) x##LL
#endif
#if ULONG_MAX >> 31 >> 31 >> 1 == 1
# define UINT64_C(x) x##UL
#elif defined _MSC_VER
# define UINT64_C(x) x##ui64
#elif @HAVE_UNSIGNED_LONG_LONG_INT@
# define UINT64_C(x) x##ULL
#endif
/* 7.18.4.2. Macros for greatest-width integer constants */
#undef INTMAX_C
#if @HAVE_LONG_LONG_INT@ && LONG_MAX >> 30 == 1
# define INTMAX_C(x) x##LL
#elif defined GL_INT64_T
# define INTMAX_C(x) INT64_C(x)
#else
# define INTMAX_C(x) x##L
#endif
#undef UINTMAX_C
#if @HAVE_UNSIGNED_LONG_LONG_INT@ && ULONG_MAX >> 31 == 1
# define UINTMAX_C(x) x##ULL
#elif defined GL_UINT64_T
# define UINTMAX_C(x) UINT64_C(x)
#else
# define UINTMAX_C(x) x##UL
#endif
#endif /* !defined __cplusplus || defined __STDC_CONSTANT_MACROS */
#endif /* _GL_STDINT_H */
#endif /* !defined _GL_STDINT_H && !defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H */

View File

@ -1,94 +0,0 @@
/* Implementation details of FILE streams.
Copyright (C) 2007-2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Many stdio implementations have the same logic and therefore can share
the same implementation of stdio extension API, except that some fields
have different naming conventions, or their access requires some casts. */
/* BSD stdio derived implementations. */
#if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */
# if defined __DragonFly__ /* DragonFly */
/* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
# define fp_ ((struct { struct __FILE_public pub; \
struct { unsigned char *_base; int _size; } _bf; \
void *cookie; \
void *_close; \
void *_read; \
void *_seek; \
void *_write; \
struct { unsigned char *_base; int _size; } _ub; \
int _ur; \
unsigned char _ubuf[3]; \
unsigned char _nbuf[1]; \
struct { unsigned char *_base; int _size; } _lb; \
int _blksize; \
fpos_t _offset; \
/* More fields, not relevant here. */ \
} *) fp)
/* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
# define _p pub._p
# define _flags pub._flags
# define _r pub._r
# define _w pub._w
# else
# define fp_ fp
# endif
# if defined __NetBSD__ || defined __OpenBSD__ /* NetBSD, OpenBSD */
/* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
struct __sfileext
{
struct __sbuf _ub; /* ungetc buffer */
/* More fields, not relevant here. */
};
# define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
# else /* FreeBSD, DragonFly, MacOS X, Cygwin */
# define fp_ub fp_->_ub
# endif
# define HASUB(fp) (fp_ub._base != NULL)
#endif
/* SystemV derived implementations. */
#if defined _IOERR
# if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
# define fp_ ((struct { unsigned char *_ptr; \
unsigned char *_base; \
unsigned char *_end; \
long _cnt; \
int _file; \
unsigned int _flag; \
} *) fp)
# else
# define fp_ fp
# endif
# if defined _SCO_DS /* OpenServer */
# define _cnt __cnt
# define _ptr __ptr
# define _base __base
# define _flag __flag
# endif
#endif

View File

@ -1,148 +0,0 @@
/* POSIX compatible FILE stream write function.
Copyright (C) 2008 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2008.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <stdio.h>
/* Replace these functions only if module 'sigpipe' is requested. */
#if GNULIB_SIGPIPE
/* On native Windows platforms, SIGPIPE does not exist. When write() is
called on a pipe with no readers, WriteFile() fails with error
GetLastError() = ERROR_NO_DATA, and write() in consequence fails with
error EINVAL. This write() function is at the basis of the function
which flushes the buffer of a FILE stream. */
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
# include <errno.h>
# include <signal.h>
# include <io.h>
# define WIN32_LEAN_AND_MEAN /* avoid including junk */
# include <windows.h>
# define CALL_WITH_SIGPIPE_EMULATION(RETTYPE, EXPRESSION, FAILED) \
if (ferror (stream)) \
return (EXPRESSION); \
else \
{ \
RETTYPE ret; \
SetLastError (0); \
ret = (EXPRESSION); \
if (FAILED && GetLastError () == ERROR_NO_DATA && ferror (stream)) \
{ \
int fd = fileno (stream); \
if (fd >= 0 \
&& GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE)\
{ \
/* Try to raise signal SIGPIPE. */ \
raise (SIGPIPE); \
/* If it is currently blocked or ignored, change errno from \
EINVAL to EPIPE. */ \
errno = EPIPE; \
} \
} \
return ret; \
}
# if !REPLACE_PRINTF_POSIX /* avoid collision with printf.c */
int
printf (const char *format, ...)
{
int retval;
va_list args;
va_start (args, format);
retval = vfprintf (stdout, format, args);
va_end (args);
return retval;
}
# endif
# if !REPLACE_FPRINTF_POSIX /* avoid collision with fprintf.c */
int
fprintf (FILE *stream, const char *format, ...)
{
int retval;
va_list args;
va_start (args, format);
retval = vfprintf (stream, format, args);
va_end (args);
return retval;
}
# endif
# if !REPLACE_VFPRINTF_POSIX /* avoid collision with vprintf.c */
int
vprintf (const char *format, va_list args)
{
return vfprintf (stdout, format, args);
}
# endif
# if !REPLACE_VPRINTF_POSIX /* avoid collision with vfprintf.c */
int
vfprintf (FILE *stream, const char *format, va_list args)
#undef vfprintf
{
CALL_WITH_SIGPIPE_EMULATION (int, vfprintf (stream, format, args), ret == EOF)
}
# endif
int
putchar (int c)
{
return fputc (c, stdout);
}
int
fputc (int c, FILE *stream)
#undef fputc
{
CALL_WITH_SIGPIPE_EMULATION (int, fputc (c, stream), ret == EOF)
}
int
fputs (const char *string, FILE *stream)
#undef fputs
{
CALL_WITH_SIGPIPE_EMULATION (int, fputs (string, stream), ret == EOF)
}
int
puts (const char *string)
#undef puts
{
FILE *stream = stdout;
CALL_WITH_SIGPIPE_EMULATION (int, puts (string), ret == EOF)
}
size_t
fwrite (const void *ptr, size_t s, size_t n, FILE *stream)
#undef fwrite
{
CALL_WITH_SIGPIPE_EMULATION (size_t, fwrite (ptr, s, n, stream), ret < n)
}
# endif
#endif

View File

@ -1,524 +0,0 @@
/* A GNU-like <stdio.h>.
Copyright (C) 2004, 2007-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
#if defined __need_FILE || defined __need___FILE
/* Special invocation convention inside glibc header files. */
#@INCLUDE_NEXT@ @NEXT_STDIO_H@
#else
/* Normal invocation convention. */
#ifndef _GL_STDIO_H
/* The include_next requires a split double-inclusion guard. */
#@INCLUDE_NEXT@ @NEXT_STDIO_H@
#ifndef _GL_STDIO_H
#define _GL_STDIO_H
#include <stdarg.h>
#include <stddef.h>
#if (@GNULIB_FSEEKO@ && @REPLACE_FSEEKO@) \
|| (@GNULIB_FTELLO@ && @REPLACE_FTELLO@) \
|| (@GNULIB_GETDELIM@ && !@HAVE_DECL_GETDELIM@) \
|| (@GNULIB_GETLINE@ && (!@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@))
/* Get off_t and ssize_t. */
# include <sys/types.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
/* The __-protected variants of `format' and `printf' attributes
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
# define __format__ format
# define __printf__ printf
# endif
#endif
/* The definition of GL_LINK_WARNING is copied here. */
#ifdef __cplusplus
extern "C" {
#endif
#if @GNULIB_FPRINTF_POSIX@
# if @REPLACE_FPRINTF@
# define fprintf rpl_fprintf
extern int fprintf (FILE *fp, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
# endif
#elif @GNULIB_FPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# define fprintf rpl_fprintf
extern int fprintf (FILE *fp, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
#elif defined GNULIB_POSIXCHECK
# undef fprintf
# define fprintf \
(GL_LINK_WARNING ("fprintf is not always POSIX compliant - " \
"use gnulib module fprintf-posix for portable " \
"POSIX compliance"), \
fprintf)
#endif
#if @GNULIB_VFPRINTF_POSIX@
# if @REPLACE_VFPRINTF@
# define vfprintf rpl_vfprintf
extern int vfprintf (FILE *fp, const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 2, 0)));
# endif
#elif @GNULIB_VFPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# define vfprintf rpl_vfprintf
extern int vfprintf (FILE *fp, const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 2, 0)));
#elif defined GNULIB_POSIXCHECK
# undef vfprintf
# define vfprintf(s,f,a) \
(GL_LINK_WARNING ("vfprintf is not always POSIX compliant - " \
"use gnulib module vfprintf-posix for portable " \
"POSIX compliance"), \
vfprintf (s, f, a))
#endif
#if @GNULIB_PRINTF_POSIX@
# if @REPLACE_PRINTF@
/* Don't break __attribute__((format(printf,M,N))). */
# define printf __printf__
extern int printf (const char *format, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
# endif
#elif @GNULIB_PRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
/* Don't break __attribute__((format(printf,M,N))). */
# define printf __printf__
extern int printf (const char *format, ...)
__attribute__ ((__format__ (__printf__, 1, 2)));
#elif defined GNULIB_POSIXCHECK
# undef printf
# define printf \
(GL_LINK_WARNING ("printf is not always POSIX compliant - " \
"use gnulib module printf-posix for portable " \
"POSIX compliance"), \
printf)
/* Don't break __attribute__((format(printf,M,N))). */
# define format(kind,m,n) format (__##kind##__, m, n)
# define __format__(kind,m,n) __format__ (__##kind##__, m, n)
# define ____printf____ __printf__
# define ____scanf____ __scanf__
# define ____strftime____ __strftime__
# define ____strfmon____ __strfmon__
#endif
#if @GNULIB_VPRINTF_POSIX@
# if @REPLACE_VPRINTF@
# define vprintf rpl_vprintf
extern int vprintf (const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 1, 0)));
# endif
#elif @GNULIB_VPRINTF@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# define vprintf rpl_vprintf
extern int vprintf (const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 1, 0)));
#elif defined GNULIB_POSIXCHECK
# undef vprintf
# define vprintf(f,a) \
(GL_LINK_WARNING ("vprintf is not always POSIX compliant - " \
"use gnulib module vprintf-posix for portable " \
"POSIX compliance"), \
vprintf (f, a))
#endif
#if @GNULIB_SNPRINTF@
# if @REPLACE_SNPRINTF@
# define snprintf rpl_snprintf
# endif
# if @REPLACE_SNPRINTF@ || !@HAVE_DECL_SNPRINTF@
extern int snprintf (char *str, size_t size, const char *format, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
# endif
#elif defined GNULIB_POSIXCHECK
# undef snprintf
# define snprintf \
(GL_LINK_WARNING ("snprintf is unportable - " \
"use gnulib module snprintf for portability"), \
snprintf)
#endif
#if @GNULIB_VSNPRINTF@
# if @REPLACE_VSNPRINTF@
# define vsnprintf rpl_vsnprintf
# endif
# if @REPLACE_VSNPRINTF@ || !@HAVE_DECL_VSNPRINTF@
extern int vsnprintf (char *str, size_t size, const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 3, 0)));
# endif
#elif defined GNULIB_POSIXCHECK
# undef vsnprintf
# define vsnprintf(b,s,f,a) \
(GL_LINK_WARNING ("vsnprintf is unportable - " \
"use gnulib module vsnprintf for portability"), \
vsnprintf (b, s, f, a))
#endif
#if @GNULIB_SPRINTF_POSIX@
# if @REPLACE_SPRINTF@
# define sprintf rpl_sprintf
extern int sprintf (char *str, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
# endif
#elif defined GNULIB_POSIXCHECK
# undef sprintf
# define sprintf \
(GL_LINK_WARNING ("sprintf is not always POSIX compliant - " \
"use gnulib module sprintf-posix for portable " \
"POSIX compliance"), \
sprintf)
#endif
#if @GNULIB_VSPRINTF_POSIX@
# if @REPLACE_VSPRINTF@
# define vsprintf rpl_vsprintf
extern int vsprintf (char *str, const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 2, 0)));
# endif
#elif defined GNULIB_POSIXCHECK
# undef vsprintf
# define vsprintf(b,f,a) \
(GL_LINK_WARNING ("vsprintf is not always POSIX compliant - " \
"use gnulib module vsprintf-posix for portable " \
"POSIX compliance"), \
vsprintf (b, f, a))
#endif
#if @GNULIB_DPRINTF@
# if @REPLACE_DPRINTF@
# define dprintf rpl_dprintf
# endif
# if @REPLACE_DPRINTF@ || !@HAVE_DPRINTF@
extern int dprintf (int fd, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
# endif
#elif defined GNULIB_POSIXCHECK
# undef dprintf
# define dprintf(d,f,a) \
(GL_LINK_WARNING ("dprintf is unportable - " \
"use gnulib module dprintf for portability"), \
dprintf (d, f, a))
#endif
#if @GNULIB_VDPRINTF@
# if @REPLACE_VDPRINTF@
# define vdprintf rpl_vdprintf
# endif
# if @REPLACE_VDPRINTF@ || !@HAVE_VDPRINTF@
extern int vdprintf (int fd, const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 2, 0)));
# endif
#elif defined GNULIB_POSIXCHECK
# undef vdprintf
# define vdprintf(d,f,a) \
(GL_LINK_WARNING ("vdprintf is unportable - " \
"use gnulib module vdprintf for portability"), \
vdprintf (d, f, a))
#endif
#if @GNULIB_VASPRINTF@
# if @REPLACE_VASPRINTF@
# define asprintf rpl_asprintf
# define vasprintf rpl_vasprintf
# endif
# if @REPLACE_VASPRINTF@ || !@HAVE_VASPRINTF@
/* Write formatted output to a string dynamically allocated with malloc().
If the memory allocation succeeds, store the address of the string in
*RESULT and return the number of resulting bytes, excluding the trailing
NUL. Upon memory allocation error, or some other error, return -1. */
extern int asprintf (char **result, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
extern int vasprintf (char **result, const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 2, 0)));
# endif
#endif
#if @GNULIB_OBSTACK_PRINTF@
# if @REPLACE_OBSTACK_PRINTF@
# define obstack_printf rpl_osbtack_printf
# define obstack_vprintf rpl_obstack_vprintf
# endif
# if @REPLACE_OBSTACK_PRINTF@ || !@HAVE_DECL_OBSTACK_PRINTF@
struct obstack;
/* Grow an obstack with formatted output. Return the number of
bytes added to OBS. No trailing nul byte is added, and the
object should be closed with obstack_finish before use. Upon
memory allocation error, call obstack_alloc_failed_handler. Upon
other error, return -1. */
extern int obstack_printf (struct obstack *obs, const char *format, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
extern int obstack_vprintf (struct obstack *obs, const char *format,
va_list args)
__attribute__ ((__format__ (__printf__, 2, 0)));
# endif
#endif
#if @GNULIB_FOPEN@
# if @REPLACE_FOPEN@
# undef fopen
# define fopen rpl_fopen
extern FILE * fopen (const char *filename, const char *mode);
# endif
#elif defined GNULIB_POSIXCHECK
# undef fopen
# define fopen(f,m) \
(GL_LINK_WARNING ("fopen on Win32 platforms is not POSIX compatible - " \
"use gnulib module fopen for portability"), \
fopen (f, m))
#endif
#if @GNULIB_FREOPEN@
# if @REPLACE_FREOPEN@
# undef freopen
# define freopen rpl_freopen
extern FILE * freopen (const char *filename, const char *mode, FILE *stream);
# endif
#elif defined GNULIB_POSIXCHECK
# undef freopen
# define freopen(f,m,s) \
(GL_LINK_WARNING ("freopen on Win32 platforms is not POSIX compatible - " \
"use gnulib module freopen for portability"), \
freopen (f, m, s))
#endif
#if @GNULIB_FSEEKO@
# if @REPLACE_FSEEKO@
/* Provide fseek, fseeko functions that are aware of a preceding
fflush(), and which detect pipes. */
# define fseeko rpl_fseeko
extern int fseeko (FILE *fp, off_t offset, int whence);
# define fseek(fp, offset, whence) fseeko (fp, (off_t)(offset), whence)
# endif
#elif defined GNULIB_POSIXCHECK
# undef fseeko
# define fseeko(f,o,w) \
(GL_LINK_WARNING ("fseeko is unportable - " \
"use gnulib module fseeko for portability"), \
fseeko (f, o, w))
#endif
#if @GNULIB_FSEEK@ && @REPLACE_FSEEK@
extern int rpl_fseek (FILE *fp, long offset, int whence);
# undef fseek
# if defined GNULIB_POSIXCHECK
# define fseek(f,o,w) \
(GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
"on 32-bit platforms - " \
"use fseeko function for handling of large files"), \
rpl_fseek (f, o, w))
# else
# define fseek rpl_fseek
# endif
#elif defined GNULIB_POSIXCHECK
# ifndef fseek
# define fseek(f,o,w) \
(GL_LINK_WARNING ("fseek cannot handle files larger than 4 GB " \
"on 32-bit platforms - " \
"use fseeko function for handling of large files"), \
fseek (f, o, w))
# endif
#endif
#if @GNULIB_FTELLO@
# if @REPLACE_FTELLO@
# define ftello rpl_ftello
extern off_t ftello (FILE *fp);
# define ftell(fp) ftello (fp)
# endif
#elif defined GNULIB_POSIXCHECK
# undef ftello
# define ftello(f) \
(GL_LINK_WARNING ("ftello is unportable - " \
"use gnulib module ftello for portability"), \
ftello (f))
#endif
#if @GNULIB_FTELL@ && @REPLACE_FTELL@
extern long rpl_ftell (FILE *fp);
# undef ftell
# if GNULIB_POSIXCHECK
# define ftell(f) \
(GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
"on 32-bit platforms - " \
"use ftello function for handling of large files"), \
rpl_ftell (f))
# else
# define ftell rpl_ftell
# endif
#elif defined GNULIB_POSIXCHECK
# ifndef ftell
# define ftell(f) \
(GL_LINK_WARNING ("ftell cannot handle files larger than 4 GB " \
"on 32-bit platforms - " \
"use ftello function for handling of large files"), \
ftell (f))
# endif
#endif
#if @GNULIB_FFLUSH@
# if @REPLACE_FFLUSH@
# define fflush rpl_fflush
/* Flush all pending data on STREAM according to POSIX rules. Both
output and seekable input streams are supported.
Note! LOSS OF DATA can occur if fflush is applied on an input stream
that is _not_seekable_ or on an update stream that is _not_seekable_
and in which the most recent operation was input. Seekability can
be tested with lseek(fileno(fp),0,SEEK_CUR). */
extern int fflush (FILE *gl_stream);
# endif
#elif defined GNULIB_POSIXCHECK
# undef fflush
# define fflush(f) \
(GL_LINK_WARNING ("fflush is not always POSIX compliant - " \
"use gnulib module fflush for portable " \
"POSIX compliance"), \
fflush (f))
#endif
#if @GNULIB_FCLOSE@
# if @REPLACE_FCLOSE@
# define fclose rpl_fclose
/* Close STREAM and its underlying file descriptor. */
extern int fclose (FILE *stream);
# endif
#elif defined GNULIB_POSIXCHECK
# undef fclose
# define fclose(f) \
(GL_LINK_WARNING ("fclose is not always POSIX compliant - " \
"use gnulib module fclose for portable " \
"POSIX compliance"), \
fclose (f))
#endif
#if @GNULIB_FPUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# undef fputc
# define fputc rpl_fputc
extern int fputc (int c, FILE *stream);
#endif
#if @GNULIB_PUTC@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# undef putc
# define putc rpl_fputc
extern int putc (int c, FILE *stream);
#endif
#if @GNULIB_PUTCHAR@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# undef putchar
# define putchar rpl_putchar
extern int putchar (int c);
#endif
#if @GNULIB_FPUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# undef fputs
# define fputs rpl_fputs
extern int fputs (const char *string, FILE *stream);
#endif
#if @GNULIB_PUTS@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# undef puts
# define puts rpl_puts
extern int puts (const char *string);
#endif
#if @GNULIB_FWRITE@ && @REPLACE_STDIO_WRITE_FUNCS@ && @GNULIB_STDIO_H_SIGPIPE@
# undef fwrite
# define fwrite rpl_fwrite
extern size_t fwrite (const void *ptr, size_t s, size_t n, FILE *stream);
#endif
#if @GNULIB_GETDELIM@
# if !@HAVE_DECL_GETDELIM@
/* Read input, up to (and including) the next occurrence of DELIMITER, from
STREAM, store it in *LINEPTR (and NUL-terminate it).
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
bytes of space. It is realloc'd as necessary.
Return the number of bytes read and stored at *LINEPTR (not including the
NUL terminator), or -1 on error or EOF. */
extern ssize_t getdelim (char **lineptr, size_t *linesize, int delimiter,
FILE *stream);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getdelim
# define getdelim(l, s, d, f) \
(GL_LINK_WARNING ("getdelim is unportable - " \
"use gnulib module getdelim for portability"), \
getdelim (l, s, d, f))
#endif
#if @GNULIB_GETLINE@
# if @REPLACE_GETLINE@
# undef getline
# define getline rpl_getline
# endif
# if !@HAVE_DECL_GETLINE@ || @REPLACE_GETLINE@
/* Read a line, up to (and including) the next newline, from STREAM, store it
in *LINEPTR (and NUL-terminate it).
*LINEPTR is a pointer returned from malloc (or NULL), pointing to *LINESIZE
bytes of space. It is realloc'd as necessary.
Return the number of bytes read and stored at *LINEPTR (not including the
NUL terminator), or -1 on error or EOF. */
extern ssize_t getline (char **lineptr, size_t *linesize, FILE *stream);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getline
# define getline(l, s, f) \
(GL_LINK_WARNING ("getline is unportable - " \
"use gnulib module getline for portability"), \
getline (l, s, f))
#endif
#if @GNULIB_PERROR@
# if @REPLACE_PERROR@
# define perror rpl_perror
/* Print a message to standard error, describing the value of ERRNO,
(if STRING is not NULL and not empty) prefixed with STRING and ": ",
and terminated with a newline. */
extern void perror (const char *string);
# endif
#elif defined GNULIB_POSIXCHECK
# undef perror
# define perror(s) \
(GL_LINK_WARNING ("perror is not always POSIX compliant - " \
"use gnulib module perror for portability"), \
perror (s))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_STDIO_H */
#endif /* _GL_STDIO_H */
#endif

View File

@ -1,383 +0,0 @@
/* A GNU-like <stdlib.h>.
Copyright (C) 1995, 2001-2004, 2006-2009 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
#if defined __need_malloc_and_calloc
/* Special invocation convention inside glibc header files. */
#@INCLUDE_NEXT@ @NEXT_STDLIB_H@
#else
/* Normal invocation convention. */
#ifndef _GL_STDLIB_H
/* The include_next requires a split double-inclusion guard. */
#@INCLUDE_NEXT@ @NEXT_STDLIB_H@
#ifndef _GL_STDLIB_H
#define _GL_STDLIB_H
/* Solaris declares getloadavg() in <sys/loadavg.h>. */
#if @GNULIB_GETLOADAVG@ && @HAVE_SYS_LOADAVG_H@
# include <sys/loadavg.h>
#endif
/* OSF/1 5.1 declares 'struct random_data' in <random.h>, which is included
from <stdlib.h> if _REENTRANT is defined. Include it always. */
#if @HAVE_RANDOM_H@
# include <random.h>
#endif
#if @GNULIB_RANDOM_R@ || !@HAVE_STRUCT_RANDOM_DATA@
# include <stdint.h>
#endif
#if !@HAVE_STRUCT_RANDOM_DATA@
struct random_data
{
int32_t *fptr; /* Front pointer. */
int32_t *rptr; /* Rear pointer. */
int32_t *state; /* Array of state values. */
int rand_type; /* Type of random number generator. */
int rand_deg; /* Degree of random number generator. */
int rand_sep; /* Distance between front and rear. */
int32_t *end_ptr; /* Pointer behind state table. */
};
#endif
/* The definition of GL_LINK_WARNING is copied here. */
/* Some systems do not define EXIT_*, despite otherwise supporting C89. */
#ifndef EXIT_SUCCESS
# define EXIT_SUCCESS 0
#endif
/* Tandem/NSK and other platforms that define EXIT_FAILURE as -1 interfere
with proper operation of xargs. */
#ifndef EXIT_FAILURE
# define EXIT_FAILURE 1
#elif EXIT_FAILURE != 1
# undef EXIT_FAILURE
# define EXIT_FAILURE 1
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if @GNULIB_MALLOC_POSIX@
# if !@HAVE_MALLOC_POSIX@
# undef malloc
# define malloc rpl_malloc
extern void * malloc (size_t size);
# endif
#elif defined GNULIB_POSIXCHECK
# undef malloc
# define malloc(s) \
(GL_LINK_WARNING ("malloc is not POSIX compliant everywhere - " \
"use gnulib module malloc-posix for portability"), \
malloc (s))
#endif
#if @GNULIB_REALLOC_POSIX@
# if !@HAVE_REALLOC_POSIX@
# undef realloc
# define realloc rpl_realloc
extern void * realloc (void *ptr, size_t size);
# endif
#elif defined GNULIB_POSIXCHECK
# undef realloc
# define realloc(p,s) \
(GL_LINK_WARNING ("realloc is not POSIX compliant everywhere - " \
"use gnulib module realloc-posix for portability"), \
realloc (p, s))
#endif
#if @GNULIB_CALLOC_POSIX@
# if !@HAVE_CALLOC_POSIX@
# undef calloc
# define calloc rpl_calloc
extern void * calloc (size_t nmemb, size_t size);
# endif
#elif defined GNULIB_POSIXCHECK
# undef calloc
# define calloc(n,s) \
(GL_LINK_WARNING ("calloc is not POSIX compliant everywhere - " \
"use gnulib module calloc-posix for portability"), \
calloc (n, s))
#endif
#if @GNULIB_ATOLL@
# if !@HAVE_ATOLL@
/* Parse a signed decimal integer.
Returns the value of the integer. Errors are not detected. */
extern long long atoll (const char *string);
# endif
#elif defined GNULIB_POSIXCHECK
# undef atoll
# define atoll(s) \
(GL_LINK_WARNING ("atoll is unportable - " \
"use gnulib module atoll for portability"), \
atoll (s))
#endif
#if @GNULIB_GETLOADAVG@
# if !@HAVE_DECL_GETLOADAVG@
/* Store max(NELEM,3) load average numbers in LOADAVG[].
The three numbers are the load average of the last 1 minute, the last 5
minutes, and the last 15 minutes, respectively.
LOADAVG is an array of NELEM numbers. */
extern int getloadavg (double loadavg[], int nelem);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getloadavg
# define getloadavg(l,n) \
(GL_LINK_WARNING ("getloadavg is not portable - " \
"use gnulib module getloadavg for portability"), \
getloadavg (l, n))
#endif
#if @GNULIB_GETSUBOPT@
/* Assuming *OPTIONP is a comma separated list of elements of the form
"token" or "token=value", getsubopt parses the first of these elements.
If the first element refers to a "token" that is member of the given
NULL-terminated array of tokens:
- It replaces the comma with a NUL byte, updates *OPTIONP to point past
the first option and the comma, sets *VALUEP to the value of the
element (or NULL if it doesn't contain an "=" sign),
- It returns the index of the "token" in the given array of tokens.
Otherwise it returns -1, and *OPTIONP and *VALUEP are undefined.
For more details see the POSIX:2001 specification.
http://www.opengroup.org/susv3xsh/getsubopt.html */
# if !@HAVE_GETSUBOPT@
extern int getsubopt (char **optionp, char *const *tokens, char **valuep);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getsubopt
# define getsubopt(o,t,v) \
(GL_LINK_WARNING ("getsubopt is unportable - " \
"use gnulib module getsubopt for portability"), \
getsubopt (o, t, v))
#endif
#if @GNULIB_MKDTEMP@
# if !@HAVE_MKDTEMP@
/* Create a unique temporary directory from TEMPLATE.
The last six characters of TEMPLATE must be "XXXXXX";
they are replaced with a string that makes the directory name unique.
Returns TEMPLATE, or a null pointer if it cannot get a unique name.
The directory is created mode 700. */
extern char * mkdtemp (char * /*template*/);
# endif
#elif defined GNULIB_POSIXCHECK
# undef mkdtemp
# define mkdtemp(t) \
(GL_LINK_WARNING ("mkdtemp is unportable - " \
"use gnulib module mkdtemp for portability"), \
mkdtemp (t))
#endif
#if @GNULIB_MKSTEMP@
# if @REPLACE_MKSTEMP@
/* Create a unique temporary file from TEMPLATE.
The last six characters of TEMPLATE must be "XXXXXX";
they are replaced with a string that makes the file name unique.
The file is then created, ensuring it didn't exist before.
The file is created read-write (mask at least 0600 & ~umask), but it may be
world-readable and world-writable (mask 0666 & ~umask), depending on the
implementation.
Returns the open file descriptor if successful, otherwise -1 and errno
set. */
# define mkstemp rpl_mkstemp
extern int mkstemp (char * /*template*/);
# else
/* On MacOS X 10.3, only <unistd.h> declares mkstemp. */
# include <unistd.h>
# endif
#elif defined GNULIB_POSIXCHECK
# undef mkstemp
# define mkstemp(t) \
(GL_LINK_WARNING ("mkstemp is unportable - " \
"use gnulib module mkstemp for portability"), \
mkstemp (t))
#endif
#if @GNULIB_PUTENV@
# if @REPLACE_PUTENV@
# undef putenv
# define putenv rpl_putenv
extern int putenv (char *string);
# endif
#endif
#if @GNULIB_RANDOM_R@
# if !@HAVE_RANDOM_R@
# ifndef RAND_MAX
# define RAND_MAX 2147483647
# endif
int srandom_r (unsigned int seed, struct random_data *rand_state);
int initstate_r (unsigned int seed, char *buf, size_t buf_size,
struct random_data *rand_state);
int setstate_r (char *arg_state, struct random_data *rand_state);
int random_r (struct random_data *buf, int32_t *result);
# endif
#elif defined GNULIB_POSIXCHECK
# undef random_r
# define random_r(b,r) \
(GL_LINK_WARNING ("random_r is unportable - " \
"use gnulib module random_r for portability"), \
random_r (b,r))
# undef initstate_r
# define initstate_r(s,b,sz,r) \
(GL_LINK_WARNING ("initstate_r is unportable - " \
"use gnulib module random_r for portability"), \
initstate_r (s,b,sz,r))
# undef srandom_r
# define srandom_r(s,r) \
(GL_LINK_WARNING ("srandom_r is unportable - " \
"use gnulib module random_r for portability"), \
srandom_r (s,r))
# undef setstate_r
# define setstate_r(a,r) \
(GL_LINK_WARNING ("setstate_r is unportable - " \
"use gnulib module random_r for portability"), \
setstate_r (a,r))
#endif
#if @GNULIB_RPMATCH@
# if !@HAVE_RPMATCH@
/* Test a user response to a question.
Return 1 if it is affirmative, 0 if it is negative, or -1 if not clear. */
extern int rpmatch (const char *response);
# endif
#elif defined GNULIB_POSIXCHECK
# undef rpmatch
# define rpmatch(r) \
(GL_LINK_WARNING ("rpmatch is unportable - " \
"use gnulib module rpmatch for portability"), \
rpmatch (r))
#endif
#if @GNULIB_SETENV@
# if !@HAVE_SETENV@
/* Set NAME to VALUE in the environment.
If REPLACE is nonzero, overwrite an existing value. */
extern int setenv (const char *name, const char *value, int replace);
# endif
#endif
#if @GNULIB_UNSETENV@
# if @HAVE_UNSETENV@
# if @VOID_UNSETENV@
/* On some systems, unsetenv() returns void.
This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4. */
# define unsetenv(name) ((unsetenv)(name), 0)
# endif
# else
/* Remove the variable NAME from the environment. */
extern int unsetenv (const char *name);
# endif
#endif
#if @GNULIB_STRTOD@
# if @REPLACE_STRTOD@
# define strtod rpl_strtod
# endif
# if !@HAVE_STRTOD@ || @REPLACE_STRTOD@
/* Parse a double from STRING, updating ENDP if appropriate. */
extern double strtod (const char *str, char **endp);
# endif
#elif defined GNULIB_POSIXCHECK
# undef strtod
# define strtod(s, e) \
(GL_LINK_WARNING ("strtod is unportable - " \
"use gnulib module strtod for portability"), \
strtod (s, e))
#endif
#if @GNULIB_STRTOLL@
# if !@HAVE_STRTOLL@
/* Parse a signed integer whose textual representation starts at STRING.
The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
"0x").
If ENDPTR is not NULL, the address of the first byte after the integer is
stored in *ENDPTR.
Upon overflow, the return value is LLONG_MAX or LLONG_MIN, and errno is set
to ERANGE. */
extern long long strtoll (const char *string, char **endptr, int base);
# endif
#elif defined GNULIB_POSIXCHECK
# undef strtoll
# define strtoll(s,e,b) \
(GL_LINK_WARNING ("strtoll is unportable - " \
"use gnulib module strtoll for portability"), \
strtoll (s, e, b))
#endif
#if @GNULIB_STRTOULL@
# if !@HAVE_STRTOULL@
/* Parse an unsigned integer whose textual representation starts at STRING.
The integer is expected to be in base BASE (2 <= BASE <= 36); if BASE == 0,
it may be decimal or octal (with prefix "0") or hexadecimal (with prefix
"0x").
If ENDPTR is not NULL, the address of the first byte after the integer is
stored in *ENDPTR.
Upon overflow, the return value is ULLONG_MAX, and errno is set to
ERANGE. */
extern unsigned long long strtoull (const char *string, char **endptr, int base);
# endif
#elif defined GNULIB_POSIXCHECK
# undef strtoull
# define strtoull(s,e,b) \
(GL_LINK_WARNING ("strtoull is unportable - " \
"use gnulib module strtoull for portability"), \
strtoull (s, e, b))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_STDLIB_H */
#endif /* _GL_STDLIB_H */
#endif

View File

@ -1,48 +0,0 @@
/* stpcpy.c -- copy a string and return pointer to end of new string
Copyright (C) 1992, 1995, 1997-1998, 2006 Free Software Foundation, Inc.
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 Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of the License, or 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <string.h>
#undef __stpcpy
#ifdef _LIBC
# undef stpcpy
#endif
#ifndef weak_alias
# define __stpcpy stpcpy
#endif
/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
char *
__stpcpy (char *dest, const char *src)
{
register char *d = dest;
register const char *s = src;
do
*d++ = *s;
while (*s++ != '\0');
return d - 1;
}
#ifdef weak_alias
weak_alias (__stpcpy, stpcpy)
#endif

View File

@ -1,55 +0,0 @@
/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004, 2006, 2007 Free
Software Foundation, Inc.
This file is part of the GNU C Library.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _LIBC
# include <config.h>
#endif
/* Get specification. */
#include <string.h>
#include <stdlib.h>
#undef __strdup
#ifdef _LIBC
# undef strdup
#endif
#ifndef weak_alias
# define __strdup strdup
#endif
/* Duplicate S, returning an identical malloc'd string. */
char *
__strdup (const char *s)
{
size_t len = strlen (s) + 1;
void *new = malloc (len);
if (new == NULL)
return NULL;
return (char *) memcpy (new, s, len);
}
#ifdef libc_hidden_def
libc_hidden_def (__strdup)
#endif
#ifdef weak_alias
weak_alias (__strdup, strdup)
#endif

View File

@ -1,341 +0,0 @@
/* strerror.c --- POSIX compatible system error routine
Copyright (C) 2007-2009 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <string.h>
#if REPLACE_STRERROR
# include <errno.h>
# include <stdio.h>
# if GNULIB_defined_ESOCK /* native Windows platforms */
# if HAVE_WINSOCK2_H
# include <winsock2.h>
# endif
# endif
# include "intprops.h"
# undef strerror
# if ! HAVE_DECL_STRERROR
# define strerror(n) NULL
# endif
char *
rpl_strerror (int n)
{
char const *msg = NULL;
/* These error messages are taken from glibc/sysdeps/gnu/errlist.c. */
switch (n)
{
# if GNULIB_defined_ETXTBSY
case ETXTBSY:
msg = "Text file busy";
break;
# endif
# if GNULIB_defined_ESOCK /* native Windows platforms */
/* EWOULDBLOCK is the same as EAGAIN. */
case EINPROGRESS:
msg = "Operation now in progress";
break;
case EALREADY:
msg = "Operation already in progress";
break;
case ENOTSOCK:
msg = "Socket operation on non-socket";
break;
case EDESTADDRREQ:
msg = "Destination address required";
break;
case EMSGSIZE:
msg = "Message too long";
break;
case EPROTOTYPE:
msg = "Protocol wrong type for socket";
break;
case ENOPROTOOPT:
msg = "Protocol not available";
break;
case EPROTONOSUPPORT:
msg = "Protocol not supported";
break;
case ESOCKTNOSUPPORT:
msg = "Socket type not supported";
break;
case EOPNOTSUPP:
msg = "Operation not supported";
break;
case EPFNOSUPPORT:
msg = "Protocol family not supported";
break;
case EAFNOSUPPORT:
msg = "Address family not supported by protocol";
break;
case EADDRINUSE:
msg = "Address already in use";
break;
case EADDRNOTAVAIL:
msg = "Cannot assign requested address";
break;
case ENETDOWN:
msg = "Network is down";
break;
case ENETUNREACH:
msg = "Network is unreachable";
break;
case ENETRESET:
msg = "Network dropped connection on reset";
break;
case ECONNABORTED:
msg = "Software caused connection abort";
break;
case ECONNRESET:
msg = "Connection reset by peer";
break;
case ENOBUFS:
msg = "No buffer space available";
break;
case EISCONN:
msg = "Transport endpoint is already connected";
break;
case ENOTCONN:
msg = "Transport endpoint is not connected";
break;
case ESHUTDOWN:
msg = "Cannot send after transport endpoint shutdown";
break;
case ETOOMANYREFS:
msg = "Too many references: cannot splice";
break;
case ETIMEDOUT:
msg = "Connection timed out";
break;
case ECONNREFUSED:
msg = "Connection refused";
break;
case ELOOP:
msg = "Too many levels of symbolic links";
break;
case EHOSTDOWN:
msg = "Host is down";
break;
case EHOSTUNREACH:
msg = "No route to host";
break;
case EPROCLIM:
msg = "Too many processes";
break;
case EUSERS:
msg = "Too many users";
break;
case EDQUOT:
msg = "Disk quota exceeded";
break;
case ESTALE:
msg = "Stale NFS file handle";
break;
case EREMOTE:
msg = "Object is remote";
break;
# if HAVE_WINSOCK2_H
/* WSA_INVALID_HANDLE maps to EBADF */
/* WSA_NOT_ENOUGH_MEMORY maps to ENOMEM */
/* WSA_INVALID_PARAMETER maps to EINVAL */
case WSA_OPERATION_ABORTED:
msg = "Overlapped operation aborted";
break;
case WSA_IO_INCOMPLETE:
msg = "Overlapped I/O event object not in signaled state";
break;
case WSA_IO_PENDING:
msg = "Overlapped operations will complete later";
break;
/* WSAEINTR maps to EINTR */
/* WSAEBADF maps to EBADF */
/* WSAEACCES maps to EACCES */
/* WSAEFAULT maps to EFAULT */
/* WSAEINVAL maps to EINVAL */
/* WSAEMFILE maps to EMFILE */
/* WSAEWOULDBLOCK maps to EWOULDBLOCK */
/* WSAEINPROGRESS is EINPROGRESS */
/* WSAEALREADY is EALREADY */
/* WSAENOTSOCK is ENOTSOCK */
/* WSAEDESTADDRREQ is EDESTADDRREQ */
/* WSAEMSGSIZE is EMSGSIZE */
/* WSAEPROTOTYPE is EPROTOTYPE */
/* WSAENOPROTOOPT is ENOPROTOOPT */
/* WSAEPROTONOSUPPORT is EPROTONOSUPPORT */
/* WSAESOCKTNOSUPPORT is ESOCKTNOSUPPORT */
/* WSAEOPNOTSUPP is EOPNOTSUPP */
/* WSAEPFNOSUPPORT is EPFNOSUPPORT */
/* WSAEAFNOSUPPORT is EAFNOSUPPORT */
/* WSAEADDRINUSE is EADDRINUSE */
/* WSAEADDRNOTAVAIL is EADDRNOTAVAIL */
/* WSAENETDOWN is ENETDOWN */
/* WSAENETUNREACH is ENETUNREACH */
/* WSAENETRESET is ENETRESET */
/* WSAECONNABORTED is ECONNABORTED */
/* WSAECONNRESET is ECONNRESET */
/* WSAENOBUFS is ENOBUFS */
/* WSAEISCONN is EISCONN */
/* WSAENOTCONN is ENOTCONN */
/* WSAESHUTDOWN is ESHUTDOWN */
/* WSAETOOMANYREFS is ETOOMANYREFS */
/* WSAETIMEDOUT is ETIMEDOUT */
/* WSAECONNREFUSED is ECONNREFUSED */
/* WSAELOOP is ELOOP */
/* WSAENAMETOOLONG maps to ENAMETOOLONG */
/* WSAEHOSTDOWN is EHOSTDOWN */
/* WSAEHOSTUNREACH is EHOSTUNREACH */
/* WSAENOTEMPTY maps to ENOTEMPTY */
/* WSAEPROCLIM is EPROCLIM */
/* WSAEUSERS is EUSERS */
/* WSAEDQUOT is EDQUOT */
/* WSAESTALE is ESTALE */
/* WSAEREMOTE is EREMOTE */
case WSASYSNOTREADY:
msg = "Network subsystem is unavailable";
break;
case WSAVERNOTSUPPORTED:
msg = "Winsock.dll version out of range";
break;
case WSANOTINITIALISED:
msg = "Successful WSAStartup not yet performed";
break;
case WSAEDISCON:
msg = "Graceful shutdown in progress";
break;
case WSAENOMORE: case WSA_E_NO_MORE:
msg = "No more results";
break;
case WSAECANCELLED: case WSA_E_CANCELLED:
msg = "Call was canceled";
break;
case WSAEINVALIDPROCTABLE:
msg = "Procedure call table is invalid";
break;
case WSAEINVALIDPROVIDER:
msg = "Service provider is invalid";
break;
case WSAEPROVIDERFAILEDINIT:
msg = "Service provider failed to initialize";
break;
case WSASYSCALLFAILURE:
msg = "System call failure";
break;
case WSASERVICE_NOT_FOUND:
msg = "Service not found";
break;
case WSATYPE_NOT_FOUND:
msg = "Class type not found";
break;
case WSAEREFUSED:
msg = "Database query was refused";
break;
case WSAHOST_NOT_FOUND:
msg = "Host not found";
break;
case WSATRY_AGAIN:
msg = "Nonauthoritative host not found";
break;
case WSANO_RECOVERY:
msg = "Nonrecoverable error";
break;
case WSANO_DATA:
msg = "Valid name, no data record of requested type";
break;
/* WSA_QOS_* omitted */
# endif
# endif
# if GNULIB_defined_ENOMSG
case ENOMSG:
msg = "No message of desired type";
break;
# endif
# if GNULIB_defined_EIDRM
case EIDRM:
msg = "Identifier removed";
break;
# endif
# if GNULIB_defined_ENOLINK
case ENOLINK:
msg = "Link has been severed";
break;
# endif
# if GNULIB_defined_EPROTO
case EPROTO:
msg = "Protocol error";
break;
# endif
# if GNULIB_defined_EMULTIHOP
case EMULTIHOP:
msg = "Multihop attempted";
break;
# endif
# if GNULIB_defined_EBADMSG
case EBADMSG:
msg = "Bad message";
break;
# endif
# if GNULIB_defined_EOVERFLOW
case EOVERFLOW:
msg = "Value too large for defined data type";
break;
# endif
# if GNULIB_defined_ENOTSUP
case ENOTSUP:
msg = "Not supported";
break;
# endif
# if GNULIB_defined_
case ECANCELED:
msg = "Operation canceled";
break;
# endif
}
if (msg)
return (char *) msg;
{
char *result = strerror (n);
if (result == NULL || result[0] == '\0')
{
static char const fmt[] = "Unknown error (%d)";
static char msg_buf[sizeof fmt + INT_STRLEN_BOUND (n)];
sprintf (msg_buf, fmt, n);
return msg_buf;
}
return result;
}
}
#endif

View File

@ -1,605 +0,0 @@
/* A GNU-like <string.h>.
Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_STRING_H
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
/* The include_next requires a split double-inclusion guard. */
#@INCLUDE_NEXT@ @NEXT_STRING_H@
#ifndef _GL_STRING_H
#define _GL_STRING_H
#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
/* The attribute __pure__ was added in gcc 2.96. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
# define __pure__ /* empty */
# endif
#endif
/* The definition of GL_LINK_WARNING is copied here. */
#ifdef __cplusplus
extern "C" {
#endif
/* Return the first occurrence of NEEDLE in HAYSTACK. */
#if @GNULIB_MEMMEM@
# if @REPLACE_MEMMEM@
# define memmem rpl_memmem
# endif
# if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@
extern void *memmem (void const *__haystack, size_t __haystack_len,
void const *__needle, size_t __needle_len)
__attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef memmem
# define memmem(a,al,b,bl) \
(GL_LINK_WARNING ("memmem is unportable and often quadratic - " \
"use gnulib module memmem-simple for portability, " \
"and module memmem for speed" ), \
memmem (a, al, b, bl))
#endif
/* Copy N bytes of SRC to DEST, return pointer to bytes after the
last written byte. */
#if @GNULIB_MEMPCPY@
# if ! @HAVE_MEMPCPY@
extern void *mempcpy (void *restrict __dest, void const *restrict __src,
size_t __n);
# endif
#elif defined GNULIB_POSIXCHECK
# undef mempcpy
# define mempcpy(a,b,n) \
(GL_LINK_WARNING ("mempcpy is unportable - " \
"use gnulib module mempcpy for portability"), \
mempcpy (a, b, n))
#endif
/* Search backwards through a block for a byte (specified as an int). */
#if @GNULIB_MEMRCHR@
# if ! @HAVE_DECL_MEMRCHR@
extern void *memrchr (void const *, int, size_t)
__attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef memrchr
# define memrchr(a,b,c) \
(GL_LINK_WARNING ("memrchr is unportable - " \
"use gnulib module memrchr for portability"), \
memrchr (a, b, c))
#endif
/* Find the first occurrence of C in S. More efficient than
memchr(S,C,N), at the expense of undefined behavior if C does not
occur within N bytes. */
#if @GNULIB_RAWMEMCHR@
# if ! @HAVE_RAWMEMCHR@
extern void *rawmemchr (void const *__s, int __c_in)
__attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef rawmemchr
# define rawmemchr(a,b) \
(GL_LINK_WARNING ("rawmemchr is unportable - " \
"use gnulib module rawmemchr for portability"), \
rawmemchr (a, b))
#endif
/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */
#if @GNULIB_STPCPY@
# if ! @HAVE_STPCPY@
extern char *stpcpy (char *restrict __dst, char const *restrict __src);
# endif
#elif defined GNULIB_POSIXCHECK
# undef stpcpy
# define stpcpy(a,b) \
(GL_LINK_WARNING ("stpcpy is unportable - " \
"use gnulib module stpcpy for portability"), \
stpcpy (a, b))
#endif
/* Copy no more than N bytes of SRC to DST, returning a pointer past the
last non-NUL byte written into DST. */
#if @GNULIB_STPNCPY@
# if ! @HAVE_STPNCPY@
# define stpncpy gnu_stpncpy
extern char *stpncpy (char *restrict __dst, char const *restrict __src,
size_t __n);
# endif
#elif defined GNULIB_POSIXCHECK
# undef stpncpy
# define stpncpy(a,b,n) \
(GL_LINK_WARNING ("stpncpy is unportable - " \
"use gnulib module stpncpy for portability"), \
stpncpy (a, b, n))
#endif
#if defined GNULIB_POSIXCHECK
/* strchr() does not work with multibyte strings if the locale encoding is
GB18030 and the character to be searched is a digit. */
# undef strchr
# define strchr(s,c) \
(GL_LINK_WARNING ("strchr cannot work correctly on character strings " \
"in some multibyte locales - " \
"use mbschr if you care about internationalization"), \
strchr (s, c))
#endif
/* Find the first occurrence of C in S or the final NUL byte. */
#if @GNULIB_STRCHRNUL@
# if ! @HAVE_STRCHRNUL@
extern char *strchrnul (char const *__s, int __c_in)
__attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef strchrnul
# define strchrnul(a,b) \
(GL_LINK_WARNING ("strchrnul is unportable - " \
"use gnulib module strchrnul for portability"), \
strchrnul (a, b))
#endif
/* Duplicate S, returning an identical malloc'd string. */
#if @GNULIB_STRDUP@
# if @REPLACE_STRDUP@
# undef strdup
# define strdup rpl_strdup
# endif
# if !(@HAVE_DECL_STRDUP@ || defined strdup) || @REPLACE_STRDUP@
extern char *strdup (char const *__s);
# endif
#elif defined GNULIB_POSIXCHECK
# undef strdup
# define strdup(a) \
(GL_LINK_WARNING ("strdup is unportable - " \
"use gnulib module strdup for portability"), \
strdup (a))
#endif
/* Return a newly allocated copy of at most N bytes of STRING. */
#if @GNULIB_STRNDUP@
# if ! @HAVE_STRNDUP@
# undef strndup
# define strndup rpl_strndup
# endif
# if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@
extern char *strndup (char const *__string, size_t __n);
# endif
#elif defined GNULIB_POSIXCHECK
# undef strndup
# define strndup(a,n) \
(GL_LINK_WARNING ("strndup is unportable - " \
"use gnulib module strndup for portability"), \
strndup (a, n))
#endif
/* Find the length (number of bytes) of STRING, but scan at most
MAXLEN bytes. If no '\0' terminator is found in that many bytes,
return MAXLEN. */
#if @GNULIB_STRNLEN@
# if ! @HAVE_DECL_STRNLEN@
extern size_t strnlen (char const *__string, size_t __maxlen)
__attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
# undef strnlen
# define strnlen(a,n) \
(GL_LINK_WARNING ("strnlen is unportable - " \
"use gnulib module strnlen for portability"), \
strnlen (a, n))
#endif
#if defined GNULIB_POSIXCHECK
/* strcspn() assumes the second argument is a list of single-byte characters.
Even in this simple case, it does not work with multibyte strings if the
locale encoding is GB18030 and one of the characters to be searched is a
digit. */
# undef strcspn
# define strcspn(s,a) \
(GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \
"in multibyte locales - " \
"use mbscspn if you care about internationalization"), \
strcspn (s, a))
#endif
/* Find the first occurrence in S of any character in ACCEPT. */
#if @GNULIB_STRPBRK@
# if ! @HAVE_STRPBRK@
extern char *strpbrk (char const *__s, char const *__accept)
__attribute__ ((__pure__));
# endif
# if defined GNULIB_POSIXCHECK
/* strpbrk() assumes the second argument is a list of single-byte characters.
Even in this simple case, it does not work with multibyte strings if the
locale encoding is GB18030 and one of the characters to be searched is a
digit. */
# undef strpbrk
# define strpbrk(s,a) \
(GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \
"in multibyte locales - " \
"use mbspbrk if you care about internationalization"), \
strpbrk (s, a))
# endif
#elif defined GNULIB_POSIXCHECK
# undef strpbrk
# define strpbrk(s,a) \
(GL_LINK_WARNING ("strpbrk is unportable - " \
"use gnulib module strpbrk for portability"), \
strpbrk (s, a))
#endif
#if defined GNULIB_POSIXCHECK
/* strspn() assumes the second argument is a list of single-byte characters.
Even in this simple case, it cannot work with multibyte strings. */
# undef strspn
# define strspn(s,a) \
(GL_LINK_WARNING ("strspn cannot work correctly on character strings " \
"in multibyte locales - " \
"use mbsspn if you care about internationalization"), \
strspn (s, a))
#endif
#if defined GNULIB_POSIXCHECK
/* strrchr() does not work with multibyte strings if the locale encoding is
GB18030 and the character to be searched is a digit. */
# undef strrchr
# define strrchr(s,c) \
(GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \
"in some multibyte locales - " \
"use mbsrchr if you care about internationalization"), \
strrchr (s, c))
#endif
/* Search the next delimiter (char listed in DELIM) starting at *STRINGP.
If one is found, overwrite it with a NUL, and advance *STRINGP
to point to the next char after it. Otherwise, set *STRINGP to NULL.
If *STRINGP was already NULL, nothing happens.
Return the old value of *STRINGP.
This is a variant of strtok() that is multithread-safe and supports
empty fields.
Caveat: It modifies the original string.
Caveat: These functions cannot be used on constant strings.
Caveat: The identity of the delimiting character is lost.
Caveat: It doesn't work with multibyte strings unless all of the delimiter
characters are ASCII characters < 0x30.
See also strtok_r(). */
#if @GNULIB_STRSEP@
# if ! @HAVE_STRSEP@
extern char *strsep (char **restrict __stringp, char const *restrict __delim);
# endif
# if defined GNULIB_POSIXCHECK
# undef strsep
# define strsep(s,d) \
(GL_LINK_WARNING ("strsep cannot work correctly on character strings " \
"in multibyte locales - " \
"use mbssep if you care about internationalization"), \
strsep (s, d))
# endif
#elif defined GNULIB_POSIXCHECK
# undef strsep
# define strsep(s,d) \
(GL_LINK_WARNING ("strsep is unportable - " \
"use gnulib module strsep for portability"), \
strsep (s, d))
#endif
#if @GNULIB_STRSTR@
# if @REPLACE_STRSTR@
# define strstr rpl_strstr
char *strstr (const char *haystack, const char *needle)
__attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
/* strstr() does not work with multibyte strings if the locale encoding is
different from UTF-8:
POSIX says that it operates on "strings", and "string" in POSIX is defined
as a sequence of bytes, not of characters. */
# undef strstr
# define strstr(a,b) \
(GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \
"work correctly on character strings in most " \
"multibyte locales - " \
"use mbsstr if you care about internationalization, " \
"or use strstr if you care about speed"), \
strstr (a, b))
#endif
/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive
comparison. */
#if @GNULIB_STRCASESTR@
# if @REPLACE_STRCASESTR@
# define strcasestr rpl_strcasestr
# endif
# if ! @HAVE_STRCASESTR@ || @REPLACE_STRCASESTR@
extern char *strcasestr (const char *haystack, const char *needle)
__attribute__ ((__pure__));
# endif
#elif defined GNULIB_POSIXCHECK
/* strcasestr() does not work with multibyte strings:
It is a glibc extension, and glibc implements it only for unibyte
locales. */
# undef strcasestr
# define strcasestr(a,b) \
(GL_LINK_WARNING ("strcasestr does work correctly on character strings " \
"in multibyte locales - " \
"use mbscasestr if you care about " \
"internationalization, or use c-strcasestr if you want " \
"a locale independent function"), \
strcasestr (a, b))
#endif
/* Parse S into tokens separated by characters in DELIM.
If S is NULL, the saved pointer in SAVE_PTR is used as
the next starting point. For example:
char s[] = "-abc-=-def";
char *sp;
x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def"
x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL
x = strtok_r(NULL, "=", &sp); // x = NULL
// s = "abc\0-def\0"
This is a variant of strtok() that is multithread-safe.
For the POSIX documentation for this function, see:
http://www.opengroup.org/susv3xsh/strtok.html
Caveat: It modifies the original string.
Caveat: These functions cannot be used on constant strings.
Caveat: The identity of the delimiting character is lost.
Caveat: It doesn't work with multibyte strings unless all of the delimiter
characters are ASCII characters < 0x30.
See also strsep(). */
#if @GNULIB_STRTOK_R@
# if ! @HAVE_DECL_STRTOK_R@
extern char *strtok_r (char *restrict s, char const *restrict delim,
char **restrict save_ptr);
# endif
# if defined GNULIB_POSIXCHECK
# undef strtok_r
# define strtok_r(s,d,p) \
(GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \
"in multibyte locales - " \
"use mbstok_r if you care about internationalization"), \
strtok_r (s, d, p))
# endif
#elif defined GNULIB_POSIXCHECK
# undef strtok_r
# define strtok_r(s,d,p) \
(GL_LINK_WARNING ("strtok_r is unportable - " \
"use gnulib module strtok_r for portability"), \
strtok_r (s, d, p))
#endif
/* The following functions are not specified by POSIX. They are gnulib
extensions. */
#if @GNULIB_MBSLEN@
/* Return the number of multibyte characters in the character string STRING.
This considers multibyte characters, unlike strlen, which counts bytes. */
extern size_t mbslen (const char *string);
#endif
#if @GNULIB_MBSNLEN@
/* Return the number of multibyte characters in the character string starting
at STRING and ending at STRING + LEN. */
extern size_t mbsnlen (const char *string, size_t len);
#endif
#if @GNULIB_MBSCHR@
/* Locate the first single-byte character C in the character string STRING,
and return a pointer to it. Return NULL if C is not found in STRING.
Unlike strchr(), this function works correctly in multibyte locales with
encodings such as GB18030. */
# define mbschr rpl_mbschr /* avoid collision with HP-UX function */
extern char * mbschr (const char *string, int c);
#endif
#if @GNULIB_MBSRCHR@
/* Locate the last single-byte character C in the character string STRING,
and return a pointer to it. Return NULL if C is not found in STRING.
Unlike strrchr(), this function works correctly in multibyte locales with
encodings such as GB18030. */
# define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */
extern char * mbsrchr (const char *string, int c);
#endif
#if @GNULIB_MBSSTR@
/* Find the first occurrence of the character string NEEDLE in the character
string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK.
Unlike strstr(), this function works correctly in multibyte locales with
encodings different from UTF-8. */
extern char * mbsstr (const char *haystack, const char *needle);
#endif
#if @GNULIB_MBSCASECMP@
/* Compare the character strings S1 and S2, ignoring case, returning less than,
equal to or greater than zero if S1 is lexicographically less than, equal to
or greater than S2.
Note: This function may, in multibyte locales, return 0 for strings of
different lengths!
Unlike strcasecmp(), this function works correctly in multibyte locales. */
extern int mbscasecmp (const char *s1, const char *s2);
#endif
#if @GNULIB_MBSNCASECMP@
/* Compare the initial segment of the character string S1 consisting of at most
N characters with the initial segment of the character string S2 consisting
of at most N characters, ignoring case, returning less than, equal to or
greater than zero if the initial segment of S1 is lexicographically less
than, equal to or greater than the initial segment of S2.
Note: This function may, in multibyte locales, return 0 for initial segments
of different lengths!
Unlike strncasecmp(), this function works correctly in multibyte locales.
But beware that N is not a byte count but a character count! */
extern int mbsncasecmp (const char *s1, const char *s2, size_t n);
#endif
#if @GNULIB_MBSPCASECMP@
/* Compare the initial segment of the character string STRING consisting of
at most mbslen (PREFIX) characters with the character string PREFIX,
ignoring case, returning less than, equal to or greater than zero if this
initial segment is lexicographically less than, equal to or greater than
PREFIX.
Note: This function may, in multibyte locales, return 0 if STRING is of
smaller length than PREFIX!
Unlike strncasecmp(), this function works correctly in multibyte
locales. */
extern char * mbspcasecmp (const char *string, const char *prefix);
#endif
#if @GNULIB_MBSCASESTR@
/* Find the first occurrence of the character string NEEDLE in the character
string HAYSTACK, using case-insensitive comparison.
Note: This function may, in multibyte locales, return success even if
strlen (haystack) < strlen (needle) !
Unlike strcasestr(), this function works correctly in multibyte locales. */
extern char * mbscasestr (const char *haystack, const char *needle);
#endif
#if @GNULIB_MBSCSPN@
/* Find the first occurrence in the character string STRING of any character
in the character string ACCEPT. Return the number of bytes from the
beginning of the string to this occurrence, or to the end of the string
if none exists.
Unlike strcspn(), this function works correctly in multibyte locales. */
extern size_t mbscspn (const char *string, const char *accept);
#endif
#if @GNULIB_MBSPBRK@
/* Find the first occurrence in the character string STRING of any character
in the character string ACCEPT. Return the pointer to it, or NULL if none
exists.
Unlike strpbrk(), this function works correctly in multibyte locales. */
# define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */
extern char * mbspbrk (const char *string, const char *accept);
#endif
#if @GNULIB_MBSSPN@
/* Find the first occurrence in the character string STRING of any character
not in the character string REJECT. Return the number of bytes from the
beginning of the string to this occurrence, or to the end of the string
if none exists.
Unlike strspn(), this function works correctly in multibyte locales. */
extern size_t mbsspn (const char *string, const char *reject);
#endif
#if @GNULIB_MBSSEP@
/* Search the next delimiter (multibyte character listed in the character
string DELIM) starting at the character string *STRINGP.
If one is found, overwrite it with a NUL, and advance *STRINGP to point
to the next multibyte character after it. Otherwise, set *STRINGP to NULL.
If *STRINGP was already NULL, nothing happens.
Return the old value of *STRINGP.
This is a variant of mbstok_r() that supports empty fields.
Caveat: It modifies the original string.
Caveat: These functions cannot be used on constant strings.
Caveat: The identity of the delimiting character is lost.
See also mbstok_r(). */
extern char * mbssep (char **stringp, const char *delim);
#endif
#if @GNULIB_MBSTOK_R@
/* Parse the character string STRING into tokens separated by characters in
the character string DELIM.
If STRING is NULL, the saved pointer in SAVE_PTR is used as
the next starting point. For example:
char s[] = "-abc-=-def";
char *sp;
x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def"
x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL
x = mbstok_r(NULL, "=", &sp); // x = NULL
// s = "abc\0-def\0"
Caveat: It modifies the original string.
Caveat: These functions cannot be used on constant strings.
Caveat: The identity of the delimiting character is lost.
See also mbssep(). */
extern char * mbstok_r (char *string, const char *delim, char **save_ptr);
#endif
/* Map any int, typically from errno, into an error message. */
#if @GNULIB_STRERROR@
# if @REPLACE_STRERROR@
# undef strerror
# define strerror rpl_strerror
extern char *strerror (int);
# endif
#elif defined GNULIB_POSIXCHECK
# undef strerror
# define strerror(e) \
(GL_LINK_WARNING ("strerror is unportable - " \
"use gnulib module strerror to guarantee non-NULL result"), \
strerror (e))
#endif
#if @GNULIB_STRSIGNAL@
# if @REPLACE_STRSIGNAL@
# define strsignal rpl_strsignal
# endif
# if ! @HAVE_DECL_STRSIGNAL@ || @REPLACE_STRSIGNAL@
extern char *strsignal (int __sig);
# endif
#elif defined GNULIB_POSIXCHECK
# undef strsignal
# define strsignal(a) \
(GL_LINK_WARNING ("strsignal is unportable - " \
"use gnulib module strsignal for portability"), \
strsignal (a))
#endif
#if @GNULIB_STRVERSCMP@
# if !@HAVE_STRVERSCMP@
extern int strverscmp (const char *, const char *);
# endif
#elif defined GNULIB_POSIXCHECK
# undef strverscmp
# define strverscmp(a, b) \
(GL_LINK_WARNING ("strverscmp is unportable - " \
"use gnulib module strverscmp for portability"), \
strverscmp (a, b))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_STRING_H */
#endif /* _GL_STRING_H */

View File

@ -1,37 +0,0 @@
/* A replacement function, for systems that lack strndup.
Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007
Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
#include <string.h>
#include <stdlib.h>
char *
strndup (char const *s, size_t n)
{
size_t len = strnlen (s, n);
char *new = malloc (len + 1);
if (new == NULL)
return NULL;
new[len] = '\0';
return memcpy (new, s, len);
}

View File

@ -1,31 +0,0 @@
/* Find the length of STRING, but scan at most MAXLEN characters.
Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
Written by Simon Josefsson.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
#include <string.h>
/* Find the length of STRING, but scan at most MAXLEN characters.
If no '\0' terminator is found in that many characters, return MAXLEN. */
size_t
strnlen (const char *string, size_t maxlen)
{
const char *end = memchr (string, '\0', maxlen);
return end ? (size_t) (end - string) : maxlen;
}

View File

@ -1,58 +0,0 @@
/* Copyright (C) 2004, 2007 Free Software Foundation, Inc.
Written by Yoann Vandoorselaere <yoann@prelude-ids.org>.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
/* Specification. */
#include <string.h>
char *
strsep (char **stringp, const char *delim)
{
char *start = *stringp;
char *ptr;
if (start == NULL)
return NULL;
/* Optimize the case of no delimiters. */
if (delim[0] == '\0')
{
*stringp = NULL;
return start;
}
/* Optimize the case of one delimiter. */
if (delim[1] == '\0')
ptr = strchr (start, delim[0]);
else
/* The general case. */
ptr = strpbrk (start, delim);
if (ptr == NULL)
{
*stringp = NULL;
return start;
}
*ptr = '\0';
*stringp = ptr + 1;
return start;
}

View File

@ -1,4 +0,0 @@
select.h
socket.h
stat.h
time.h

View File

@ -1,4 +0,0 @@
select.h
socket.h
stat.h
time.h

View File

@ -1,70 +0,0 @@
/* Substitute for and wrapper around <sys/ioctl.h>.
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_SYS_IOCTL_H
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
/* The include_next requires a split double-inclusion guard. */
#if @HAVE_SYS_IOCTL_H@
# @INCLUDE_NEXT@ @NEXT_SYS_IOCTL_H@
#endif
#ifndef _GL_SYS_IOCTL_H
#define _GL_SYS_IOCTL_H
/* AIX 5.1 and Solaris 10 declare ioctl() in <unistd.h> and in <stropts.h>,
but not in <sys/ioctl.h>. */
#include <unistd.h>
/* The definition of GL_LINK_WARNING is copied here. */
/* Declare overridden functions. */
#ifdef __cplusplus
extern "C" {
#endif
#if @GNULIB_IOCTL@
# if @SYS_IOCTL_H_HAVE_WINSOCK2_H@
# undef ioctl
# define ioctl rpl_ioctl
extern int ioctl (int fd, int request, ... /* {void *,char *} arg */);
# endif
#elif @SYS_IOCTL_H_HAVE_WINSOCK2_H@
# undef ioctl
# define ioctl ioctl_used_without_requesting_gnulib_module_ioctl
#elif defined GNULIB_POSIXCHECK
# undef ioctl
# define ioctl(f,c,a) \
(GL_LINK_WARNING ("ioctl does not portably work on sockets - " \
"use gnulib module ioctl for portability"), \
ioctl (f, c, a))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_SYS_IOCTL_H */
#endif /* _GL_SYS_IOCTL_H */

View File

@ -1,93 +0,0 @@
/* Substitute for <sys/select.h>.
Copyright (C) 2007-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
# if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
# endif
/* On OSF/1, <sys/types.h> and <sys/time.h> include <sys/select.h>.
Simply delegate to the system's header in this case. */
#if @HAVE_SYS_SELECT_H@ && defined __osf__ && (defined _SYS_TYPES_H_ && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H) && defined _OSF_SOURCE
# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TYPES_H
# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
#elif @HAVE_SYS_SELECT_H@ && defined __osf__ && (defined _SYS_TIME_H_ && !defined _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H) && defined _OSF_SOURCE
# define _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H
# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
#else
#ifndef _GL_SYS_SELECT_H
#if @HAVE_SYS_SELECT_H@
/* On many platforms, <sys/select.h> assumes prior inclusion of
<sys/types.h>. */
# include <sys/types.h>
/* On OSF/1 4.0, <sys/select.h> provides only a forward declaration
of 'struct timeval', and no definition of this type.. */
# include <sys/time.h>
/* The include_next requires a split double-inclusion guard. */
# @INCLUDE_NEXT@ @NEXT_SYS_SELECT_H@
#endif
#ifndef _GL_SYS_SELECT_H
#define _GL_SYS_SELECT_H
#if !@HAVE_SYS_SELECT_H@
/* A platform that lacks <sys/select.h>. */
# include <sys/socket.h>
/* The definition of GL_LINK_WARNING is copied here. */
# ifdef __cplusplus
extern "C" {
# endif
# if @GNULIB_SELECT@
# if @HAVE_WINSOCK2_H@
# undef select
# define select rpl_select
extern int rpl_select (int, fd_set *, fd_set *, fd_set *, struct timeval *);
# endif
# elif @HAVE_WINSOCK2_H@
# undef select
# define select select_used_without_requesting_gnulib_module_select
# elif defined GNULIB_POSIXCHECK
# undef select
# define select(n,r,w,e,t) \
(GL_LINK_WARNING ("select is not always POSIX compliant - " \
"use gnulib module select for portability"), \
select (n, r, w, e, t))
# endif
# ifdef __cplusplus
}
# endif
#endif
#endif /* _GL_SYS_SELECT_H */
#endif /* _GL_SYS_SELECT_H */
#endif /* OSF/1 */

View File

@ -1,403 +0,0 @@
/* Provide a sys/socket header file for systems lacking it (read: MinGW)
and for systems where it is incomplete.
Copyright (C) 2005-2008 Free Software Foundation, Inc.
Written by Simon Josefsson.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* This file is supposed to be used on platforms that lack <sys/socket.h>,
on platforms where <sys/socket.h> cannot be included standalone, and on
platforms where <sys/socket.h> does not provide all necessary definitions.
It is intended to provide definitions and prototypes needed by an
application. */
#ifndef _GL_SYS_SOCKET_H
#if @HAVE_SYS_SOCKET_H@
# if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
# endif
/* On many platforms, <sys/socket.h> assumes prior inclusion of
<sys/types.h>. */
# include <sys/types.h>
/* The include_next requires a split double-inclusion guard. */
# @INCLUDE_NEXT@ @NEXT_SYS_SOCKET_H@
#endif
#ifndef _GL_SYS_SOCKET_H
#define _GL_SYS_SOCKET_H
#if @HAVE_SYS_SOCKET_H@
/* A platform that has <sys/socket.h>. */
/* For shutdown(). */
# if !defined SHUT_RD
# define SHUT_RD 0
# endif
# if !defined SHUT_WR
# define SHUT_WR 1
# endif
# if !defined SHUT_RDWR
# define SHUT_RDWR 2
# endif
#else
# ifdef __CYGWIN__
# error "Cygwin does have a sys/socket.h, doesn't it?!?"
# endif
/* A platform that lacks <sys/socket.h>.
Currently only MinGW is supported. See the gnulib manual regarding
Windows sockets. MinGW has the header files winsock2.h and
ws2tcpip.h that declare the sys/socket.h definitions we need. Note
that you can influence which definitions you get by setting the
WINVER symbol before including these two files. For example,
getaddrinfo is only available if _WIN32_WINNT >= 0x0501 (that
symbol is set indiriectly through WINVER). You can set this by
adding AC_DEFINE(WINVER, 0x0501) to configure.ac. Note that your
code may not run on older Windows releases then. My Windows 2000
box was not able to run the code, for example. The situation is
slightly confusing because:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/getaddrinfo_2.asp
suggests that getaddrinfo should be available on all Windows
releases. */
# if @HAVE_WINSOCK2_H@
# include <winsock2.h>
# endif
# if @HAVE_WS2TCPIP_H@
# include <ws2tcpip.h>
# endif
/* For shutdown(). */
# if !defined SHUT_RD && defined SD_RECEIVE
# define SHUT_RD SD_RECEIVE
# endif
# if !defined SHUT_WR && defined SD_SEND
# define SHUT_WR SD_SEND
# endif
# if !defined SHUT_RDWR && defined SD_BOTH
# define SHUT_RDWR SD_BOTH
# endif
/* The definition of GL_LINK_WARNING is copied here. */
# if @HAVE_WINSOCK2_H@
/* Include headers needed by the emulation code. */
# include <sys/types.h>
# include <io.h>
typedef int socklen_t;
# endif
# ifdef __cplusplus
extern "C" {
# endif
# if @HAVE_WINSOCK2_H@
/* Re-define FD_ISSET to avoid a WSA call while we are not using
network sockets. */
static inline int
rpl_fd_isset (SOCKET fd, fd_set * set)
{
u_int i;
if (set == NULL)
return 0;
for (i = 0; i < set->fd_count; i++)
if (set->fd_array[i] == fd)
return 1;
return 0;
}
# undef FD_ISSET
# define FD_ISSET(fd, set) rpl_fd_isset(fd, set)
# endif
/* Wrap everything else to use libc file descriptors for sockets. */
# if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
# undef close
# define close close_used_without_including_unistd_h
# endif
# if @HAVE_WINSOCK2_H@ && !defined _GL_UNISTD_H
# undef gethostname
# define gethostname gethostname_used_without_including_unistd_h
# endif
# if @GNULIB_SOCKET@
# if @HAVE_WINSOCK2_H@
# undef socket
# define socket rpl_socket
extern int rpl_socket (int, int, int protocol);
# endif
# elif @HAVE_WINSOCK2_H@
# undef socket
# define socket socket_used_without_requesting_gnulib_module_socket
# elif defined GNULIB_POSIXCHECK
# undef socket
# define socket(d,t,p) \
(GL_LINK_WARNING ("socket is not always POSIX compliant - " \
"use gnulib module socket for portability"), \
socket (d, t, p))
# endif
# if @GNULIB_CONNECT@
# if @HAVE_WINSOCK2_H@
# undef connect
# define connect rpl_connect
extern int rpl_connect (int, struct sockaddr *, int);
# endif
# elif @HAVE_WINSOCK2_H@
# undef connect
# define connect socket_used_without_requesting_gnulib_module_connect
# elif defined GNULIB_POSIXCHECK
# undef connect
# define connect(s,a,l) \
(GL_LINK_WARNING ("connect is not always POSIX compliant - " \
"use gnulib module connect for portability"), \
connect (s, a, l))
# endif
# if @GNULIB_ACCEPT@
# if @HAVE_WINSOCK2_H@
# undef accept
# define accept rpl_accept
extern int rpl_accept (int, struct sockaddr *, int *);
# endif
# elif @HAVE_WINSOCK2_H@
# undef accept
# define accept accept_used_without_requesting_gnulib_module_accept
# elif defined GNULIB_POSIXCHECK
# undef accept
# define accept(s,a,l) \
(GL_LINK_WARNING ("accept is not always POSIX compliant - " \
"use gnulib module accept for portability"), \
accept (s, a, l))
# endif
# if @GNULIB_BIND@
# if @HAVE_WINSOCK2_H@
# undef bind
# define bind rpl_bind
extern int rpl_bind (int, struct sockaddr *, int);
# endif
# elif @HAVE_WINSOCK2_H@
# undef bind
# define bind bind_used_without_requesting_gnulib_module_bind
# elif defined GNULIB_POSIXCHECK
# undef bind
# define bind(s,a,l) \
(GL_LINK_WARNING ("bind is not always POSIX compliant - " \
"use gnulib module bind for portability"), \
bind (s, a, l))
# endif
# if @GNULIB_GETPEERNAME@
# if @HAVE_WINSOCK2_H@
# undef getpeername
# define getpeername rpl_getpeername
extern int rpl_getpeername (int, struct sockaddr *, int *);
# endif
# elif @HAVE_WINSOCK2_H@
# undef getpeername
# define getpeername getpeername_used_without_requesting_gnulib_module_getpeername
# elif defined GNULIB_POSIXCHECK
# undef getpeername
# define getpeername(s,a,l) \
(GL_LINK_WARNING ("getpeername is not always POSIX compliant - " \
"use gnulib module getpeername for portability"), \
getpeername (s, a, l))
# endif
# if @GNULIB_GETSOCKNAME@
# if @HAVE_WINSOCK2_H@
# undef getsockname
# define getsockname rpl_getsockname
extern int rpl_getsockname (int, struct sockaddr *, int *);
# endif
# elif @HAVE_WINSOCK2_H@
# undef getsockname
# define getsockname getsockname_used_without_requesting_gnulib_module_getsockname
# elif defined GNULIB_POSIXCHECK
# undef getsockname
# define getsockname(s,a,l) \
(GL_LINK_WARNING ("getsockname is not always POSIX compliant - " \
"use gnulib module getsockname for portability"), \
getsockname (s, a, l))
# endif
# if @GNULIB_GETSOCKOPT@
# if @HAVE_WINSOCK2_H@
# undef getsockopt
# define getsockopt rpl_getsockopt
extern int rpl_getsockopt (int, int, int, void *, int *);
# endif
# elif @HAVE_WINSOCK2_H@
# undef getsockopt
# define getsockopt getsockopt_used_without_requesting_gnulib_module_getsockopt
# elif defined GNULIB_POSIXCHECK
# undef getsockopt
# define getsockopt(s,lvl,o,v,l) \
(GL_LINK_WARNING ("getsockopt is not always POSIX compliant - " \
"use gnulib module getsockopt for portability"), \
getsockopt (s, lvl, o, v, l))
# endif
# if @GNULIB_LISTEN@
# if @HAVE_WINSOCK2_H@
# undef listen
# define listen rpl_listen
extern int rpl_listen (int, int);
# endif
# elif @HAVE_WINSOCK2_H@
# undef listen
# define listen listen_used_without_requesting_gnulib_module_listen
# elif defined GNULIB_POSIXCHECK
# undef listen
# define listen(s,b) \
(GL_LINK_WARNING ("listen is not always POSIX compliant - " \
"use gnulib module listen for portability"), \
listen (s, b))
# endif
# if @GNULIB_RECV@
# if @HAVE_WINSOCK2_H@
# undef recv
# define recv rpl_recv
extern int rpl_recv (int, void *, int, int);
# endif
# elif @HAVE_WINSOCK2_H@
# undef recv
# define recv recv_used_without_requesting_gnulib_module_recv
# elif defined GNULIB_POSIXCHECK
# undef recv
# define recv(s,b,n,f) \
(GL_LINK_WARNING ("recv is not always POSIX compliant - " \
"use gnulib module recv for portability"), \
recv (s, b, n, f))
# endif
# if @GNULIB_SEND@
# if @HAVE_WINSOCK2_H@
# undef send
# define send rpl_send
extern int rpl_send (int, const void *, int, int);
# endif
# elif @HAVE_WINSOCK2_H@
# undef send
# define send send_used_without_requesting_gnulib_module_send
# elif defined GNULIB_POSIXCHECK
# undef send
# define send(s,b,n,f) \
(GL_LINK_WARNING ("send is not always POSIX compliant - " \
"use gnulib module send for portability"), \
send (s, b, n, f))
# endif
# if @GNULIB_RECVFROM@
# if @HAVE_WINSOCK2_H@
# undef recvfrom
# define recvfrom rpl_recvfrom
extern int rpl_recvfrom (int, void *, int, int, struct sockaddr *, int *);
# endif
# elif @HAVE_WINSOCK2_H@
# undef recvfrom
# define recvfrom recvfrom_used_without_requesting_gnulib_module_recvfrom
# elif defined GNULIB_POSIXCHECK
# undef recvfrom
# define recvfrom(s,b,n,f,a,l) \
(GL_LINK_WARNING ("recvfrom is not always POSIX compliant - " \
"use gnulib module recvfrom for portability"), \
recvfrom (s, b, n, f, a, l))
# endif
# if @GNULIB_SENDTO@
# if @HAVE_WINSOCK2_H@
# undef sendto
# define sendto rpl_sendto
extern int rpl_sendto (int, const void *, int, int, struct sockaddr *, int);
# endif
# elif @HAVE_WINSOCK2_H@
# undef sendto
# define sendto sendto_used_without_requesting_gnulib_module_sendto
# elif defined GNULIB_POSIXCHECK
# undef sendto
# define sendto(s,b,n,f,a,l) \
(GL_LINK_WARNING ("sendto is not always POSIX compliant - " \
"use gnulib module sendto for portability"), \
sendto (s, b, n, f, a, l))
# endif
# if @GNULIB_SETSOCKOPT@
# if @HAVE_WINSOCK2_H@
# undef setsockopt
# define setsockopt rpl_setsockopt
extern int rpl_setsockopt (int, int, int, const void *, int);
# endif
# elif @HAVE_WINSOCK2_H@
# undef setsockopt
# define setsockopt setsockopt_used_without_requesting_gnulib_module_setsockopt
# elif defined GNULIB_POSIXCHECK
# undef setsockopt
# define setsockopt(s,lvl,o,v,l) \
(GL_LINK_WARNING ("setsockopt is not always POSIX compliant - " \
"use gnulib module setsockopt for portability"), \
setsockopt (s, lvl, o, v, l))
# endif
# if @GNULIB_SHUTDOWN@
# if @HAVE_WINSOCK2_H@
# undef shutdown
# define shutdown rpl_shutdown
extern int rpl_shutdown (int, int);
# endif
# elif @HAVE_WINSOCK2_H@
# undef shutdown
# define shutdown shutdown_used_without_requesting_gnulib_module_shutdown
# elif defined GNULIB_POSIXCHECK
# undef shutdown
# define shutdown(s,h) \
(GL_LINK_WARNING ("shutdown is not always POSIX compliant - " \
"use gnulib module shutdown for portability"), \
shutdown (s, h))
# endif
# if @HAVE_WINSOCK2_H@
# undef select
# define select select_used_without_including_sys_select_h
# endif
# ifdef __cplusplus
}
# endif
#endif /* HAVE_SYS_SOCKET_H */
#endif /* _GL_SYS_SOCKET_H */
#endif /* _GL_SYS_SOCKET_H */

View File

@ -1,361 +0,0 @@
/* Provide a more complete sys/stat header file.
Copyright (C) 2005-2009 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Eric Blake, Paul Eggert, and Jim Meyering. */
/* This file is supposed to be used on platforms where <sys/stat.h> is
incomplete. It is intended to provide definitions and prototypes
needed by an application. Start with what the system provides. */
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
#if defined __need_system_sys_stat_h
/* Special invocation convention. */
#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
#else
/* Normal invocation convention. */
#ifndef _GL_SYS_STAT_H
/* Get nlink_t. */
#include <sys/types.h>
/* The include_next requires a split double-inclusion guard. */
#@INCLUDE_NEXT@ @NEXT_SYS_STAT_H@
#ifndef _GL_SYS_STAT_H
#define _GL_SYS_STAT_H
/* The definition of GL_LINK_WARNING is copied here. */
/* Before doing "#define mkdir rpl_mkdir" below, we need to include all
headers that may declare mkdir(). */
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
# include <io.h>
#endif
#ifndef S_IFMT
# define S_IFMT 0170000
#endif
#if STAT_MACROS_BROKEN
# undef S_ISBLK
# undef S_ISCHR
# undef S_ISDIR
# undef S_ISFIFO
# undef S_ISLNK
# undef S_ISNAM
# undef S_ISMPB
# undef S_ISMPC
# undef S_ISNWK
# undef S_ISREG
# undef S_ISSOCK
#endif
#ifndef S_ISBLK
# ifdef S_IFBLK
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
# else
# define S_ISBLK(m) 0
# endif
#endif
#ifndef S_ISCHR
# ifdef S_IFCHR
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
# else
# define S_ISCHR(m) 0
# endif
#endif
#ifndef S_ISDIR
# ifdef S_IFDIR
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
# else
# define S_ISDIR(m) 0
# endif
#endif
#ifndef S_ISDOOR /* Solaris 2.5 and up */
# define S_ISDOOR(m) 0
#endif
#ifndef S_ISFIFO
# ifdef S_IFIFO
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
# else
# define S_ISFIFO(m) 0
# endif
#endif
#ifndef S_ISLNK
# ifdef S_IFLNK
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
# else
# define S_ISLNK(m) 0
# endif
#endif
#ifndef S_ISMPB /* V7 */
# ifdef S_IFMPB
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
# else
# define S_ISMPB(m) 0
# define S_ISMPC(m) 0
# endif
#endif
#ifndef S_ISNAM /* Xenix */
# ifdef S_IFNAM
# define S_ISNAM(m) (((m) & S_IFMT) == S_IFNAM)
# else
# define S_ISNAM(m) 0
# endif
#endif
#ifndef S_ISNWK /* HP/UX */
# ifdef S_IFNWK
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
# else
# define S_ISNWK(m) 0
# endif
#endif
#ifndef S_ISPORT /* Solaris 10 and up */
# define S_ISPORT(m) 0
#endif
#ifndef S_ISREG
# ifdef S_IFREG
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
# else
# define S_ISREG(m) 0
# endif
#endif
#ifndef S_ISSOCK
# ifdef S_IFSOCK
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
# else
# define S_ISSOCK(m) 0
# endif
#endif
#ifndef S_TYPEISMQ
# define S_TYPEISMQ(p) 0
#endif
#ifndef S_TYPEISTMO
# define S_TYPEISTMO(p) 0
#endif
#ifndef S_TYPEISSEM
# ifdef S_INSEM
# define S_TYPEISSEM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSEM)
# else
# define S_TYPEISSEM(p) 0
# endif
#endif
#ifndef S_TYPEISSHM
# ifdef S_INSHD
# define S_TYPEISSHM(p) (S_ISNAM ((p)->st_mode) && (p)->st_rdev == S_INSHD)
# else
# define S_TYPEISSHM(p) 0
# endif
#endif
/* high performance ("contiguous data") */
#ifndef S_ISCTG
# define S_ISCTG(p) 0
#endif
/* Cray DMF (data migration facility): off line, with data */
#ifndef S_ISOFD
# define S_ISOFD(p) 0
#endif
/* Cray DMF (data migration facility): off line, with no data */
#ifndef S_ISOFL
# define S_ISOFL(p) 0
#endif
/* 4.4BSD whiteout */
#ifndef S_ISWHT
# define S_ISWHT(m) 0
#endif
/* If any of the following are undefined,
define them to their de facto standard values. */
#if !S_ISUID
# define S_ISUID 04000
#endif
#if !S_ISGID
# define S_ISGID 02000
#endif
/* S_ISVTX is a common extension to POSIX. */
#ifndef S_ISVTX
# define S_ISVTX 01000
#endif
#if !S_IRUSR && S_IREAD
# define S_IRUSR S_IREAD
#endif
#if !S_IRUSR
# define S_IRUSR 00400
#endif
#if !S_IRGRP
# define S_IRGRP (S_IRUSR >> 3)
#endif
#if !S_IROTH
# define S_IROTH (S_IRUSR >> 6)
#endif
#if !S_IWUSR && S_IWRITE
# define S_IWUSR S_IWRITE
#endif
#if !S_IWUSR
# define S_IWUSR 00200
#endif
#if !S_IWGRP
# define S_IWGRP (S_IWUSR >> 3)
#endif
#if !S_IWOTH
# define S_IWOTH (S_IWUSR >> 6)
#endif
#if !S_IXUSR && S_IEXEC
# define S_IXUSR S_IEXEC
#endif
#if !S_IXUSR
# define S_IXUSR 00100
#endif
#if !S_IXGRP
# define S_IXGRP (S_IXUSR >> 3)
#endif
#if !S_IXOTH
# define S_IXOTH (S_IXUSR >> 6)
#endif
#if !S_IRWXU
# define S_IRWXU (S_IRUSR | S_IWUSR | S_IXUSR)
#endif
#if !S_IRWXG
# define S_IRWXG (S_IRGRP | S_IWGRP | S_IXGRP)
#endif
#if !S_IRWXO
# define S_IRWXO (S_IROTH | S_IWOTH | S_IXOTH)
#endif
/* S_IXUGO is a common extension to POSIX. */
#if !S_IXUGO
# define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
#endif
#ifndef S_IRWXUGO
# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO)
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if @GNULIB_LSTAT@
# if ! @HAVE_LSTAT@
/* mingw does not support symlinks, therefore it does not have lstat. But
without links, stat does just fine. */
# define lstat stat
# elif @REPLACE_LSTAT@
# undef lstat
# define lstat rpl_lstat
extern int rpl_lstat (const char *name, struct stat *buf);
# endif
#elif defined GNULIB_POSIXCHECK
# undef lstat
# define lstat(p,b) \
(GL_LINK_WARNING ("lstat is unportable - " \
"use gnulib module lstat for portability"), \
lstat (p, b))
#endif
#if @REPLACE_MKDIR@
# undef mkdir
# define mkdir rpl_mkdir
extern int mkdir (char const *name, mode_t mode);
#else
/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
Additionally, it declares _mkdir (and depending on compile flags, an
alias mkdir), only in the nonstandard <io.h>, which is included above. */
# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
static inline int
rpl_mkdir (char const *name, mode_t mode)
{
return _mkdir (name);
}
# define mkdir rpl_mkdir
# endif
#endif
/* Declare BSD extensions. */
#if @GNULIB_LCHMOD@
/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
denotes a symbolic link. */
# if !@HAVE_LCHMOD@
/* The lchmod replacement follows symbolic links. Callers should take
this into account; lchmod should be applied only to arguments that
are known to not be symbolic links. On hosts that lack lchmod,
this can lead to race conditions between the check and the
invocation of lchmod, but we know of no workarounds that are
reliable in general. You might try requesting support for lchmod
from your operating system supplier. */
# define lchmod chmod
# endif
# if 0 /* assume already declared */
extern int lchmod (const char *filename, mode_t mode);
# endif
#elif defined GNULIB_POSIXCHECK
# undef lchmod
# define lchmod(f,m) \
(GL_LINK_WARNING ("lchmod is unportable - " \
"use gnulib module lchmod for portability"), \
lchmod (f, m))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_SYS_STAT_H */
#endif /* _GL_SYS_STAT_H */
#endif

View File

@ -1,64 +0,0 @@
/* Provide a more complete sys/time.h.
Copyright (C) 2007-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
#if defined _GL_SYS_TIME_H
/* Simply delegate to the system's header, without adding anything. */
# if @HAVE_SYS_TIME_H@
# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
# endif
#else
# define _GL_SYS_TIME_H
# if @HAVE_SYS_TIME_H@
# @INCLUDE_NEXT@ @NEXT_SYS_TIME_H@
# else
# include <time.h>
# endif
#ifdef __cplusplus
extern "C" {
#endif
# if ! @HAVE_STRUCT_TIMEVAL@
struct timeval
{
time_t tv_sec;
long int tv_usec;
};
# endif
# if @REPLACE_GETTIMEOFDAY@
# undef gettimeofday
# define gettimeofday rpl_gettimeofday
int gettimeofday (struct timeval *restrict, void *restrict);
# endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_SYS_TIME_H */

View File

@ -1,314 +0,0 @@
/* tempname.c - generate the name of a temporary file.
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
2000, 2001, 2002, 2003, 2005, 2006, 2007 Free Software Foundation,
Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Extracted from glibc sysdeps/posix/tempname.c. See also tmpdir.c. */
#if !_LIBC
# include <config.h>
# include "tempname.h"
#endif
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#ifndef __set_errno
# define __set_errno(Val) errno = (Val)
#endif
#include <stdio.h>
#ifndef P_tmpdir
# define P_tmpdir "/tmp"
#endif
#ifndef TMP_MAX
# define TMP_MAX 238328
#endif
#ifndef __GT_FILE
# define __GT_FILE 0
# define __GT_BIGFILE 1
# define __GT_DIR 2
# define __GT_NOCREATE 3
#endif
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/time.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/stat.h>
#if _LIBC
# define struct_stat64 struct stat64
# define small_open __open
# define large_open __open64
#else
# define struct_stat64 struct stat
# define small_open open
# define large_open open
# define __gen_tempname gen_tempname
# define __getpid getpid
# define __gettimeofday gettimeofday
# define __mkdir mkdir
# define __lxstat64(version, file, buf) lstat (file, buf)
# define __xstat64(version, file, buf) stat (file, buf)
#endif
#if ! (HAVE___SECURE_GETENV || _LIBC)
# define __secure_getenv getenv
#endif
#ifdef _LIBC
# include <hp-timing.h>
# if HP_TIMING_AVAIL
# define RANDOM_BITS(Var) \
if (__builtin_expect (value == UINT64_C (0), 0)) \
{ \
/* If this is the first time this function is used initialize \
the variable we accumulate the value in to some somewhat \
random value. If we'd not do this programs at startup time \
might have a reduced set of possible names, at least on slow \
machines. */ \
struct timeval tv; \
__gettimeofday (&tv, NULL); \
value = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; \
} \
HP_TIMING_NOW (Var)
# endif
#endif
/* Use the widest available unsigned type if uint64_t is not
available. The algorithm below extracts a number less than 62**6
(approximately 2**35.725) from uint64_t, so ancient hosts where
uintmax_t is only 32 bits lose about 3.725 bits of randomness,
which is better than not having mkstemp at all. */
#if !defined UINT64_MAX && !defined uint64_t
# define uint64_t uintmax_t
#endif
#if _LIBC
/* Return nonzero if DIR is an existent directory. */
static int
direxists (const char *dir)
{
struct_stat64 buf;
return __xstat64 (_STAT_VER, dir, &buf) == 0 && S_ISDIR (buf.st_mode);
}
/* Path search algorithm, for tmpnam, tmpfile, etc. If DIR is
non-null and exists, uses it; otherwise uses the first of $TMPDIR,
P_tmpdir, /tmp that exists. Copies into TMPL a template suitable
for use with mk[s]temp. Will fail (-1) if DIR is non-null and
doesn't exist, none of the searched dirs exists, or there's not
enough space in TMPL. */
int
__path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
int try_tmpdir)
{
const char *d;
size_t dlen, plen;
if (!pfx || !pfx[0])
{
pfx = "file";
plen = 4;
}
else
{
plen = strlen (pfx);
if (plen > 5)
plen = 5;
}
if (try_tmpdir)
{
d = __secure_getenv ("TMPDIR");
if (d != NULL && direxists (d))
dir = d;
else if (dir != NULL && direxists (dir))
/* nothing */ ;
else
dir = NULL;
}
if (dir == NULL)
{
if (direxists (P_tmpdir))
dir = P_tmpdir;
else if (strcmp (P_tmpdir, "/tmp") != 0 && direxists ("/tmp"))
dir = "/tmp";
else
{
__set_errno (ENOENT);
return -1;
}
}
dlen = strlen (dir);
while (dlen > 1 && dir[dlen - 1] == '/')
dlen--; /* remove trailing slashes */
/* check we have room for "${dir}/${pfx}XXXXXX\0" */
if (tmpl_len < dlen + 1 + plen + 6 + 1)
{
__set_errno (EINVAL);
return -1;
}
sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx);
return 0;
}
#endif /* _LIBC */
/* These are the characters used in temporary file names. */
static const char letters[] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
/* Generate a temporary file name based on TMPL. TMPL must match the
rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed
does not exist at the time of the call to __gen_tempname. TMPL is
overwritten with the result.
KIND may be one of:
__GT_NOCREATE: simply verify that the name does not exist
at the time of the call.
__GT_FILE: create the file using open(O_CREAT|O_EXCL)
and return a read-write fd. The file is mode 0600.
__GT_BIGFILE: same as __GT_FILE but use open64().
__GT_DIR: create a directory, which will be mode 0700.
We use a clever algorithm to get hard-to-predict names. */
int
__gen_tempname (char *tmpl, int kind)
{
int len;
char *XXXXXX;
static uint64_t value;
uint64_t random_time_bits;
unsigned int count;
int fd = -1;
int save_errno = errno;
struct_stat64 st;
/* A lower bound on the number of temporary files to attempt to
generate. The maximum total number of temporary file names that
can exist for a given template is 62**6. It should never be
necessary to try all these combinations. Instead if a reasonable
number of names is tried (we define reasonable as 62**3) fail to
give the system administrator the chance to remove the problems. */
#define ATTEMPTS_MIN (62 * 62 * 62)
/* The number of times to attempt to generate a temporary file. To
conform to POSIX, this must be no smaller than TMP_MAX. */
#if ATTEMPTS_MIN < TMP_MAX
unsigned int attempts = TMP_MAX;
#else
unsigned int attempts = ATTEMPTS_MIN;
#endif
len = strlen (tmpl);
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
{
__set_errno (EINVAL);
return -1;
}
/* This is where the Xs start. */
XXXXXX = &tmpl[len - 6];
/* Get some more or less random data. */
#ifdef RANDOM_BITS
RANDOM_BITS (random_time_bits);
#else
{
struct timeval tv;
__gettimeofday (&tv, NULL);
random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;
}
#endif
value += random_time_bits ^ __getpid ();
for (count = 0; count < attempts; value += 7777, ++count)
{
uint64_t v = value;
/* Fill in the random bits. */
XXXXXX[0] = letters[v % 62];
v /= 62;
XXXXXX[1] = letters[v % 62];
v /= 62;
XXXXXX[2] = letters[v % 62];
v /= 62;
XXXXXX[3] = letters[v % 62];
v /= 62;
XXXXXX[4] = letters[v % 62];
v /= 62;
XXXXXX[5] = letters[v % 62];
switch (kind)
{
case __GT_FILE:
fd = small_open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
break;
case __GT_BIGFILE:
fd = large_open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
break;
case __GT_DIR:
fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
break;
case __GT_NOCREATE:
/* This case is backward from the other three. __gen_tempname
succeeds if __xstat fails because the name does not exist.
Note the continue to bypass the common logic at the bottom
of the loop. */
if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
{
if (errno == ENOENT)
{
__set_errno (save_errno);
return 0;
}
else
/* Give up now. */
return -1;
}
continue;
default:
assert (! "invalid KIND in __gen_tempname");
}
if (fd >= 0)
{
__set_errno (save_errno);
return fd;
}
else if (errno != EEXIST)
return -1;
}
/* We got out of the loop because we ran out of combinations to try. */
__set_errno (EEXIST);
return -1;
}

View File

@ -1,39 +0,0 @@
/* Create a temporary file or directory.
Copyright (C) 2006 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* header written by Eric Blake */
/* In gnulib, always prefer large files. GT_FILE maps to
__GT_BIGFILE, not __GT_FILE, for a reason. */
#define GT_FILE 1
#define GT_DIR 2
#define GT_NOCREATE 3
/* Generate a temporary file name based on TMPL. TMPL must match the
rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed
does not exist at the time of the call to gen_tempname. TMPL is
overwritten with the result.
KIND may be one of:
GT_NOCREATE: simply verify that the name does not exist
at the time of the call.
GT_FILE: create a large file using open(O_CREAT|O_EXCL)
and return a read-write fd. The file is mode 0600.
GT_DIR: create a directory, which will be mode 0700.
We use a clever algorithm to get hard-to-predict names. */
extern int gen_tempname (char *tmpl, int kind);

View File

@ -1,118 +0,0 @@
/* A more-standard <time.h>.
Copyright (C) 2007-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
/* Don't get in the way of glibc when it includes time.h merely to
declare a few standard symbols, rather than to declare all the
symbols. Also, Solaris 8 <time.h> eventually includes itself
recursively; if that is happening, just include the system <time.h>
without adding our own declarations. */
#if (defined __need_time_t || defined __need_clock_t \
|| defined __need_timespec \
|| defined _GL_TIME_H)
# @INCLUDE_NEXT@ @NEXT_TIME_H@
#else
# define _GL_TIME_H
# @INCLUDE_NEXT@ @NEXT_TIME_H@
# ifdef __cplusplus
extern "C" {
# endif
/* Some systems don't define struct timespec (e.g., AIX 4.1, Ultrix 4.3).
Or they define it with the wrong member names or define it in <sys/time.h>
(e.g., FreeBSD circa 1997). */
# if ! @TIME_H_DEFINES_STRUCT_TIMESPEC@
# if @SYS_TIME_H_DEFINES_STRUCT_TIMESPEC@
# include <sys/time.h>
# else
# undef timespec
# define timespec rpl_timespec
struct timespec
{
time_t tv_sec;
long int tv_nsec;
};
# endif
# endif
/* Sleep for at least RQTP seconds unless interrupted, If interrupted,
return -1 and store the remaining time into RMTP. See
<http://www.opengroup.org/susv3xsh/nanosleep.html>. */
# if @REPLACE_NANOSLEEP@
# define nanosleep rpl_nanosleep
int nanosleep (struct timespec const *__rqtp, struct timespec *__rmtp);
# endif
/* Convert TIMER to RESULT, assuming local time and UTC respectively. See
<http://www.opengroup.org/susv3xsh/localtime_r.html> and
<http://www.opengroup.org/susv3xsh/gmtime_r.html>. */
# if @REPLACE_LOCALTIME_R@
# undef localtime_r
# define localtime_r rpl_localtime_r
# undef gmtime_r
# define gmtime_r rpl_gmtime_r
struct tm *localtime_r (time_t const *restrict __timer,
struct tm *restrict __result);
struct tm *gmtime_r (time_t const *restrict __timer,
struct tm *restrict __result);
# endif
/* Parse BUF as a time stamp, assuming FORMAT specifies its layout, and store
the resulting broken-down time into TM. See
<http://www.opengroup.org/susv3xsh/strptime.html>. */
# if @REPLACE_STRPTIME@
# undef strptime
# define strptime rpl_strptime
char *strptime (char const *restrict __buf, char const *restrict __format,
struct tm *restrict __tm);
# endif
/* Convert TM to a time_t value, assuming UTC. */
# if @REPLACE_TIMEGM@
# undef timegm
# define timegm rpl_timegm
time_t timegm (struct tm *__tm);
# endif
/* Encourage applications to avoid unsafe functions that can overrun
buffers when given outlandish struct tm values. Portable
applications should use strftime (or even sprintf) instead. */
# if GNULIB_PORTCHECK
# undef asctime
# define asctime eschew_asctime
# undef asctime_r
# define asctime_r eschew_asctime_r
# undef ctime
# define ctime eschew_ctime
# undef ctime_r
# define ctime_r eschew_ctime_r
# endif
# ifdef __cplusplus
}
# endif
#endif

View File

@ -1,47 +0,0 @@
/* Reentrant time functions like localtime_r.
Copyright (C) 2003, 2006, 2007 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Paul Eggert. */
#include <config.h>
#include <time.h>
#include <string.h>
static struct tm *
copy_tm_result (struct tm *dest, struct tm const *src)
{
if (! src)
return 0;
*dest = *src;
return dest;
}
struct tm *
gmtime_r (time_t const * restrict t, struct tm * restrict tp)
{
return copy_tm_result (tp, gmtime (t));
}
struct tm *
localtime_r (time_t const * restrict t, struct tm * restrict tp)
{
return copy_tm_result (tp, localtime (t));
}

View File

@ -1,582 +0,0 @@
/* Substitute for and wrapper around <unistd.h>.
Copyright (C) 2003-2009 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _GL_UNISTD_H
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
/* The include_next requires a split double-inclusion guard. */
#if @HAVE_UNISTD_H@
# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
#endif
#ifndef _GL_UNISTD_H
#define _GL_UNISTD_H
/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
#if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET)
# include <stdio.h>
#endif
/* mingw fails to declare _exit in <unistd.h>. */
/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
#include <stdlib.h>
#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
/* Get ssize_t. */
# include <sys/types.h>
#endif
#if @GNULIB_GETHOSTNAME@
/* Get all possible declarations of gethostname(). */
# if @UNISTD_H_HAVE_WINSOCK2_H@
# include <winsock2.h>
# if !defined _GL_SYS_SOCKET_H
# undef socket
# define socket socket_used_without_including_sys_socket_h
# undef connect
# define connect connect_used_without_including_sys_socket_h
# undef accept
# define accept accept_used_without_including_sys_socket_h
# undef bind
# define bind bind_used_without_including_sys_socket_h
# undef getpeername
# define getpeername getpeername_used_without_including_sys_socket_h
# undef getsockname
# define getsockname getsockname_used_without_including_sys_socket_h
# undef getsockopt
# define getsockopt getsockopt_used_without_including_sys_socket_h
# undef listen
# define listen listen_used_without_including_sys_socket_h
# undef recv
# define recv recv_used_without_including_sys_socket_h
# undef send
# define send send_used_without_including_sys_socket_h
# undef recvfrom
# define recvfrom recvfrom_used_without_including_sys_socket_h
# undef sendto
# define sendto sendto_used_without_including_sys_socket_h
# undef setsockopt
# define setsockopt setsockopt_used_without_including_sys_socket_h
# undef shutdown
# define shutdown shutdown_used_without_including_sys_socket_h
# endif
# if !defined _GL_SYS_SELECT_H
# undef select
# define select select_used_without_including_sys_select_h
# endif
# endif
#endif
/* The definition of GL_LINK_WARNING is copied here. */
/* OS/2 EMX lacks these macros. */
#ifndef STDIN_FILENO
# define STDIN_FILENO 0
#endif
#ifndef STDOUT_FILENO
# define STDOUT_FILENO 1
#endif
#ifndef STDERR_FILENO
# define STDERR_FILENO 2
#endif
/* Declare overridden functions. */
#ifdef __cplusplus
extern "C" {
#endif
#if @GNULIB_CHOWN@
# if @REPLACE_CHOWN@
# ifndef REPLACE_CHOWN
# define REPLACE_CHOWN 1
# endif
# if REPLACE_CHOWN
/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
to GID (if GID is not -1). Follow symbolic links.
Return 0 if successful, otherwise -1 and errno set.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/chown.html>. */
# define chown rpl_chown
extern int chown (const char *file, uid_t uid, gid_t gid);
# endif
# endif
#elif defined GNULIB_POSIXCHECK
# undef chown
# define chown(f,u,g) \
(GL_LINK_WARNING ("chown fails to follow symlinks on some systems and " \
"doesn't treat a uid or gid of -1 on some systems - " \
"use gnulib module chown for portability"), \
chown (f, u, g))
#endif
#if @GNULIB_CLOSE@
# if @UNISTD_H_HAVE_WINSOCK2_H@
/* Need a gnulib internal function. */
# define HAVE__GL_CLOSE_FD_MAYBE_SOCKET 1
# endif
# if @REPLACE_CLOSE@
/* Automatically included by modules that need a replacement for close. */
# undef close
# define close rpl_close
extern int close (int);
# endif
#elif @UNISTD_H_HAVE_WINSOCK2_H@
# undef close
# define close close_used_without_requesting_gnulib_module_close
#elif defined GNULIB_POSIXCHECK
# undef close
# define close(f) \
(GL_LINK_WARNING ("close does not portably work on sockets - " \
"use gnulib module close for portability"), \
close (f))
#endif
#if @GNULIB_DUP2@
# if !@HAVE_DUP2@
/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
NEWFD = OLDFD, otherwise close NEWFD first if it is open.
Return 0 if successful, otherwise -1 and errno set.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/dup2.html>. */
extern int dup2 (int oldfd, int newfd);
# endif
#elif defined GNULIB_POSIXCHECK
# undef dup2
# define dup2(o,n) \
(GL_LINK_WARNING ("dup2 is unportable - " \
"use gnulib module dup2 for portability"), \
dup2 (o, n))
#endif
#if @GNULIB_ENVIRON@
# if !@HAVE_DECL_ENVIRON@
/* Set of environment variables and values. An array of strings of the form
"VARIABLE=VALUE", terminated with a NULL. */
# if defined __APPLE__ && defined __MACH__
# include <crt_externs.h>
# define environ (*_NSGetEnviron ())
# else
extern char **environ;
# endif
# endif
#elif defined GNULIB_POSIXCHECK
# undef environ
# define environ \
(GL_LINK_WARNING ("environ is unportable - " \
"use gnulib module environ for portability"), \
environ)
#endif
#if @GNULIB_EUIDACCESS@
# if !@HAVE_EUIDACCESS@
/* Like access(), except that is uses the effective user id and group id of
the current process. */
extern int euidaccess (const char *filename, int mode);
# endif
#elif defined GNULIB_POSIXCHECK
# undef euidaccess
# define euidaccess(f,m) \
(GL_LINK_WARNING ("euidaccess is unportable - " \
"use gnulib module euidaccess for portability"), \
euidaccess (f, m))
#endif
#if @GNULIB_FCHDIR@
# if @REPLACE_FCHDIR@
/* Change the process' current working directory to the directory on which
the given file descriptor is open.
Return 0 if successful, otherwise -1 and errno set.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/fchdir.html>. */
extern int fchdir (int /*fd*/);
# define dup rpl_dup
extern int dup (int);
# define dup2 rpl_dup2
extern int dup2 (int, int);
# endif
#elif defined GNULIB_POSIXCHECK
# undef fchdir
# define fchdir(f) \
(GL_LINK_WARNING ("fchdir is unportable - " \
"use gnulib module fchdir for portability"), \
fchdir (f))
#endif
#if @GNULIB_FSYNC@
/* Synchronize changes to a file.
Return 0 if successful, otherwise -1 and errno set.
See POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/fsync.html>. */
# if !@HAVE_FSYNC@
extern int fsync (int fd);
# endif
#elif defined GNULIB_POSIXCHECK
# undef fsync
# define fsync(fd) \
(GL_LINK_WARNING ("fsync is unportable - " \
"use gnulib module fsync for portability"), \
fsync (fd))
#endif
#if @GNULIB_FTRUNCATE@
# if !@HAVE_FTRUNCATE@
/* Change the size of the file to which FD is opened to become equal to LENGTH.
Return 0 if successful, otherwise -1 and errno set.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/ftruncate.html>. */
extern int ftruncate (int fd, off_t length);
# endif
#elif defined GNULIB_POSIXCHECK
# undef ftruncate
# define ftruncate(f,l) \
(GL_LINK_WARNING ("ftruncate is unportable - " \
"use gnulib module ftruncate for portability"), \
ftruncate (f, l))
#endif
#if @GNULIB_GETCWD@
/* Include the headers that might declare getcwd so that they will not
cause confusion if included after this file. */
# include <stdlib.h>
# if @REPLACE_GETCWD@
/* Get the name of the current working directory, and put it in SIZE bytes
of BUF.
Return BUF if successful, or NULL if the directory couldn't be determined
or SIZE was too small.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/getcwd.html>.
Additionally, the gnulib module 'getcwd' guarantees the following GNU
extension: If BUF is NULL, an array is allocated with 'malloc'; the array
is SIZE bytes long, unless SIZE == 0, in which case it is as big as
necessary. */
# define getcwd rpl_getcwd
extern char * getcwd (char *buf, size_t size);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getcwd
# define getcwd(b,s) \
(GL_LINK_WARNING ("getcwd is unportable - " \
"use gnulib module getcwd for portability"), \
getcwd (b, s))
#endif
#if @GNULIB_GETDOMAINNAME@
/* Return the NIS domain name of the machine.
WARNING! The NIS domain name is unrelated to the fully qualified host name
of the machine. It is also unrelated to email addresses.
WARNING! The NIS domain name is usually the empty string or "(none)" when
not using NIS.
Put up to LEN bytes of the NIS domain name into NAME.
Null terminate it if the name is shorter than LEN.
If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
Return 0 if successful, otherwise set errno and return -1. */
# if !@HAVE_GETDOMAINNAME@
extern int getdomainname(char *name, size_t len);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getdomainname
# define getdomainname(n,l) \
(GL_LINK_WARNING ("getdomainname is unportable - " \
"use gnulib module getdomainname for portability"), \
getdomainname (n, l))
#endif
#if @GNULIB_GETDTABLESIZE@
# if !@HAVE_GETDTABLESIZE@
/* Return the maximum number of file descriptors in the current process. */
extern int getdtablesize (void);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getdtablesize
# define getdtablesize() \
(GL_LINK_WARNING ("getdtablesize is unportable - " \
"use gnulib module getdtablesize for portability"), \
getdtablesize ())
#endif
#if @GNULIB_GETHOSTNAME@
/* Return the standard host name of the machine.
WARNING! The host name may or may not be fully qualified.
Put up to LEN bytes of the host name into NAME.
Null terminate it if the name is shorter than LEN.
If the host name is longer than LEN, set errno = EINVAL and return -1.
Return 0 if successful, otherwise set errno and return -1. */
# if @UNISTD_H_HAVE_WINSOCK2_H@
# undef gethostname
# define gethostname rpl_gethostname
# endif
# if @UNISTD_H_HAVE_WINSOCK2_H@ || !@HAVE_GETHOSTNAME@
extern int gethostname(char *name, size_t len);
# endif
#elif @UNISTD_H_HAVE_WINSOCK2_H@
# undef gethostname
# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
#elif defined GNULIB_POSIXCHECK
# undef gethostname
# define gethostname(n,l) \
(GL_LINK_WARNING ("gethostname is unportable - " \
"use gnulib module gethostname for portability"), \
gethostname (n, l))
#endif
#if @GNULIB_GETLOGIN_R@
/* Copies the user's login name to NAME.
The array pointed to by NAME has room for SIZE bytes.
Returns 0 if successful. Upon error, an error number is returned, or -1 in
the case that the login name cannot be found but no specific error is
provided (this case is hopefully rare but is left open by the POSIX spec).
See <http://www.opengroup.org/susv3xsh/getlogin.html>.
*/
# if !@HAVE_DECL_GETLOGIN_R@
# include <stddef.h>
extern int getlogin_r (char *name, size_t size);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getlogin_r
# define getlogin_r(n,s) \
(GL_LINK_WARNING ("getlogin_r is unportable - " \
"use gnulib module getlogin_r for portability"), \
getlogin_r (n, s))
#endif
#if @GNULIB_GETPAGESIZE@
# if @REPLACE_GETPAGESIZE@
# define getpagesize rpl_getpagesize
extern int getpagesize (void);
# elif !@HAVE_GETPAGESIZE@
/* This is for POSIX systems. */
# if !defined getpagesize && defined _SC_PAGESIZE
# if ! (defined __VMS && __VMS_VER < 70000000)
# define getpagesize() sysconf (_SC_PAGESIZE)
# endif
# endif
/* This is for older VMS. */
# if !defined getpagesize && defined __VMS
# ifdef __ALPHA
# define getpagesize() 8192
# else
# define getpagesize() 512
# endif
# endif
/* This is for BeOS. */
# if !defined getpagesize && @HAVE_OS_H@
# include <OS.h>
# if defined B_PAGE_SIZE
# define getpagesize() B_PAGE_SIZE
# endif
# endif
/* This is for AmigaOS4.0. */
# if !defined getpagesize && defined __amigaos4__
# define getpagesize() 2048
# endif
/* This is for older Unix systems. */
# if !defined getpagesize && @HAVE_SYS_PARAM_H@
# include <sys/param.h>
# ifdef EXEC_PAGESIZE
# define getpagesize() EXEC_PAGESIZE
# else
# ifdef NBPG
# ifndef CLSIZE
# define CLSIZE 1
# endif
# define getpagesize() (NBPG * CLSIZE)
# else
# ifdef NBPC
# define getpagesize() NBPC
# endif
# endif
# endif
# endif
# endif
#elif defined GNULIB_POSIXCHECK
# undef getpagesize
# define getpagesize() \
(GL_LINK_WARNING ("getpagesize is unportable - " \
"use gnulib module getpagesize for portability"), \
getpagesize ())
#endif
#if @GNULIB_GETUSERSHELL@
# if !@HAVE_GETUSERSHELL@
/* Return the next valid login shell on the system, or NULL when the end of
the list has been reached. */
extern char *getusershell (void);
/* Rewind to pointer that is advanced at each getusershell() call. */
extern void setusershell (void);
/* Free the pointer that is advanced at each getusershell() call and
associated resources. */
extern void endusershell (void);
# endif
#elif defined GNULIB_POSIXCHECK
# undef getusershell
# define getusershell() \
(GL_LINK_WARNING ("getusershell is unportable - " \
"use gnulib module getusershell for portability"), \
getusershell ())
# undef setusershell
# define setusershell() \
(GL_LINK_WARNING ("setusershell is unportable - " \
"use gnulib module getusershell for portability"), \
setusershell ())
# undef endusershell
# define endusershell() \
(GL_LINK_WARNING ("endusershell is unportable - " \
"use gnulib module getusershell for portability"), \
endusershell ())
#endif
#if @GNULIB_LCHOWN@
# if @REPLACE_LCHOWN@
/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
to GID (if GID is not -1). Do not follow symbolic links.
Return 0 if successful, otherwise -1 and errno set.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/lchown.html>. */
# define lchown rpl_lchown
extern int lchown (char const *file, uid_t owner, gid_t group);
# endif
#elif defined GNULIB_POSIXCHECK
# undef lchown
# define lchown(f,u,g) \
(GL_LINK_WARNING ("lchown is unportable to pre-POSIX.1-2001 " \
"systems - use gnulib module lchown for portability"), \
lchown (f, u, g))
#endif
#if @GNULIB_LINK@
/* Create a new hard link for an existing file.
Return 0 if successful, otherwise -1 and errno set.
See POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/link.html>. */
# if !@HAVE_LINK@
extern int link (const char *path1, const char *path2);
# endif
#elif defined GNULIB_POSIXCHECK
# undef link
# define link(path1,path2) \
(GL_LINK_WARNING ("link is unportable - " \
"use gnulib module link for portability"), \
link (path1, path2))
#endif
#if @GNULIB_LSEEK@
# if @REPLACE_LSEEK@
/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
Return the new offset if successful, otherwise -1 and errno set.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/lseek.html>. */
# define lseek rpl_lseek
extern off_t lseek (int fd, off_t offset, int whence);
# endif
#elif defined GNULIB_POSIXCHECK
# undef lseek
# define lseek(f,o,w) \
(GL_LINK_WARNING ("lseek does not fail with ESPIPE on pipes on some " \
"systems - use gnulib module lseek for portability"), \
lseek (f, o, w))
#endif
#if @GNULIB_READLINK@
/* Read the contents of the symbolic link FILE and place the first BUFSIZE
bytes of it into BUF. Return the number of bytes placed into BUF if
successful, otherwise -1 and errno set.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/readlink.html>. */
# if !@HAVE_READLINK@
# include <stddef.h>
extern int readlink (const char *file, char *buf, size_t bufsize);
# endif
#elif defined GNULIB_POSIXCHECK
# undef readlink
# define readlink(f,b,s) \
(GL_LINK_WARNING ("readlink is unportable - " \
"use gnulib module readlink for portability"), \
readlink (f, b, s))
#endif
#if @GNULIB_SLEEP@
/* Pause the execution of the current thread for N seconds.
Returns the number of seconds left to sleep.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/sleep.html>. */
# if !@HAVE_SLEEP@
extern unsigned int sleep (unsigned int n);
# endif
#elif defined GNULIB_POSIXCHECK
# undef sleep
# define sleep(n) \
(GL_LINK_WARNING ("sleep is unportable - " \
"use gnulib module sleep for portability"), \
sleep (n))
#endif
#if @GNULIB_WRITE@ && @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
/* Write up to COUNT bytes starting at BUF to file descriptor FD.
See the POSIX:2001 specification
<http://www.opengroup.org/susv3xsh/write.html>. */
# undef write
# define write rpl_write
extern ssize_t write (int fd, const void *buf, size_t count);
#endif
#ifdef FCHDIR_REPLACEMENT
/* gnulib internal function. */
extern void _gl_unregister_fd (int fd);
#endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_UNISTD_H */
#endif /* _GL_UNISTD_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,81 +0,0 @@
/* vsprintf with automatic memory allocation.
Copyright (C) 2002-2004, 2007-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _VASNPRINTF_H
#define _VASNPRINTF_H
/* Get va_list. */
#include <stdarg.h>
/* Get size_t. */
#include <stddef.h>
#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
/* The __-protected variants of `format' and `printf' attributes
are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
# define __format__ format
# define __printf__ printf
# endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Write formatted output to a string dynamically allocated with malloc().
You can pass a preallocated buffer for the result in RESULTBUF and its
size in *LENGTHP; otherwise you pass RESULTBUF = NULL.
If successful, return the address of the string (this may be = RESULTBUF
if no dynamic memory allocation was necessary) and set *LENGTHP to the
number of resulting bytes, excluding the trailing NUL. Upon error, set
errno and return NULL.
When dynamic memory allocation occurs, the preallocated buffer is left
alone (with possibly modified contents). This makes it possible to use
a statically allocated or stack-allocated buffer, like this:
char buf[100];
size_t len = sizeof (buf);
char *output = vasnprintf (buf, &len, format, args);
if (output == NULL)
... error handling ...;
else
{
... use the output string ...;
if (output != buf)
free (output);
}
*/
#if REPLACE_VASNPRINTF
# define asnprintf rpl_asnprintf
# define vasnprintf rpl_vasnprintf
#endif
extern char * asnprintf (char *resultbuf, size_t *lengthp, const char *format, ...)
__attribute__ ((__format__ (__printf__, 3, 4)));
extern char * vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args)
__attribute__ ((__format__ (__printf__, 3, 0)));
#ifdef __cplusplus
}
#endif
#endif /* _VASNPRINTF_H */

View File

@ -1,51 +0,0 @@
/* Formatted output to strings.
Copyright (C) 1999, 2002, 2006-2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#include <config.h>
/* Specification. */
#ifdef IN_LIBASPRINTF
# include "vasprintf.h"
#else
# include <stdio.h>
#endif
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include "vasnprintf.h"
int
vasprintf (char **resultp, const char *format, va_list args)
{
size_t length;
char *result = vasnprintf (NULL, &length, format, args);
if (result == NULL)
return -1;
if (length > INT_MAX)
{
free (result);
errno = EOVERFLOW;
return -1;
}
*resultp = result;
/* Return the number of resulting bytes, excluding the trailing NUL. */
return length;
}

View File

@ -1,140 +0,0 @@
/* Compile-time assert-like macros.
Copyright (C) 2005, 2006 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paul Eggert, Bruno Haible, and Jim Meyering. */
#ifndef VERIFY_H
# define VERIFY_H 1
/* Each of these macros verifies that its argument R is nonzero. To
be portable, R should be an integer constant expression. Unlike
assert (R), there is no run-time overhead.
There are two macros, since no single macro can be used in all
contexts in C. verify_true (R) is for scalar contexts, including
integer constant expression contexts. verify (R) is for declaration
contexts, e.g., the top level.
Symbols ending in "__" are private to this header.
The code below uses several ideas.
* The first step is ((R) ? 1 : -1). Given an expression R, of
integral or boolean or floating-point type, this yields an
expression of integral type, whose value is later verified to be
constant and nonnegative.
* Next this expression W is wrapped in a type
struct verify_type__ { unsigned int verify_error_if_negative_size__: W; }.
If W is negative, this yields a compile-time error. No compiler can
deal with a bit-field of negative size.
One might think that an array size check would have the same
effect, that is, that the type struct { unsigned int dummy[W]; }
would work as well. However, inside a function, some compilers
(such as C++ compilers and GNU C) allow local parameters and
variables inside array size expressions. With these compilers,
an array size check would not properly diagnose this misuse of
the verify macro:
void function (int n) { verify (n < 0); }
* For the verify macro, the struct verify_type__ will need to
somehow be embedded into a declaration. To be portable, this
declaration must declare an object, a constant, a function, or a
typedef name. If the declared entity uses the type directly,
such as in
struct dummy {...};
typedef struct {...} dummy;
extern struct {...} *dummy;
extern void dummy (struct {...} *);
extern struct {...} *dummy (void);
two uses of the verify macro would yield colliding declarations
if the entity names are not disambiguated. A workaround is to
attach the current line number to the entity name:
#define GL_CONCAT0(x, y) x##y
#define GL_CONCAT(x, y) GL_CONCAT0 (x, y)
extern struct {...} * GL_CONCAT(dummy,__LINE__);
But this has the problem that two invocations of verify from
within the same macro would collide, since the __LINE__ value
would be the same for both invocations.
A solution is to use the sizeof operator. It yields a number,
getting rid of the identity of the type. Declarations like
extern int dummy [sizeof (struct {...})];
extern void dummy (int [sizeof (struct {...})]);
extern int (*dummy (void)) [sizeof (struct {...})];
can be repeated.
* Should the implementation use a named struct or an unnamed struct?
Which of the following alternatives can be used?
extern int dummy [sizeof (struct {...})];
extern int dummy [sizeof (struct verify_type__ {...})];
extern void dummy (int [sizeof (struct {...})]);
extern void dummy (int [sizeof (struct verify_type__ {...})]);
extern int (*dummy (void)) [sizeof (struct {...})];
extern int (*dummy (void)) [sizeof (struct verify_type__ {...})];
In the second and sixth case, the struct type is exported to the
outer scope; two such declarations therefore collide. GCC warns
about the first, third, and fourth cases. So the only remaining
possibility is the fifth case:
extern int (*dummy (void)) [sizeof (struct {...})];
* This implementation exploits the fact that GCC does not warn about
the last declaration mentioned above. If a future version of GCC
introduces a warning for this, the problem could be worked around
by using code specialized to GCC, e.g.,:
#if 4 <= __GNUC__
# define verify(R) \
extern int (* verify_function__ (void)) \
[__builtin_constant_p (R) && (R) ? 1 : -1]
#endif
* In C++, any struct definition inside sizeof is invalid.
Use a template type to work around the problem. */
/* Verify requirement R at compile-time, as an integer constant expression.
Return 1. */
# ifdef __cplusplus
template <int w>
struct verify_type__ { unsigned int verify_error_if_negative_size__: w; };
# define verify_true(R) \
(!!sizeof (verify_type__<(R) ? 1 : -1>))
# else
# define verify_true(R) \
(!!sizeof \
(struct { unsigned int verify_error_if_negative_size__: (R) ? 1 : -1; }))
# endif
/* Verify requirement R at compile-time, as a declaration without a
trailing ';'. */
# define verify(R) extern int (* verify_function__ (void)) [verify_true (R)]
#endif

View File

@ -1,62 +0,0 @@
/* w32sock.h --- internal auxilliary functions for Windows socket functions
Copyright (C) 2008 Free Software Foundation, Inc.
This program 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.1 of the License, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Paolo Bonzini */
#include <errno.h>
/* Get O_RDWR and O_BINARY. */
#include <fcntl.h>
/* Get _get_osfhandle() and _open_osfhandle(). */
#include <io.h>
#define FD_TO_SOCKET(fd) ((SOCKET) _get_osfhandle ((fd)))
#define SOCKET_TO_FD(fh) (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
static inline void
set_winsock_errno (void)
{
int err = WSAGetLastError ();
WSASetLastError (0);
/* Map some WSAE* errors to the runtime library's error codes. */
switch (err)
{
case WSA_INVALID_HANDLE:
errno = EBADF;
break;
case WSA_NOT_ENOUGH_MEMORY:
errno = ENOMEM;
break;
case WSA_INVALID_PARAMETER:
errno = EINVAL;
break;
case WSAEWOULDBLOCK:
errno = EWOULDBLOCK;
break;
case WSAENAMETOOLONG:
errno = ENAMETOOLONG;
break;
case WSAENOTEMPTY:
errno = ENOTEMPTY;
break;
default:
errno = (err > 10000 && err < 10025) ? err - 10000 : err;
break;
}
}

View File

@ -1,306 +0,0 @@
/* A substitute for ISO C99 <wchar.h>, for platforms that have issues.
Copyright (C) 2007-2009 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
/* Written by Eric Blake. */
/*
* ISO C 99 <wchar.h> for platforms that have issues.
* <http://www.opengroup.org/susv3xbd/wchar.h.html>
*
* For now, this just ensures proper prerequisite inclusion order and
* the declaration of wcwidth().
*/
#if __GNUC__ >= 3
@PRAGMA_SYSTEM_HEADER@
#endif
#if defined __need_mbstate_t || (defined __hpux && ((defined _INTTYPES_INCLUDED && !defined strtoimax) || defined _GL_JUST_INCLUDE_SYSTEM_WCHAR_H)) || defined _GL_ALREADY_INCLUDING_WCHAR_H
/* Special invocation convention:
- Inside uClibc header files.
- On HP-UX 11.00 we have a sequence of nested includes
<wchar.h> -> <stdlib.h> -> <stdint.h>, and the latter includes <wchar.h>,
once indirectly <stdint.h> -> <sys/types.h> -> <inttypes.h> -> <wchar.h>
and once directly. In both situations 'wint_t' is not yet defined,
therefore we cannot provide the function overrides; instead include only
the system's <wchar.h>.
- On IRIX 6.5, similarly, we have an include <wchar.h> -> <wctype.h>, and
the latter includes <wchar.h>. But here, we have no way to detect whether
<wctype.h> is completely included or is still being included. */
#@INCLUDE_NEXT@ @NEXT_WCHAR_H@
#else
/* Normal invocation convention. */
#ifndef _GL_WCHAR_H
#define _GL_ALREADY_INCLUDING_WCHAR_H
/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
<wchar.h>.
BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
included before <wchar.h>. */
#include <stddef.h>
#include <stdio.h>
#include <time.h>
/* Include the original <wchar.h> if it exists.
Some builds of uClibc lack it. */
/* The include_next requires a split double-inclusion guard. */
#if @HAVE_WCHAR_H@
# @INCLUDE_NEXT@ @NEXT_WCHAR_H@
#endif
#undef _GL_ALREADY_INCLUDING_WCHAR_H
#ifndef _GL_WCHAR_H
#define _GL_WCHAR_H
/* The definition of GL_LINK_WARNING is copied here. */
#ifdef __cplusplus
extern "C" {
#endif
/* Define wint_t. (Also done in wctype.in.h.) */
#if !@HAVE_WINT_T@ && !defined wint_t
# define wint_t int
# ifndef WEOF
# define WEOF -1
# endif
#endif
/* Override mbstate_t if it is too small.
On IRIX 6.5, sizeof (mbstate_t) == 1, which is not sufficient for
implementing mbrtowc for encodings like UTF-8. */
#if !(@HAVE_MBSINIT@ && @HAVE_MBRTOWC@) || @REPLACE_MBSTATE_T@
typedef int rpl_mbstate_t;
# undef mbstate_t
# define mbstate_t rpl_mbstate_t
# define GNULIB_defined_mbstate_t 1
#endif
/* Convert a single-byte character to a wide character. */
#if @GNULIB_BTOWC@
# if @REPLACE_BTOWC@
# undef btowc
# define btowc rpl_btowc
# endif
# if !@HAVE_BTOWC@ || @REPLACE_BTOWC@
extern wint_t btowc (int c);
# endif
#elif defined GNULIB_POSIXCHECK
# undef btowc
# define btowc(c) \
(GL_LINK_WARNING ("btowc is unportable - " \
"use gnulib module btowc for portability"), \
btowc (c))
#endif
/* Convert a wide character to a single-byte character. */
#if @GNULIB_WCTOB@
# if @REPLACE_WCTOB@
# undef wctob
# define wctob rpl_wctob
# endif
# if (!defined wctob && !@HAVE_DECL_WCTOB@) || @REPLACE_WCTOB@
/* wctob is provided by gnulib, or wctob exists but is not declared. */
extern int wctob (wint_t wc);
# endif
#elif defined GNULIB_POSIXCHECK
# undef wctob
# define wctob(w) \
(GL_LINK_WARNING ("wctob is unportable - " \
"use gnulib module wctob for portability"), \
wctob (w))
#endif
/* Test whether *PS is in the initial state. */
#if @GNULIB_MBSINIT@
# if @REPLACE_MBSINIT@
# undef mbsinit
# define mbsinit rpl_mbsinit
# endif
# if !@HAVE_MBSINIT@ || @REPLACE_MBSINIT@
extern int mbsinit (const mbstate_t *ps);
# endif
#elif defined GNULIB_POSIXCHECK
# undef mbsinit
# define mbsinit(p) \
(GL_LINK_WARNING ("mbsinit is unportable - " \
"use gnulib module mbsinit for portability"), \
mbsinit (p))
#endif
/* Convert a multibyte character to a wide character. */
#if @GNULIB_MBRTOWC@
# if @REPLACE_MBRTOWC@
# undef mbrtowc
# define mbrtowc rpl_mbrtowc
# endif
# if !@HAVE_MBRTOWC@ || @REPLACE_MBRTOWC@
extern size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
# endif
#elif defined GNULIB_POSIXCHECK
# undef mbrtowc
# define mbrtowc(w,s,n,p) \
(GL_LINK_WARNING ("mbrtowc is unportable - " \
"use gnulib module mbrtowc for portability"), \
mbrtowc (w, s, n, p))
#endif
/* Recognize a multibyte character. */
#if @GNULIB_MBRLEN@
# if @REPLACE_MBRLEN@
# undef mbrlen
# define mbrlen rpl_mbrlen
# endif
# if !@HAVE_MBRLEN@ || @REPLACE_MBRLEN@
extern size_t mbrlen (const char *s, size_t n, mbstate_t *ps);
# endif
#elif defined GNULIB_POSIXCHECK
# undef mbrlen
# define mbrlen(s,n,p) \
(GL_LINK_WARNING ("mbrlen is unportable - " \
"use gnulib module mbrlen for portability"), \
mbrlen (s, n, p))
#endif
/* Convert a string to a wide string. */
#if @GNULIB_MBSRTOWCS@
# if @REPLACE_MBSRTOWCS@
# undef mbsrtowcs
# define mbsrtowcs rpl_mbsrtowcs
# endif
# if !@HAVE_MBSRTOWCS@ || @REPLACE_MBSRTOWCS@
extern size_t mbsrtowcs (wchar_t *dest, const char **srcp, size_t len, mbstate_t *ps);
# endif
#elif defined GNULIB_POSIXCHECK
# undef mbsrtowcs
# define mbsrtowcs(d,s,l,p) \
(GL_LINK_WARNING ("mbsrtowcs is unportable - " \
"use gnulib module mbsrtowcs for portability"), \
mbsrtowcs (d, s, l, p))
#endif
/* Convert a string to a wide string. */
#if @GNULIB_MBSNRTOWCS@
# if @REPLACE_MBSNRTOWCS@
# undef mbsnrtowcs
# define mbsnrtowcs rpl_mbsnrtowcs
# endif
# if !@HAVE_MBSNRTOWCS@ || @REPLACE_MBSNRTOWCS@
extern size_t mbsnrtowcs (wchar_t *dest, const char **srcp, size_t srclen, size_t len, mbstate_t *ps);
# endif
#elif defined GNULIB_POSIXCHECK
# undef mbsnrtowcs
# define mbsnrtowcs(d,s,n,l,p) \
(GL_LINK_WARNING ("mbsnrtowcs is unportable - " \
"use gnulib module mbsnrtowcs for portability"), \
mbsnrtowcs (d, s, n, l, p))
#endif
/* Convert a wide character to a multibyte character. */
#if @GNULIB_WCRTOMB@
# if @REPLACE_WCRTOMB@
# undef wcrtomb
# define wcrtomb rpl_wcrtomb
# endif
# if !@HAVE_WCRTOMB@ || @REPLACE_WCRTOMB@
extern size_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps);
# endif
#elif defined GNULIB_POSIXCHECK
# undef wcrtomb
# define wcrtomb(s,w,p) \
(GL_LINK_WARNING ("wcrtomb is unportable - " \
"use gnulib module wcrtomb for portability"), \
wcrtomb (s, w, p))
#endif
/* Convert a wide string to a string. */
#if @GNULIB_WCSRTOMBS@
# if @REPLACE_WCSRTOMBS@
# undef wcsrtombs
# define wcsrtombs rpl_wcsrtombs
# endif
# if !@HAVE_WCSRTOMBS@ || @REPLACE_WCSRTOMBS@
extern size_t wcsrtombs (char *dest, const wchar_t **srcp, size_t len, mbstate_t *ps);
# endif
#elif defined GNULIB_POSIXCHECK
# undef wcsrtombs
# define wcsrtombs(d,s,l,p) \
(GL_LINK_WARNING ("wcsrtombs is unportable - " \
"use gnulib module wcsrtombs for portability"), \
wcsrtombs (d, s, l, p))
#endif
/* Convert a wide string to a string. */
#if @GNULIB_WCSNRTOMBS@
# if !@HAVE_WCSNRTOMBS@
extern size_t wcsnrtombs (char *dest, const wchar_t **srcp, size_t srclen, size_t len, mbstate_t *ps);
# endif
#elif defined GNULIB_POSIXCHECK
# undef wcsnrtombs
# define wcsnrtombs(d,s,n,l,p) \
(GL_LINK_WARNING ("wcsnrtombs is unportable - " \
"use gnulib module wcsnrtombs for portability"), \
wcsnrtombs (d, s, n, l, p))
#endif
/* Return the number of screen columns needed for WC. */
#if @GNULIB_WCWIDTH@
# if @REPLACE_WCWIDTH@
# undef wcwidth
# define wcwidth rpl_wcwidth
extern int wcwidth (wchar_t);
# else
# if !defined wcwidth && !@HAVE_DECL_WCWIDTH@
/* wcwidth exists but is not declared. */
extern int wcwidth (int /* actually wchar_t */);
# endif
# endif
#elif defined GNULIB_POSIXCHECK
# undef wcwidth
# define wcwidth(w) \
(GL_LINK_WARNING ("wcwidth is unportable - " \
"use gnulib module wcwidth for portability"), \
wcwidth (w))
#endif
#ifdef __cplusplus
}
#endif
#endif /* _GL_WCHAR_H */
#endif /* _GL_WCHAR_H */
#endif

View File

@ -1,108 +0,0 @@
/* xsize.h -- Checked size_t computations.
Copyright (C) 2003, 2008 Free Software Foundation, Inc.
This program 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.1, 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
#ifndef _XSIZE_H
#define _XSIZE_H
/* Get size_t. */
#include <stddef.h>
/* Get SIZE_MAX. */
#include <limits.h>
#if HAVE_STDINT_H
# include <stdint.h>
#endif
/* The size of memory objects is often computed through expressions of
type size_t. Example:
void* p = malloc (header_size + n * element_size).
These computations can lead to overflow. When this happens, malloc()
returns a piece of memory that is way too small, and the program then
crashes while attempting to fill the memory.
To avoid this, the functions and macros in this file check for overflow.
The convention is that SIZE_MAX represents overflow.
malloc (SIZE_MAX) is not guaranteed to fail -- think of a malloc
implementation that uses mmap --, it's recommended to use size_overflow_p()
or size_in_bounds_p() before invoking malloc().
The example thus becomes:
size_t size = xsum (header_size, xtimes (n, element_size));
void *p = (size_in_bounds_p (size) ? malloc (size) : NULL);
*/
/* Convert an arbitrary value >= 0 to type size_t. */
#define xcast_size_t(N) \
((N) <= SIZE_MAX ? (size_t) (N) : SIZE_MAX)
/* Sum of two sizes, with overflow check. */
static inline size_t
#if __GNUC__ >= 3
__attribute__ ((__pure__))
#endif
xsum (size_t size1, size_t size2)
{
size_t sum = size1 + size2;
return (sum >= size1 ? sum : SIZE_MAX);
}
/* Sum of three sizes, with overflow check. */
static inline size_t
#if __GNUC__ >= 3
__attribute__ ((__pure__))
#endif
xsum3 (size_t size1, size_t size2, size_t size3)
{
return xsum (xsum (size1, size2), size3);
}
/* Sum of four sizes, with overflow check. */
static inline size_t
#if __GNUC__ >= 3
__attribute__ ((__pure__))
#endif
xsum4 (size_t size1, size_t size2, size_t size3, size_t size4)
{
return xsum (xsum (xsum (size1, size2), size3), size4);
}
/* Maximum of two sizes, with overflow check. */
static inline size_t
#if __GNUC__ >= 3
__attribute__ ((__pure__))
#endif
xmax (size_t size1, size_t size2)
{
/* No explicit check is needed here, because for any n:
max (SIZE_MAX, n) == SIZE_MAX and max (n, SIZE_MAX) == SIZE_MAX. */
return (size1 >= size2 ? size1 : size2);
}
/* Multiplication of a count with an element size, with overflow check.
The count must be >= 0 and the element size must be > 0.
This is a macro, not an inline function, so that it works correctly even
when N is of a wider type and N > SIZE_MAX. */
#define xtimes(N, ELSIZE) \
((N) <= SIZE_MAX / (ELSIZE) ? (size_t) (N) * (ELSIZE) : SIZE_MAX)
/* Check for overflow. */
#define size_overflow_p(SIZE) \
((SIZE) == SIZE_MAX)
/* Check against overflow. */
#define size_in_bounds_p(SIZE) \
((SIZE) != SIZE_MAX)
#endif /* _XSIZE_H */

View File

@ -1,30 +0,0 @@
# 00gnulib.m4 serial 1
dnl Copyright (C) 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl This file must be named something that sorts before all other
dnl gnulib-provided .m4 files. It is needed until such time as we can
dnl assume Autoconf 2.64, with its improved AC_DEFUN_ONCE semantics.
# AC_DEFUN_ONCE(NAME, VALUE)
# --------------------------
# Define NAME to expand to VALUE on the first use (whether by direct
# expansion, or by AC_REQUIRE), and to nothing on all subsequent uses.
# Avoid bugs in AC_REQUIRE in Autoconf 2.63 and earlier. This
# definition is slower than the version in Autoconf 2.64, because it
# can only use interfaces that existed since 2.59; but it achieves the
# same effect. Quoting is necessary to avoid confusing Automake.
m4_version_prereq([2.63.263], [],
[m4_define([AC][_DEFUN_ONCE],
[AC][_DEFUN([$1],
[AC_REQUIRE([_gl_DEFUN_ONCE([$1])],
[m4_indir([_gl_DEFUN_ONCE([$1])])])])]dnl
[AC][_DEFUN([_gl_DEFUN_ONCE([$1])], [$2])])])
# gl_00GNULIB
# -----------
# Witness macro that this file has been included. Needed to force
# Automake to include this file prior to all other gnulib .m4 files.
AC_DEFUN([gl_00GNULIB])

View File

@ -1,46 +0,0 @@
# alloca.m4 serial 9
dnl Copyright (C) 2002-2004, 2006, 2007, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_ALLOCA],
[
dnl Work around a bug of AC_EGREP_CPP in autoconf-2.57.
AC_REQUIRE([AC_PROG_CPP])
AC_REQUIRE([AC_PROG_EGREP])
AC_REQUIRE([AC_FUNC_ALLOCA])
if test $ac_cv_func_alloca_works = no; then
gl_PREREQ_ALLOCA
fi
# Define an additional variable used in the Makefile substitution.
if test $ac_cv_working_alloca_h = yes; then
AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [
AC_EGREP_CPP([Need own alloca], [
#if defined __GNUC__ || defined _AIX || defined _MSC_VER
Need own alloca
#endif
], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no])
])
if test $gl_cv_rpl_alloca = yes; then
dnl OK, alloca can be implemented through a compiler built-in.
AC_DEFINE([HAVE_ALLOCA], [1],
[Define to 1 if you have 'alloca' after including <alloca.h>,
a header that may be supplied by this distribution.])
ALLOCA_H=alloca.h
else
dnl alloca exists as a library function, i.e. it is slow and probably
dnl a memory leak. Don't define HAVE_ALLOCA in this case.
ALLOCA_H=
fi
else
ALLOCA_H=alloca.h
fi
AC_SUBST([ALLOCA_H])
])
# Prerequisites of lib/alloca.c.
# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
AC_DEFUN([gl_PREREQ_ALLOCA], [:])

View File

@ -1,50 +0,0 @@
# arpa_inet_h.m4 serial 5
dnl Copyright (C) 2006, 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl Written by Simon Josefsson and Bruno Haible
AC_DEFUN([gl_HEADER_ARPA_INET],
[
dnl Use AC_REQUIRE here, so that the default behavior below is expanded
dnl once only, before all statements that occur in other macros.
AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
AC_CHECK_HEADERS_ONCE([arpa/inet.h])
if test $ac_cv_header_arpa_inet_h = yes; then
HAVE_ARPA_INET_H=1
else
ARPA_INET_H='arpa/inet.h'
HAVE_ARPA_INET_H=0
fi
AC_SUBST([HAVE_ARPA_INET_H])
dnl Execute this unconditionally, because ARPA_INET_H may be set by other
dnl modules, after this code is executed.
gl_CHECK_NEXT_HEADERS([arpa/inet.h])
])
dnl Unconditionally enables the replacement of <arpa/inet.h>.
AC_DEFUN([gl_REPLACE_ARPA_INET_H],
[
AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
ARPA_INET_H='arpa/inet.h'
])
AC_DEFUN([gl_ARPA_INET_MODULE_INDICATOR],
[
dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
AC_REQUIRE([gl_ARPA_INET_H_DEFAULTS])
GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
])
AC_DEFUN([gl_ARPA_INET_H_DEFAULTS],
[
GNULIB_INET_NTOP=0; AC_SUBST([GNULIB_INET_NTOP])
GNULIB_INET_PTON=0; AC_SUBST([GNULIB_INET_PTON])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_DECL_INET_NTOP=1; AC_SUBST([HAVE_DECL_INET_NTOP])
HAVE_DECL_INET_PTON=1; AC_SUBST([HAVE_DECL_INET_PTON])
ARPA_INET_H=''; AC_SUBST([ARPA_INET_H])
])

View File

@ -1,25 +0,0 @@
# close.m4 serial 2
dnl Copyright (C) 2008 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_CLOSE],
[
m4_ifdef([gl_PREREQ_SYS_H_WINSOCK2], [
gl_PREREQ_SYS_H_WINSOCK2
if test $UNISTD_H_HAVE_WINSOCK2_H = 1; then
gl_REPLACE_CLOSE
fi
])
])
AC_DEFUN([gl_REPLACE_CLOSE],
[
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
if test $REPLACE_CLOSE != 1; then
AC_LIBOBJ([close])
fi
REPLACE_CLOSE=1
gl_REPLACE_FCLOSE
])

View File

@ -1,21 +0,0 @@
# codeset.m4 serial 4 (gettext-0.18)
dnl Copyright (C) 2000-2002, 2006, 2008, 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
dnl From Bruno Haible.
AC_DEFUN([AM_LANGINFO_CODESET],
[
AC_CACHE_CHECK([for nl_langinfo and CODESET], [am_cv_langinfo_codeset],
[AC_TRY_LINK([#include <langinfo.h>],
[char* cs = nl_langinfo(CODESET); return !cs;],
[am_cv_langinfo_codeset=yes],
[am_cv_langinfo_codeset=no])
])
if test $am_cv_langinfo_codeset = yes; then
AC_DEFINE([HAVE_LANGINFO_CODESET], [1],
[Define if you have <langinfo.h> and nl_langinfo(CODESET).])
fi
])

Some files were not shown because too many files have changed in this diff Show More