From: Christos Zoulas Date: Thu, 3 Jul 2008 15:48:18 +0000 (+0000) Subject: more fixes for ancient systems X-Git-Tag: FILE5_05~367 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e25e3a944803abea60fd972f8bce04864d18aab7;p=file more fixes for ancient systems --- diff --git a/configure.ac b/configure.ac index d79cad48..9fd15bde 100644 --- a/configure.ac +++ b/configure.ac @@ -62,6 +62,7 @@ AC_HEADER_MAJOR AC_HEADER_SYS_WAIT AC_CHECK_HEADERS(stdint.h fcntl.h locale.h stdint.h inttypes.h unistd.h) AC_CHECK_HEADERS(utime.h wchar.h wctype.h limits.h) +AC_CHECK_HEADERS(getopt.h err.h) AC_CHECK_HEADERS(sys/mman.h sys/stat.h sys/types.h sys/utime.h sys/time.h) AC_CHECK_HEADERS(zlib.h) diff --git a/src/file.c b/src/file.c index 2aa2abd6..2f518da9 100644 --- a/src/file.c +++ b/src/file.c @@ -60,7 +60,11 @@ #include #endif +#ifdef HAVE_GETOPT_H #include +#else +#include "mygetopt.h" +#endif #ifndef HAVE_GETOPT_LONG int getopt_long(int argc, char * const *argv, const char *optstring, const struct option *longopts, int *longindex); #endif @@ -70,7 +74,7 @@ int getopt_long(int argc, char * const *argv, const char *optstring, const struc #include "patchlevel.h" #ifndef lint -FILE_RCSID("@(#)$File: file.c,v 1.120 2008/05/18 23:21:17 christos Exp $") +FILE_RCSID("@(#)$File: file.c,v 1.121 2008/07/03 15:48:18 christos Exp $") #endif /* lint */ diff --git a/src/funcs.c b/src/funcs.c index db7ffdc5..21fc672a 100644 --- a/src/funcs.c +++ b/src/funcs.c @@ -38,9 +38,13 @@ #endif #ifndef lint -FILE_RCSID("@(#)$File: funcs.c,v 1.41 2008/05/16 14:25:01 christos Exp $") +FILE_RCSID("@(#)$File: funcs.c,v 1.42 2008/07/03 15:48:18 christos Exp $") #endif /* lint */ +#ifndef SIZE_MAX +#define SIZE_MAX ((size_t)~0) +#endif + /* * Like printf, only we append to a buffer. */ diff --git a/src/getopt_long.c b/src/getopt_long.c index e6efd0f5..4d9c8788 100644 --- a/src/getopt_long.c +++ b/src/getopt_long.c @@ -29,16 +29,30 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include +#ifdef HAVE_ERR_H #include +#else +#include +#define warnx printf +#endif #include +#ifdef HAVE_GETOPT_H #include +#else +#include "mygetopt.h" +#endif #include #include #define REPLACE_GETOPT +#ifndef _DIAGASSERT #define _DIAGASSERT assert +#endif #ifdef REPLACE_GETOPT #ifdef __weak_alias diff --git a/src/mygetopt.h b/src/mygetopt.h new file mode 100644 index 00000000..63bb69b9 --- /dev/null +++ b/src/mygetopt.h @@ -0,0 +1,71 @@ +/* $NetBSD: getopt.h,v 1.8 2007/11/06 19:21:18 christos Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Dieter Baron and Thomas Klausner. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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. + */ + +#ifndef _GETOPT_H_ +#define _GETOPT_H_ + +#include +#include + +/* + * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions + */ +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + /* name of long option */ + const char *name; + /* + * one of no_argument, required_argument, and optional_argument: + * whether option takes an argument + */ + int has_arg; + /* if not NULL, set *flag to val when option found */ + int *flag; + /* if flag not NULL, value to set *flag to; else return value */ + int val; +}; + +__BEGIN_DECLS +int getopt_long(int, char * const *, const char *, + const struct option *, int *); +__END_DECLS + +#endif /* !_GETOPT_H_ */