diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2012-08-11 16:45:31 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-10-18 12:43:06 +0000 |
commit | 7c432b265ed7ca5f8304938db73912df8ce35032 (patch) | |
tree | c95de7bee7b742ed92b9924d904adca706e48d80 /compat | |
download | autogen-7c432b265ed7ca5f8304938db73912df8ce35032.tar.gz |
Imported from /srv/lorry/lorry-area/autogen/autogen-5.16.2.tar.gz.HEADautogen-5.16.2master
Diffstat (limited to 'compat')
-rw-r--r-- | compat/Makefile.am | 52 | ||||
-rw-r--r-- | compat/Makefile.in | 463 | ||||
-rw-r--r-- | compat/bootstrap.dir | 24 | ||||
-rw-r--r-- | compat/chmod.c | 4 | ||||
-rw-r--r-- | compat/compat.h | 403 | ||||
-rw-r--r-- | compat/pathfind.c | 335 | ||||
-rw-r--r-- | compat/snprintf.c | 60 | ||||
-rw-r--r-- | compat/strchr.c | 60 | ||||
-rw-r--r-- | compat/strdup.c | 19 | ||||
-rw-r--r-- | compat/strftime.c | 1049 | ||||
-rw-r--r-- | compat/strsignal.c | 121 | ||||
-rw-r--r-- | compat/strsignal.def | 151 | ||||
-rw-r--r-- | compat/strsignal.h | 110 | ||||
-rw-r--r-- | compat/strsignal.tpl | 126 | ||||
-rw-r--r-- | compat/unlocked-io.h | 136 | ||||
-rw-r--r-- | compat/windows-config.h | 156 |
16 files changed, 3269 insertions, 0 deletions
diff --git a/compat/Makefile.am b/compat/Makefile.am new file mode 100644 index 0000000..81b9476 --- /dev/null +++ b/compat/Makefile.am @@ -0,0 +1,52 @@ +## -*- Mode: Makefile -*- +## +## Makefile.am -- process this file with automake to produce Makefile.in +## +## Time-stamp: "2012-04-07 09:31:30 bkorb" +## Copyright (c) 1997-2012 by Bruce Korb +## Author: Bruce Korb <bkorb@gnu.org> +## +## This file is part of AutoGen. +## +## AutoGen 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. +## +## AutoGen 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/>. + +COMPAT_CSRC = chmod.c pathfind.c snprintf.c strchr.c strdup.c strftime.c \ + strsignal.c +COMPAT_HDRS = compat.h strsignal.h windows-config.h unlocked-io.h +COMPAT_GEN = bootstrap.dir strsignal.def strsignal.tpl +EXTRA_DIST = $(COMPAT_CSRC) $(COMPAT_HDRS) $(COMPAT_GEN) + +MAINTAINERCLEANFILES = strsignal.h + +all: + : + +strsignal.h : strsignal.def strsignal.tpl + @if $(AGexe) --version >&- 2>&- ; then \ + echo $(AGexe) -L $(srcdir) $(srcdir)/strsignal.def ; \ + top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \ + $(AGexe) -L $(srcdir) $(srcdir)/strsignal.def ; \ + elif $(AGnam) --version >&- 2>&- ; then \ + echo $(AGnam) -L $(srcdir) $(srcdir)/strsignal.def ; \ + top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \ + $(AGnam) -L $(srcdir) $(srcdir)/strsignal.def ; \ + elif test -s $(srcdir)/$@; then \ + echo "WARNING: $(AGnam) not available, current $(srcdir)/$@ used"; \ + else \ + echo "ERROR: $(srcdir)/$@ has been corrupted"; exit 1;\ + fi + +.NOTPARALLEL: + +# compat/Makefile.am ends here diff --git a/compat/Makefile.in b/compat/Makefile.in new file mode 100644 index 0000000..5ea0a59 --- /dev/null +++ b/compat/Makefile.in @@ -0,0 +1,463 @@ +# Makefile.in generated by automake 1.12.2 from Makefile.am. +# @configure_input@ + +# Copyright (C) 1994-2012 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ +VPATH = @srcdir@ +am__make_dryrun = \ + { \ + am__dry=no; \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + echo 'am--echo: ; @echo "AM" OK' | $(MAKE) -f - 2>/dev/null \ + | grep '^AM OK$$' >/dev/null || am__dry=yes;; \ + *) \ + for am__flg in $$MAKEFLAGS; do \ + case $$am__flg in \ + *=*|--*) ;; \ + *n*) am__dry=yes; break;; \ + esac; \ + done;; \ + esac; \ + test $$am__dry = yes; \ + } +pkgdatadir = $(datadir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkglibexecdir = $(libexecdir)/@PACKAGE@ +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = @build@ +host_triplet = @host@ +target_triplet = @target@ +subdir = compat +DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/config/ag_macros.m4 \ + $(top_srcdir)/config/extensions.m4 \ + $(top_srcdir)/config/libopts.m4 \ + $(top_srcdir)/config/libtool.m4 \ + $(top_srcdir)/config/ltoptions.m4 \ + $(top_srcdir)/config/ltsugar.m4 \ + $(top_srcdir)/config/ltversion.m4 \ + $(top_srcdir)/config/lt~obsolete.m4 \ + $(top_srcdir)/config/onceonly.m4 \ + $(top_srcdir)/config/snprintfv.m4 \ + $(top_srcdir)/config/unlocked-io.m4 $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +SOURCES = +DIST_SOURCES = +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = @ACLOCAL@ +AGEN5_TESTS = @AGEN5_TESTS@ +AG_GUILE = @AG_GUILE@ +AG_LDFLAGS = @AG_LDFLAGS@ +AG_MAJOR_VERSION = @AG_MAJOR_VERSION@ +AG_MINOR_VERSION = @AG_MINOR_VERSION@ +AG_TIMEOUT = @AG_TIMEOUT@ +AG_VERSION = @AG_VERSION@ +AG_XML2 = @AG_XML2@ +AGexe = @AGexe@ +AGnam = @AGnam@ +AMTAR = @AMTAR@ +AO_AGE = @AO_AGE@ +AO_CURRENT = @AO_CURRENT@ +AO_REVISION = @AO_REVISION@ +AO_TEMPLATE_VERSION = @AO_TEMPLATE_VERSION@ +AR = @AR@ +AS = @AS@ +AUTOCONF = @AUTOCONF@ +AUTOHEADER = @AUTOHEADER@ +AUTOMAKE = @AUTOMAKE@ +AWK = @AWK@ +CC = @CC@ +CCDEPMODE = @CCDEPMODE@ +CFLAGS = @CFLAGS@ +CLexe = @CLexe@ +CLnam = @CLnam@ +CONFIG_SHELL = @CONFIG_SHELL@ +CPP = @CPP@ +CPPFLAGS = @CPPFLAGS@ +CYGPATH_W = @CYGPATH_W@ +DEBUG_ENABLED = @DEBUG_ENABLED@ +DEFS = @DEFS@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DSYMUTIL = @DSYMUTIL@ +DUMPBIN = @DUMPBIN@ +DYNAMIC_AG = @DYNAMIC_AG@ +ECHO_C = @ECHO_C@ +ECHO_N = @ECHO_N@ +ECHO_T = @ECHO_T@ +EGREP = @EGREP@ +ENABLE_STATIC = @ENABLE_STATIC@ +EXEEXT = @EXEEXT@ +FGREP = @FGREP@ +GDexe = @GDexe@ +GDnam = @GDnam@ +GO_AGE = @GO_AGE@ +GO_CURRENT = @GO_CURRENT@ +GO_REVISION = @GO_REVISION@ +GREP = @GREP@ +GUILE_VERSION = @GUILE_VERSION@ +INCLIST = @INCLIST@ +INCSNPRINTFV = @INCSNPRINTFV@ +INSTALL = @INSTALL@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LD = @LD@ +LDFLAGS = @LDFLAGS@ +LIBGUILE_CFLAGS = @LIBGUILE_CFLAGS@ +LIBGUILE_LIBS = @LIBGUILE_LIBS@ +LIBGUILE_PATH = @LIBGUILE_PATH@ +LIBOBJS = @LIBOBJS@ +LIBS = @LIBS@ +LIBSNPRINTFV = @LIBSNPRINTFV@ +LIBTOOL = @LIBTOOL@ +LIBXML2_CFLAGS = @LIBXML2_CFLAGS@ +LIBXML2_LIBS = @LIBXML2_LIBS@ +LIBXML2_PATH = @LIBXML2_PATH@ +LIPO = @LIPO@ +LN_S = @LN_S@ +LTLIBOBJS = @LTLIBOBJS@ +M4_SRC = @M4_SRC@ +MAKEINFO = @MAKEINFO@ +MANIFEST_TOOL = @MANIFEST_TOOL@ +MKDIR_P = @MKDIR_P@ +NM = @NM@ +NMEDIT = @NMEDIT@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +OPTS_TESTDIR = @OPTS_TESTDIR@ +OTOOL = @OTOOL@ +OTOOL64 = @OTOOL64@ +PACKAGE = @PACKAGE@ +PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ +PACKAGE_NAME = @PACKAGE_NAME@ +PACKAGE_STRING = @PACKAGE_STRING@ +PACKAGE_TARNAME = @PACKAGE_TARNAME@ +PACKAGE_URL = @PACKAGE_URL@ +PACKAGE_VERSION = @PACKAGE_VERSION@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +POSIX_SHELL = @POSIX_SHELL@ +RANLIB = @RANLIB@ +SED = @SED@ +SET_MAKE = @SET_MAKE@ +SHELL = @SHELL@ +STRIP = @STRIP@ +TEXI2HTML = @TEXI2HTML@ +VERSION = @VERSION@ +abs_builddir = @abs_builddir@ +abs_srcdir = @abs_srcdir@ +abs_top_builddir = @abs_top_builddir@ +abs_top_srcdir = @abs_top_srcdir@ +ac_aux_dir = @ac_aux_dir@ +ac_ct_AR = @ac_ct_AR@ +ac_ct_CC = @ac_ct_CC@ +ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ +am__include = @am__include@ +am__leading_dot = @am__leading_dot@ +am__quote = @am__quote@ +am__tar = @am__tar@ +am__untar = @am__untar@ +bindir = @bindir@ +build = @build@ +build_alias = @build_alias@ +build_cpu = @build_cpu@ +build_os = @build_os@ +build_vendor = @build_vendor@ +builddir = @builddir@ +datadir = @datadir@ +datarootdir = @datarootdir@ +docdir = @docdir@ +dvidir = @dvidir@ +exec_prefix = @exec_prefix@ +host = @host@ +host_alias = @host_alias@ +host_cpu = @host_cpu@ +host_os = @host_os@ +host_vendor = @host_vendor@ +htmldir = @htmldir@ +includedir = @includedir@ +infodir = @infodir@ +install_sh = @install_sh@ +libdir = @libdir@ +libexecdir = @libexecdir@ +localedir = @localedir@ +localstatedir = @localstatedir@ +mandir = @mandir@ +mkdir_p = @mkdir_p@ +oldincludedir = @oldincludedir@ +pdfdir = @pdfdir@ +prefix = @prefix@ +program_transform_name = @program_transform_name@ +psdir = @psdir@ +sbindir = @sbindir@ +sharedstatedir = @sharedstatedir@ +srcdir = @srcdir@ +sysconfdir = @sysconfdir@ +target = @target@ +target_alias = @target_alias@ +target_cpu = @target_cpu@ +target_os = @target_os@ +target_vendor = @target_vendor@ +top_build_prefix = @top_build_prefix@ +top_builddir = @top_builddir@ +top_srcdir = @top_srcdir@ +COMPAT_CSRC = chmod.c pathfind.c snprintf.c strchr.c strdup.c strftime.c \ + strsignal.c + +COMPAT_HDRS = compat.h strsignal.h windows-config.h unlocked-io.h +COMPAT_GEN = bootstrap.dir strsignal.def strsignal.tpl +EXTRA_DIST = $(COMPAT_CSRC) $(COMPAT_HDRS) $(COMPAT_GEN) +MAINTAINERCLEANFILES = strsignal.h +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu compat/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --gnu compat/Makefile +.PRECIOUS: Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs +tags: TAGS +TAGS: + +ctags: CTAGS +CTAGS: + +cscope cscopelist: + + +distdir: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." + -test -z "$(MAINTAINERCLEANFILES)" || rm -f $(MAINTAINERCLEANFILES) +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + -rm -f Makefile +distclean-am: clean-am distclean-generic + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: all all-am check check-am clean clean-generic clean-libtool \ + distclean distclean-generic distclean-libtool distdir dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ + install-info install-info-am install-man install-pdf \ + install-pdf-am install-ps install-ps-am install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool pdf pdf-am ps ps-am uninstall uninstall-am + + +all: + : + +strsignal.h : strsignal.def strsignal.tpl + @if $(AGexe) --version >&- 2>&- ; then \ + echo $(AGexe) -L $(srcdir) $(srcdir)/strsignal.def ; \ + top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \ + $(AGexe) -L $(srcdir) $(srcdir)/strsignal.def ; \ + elif $(AGnam) --version >&- 2>&- ; then \ + echo $(AGnam) -L $(srcdir) $(srcdir)/strsignal.def ; \ + top_srcdir=$(top_srcdir) top_builddir=$(top_builddir) \ + $(AGnam) -L $(srcdir) $(srcdir)/strsignal.def ; \ + elif test -s $(srcdir)/$@; then \ + echo "WARNING: $(AGnam) not available, current $(srcdir)/$@ used"; \ + else \ + echo "ERROR: $(srcdir)/$@ has been corrupted"; exit 1;\ + fi + +.NOTPARALLEL: + +# compat/Makefile.am ends here + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/compat/bootstrap.dir b/compat/bootstrap.dir new file mode 100644 index 0000000..2c8027c --- /dev/null +++ b/compat/bootstrap.dir @@ -0,0 +1,24 @@ +#! /bin/echo This_file_must_be_sourced,_not_executed +## +## AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved +## +## AutoGen 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. +## +## AutoGen 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/>. + +if [ -n "${AGexe}" ] +then + top_srcdir=.. top_builddir=.. + export top_srcdir top_builddir + echo "Rebuilding strsignal.h" + ${AGexe} strsignal.def +fi diff --git a/compat/chmod.c b/compat/chmod.c new file mode 100644 index 0000000..01a1be0 --- /dev/null +++ b/compat/chmod.c @@ -0,0 +1,4 @@ + +inline int chmod(char const * path, mode_t mode) { + return 0; +} diff --git a/compat/compat.h b/compat/compat.h new file mode 100644 index 0000000..d3d1eab --- /dev/null +++ b/compat/compat.h @@ -0,0 +1,403 @@ +/* -*- Mode: C -*- */ + +/** + * \file compat.h --- fake the preprocessor into handlng portability + * + * Time-stamp: "2012-08-11 08:17:36 bkorb" + * + * compat.h is free software. + * This file is part of AutoGen. + * + * AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * + * AutoGen 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. + * + * AutoGen 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/>. + * + * As a special exception, Bruce Korb gives permission for additional + * uses of the text contained in the release of compat.h. + * + * The exception is that, if you link the compat.h library with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the compat.h library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by Bruce Korb under + * the name compat.h. If you copy code from other sources under the + * General Public License into a copy of compat.h, as the General Public + * License permits, the exception does not apply to the code that you add + * in this way. To avoid misleading anyone as to the status of such + * modified files, you must delete this exception notice from them. + * + * If you write modifications of your own for compat.h, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + */ +#ifndef COMPAT_H_GUARD +#define COMPAT_H_GUARD 1 + +#if defined(HAVE_CONFIG_H) +# include <config.h> + +#elif defined(_WIN32) && !defined(__CYGWIN__) +# include "windows-config.h" + +#else +# error "compat.h" requires "config.h" + choke me. +#endif + + +#ifndef HAVE_STRSIGNAL +# ifndef HAVE_RAW_DECL_STRSIGNAL + char * strsignal(int signo); +# endif +#endif + +#define _GNU_SOURCE 1 /* for strsignal in GNU's libc */ +#define __USE_GNU 1 /* exact same thing as above */ +#define __EXTENSIONS__ 1 /* and another way to call for it */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * + * SYSTEM HEADERS: + */ +#include <sys/types.h> +#ifdef HAVE_SYS_MMAN_H +# include <sys/mman.h> +#endif +#include <sys/param.h> +#if HAVE_SYS_PROCSET_H +# include <sys/procset.h> +#endif +#include <sys/stat.h> +#ifdef HAVE_SYS_WAIT_H +# include <sys/wait.h> +#endif + +#if defined( HAVE_SOLARIS_SYSINFO ) +# include <sys/systeminfo.h> +#elif defined( HAVE_UNAME_SYSCALL ) +# include <sys/utsname.h> +#endif + +#ifdef DAEMON_ENABLED +# if HAVE_SYS_STROPTS_H +# include <sys/stropts.h> +# endif + +# if HAVE_SYS_SOCKET_H +# include <sys/socket.h> +# endif + +# if ! defined(HAVE_SYS_POLL_H) && ! defined(HAVE_SYS_SELECT_H) +# error This system cannot support daemon processing + Choke Me. +# endif + +# if HAVE_SYS_POLL_H +# include <sys/poll.h> +# endif + +# if HAVE_SYS_SELECT_H +# include <sys/select.h> +# endif + +# if HAVE_NETINET_IN_H +# include <netinet/in.h> +# endif + +# if HAVE_SYS_UN_H +# include <sys/un.h> +# endif +#endif + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * + * USER HEADERS: + */ +#include <stdio.h> +#include <assert.h> +#include <ctype.h> + +/* + * Directory opening stuff: + */ +# if defined (_POSIX_SOURCE) +/* Posix does not require that the d_ino field be present, and some + systems do not provide it. */ +# define REAL_DIR_ENTRY(dp) 1 +# else /* !_POSIX_SOURCE */ +# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0) +# endif /* !_POSIX_SOURCE */ + +# if defined (HAVE_DIRENT_H) +# include <dirent.h> +# define D_NAMLEN(dirent) strlen((dirent)->d_name) +# else /* !HAVE_DIRENT_H */ +# define dirent direct +# define D_NAMLEN(dirent) (dirent)->d_namlen +# if defined (HAVE_SYS_NDIR_H) +# include <sys/ndir.h> +# endif /* HAVE_SYS_NDIR_H */ +# if defined (HAVE_SYS_DIR_H) +# include <sys/dir.h> +# endif /* HAVE_SYS_DIR_H */ +# if defined (HAVE_NDIR_H) +# include <ndir.h> +# endif /* HAVE_NDIR_H */ +# endif /* !HAVE_DIRENT_H */ + +#include <errno.h> +#ifdef HAVE_FCNTL_H +# include <fcntl.h> +#endif +#ifndef O_NONBLOCK +# define O_NONBLOCK FNDELAY +#endif + +#if defined(HAVE_LIBGEN) && defined(HAVE_LIBGEN_H) +# include <libgen.h> +#endif + +#if defined(HAVE_LIMITS_H) /* this is also in options.h */ +# include <limits.h> +#elif defined(HAVE_SYS_LIMITS_H) +# include <sys/limits.h> +#endif /* HAVE_LIMITS/SYS_LIMITS_H */ + +#include <memory.h> +#include <setjmp.h> +#include <signal.h> + +#if defined(HAVE_STDINT_H) +# include <stdint.h> + +#elif defined(HAVE_INTTYPES_H) +# include <inttypes.h> +#endif + +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#ifdef HAVE_UTIME_H +# include <utime.h> +#endif + +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +#ifdef HAVE_STDBOOL_H +# include <stdbool.h> +#else + typedef enum { false = 0, true = 1 } _Bool; +# define bool _Bool + + /* The other macros must be usable in preprocessor directives. */ +# define false 0 +# define true 1 +#endif + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * + * FIXUPS and CONVIENCE STUFF: + */ +#ifdef __cplusplus +# define EXTERN extern "C" +#else +# define EXTERN extern +#endif + +/* some systems #def errno! and others do not declare it!! */ +#ifndef errno + extern int errno; +#endif + +/* Some machines forget this! */ + +# ifndef EXIT_FAILURE +# define EXIT_SUCCESS 0 +# define EXIT_FAILURE 1 +# endif + +#ifndef NUL +# define NUL '\0' +#endif + +#ifndef NULL +# define NULL 0 +#endif + +#if !defined (MAXPATHLEN) && defined (HAVE_SYS_PARAM_H) +# include <sys/param.h> +#endif /* !MAXPATHLEN && HAVE_SYS_PARAM_H */ + +#if !defined (MAXPATHLEN) && defined (PATH_MAX) +# define MAXPATHLEN PATH_MAX +#endif /* !MAXPATHLEN && PATH_MAX */ + +#if !defined (MAXPATHLEN) && defined(_MAX_PATH) +# define PATH_MAX _MAX_PATH +# define MAXPATHLEN _MAX_PATH +#endif + +#if !defined (MAXPATHLEN) +# define MAXPATHLEN ((size_t)4096) +#endif /* MAXPATHLEN */ + +#define AG_PATH_MAX ((size_t)MAXPATHLEN) + +#ifndef LONG_MAX +# define LONG_MAX ~(1L << (8*sizeof(long) -1)) +# define INT_MAX ~(1 << (8*sizeof(int) -1)) +#endif + +#ifndef ULONG_MAX +# define ULONG_MAX ~(OUL) +# define UINT_MAX ~(OU) +#endif + +#ifndef SHORT_MAX +# define SHORT_MAX ~(1 << (8*sizeof(short) - 1)) +#else +# define USHORT_MAX ~(OUS) +#endif + +#ifndef HAVE_INT8_T + typedef signed char int8_t; +# define HAVE_INT8_T 1 +#endif +#ifndef HAVE_UINT8_T + typedef unsigned char uint8_t; +# define HAVE_UINT8_T 1 +#endif +#ifndef HAVE_INT16_T + typedef signed short int16_t; +# define HAVE_INT16_T 1 +#endif +#ifndef HAVE_UINT16_T + typedef unsigned short uint16_t; +# define HAVE_UINT16_T 1 +#endif + +#ifndef HAVE_INT32_T +# if SIZEOF_INT == 4 + typedef signed int int32_t; +# elif SIZEOF_LONG == 4 + typedef signed long int32_t; +# endif +# define HAVE_INT32_T 1 +#endif + +#ifndef HAVE_UINT32_T +# if SIZEOF_INT == 4 + typedef unsigned int uint32_t; +# elif SIZEOF_LONG == 4 + typedef unsigned long uint32_t; +# else +# error Cannot create a uint32_t type. + Choke Me. +# endif +# define HAVE_UINT32_T 1 +#endif + +#ifndef HAVE_INTPTR_T +# if SIZEOF_CHARP == SIZEOF_LONG + typedef signed long intptr_t; +# else + typedef signed int intptr_t; +# endif +# define HAVE_INTPTR_T 1 +#endif + +#ifndef HAVE_UINTPTR_T +# if SIZEOF_CHARP == SIZEOF_LONG + typedef unsigned long intptr_t; +# else + typedef unsigned int intptr_t; +# endif +# define HAVE_INTPTR_T 1 +#endif + +#ifndef HAVE_UINT_T + typedef unsigned int uint_t; +# define HAVE_UINT_T 1 +#endif + +#ifndef HAVE_SIZE_T + typedef unsigned int size_t; +# define HAVE_SIZE_T 1 +#endif +#ifndef HAVE_WINT_T + typedef unsigned int wint_t; +# define HAVE_WINT_T 1 +#endif +#ifndef HAVE_PID_T + typedef signed int pid_t; +# define HAVE_PID_T 1 +#endif + +/* redefine these for BSD style string libraries */ +#ifndef HAVE_STRCHR +# define strchr index +# define strrchr rindex +#endif + +#ifdef USE_FOPEN_BINARY +# ifndef FOPEN_BINARY_FLAG +# define FOPEN_BINARY_FLAG "b" +# endif +# ifndef FOPEN_TEXT_FLAG +# define FOPEN_TEXT_FLAG "t" +# endif +#else +# ifndef FOPEN_BINARY_FLAG +# define FOPEN_BINARY_FLAG +# endif +# ifndef FOPEN_TEXT_FLAG +# define FOPEN_TEXT_FLAG +# endif +#endif + +#ifndef STR +# define _STR(s) #s +# define STR(s) _STR(s) +#endif + +/* ##### Pointer sized word ##### */ + +/* FIXME: the MAX stuff in here is broken! */ +#if SIZEOF_CHARP > SIZEOF_INT + typedef long t_word; + #define WORD_MAX LONG_MAX + #define WORD_MIN LONG_MIN +#else /* SIZEOF_CHARP <= SIZEOF_INT */ + typedef int t_word; + #define WORD_MAX INT_MAX + #define WORD_MIN INT_MIN +#endif + +#endif /* COMPAT_H_GUARD */ + +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of compat/compat.h */ diff --git a/compat/pathfind.c b/compat/pathfind.c new file mode 100644 index 0000000..3f66812 --- /dev/null +++ b/compat/pathfind.c @@ -0,0 +1,335 @@ +/* -*- Mode: C -*- */ + +/* pathfind.c --- find a FILE MODE along PATH */ + +/* + * Author: Gary V Vaughan <gvaughan@oranda.demon.co.uk> + * Time-stamp: "2012-08-11 08:19:39 bkorb" + */ + +/* Code: */ + +#include "compat.h" +#ifndef HAVE_PATHFIND +#if defined(__windows__) && !defined(__CYGWIN__) +char* +pathfind( char const* path, + char const* fileName, + char const* mode ) +{ + return NULL; +} +#else + +static char* make_absolute( char const *string, char const *dot_path ); +static char* canonicalize_pathname( char *path ); +static char* extract_colon_unit( char* dir, char const *string, int *p_index ); + + +/*=export_func pathfind + * + * what: fild a file in a list of directories + * + * ifndef: HAVE_PATHFIND + * + * arg: + char const* + path + colon separated list of search directories + + * arg: + char const* + file + the name of the file to look for + + * arg: + char const* + mode + the mode bits that must be set to match + + * + * ret_type: char* + * ret_desc: the path to the located file + * + * doc: + * + * pathfind looks for a a file with name "FILE" and "MODE" access + * along colon delimited "PATH", and returns the full pathname as a + * string, or NULL if not found. If "FILE" contains a slash, then + * it is treated as a relative or absolute path and "PATH" is ignored. + * + * @strong{NOTE}: this function is compiled into @file{libopts} only if + * it is not natively supplied. + * + * The "MODE" argument is a string of option letters chosen from the + * list below: + * @example + * Letter Meaning + * r readable + * w writable + * x executable + * f normal file (NOT IMPLEMENTED) + * b block special (NOT IMPLEMENTED) + * c character special (NOT IMPLEMENTED) + * d directory (NOT IMPLEMENTED) + * p FIFO (pipe) (NOT IMPLEMENTED) + * u set user ID bit (NOT IMPLEMENTED) + * g set group ID bit (NOT IMPLEMENTED) + * k sticky bit (NOT IMPLEMENTED) + * s size nonzero (NOT IMPLEMENTED) + * @end example + * + * example: + * To find the "ls" command using the "PATH" environment variable: + * @example + * #include <stdlib.h> + * char* pz_ls = pathfind( getenv("PATH"), "ls", "rx" ); + * <<do whatever with pz_ls>> + * free( pz_ls ); + * @end example + * The path is allocated with @code{malloc(3C)}, so you must @code{free(3C)} + * the result. Also, do not use unimplemented file modes. :-) + * + * err: returns NULL if the file is not found. +=*/ +char* +pathfind( char const* path, + char const* fileName, + char const* mode ) +{ + int p_index = 0; + int mode_bits = 0; + char* pathName = NULL; + char zPath[ AG_PATH_MAX + 1 ]; + + if (strchr( mode, 'r' )) mode_bits |= R_OK; + if (strchr( mode, 'w' )) mode_bits |= W_OK; + if (strchr( mode, 'x' )) mode_bits |= X_OK; + + /* + * FOR each non-null entry in the colon-separated path, DO ... + */ + for (;;) { + DIR* dirP; + char* colon_unit = extract_colon_unit( zPath, path, &p_index ); + + /* + * IF no more entries, THEN quit + */ + if (colon_unit == NULL) + break; + + dirP = opendir( colon_unit ); + + /* + * IF the directory is inaccessable, THEN next directory + */ + if (dirP == NULL) + continue; + + /* + * FOR every entry in the given directory, ... + */ + for (;;) { + struct dirent *entP = readdir( dirP ); + + if (entP == (struct dirent*)NULL) + break; + + /* + * IF the file name matches the one we are looking for, ... + */ + if (strcmp( entP->d_name, fileName ) == 0) { + char* pzFullName = make_absolute( fileName, colon_unit); + + /* + * Make sure we can access it in the way we want + */ + if (access( pzFullName, mode_bits ) >= 0) { + /* + * We can, so normalize the name and return it below + */ + pathName = canonicalize_pathname( pzFullName ); + } + + free( (void*)pzFullName ); + break; + } + } + + closedir( dirP ); + + if (pathName != NULL) + break; + } + + return pathName; +} + +/* + * Turn STRING (a pathname) into an absolute pathname, assuming that + * DOT_PATH contains the symbolic location of `.'. This always returns + * a new string, even if STRING was an absolute pathname to begin with. + */ +static char* +make_absolute( char const *string, char const *dot_path ) +{ + char *result; + int result_len; + + if (!dot_path || *string == '/') { + result = strdup( string ); + } else { + if (dot_path && dot_path[0]) { + result = malloc( 2 + strlen( dot_path ) + strlen( string ) ); + strcpy( result, dot_path ); + result_len = strlen( result ); + if (result[result_len - 1] != '/') { + result[result_len++] = '/'; + result[result_len] = '\0'; + } + } else { + result = malloc( 3 + strlen( string ) ); + result[0] = '.'; result[1] = '/'; result[2] = '\0'; + result_len = 2; + } + + strcpy( result + result_len, string ); + } + + return result; +} + +/* + * Canonicalize PATH, and return a new path. The new path differs from + * PATH in that: + * + * Multiple `/'s are collapsed to a single `/'. + * Leading `./'s are removed. + * Trailing `/.'s are removed. + * Trailing `/'s are removed. + * Non-leading `../'s and trailing `..'s are handled by removing + * portions of the path. + */ +static char* +canonicalize_pathname( char *path ) +{ + int i, start; + char stub_char, *result; + + /* The result cannot be larger than the input PATH. */ + result = strdup( path ); + + stub_char = (*path == '/') ? '/' : '.'; + + /* Walk along RESULT looking for things to compact. */ + i = 0; + while (result[i]) { + while (result[i] != '\0' && result[i] != '/') + i++; + + start = i++; + + /* If we didn't find any slashes, then there is nothing left to + * do. + */ + if (!result[start]) + break; + + /* Handle multiple `/'s in a row. */ + while (result[i] == '/') + i++; + +#if !defined (apollo) + if ((start + 1) != i) +#else + if ((start + 1) != i && (start != 0 || i != 2)) +#endif /* apollo */ + { + strcpy( result + start + 1, result + i ); + i = start + 1; + } + + /* Handle backquoted `/'. */ + if (start > 0 && result[start - 1] == '\\') + continue; + + /* Check for trailing `/', and `.' by itself. */ + if ((start && !result[i]) + || (result[i] == '.' && !result[i+1])) { + result[--i] = '\0'; + break; + } + + /* Check for `../', `./' or trailing `.' by itself. */ + if (result[i] == '.') { + /* Handle `./'. */ + if (result[i + 1] == '/') { + strcpy( result + i, result + i + 1 ); + i = (start < 0) ? 0 : start; + continue; + } + + /* Handle `../' or trailing `..' by itself. */ + if (result[i + 1] == '.' && + (result[i + 2] == '/' || !result[i + 2])) { + while (--start > -1 && result[start] != '/') + ; + strcpy( result + start + 1, result + i + 2 ); + i = (start < 0) ? 0 : start; + continue; + } + } + } + + if (!*result) { + *result = stub_char; + result[1] = '\0'; + } + + return result; +} + +/* + * Given a string containing units of information separated by colons, + * return the next one pointed to by (P_INDEX), or NULL if there are no + * more. Advance (P_INDEX) to the character after the colon. + */ +static char* +extract_colon_unit( char* pzDir, char const *string, int *p_index ) +{ + char* pzDest = pzDir; + int ix = *p_index; + + if (string == NULL) + return NULL; + + if ((unsigned)ix >= strlen( string )) + return NULL; + + { + char const* pzSrc = string + ix; + + while (*pzSrc == ':') pzSrc++; + + for (;;) { + char ch = (*(pzDest++) = *(pzSrc++)); + switch (ch) { + case ':': + pzDest[-1] = NUL; + /* FALLTHROUGH */ + case NUL: + goto copy_done; + } + + if ((unsigned long)(pzDest - pzDir) >= AG_PATH_MAX) + break; + } copy_done:; + + ix = pzSrc - string; + } + + if (*pzDir == NUL) + return NULL; + + *p_index = ix; + return pzDir; +} +#endif /* __windows__ / __CYGWIN__ */ +#endif /* HAVE_PATHFIND */ + +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of compat/pathfind.c */ diff --git a/compat/snprintf.c b/compat/snprintf.c new file mode 100644 index 0000000..fc91d63 --- /dev/null +++ b/compat/snprintf.c @@ -0,0 +1,60 @@ + +#ifndef HAVE_VPRINTF +#include "choke-me: no vprintf and no snprintf" +#endif + +#if defined(HAVE_STDARG_H) +# include <stdarg.h> +# ifndef VA_START +# define VA_START(a, f) va_start(a, f) +# define VA_END(a) va_end(a) +# endif /* VA_START */ +# define SNV_USING_STDARG_H + +#elif defined(HAVE_VARARGS_H) +# include <varargs.h> +# ifndef VA_START +# define VA_START(a, f) va_start(a) +# define VA_END(a) va_end(a) +# endif /* VA_START */ +# undef SNV_USING_STDARG_H + +#else +# include "must-have-stdarg-or-varargs" +#endif + +static int +snprintf(char *str, size_t n, char const *fmt, ...) +{ + va_list ap; + int rval; + +#ifdef VSPRINTF_CHARSTAR + char *rp; + VA_START(ap, fmt); + rp = vsprintf(str, fmt, ap); + VA_END(ap); + rval = strlen(rp); + +#else + VA_START(ap, fmt); + rval = vsprintf(str, fmt, ap); + VA_END(ap); +#endif + + if (rval > n) { + fprintf(stderr, "snprintf buffer overrun %d > %d\n", rval, (int)n); + abort(); + } + return rval; +} + +static int +vsnprintf( char *str, size_t n, char const *fmt, va_list ap ) +{ +#ifdef VSPRINTF_CHARSTAR + return (strlen(vsprintf(str, fmt, ap))); +#else + return (vsprintf(str, fmt, ap)); +#endif +} diff --git a/compat/strchr.c b/compat/strchr.c new file mode 100644 index 0000000..413f999 --- /dev/null +++ b/compat/strchr.c @@ -0,0 +1,60 @@ +/* + SYNOPSIS + #include <string.h> + + char *strchr(char const *s, int c); + + char *strrchr(char const *s, int c); + + DESCRIPTION + The strchr() function returns a pointer to the first occurrence of the + character c in the string s. + + The strrchr() function returns a pointer to the last occurrence of the + character c in the string s. + + Here "character" means "byte" - these functions do not work with wide + or multi-byte characters. + + RETURN VALUE + The strchr() and strrchr() functions return a pointer to the matched + character or NULL if the character is not found. + + CONFORMING TO + SVID 3, POSIX, BSD 4.3, ISO 9899 +*/ + +char* +strchr( char const *s, int c) +{ + do { + if ((unsigned)*s == (unsigned)c) + return s; + + } while (*(++s) != NUL); + + return NULL; +} + +char* +strrchr( char const *s, int c) +{ + char const *e = s + strlen(s); + + for (;;) { + if (--e < s) + break; + + if ((unsigned)*e == (unsigned)c) + return e; + } + return NULL; +} + +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of compat/strsignal.c */ diff --git a/compat/strdup.c b/compat/strdup.c new file mode 100644 index 0000000..e2933a8 --- /dev/null +++ b/compat/strdup.c @@ -0,0 +1,19 @@ +/* + * Platforms without strdup ?!?!?! + */ + +static char * +strdup( char const *s ) +{ + char *cp; + + if (s == NULL) + return NULL; + + cp = (char *) AGALOC((unsigned) (strlen(s)+1), "strdup"); + + if (cp != NULL) + (void) strcpy(cp, s); + + return cp; +} diff --git a/compat/strftime.c b/compat/strftime.c new file mode 100644 index 0000000..400ad52 --- /dev/null +++ b/compat/strftime.c @@ -0,0 +1,1049 @@ +/* + NOTE: The canonical source of this file is maintained with the GNU C + Library. Bugs can be reported to bug-glibc@prep.ai.mit.edu. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This program is 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/>. + + */ + +#if HAVE_CONFIG_H +# include <config.h> +#endif + +#ifdef _LIBC +# define HAVE_LIMITS_H 1 +# define HAVE_MBLEN 1 +# define HAVE_MBRLEN 1 +# define HAVE_STRUCT_ERA_ENTRY 1 +# define HAVE_TM_GMTOFF 1 +# define HAVE_TM_ZONE 1 +# define HAVE_TZNAME 1 +# define HAVE_TZSET 1 +# define MULTIBYTE_IS_FORMAT_SAFE 1 +# define STDC_HEADERS 1 +# include <ansidecl.h> +# include "../locale/localeinfo.h" +#endif + +#include <ctype.h> +#include <sys/types.h> /* Some systems define `time_t' here. */ + +#ifdef TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# else +# include <time.h> +# endif +#endif +#if HAVE_TZNAME +extern char *tzname[]; +#endif + +/* Do multibyte processing if multibytes are supported, unless + multibyte sequences are safe in formats. Multibyte sequences are + safe if they cannot contain byte sequences that look like format + conversion specifications. The GNU C Library uses UTF8 multibyte + encoding, which is safe for formats, but strftime.c can be used + with other C libraries that use unsafe encodings. */ +#define DO_MULTIBYTE (HAVE_MBLEN && ! MULTIBYTE_IS_FORMAT_SAFE) + +#if DO_MULTIBYTE +# if HAVE_MBRLEN +# include <wchar.h> +# else + /* Simulate mbrlen with mblen as best we can. */ +# define mbstate_t int +# define mbrlen(s, n, ps) mblen (s, n) +# define mbsinit(ps) (*(ps) == 0) +# endif + static const mbstate_t mbstate_zero; +#endif + +#if HAVE_LIMITS_H +# include <limits.h> +#endif + +#if STDC_HEADERS +# include <stddef.h> +# include <stdlib.h> +# include <string.h> +#else +# define memcpy(d, s, n) bcopy ((s), (d), (n)) +#endif + +#ifndef __P +# if defined (__GNUC__) || (defined (__STDC__) && __STDC__) +# define __P(args) args +# else +# define __P(args) () +# endif /* GCC. */ +#endif /* Not __P. */ + +#ifndef PTR +# ifdef __STDC__ +# define PTR void * +# else +# define PTR char * +# endif +#endif + +#ifndef CHAR_BIT +# define CHAR_BIT 8 +#endif + +#ifndef NULL +# define NULL 0 +#endif + +#define TYPE_SIGNED(t) ((t) -1 < 0) + +/* Bound on length of the string representing an integer value of type t. + Subtract one for the sign bit if t is signed; + 302 / 1000 is log10 (2) rounded up; + add one for integer division truncation; + add one more for a minus sign if t is signed. */ +#define INT_STRLEN_BOUND(t) \ + ((sizeof (t) * CHAR_BIT - TYPE_SIGNED (t)) * 302 / 100 + 1 + TYPE_SIGNED (t)) + +#define TM_YEAR_BASE 1900 + +#ifndef __isleap +/* Nonzero if YEAR is a leap year (every 4 years, + except every 100th isn't, and every 400th is). */ +# define __isleap(year) \ + ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) +#endif + + +#ifdef _LIBC +# define gmtime_r __gmtime_r +# define localtime_r __localtime_r +extern int __tz_compute __P ((time_t timer, const struct tm *tm)); +# define tzname __tzname +# define tzset __tzset +#else +# if ! HAVE_LOCALTIME_R +# if ! HAVE_TM_GMTOFF +/* Approximate gmtime_r as best we can in its absence. */ +# define gmtime_r my_gmtime_r +static struct tm *gmtime_r __P ((const time_t *, struct tm *)); +static struct tm * +gmtime_r (const time_t *t, struct tm *tp) +{ + struct tm *l = gmtime (t); + if (! l) + return 0; + *tp = *l; + return tp; +} +# endif /* ! HAVE_TM_GMTOFF */ + +/* Approximate localtime_r as best we can in its absence. */ +# define localtime_r my_localtime_r +static struct tm *localtime_r __P ((const time_t *, struct tm *)); +static struct tm * +localtime_r (const time_t *t, struct tm *tp) +{ + struct tm *l = localtime (t); + if (! l) + return 0; + *tp = *l; + return tp; +} +# endif /* ! HAVE_LOCALTIME_R */ +#endif /* ! defined (_LIBC) */ + + +#if !defined (memset) && !HAVE_MEMSET && !_LIBC +/* Some systems lack the `memset' function and we don't want to + introduce additional dependencies. */ +static char const spaces[16] = " "; + +# define memset_space(P, Len) \ + do { \ + int _len = (Len); \ + \ + do \ + { \ + int _this = _len > 16 ? 16 : _len; \ + memcpy ((P), spaces, (size_t) _this); \ + (P) += _this; \ + _len -= _this; \ + } \ + while (_len > 0); \ + } while (false) +#else +# define memset_space(P, Len) memset ((P), ' ', (size_t) (Len)) +#endif + +#define add(n, f) \ + do \ + { \ + int _n = (n); \ + int _delta = width - _n; \ + int _incr = _n + (_delta > 0 ? _delta : 0); \ + if (i + _incr >= maxsize) \ + return 0; \ + if (p) \ + { \ + if (_delta > 0) \ + memset_space (p, _delta); \ + f; \ + p += _n; \ + } \ + i += _incr; \ + } while (false) + +#define cpy(n, s) \ + add ((n), \ + if (to_lowcase) \ + memcpy_lowcase (p, (s), (size_t) _n); \ + else if (to_uppcase) \ + memcpy_uppcase (p, (s), (size_t) _n); \ + else \ + memcpy ((PTR) p, (PTR) (s), (size_t) _n)) + + + +#ifdef _LIBC +# define TOUPPER(Ch) toupper (Ch) +# define TOLOWER(Ch) tolower (Ch) +#else +# define TOUPPER(Ch) (islower (Ch) ? toupper (Ch) : (Ch)) +# define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch)) +#endif +/* We don't use `isdigit' here since the locale dependent + interpretation is not what we want here. We only need to accept + the arabic digits in the ASCII range. One day there is perhaps a + more reliable way to accept other sets of digits. */ +#define ISDIGIT(Ch) ((unsigned int) (Ch) - '0' <= 9) + +static char *memcpy_lowcase __P ((char *dest, char const *src, size_t len)); + +static char * +memcpy_lowcase (char *dest, char const *src, size_t len) +{ + while (len-- > 0) + dest[len] = TOLOWER (src[len]); + return dest; +} + +static char *memcpy_uppcase __P ((char *dest, char const *src, size_t len)); + +static char * +memcpy_uppcase (char *dest, char const *src, size_t len) +{ + while (len-- > 0) + dest[len] = TOUPPER (src[len]); + return dest; +} + +#if ! HAVE_TM_GMTOFF +/* Yield the difference between *A and *B, + measured in seconds, ignoring leap seconds. */ +static int tm_diff __P ((const struct tm *, const struct tm *)); +static int +tm_diff (const struct tm *a, const struct tm *b) +{ + /* Compute intervening leap days correctly even if year is negative. + Take care to avoid int overflow in leap day calculations, + but it's OK to assume that A and B are close to each other. */ + int a4 = (a->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (a->tm_year & 3); + int b4 = (b->tm_year >> 2) + (TM_YEAR_BASE >> 2) - ! (b->tm_year & 3); + int a100 = a4 / 25 - (a4 % 25 < 0); + int b100 = b4 / 25 - (b4 % 25 < 0); + int a400 = a100 >> 2; + int b400 = b100 >> 2; + int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400); + int years = a->tm_year - b->tm_year; + int days = (365 * years + intervening_leap_days + + (a->tm_yday - b->tm_yday)); + return (60 * (60 * (24 * days + (a->tm_hour - b->tm_hour)) + + (a->tm_min - b->tm_min)) + + (a->tm_sec - b->tm_sec)); +} +#endif /* ! HAVE_TM_GMTOFF */ + + + +/* The number of days from the first day of the first ISO week of this + year to the year day YDAY with week day WDAY. ISO weeks start on + Monday; the first ISO week has the year's first Thursday. YDAY may + be as small as YDAY_MINIMUM. */ +#define ISO_WEEK_START_WDAY 1 /* Monday */ +#define ISO_WEEK1_WDAY 4 /* Thursday */ +#define YDAY_MINIMUM (-366) +static int iso_week_days __P ((int, int)); +#ifdef __GNUC__ +inline +#endif +static int +iso_week_days (int yday, int wday) +{ + /* Add enough to the first operand of % to make it nonnegative. */ + int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7; + return (yday + - (yday - wday + ISO_WEEK1_WDAY + big_enough_multiple_of_7) % 7 + + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY); +} + + +#ifndef _NL_CURRENT +static char const weekday_name[][10] = + { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" + }; +static char const month_name[][10] = + { + "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" + }; +#endif + + +#if !defined _LIBC && HAVE_TZNAME && HAVE_TZSET + /* Solaris 2.5 tzset sometimes modifies the storage returned by localtime. + Work around this bug by copying *tp before it might be munged. */ + size_t _strftime_copytm __P ((char *, size_t, char const *, + const struct tm *)); + size_t + strftime (s, maxsize, format, tp) + char *s; + size_t maxsize; + char const *format; + const struct tm *tp; + { + struct tm tmcopy; + tmcopy = *tp; + return _strftime_copytm (s, maxsize, format, &tmcopy); +} +# ifdef strftime +# undef strftime +# endif +# define strftime _strftime_copytm +#endif + + + +/* Write information from TP into S according to the format + string FORMAT, writing no more that MAXSIZE characters + (including the terminating '\0') and returning number of + characters written. If S is NULL, nothing will be written + anywhere, so to determine how many characters would be + written, use NULL for S and (size_t) UINT_MAX for MAXSIZE. */ +size_t +strftime (char *s, size_t maxsize, char const *format, const struct tm *tp) +{ + int hour12 = tp->tm_hour; +#ifdef _NL_CURRENT + char const *const a_wkday = _NL_CURRENT (LC_TIME, ABDAY_1 + tp->tm_wday); + char const *const f_wkday = _NL_CURRENT (LC_TIME, DAY_1 + tp->tm_wday); + char const *const a_month = _NL_CURRENT (LC_TIME, ABMON_1 + tp->tm_mon); + char const *const f_month = _NL_CURRENT (LC_TIME, MON_1 + tp->tm_mon); + char const *const ampm = _NL_CURRENT (LC_TIME, + hour12 > 11 ? PM_STR : AM_STR); + size_t aw_len = strlen (a_wkday); + size_t am_len = strlen (a_month); + size_t ap_len = strlen (ampm); +#else + char const *const f_wkday = weekday_name[tp->tm_wday]; + char const *const f_month = month_name[tp->tm_mon]; + char const *const a_wkday = f_wkday; + char const *const a_month = f_month; + char const *const ampm = "AMPM" + 2 * (hour12 > 11); + size_t aw_len = 3; + size_t am_len = 3; + size_t ap_len = 2; +#endif + size_t wkday_len = strlen (f_wkday); + size_t month_len = strlen (f_month); + char const *zone; + size_t zonelen; + size_t i = 0; + char *p = s; + char const *f; + + zone = NULL; +#if !defined _LIBC && HAVE_TM_ZONE + /* XXX We have some problems here. First, the string pointed to by + tm_zone is dynamically allocated while loading the zone data. But + when another zone is loaded since the information in TP were + computed this would be a stale pointer. + The second problem is the POSIX test suite which assumes setting + the environment variable TZ to a new value before calling strftime() + will influence the result (the %Z format) even if the information in + TP is computed with a totally different time zone. --drepper@gnu */ + zone = (char const *) tp->tm_zone; +#endif +#if HAVE_TZNAME + /* POSIX.1 8.1.1 requires that whenever strftime() is called, the + time zone names contained in the external variable `tzname' shall + be set as if the tzset() function had been called. */ +# if HAVE_TZSET + tzset (); +# endif + + if (!(zone && *zone) && tp->tm_isdst >= 0) + zone = tzname[tp->tm_isdst]; +#endif + if (! zone) + zone = ""; /* POSIX.2 requires the empty string here. */ + + zonelen = strlen (zone); + + if (hour12 > 12) + hour12 -= 12; + else + if (hour12 == 0) hour12 = 12; + + for (f = format; *f != '\0'; ++f) + { + int pad; /* Padding for number ('-', '_', or 0). */ + int modifier; /* Field modifier ('E', 'O', or 0). */ + int digits; /* Max digits for numeric format. */ + int number_value; /* Numeric value to be printed. */ + int negative_number; /* 1 if the number is negative. */ + char const *subfmt; + char *bufp; + char buf[1 + (sizeof (int) < sizeof (time_t) + ? INT_STRLEN_BOUND (time_t) + : INT_STRLEN_BOUND (int))]; + int width = -1; + int to_lowcase = 0; + int to_uppcase = 0; + +#if DO_MULTIBYTE + + switch (*f) + { + case '%': + break; + +#if __STDC__ + case '\a': +#else + case 7: /* '\a' is ASCII decimal value 7. */ +#endif + case '\b': case '\t': case '\n': + case '\v': case '\f': case '\r': + 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 '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 '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 '~': + /* The C Standard requires these 98 characters (plus '%') to + be in the basic execution character set. None of these + characters can start a multibyte sequence, so they need + not be analyzed further. */ + add (1, *p = *f); + continue; + + default: + /* Copy this multibyte sequence until we reach its end, find + an error, or come back to the initial shift state. */ + { + mbstate_t mbstate = mbstate_zero; + size_t len = 0; + + do + { + size_t bytes = mbrlen (f + len, (size_t) -1, &mbstate); + + if (bytes == 0) + break; + + if (bytes == (size_t) -2 || bytes == (size_t) -1) + { + len++; + break; + } + + len += bytes; + } + while (! mbsinit (&mbstate)); + + cpy (len, f); + continue; + } + } + +#else /* ! DO_MULTIBYTE */ + + /* Either multibyte encodings are not supported, or they are + safe for formats, so any non-'%' byte can be copied through. */ + if (*f != '%') + { + add (1, *p = *f); + continue; + } + +#endif /* ! DO_MULTIBYTE */ + + /* Check for flags that can modify a format. */ + pad = 0; + while (1) + { + switch (*++f) + { + /* This influences the number formats. */ + case '_': + case '-': + case '0': + pad = *f; + continue; + + /* This changes textual output. */ + case '^': + to_uppcase = 1; + continue; + + default: + break; + } + break; + } + + /* As a GNU extension we allow to specify the field width. */ + if (ISDIGIT (*f)) + { + width = 0; + do + { + width *= 10; + width += *f - '0'; + ++f; + } + while (ISDIGIT (*f)); + } + + /* Check for modifiers. */ + switch (*f) + { + case 'E': + case 'O': + modifier = *f++; + break; + + default: + modifier = 0; + break; + } + + /* Now do the specified format. */ + switch (*f) + { +#define DO_NUMBER(d, v) \ + digits = d; number_value = v; goto do_number +#define DO_NUMBER_SPACEPAD(d, v) \ + digits = d; number_value = v; goto do_number_spacepad + + case '%': + if (modifier != 0) + goto bad_format; + add (1, *p = *f); + break; + + case 'a': + if (modifier != 0) + goto bad_format; + cpy (aw_len, a_wkday); + break; + + case 'A': + if (modifier != 0) + goto bad_format; + cpy (wkday_len, f_wkday); + break; + + case 'b': + case 'h': /* POSIX.2 extension. */ + if (modifier != 0) + goto bad_format; + cpy (am_len, a_month); + break; + + case 'B': + if (modifier != 0) + goto bad_format; + cpy (month_len, f_month); + break; + + case 'c': + if (modifier == 'O') + goto bad_format; +#ifdef _NL_CURRENT + if (! (modifier == 'E' + && *(subfmt = _NL_CURRENT (LC_TIME, ERA_D_T_FMT)) != '\0')) + subfmt = _NL_CURRENT (LC_TIME, D_T_FMT); +#else + subfmt = "%a %b %e %H:%M:%S %Y"; +#endif + + subformat: + { + char *old_start = p; + size_t len = strftime (NULL, maxsize - i, subfmt, tp); + if (len == 0 && *subfmt) + return 0; + add (len, strftime (p, maxsize - i, subfmt, tp)); + + if (to_uppcase) + while (old_start < p) + { + *old_start = TOUPPER (*old_start); + ++old_start; + } + } + break; + + case 'C': /* POSIX.2 extension. */ + if (modifier == 'O') + goto bad_format; +#if HAVE_STRUCT_ERA_ENTRY + if (modifier == 'E') + { + struct era_entry *era = _nl_get_era_entry (tp); + if (era) + { + size_t len = strlen (era->name_fmt); + cpy (len, era->name_fmt); + break; + } + } +#endif + { + int year = tp->tm_year + TM_YEAR_BASE; + DO_NUMBER (1, year / 100 - (year % 100 < 0)); + } + + case 'x': + if (modifier == 'O') + goto bad_format; +#ifdef _NL_CURRENT + if (! (modifier == 'E' + && *(subfmt = _NL_CURRENT (LC_TIME, ERA_D_FMT)) != '\0')) + subfmt = _NL_CURRENT (LC_TIME, D_FMT); + goto subformat; +#endif + /* Fall through. */ + case 'D': /* POSIX.2 extension. */ + if (modifier != 0) + goto bad_format; + subfmt = "%m/%d/%y"; + goto subformat; + + case 'd': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (2, tp->tm_mday); + + case 'e': /* POSIX.2 extension. */ + if (modifier == 'E') + goto bad_format; + + DO_NUMBER_SPACEPAD (2, tp->tm_mday); + + /* All numeric formats set DIGITS and NUMBER_VALUE and then + jump to one of these two labels. */ + + do_number_spacepad: + /* Force `_' flag unless overwritten by `0' flag. */ + if (pad != '0') + pad = '_'; + + do_number: + /* Format the number according to the MODIFIER flag. */ + +#ifdef _NL_CURRENT + if (modifier == 'O' && 0 <= number_value) + { + /* Get the locale specific alternate representation of + the number NUMBER_VALUE. If none exist NULL is returned. */ + char const *cp = _nl_get_alt_digit (number_value); + + if (cp != NULL) + { + size_t digitlen = strlen (cp); + if (digitlen != 0) + { + cpy (digitlen, cp); + break; + } + } + } +#endif + { + unsigned int u = number_value; + + bufp = buf + sizeof (buf); + negative_number = number_value < 0; + + if (negative_number) + u = -u; + + do + *--bufp = u % 10 + '0'; + while ((u /= 10) != 0); + } + + do_number_sign_and_padding: + if (negative_number) + *--bufp = '-'; + + if (pad != '-') + { + int padding = digits - (buf + sizeof (buf) - bufp); + + if (pad == '_') + { + while (0 < padding--) + *--bufp = ' '; + } + else + { + bufp += negative_number; + while (0 < padding--) + *--bufp = '0'; + if (negative_number) + *--bufp = '-'; + } + } + + cpy (buf + sizeof (buf) - bufp, bufp); + break; + + + case 'H': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (2, tp->tm_hour); + + case 'I': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (2, hour12); + + case 'k': /* GNU extension. */ + if (modifier == 'E') + goto bad_format; + + DO_NUMBER_SPACEPAD (2, tp->tm_hour); + + case 'l': /* GNU extension. */ + if (modifier == 'E') + goto bad_format; + + DO_NUMBER_SPACEPAD (2, hour12); + + case 'j': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (3, 1 + tp->tm_yday); + + case 'M': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (2, tp->tm_min); + + case 'm': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (2, tp->tm_mon + 1); + + case 'n': /* POSIX.2 extension. */ + add (1, *p = '\n'); + break; + + case 'P': + to_lowcase = 1; + /* FALLTHROUGH */ + + case 'p': + cpy (ap_len, ampm); + break; + + case 'R': /* GNU extension. */ + subfmt = "%H:%M"; + goto subformat; + + case 'r': /* POSIX.2 extension. */ +#ifdef _NL_CURRENT + if (*(subfmt = _NL_CURRENT (LC_TIME, T_FMT_AMPM)) == '\0') +#endif + subfmt = "%I:%M:%S %p"; + goto subformat; + + case 'S': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (2, tp->tm_sec); + + case 's': /* GNU extension. */ + { + struct tm ltm; + time_t t; + + ltm = *tp; + t = mktime (<m); + + /* Generate string value for T using time_t arithmetic; + this works even if sizeof (long) < sizeof (time_t). */ + + bufp = buf + sizeof (buf); + negative_number = t < 0; + + do + { + int d = t % 10; + t /= 10; + + if (negative_number) + { + d = -d; + + /* Adjust if division truncates to minus infinity. */ + if (0 < -1 % 10 && d < 0) + { + t++; + d += 10; + } + } + + *--bufp = d + '0'; + } + while (t != 0); + + digits = 1; + goto do_number_sign_and_padding; + } + + case 'X': + if (modifier == 'O') + goto bad_format; +#ifdef _NL_CURRENT + if (! (modifier == 'E' + && *(subfmt = _NL_CURRENT (LC_TIME, ERA_T_FMT)) != '\0')) + subfmt = _NL_CURRENT (LC_TIME, T_FMT); + goto subformat; +#endif + /* Fall through. */ + case 'T': /* POSIX.2 extension. */ + subfmt = "%H:%M:%S"; + goto subformat; + + case 't': /* POSIX.2 extension. */ + add (1, *p = '\t'); + break; + + case 'u': /* POSIX.2 extension. */ + DO_NUMBER (1, (tp->tm_wday - 1 + 7) % 7 + 1); + + case 'U': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (2, (tp->tm_yday - tp->tm_wday + 7) / 7); + + case 'V': + case 'g': /* GNU extension. */ + case 'G': /* GNU extension. */ + if (modifier == 'E') + goto bad_format; + { + int year = tp->tm_year + TM_YEAR_BASE; + int days = iso_week_days (tp->tm_yday, tp->tm_wday); + + if (days < 0) + { + /* This ISO week belongs to the previous year. */ + year--; + days = iso_week_days (tp->tm_yday + (365 + __isleap (year)), + tp->tm_wday); + } + else + { + int d = iso_week_days (tp->tm_yday - (365 + __isleap (year)), + tp->tm_wday); + if (0 <= d) + { + /* This ISO week belongs to the next year. */ + year++; + days = d; + } + } + + switch (*f) + { + case 'g': + DO_NUMBER (2, (year % 100 + 100) % 100); + + case 'G': + DO_NUMBER (1, year); + + default: + DO_NUMBER (2, days / 7 + 1); + } + } + + case 'W': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (2, (tp->tm_yday - (tp->tm_wday - 1 + 7) % 7 + 7) / 7); + + case 'w': + if (modifier == 'E') + goto bad_format; + + DO_NUMBER (1, tp->tm_wday); + + case 'Y': +#if HAVE_STRUCT_ERA_ENTRY + if (modifier == 'E') + { + struct era_entry *era = _nl_get_era_entry (tp); + if (era) + { + subfmt = strchr (era->name_fmt, '\0') + 1; + goto subformat; + } + } +#endif + if (modifier == 'O') + goto bad_format; + else + DO_NUMBER (1, tp->tm_year + TM_YEAR_BASE); + + case 'y': +#if HAVE_STRUCT_ERA_ENTRY + if (modifier == 'E') + { + struct era_entry *era = _nl_get_era_entry (tp); + if (era) + { + int delta = tp->tm_year - era->start_date[0]; + DO_NUMBER (1, (era->offset + + (era->direction == '-' ? -delta : delta))); + } + } +#endif + DO_NUMBER (2, (tp->tm_year % 100 + 100) % 100); + + case 'Z': + cpy (zonelen, zone); + break; + + case 'z': /* GNU extension. */ + if (tp->tm_isdst < 0) + break; + + { + int diff; +#if HAVE_TM_GMTOFF + diff = tp->tm_gmtoff; +#else + struct tm gtm; + struct tm ltm; + time_t lt; + + ltm = *tp; + lt = mktime (<m); + + if (lt == (time_t) -1) + { + /* mktime returns -1 for errors, but -1 is also a + valid time_t value. Check whether an error really + occurred. */ + struct tm tm; + localtime_r (<, &tm); + + if ((ltm.tm_sec ^ tm.tm_sec) + | (ltm.tm_min ^ tm.tm_min) + | (ltm.tm_hour ^ tm.tm_hour) + | (ltm.tm_mday ^ tm.tm_mday) + | (ltm.tm_mon ^ tm.tm_mon) + | (ltm.tm_year ^ tm.tm_year)) + break; + } + + if (! gmtime_r (<, >m)) + break; + + diff = tm_diff (<m, >m); +#endif + + if (diff < 0) + { + add (1, *p = '-'); + diff = -diff; + } + else + add (1, *p = '+'); + + diff /= 60; + DO_NUMBER (4, (diff / 60) * 100 + diff % 60); + } + + case '\0': /* GNU extension: % at end of format. */ + --f; + /* Fall through. */ + default: + /* Unknown format; output the format, including the '%', + since this is most likely the right thing to do if a + multibyte string has been misparsed. */ + bad_format: + { + int flen; + for (flen = 1; f[1 - flen] != '%'; flen++) + continue; + cpy (flen, &f[1 - flen]); + } + break; + } + } + + if (p) + *p = '\0'; + return i; +} + +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of compat/strftime.c */ diff --git a/compat/strsignal.c b/compat/strsignal.c new file mode 100644 index 0000000..cb92550 --- /dev/null +++ b/compat/strsignal.c @@ -0,0 +1,121 @@ + +/** + * \file strsignal.c + * + * Time-stamp: "2010-07-16 15:12:27 bkorb" + * + * This file is part of AutoGen. + * + * AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * + * AutoGen 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. + * + * AutoGen 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/>. + * + * As a special exception, Bruce Korb gives permission for additional + * uses of the text contained in the release of strsignal. + * + * The exception is that, if you link the strsignal library with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the strsignal library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by Bruce Korb under + * the name strsignal. If you copy code from other sources under the + * General Public License into a copy of strsignal, as the General Public + * License permits, the exception does not apply to the code that you add + * in this way. To avoid misleading anyone as to the status of such + * modified files, you must delete this exception notice from them. + * + * If you write modifications of your own for strsignal, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + */ + +#include "compat.h" + +/* Routines imported from standard C runtime libraries. */ + +#if ! defined(HAVE_STRSIGNAL) + +#ifdef __STDC__ +# include <stddef.h> +#else /* !__STDC__ */ +# ifndef const +# define const +# endif +#endif /* __STDC__ */ + +#ifdef HAVE_SYS_SIGLIST +# include <signal.h> +#endif + +/* + * Import the generated tables + */ +#include "strsignal.h" +#endif + +#ifndef HAVE_STRSIGNAL + +/* + +NAME + + strsignal -- map a signal number to a signal message string + +SYNOPSIS + + char *strsignal (int signo) + +DESCRIPTION + + Maps an signal number to an signal message string, the contents of + which are implementation defined. On systems which have the external + variable sys_siglist, these strings will be the same as the ones used + by psignal(). + + If the supplied signal number is within the valid range of indices + for the sys_siglist, but no message is available for the particular + signal number, then returns the string "Signal NUM", where NUM is the + signal number. + + If the supplied signal number is not a valid index into sys_siglist, + returns NULL. + + The returned string is only guaranteed to be valid only until the + next call to strsignal. + + Also, though not declared "const", it is. +*/ + +char * +strsignal( int signo ) +{ + if (SIGNAL_IN_RANGE( signo )) + return (char*)SIGNAL_INFO( signo ); + + return NULL; +} +#endif /* HAVE_STRSIGNAL */ + +/* + * Local Variables: + * mode: C + * c-file-style: "stroustrup" + * indent-tabs-mode: nil + * End: + * end of compat/strsignal.c */ diff --git a/compat/strsignal.def b/compat/strsignal.def new file mode 100644 index 0000000..f645d10 --- /dev/null +++ b/compat/strsignal.def @@ -0,0 +1,151 @@ +autogen definitions strsignal; + +/* + * Dynamic definitions for creating the strsignal.h header file + * + * This file is part of AutoGen. + * + * AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * + * AutoGen 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. + * + * AutoGen 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/>. + */ + +#shell + +RE_sigfind='[A-Z12]+[ ]+[1-9][0-9]*' +RE_sigdef='^#[ ]*define[ ][ ]*_*SIG' +RE_inc='^#[ ]*include[ ][ ]*<' + +threshold=5 # minimum number of signals to accept +num=0 # number of signals defined in this file +seen="" # include files already searched +files="sys/signal.h" # initial files to search + +cd /usr/include +while test -n "$files" +do + for file in $files; do + # look for $threshold or more matches in one of the search files + test -f $file || continue + sigs=`egrep "$RE_sigdef$RE_sigfind" $file|sed "s,$RE_sigdef,,"` + test -z "$sigs" || num=`echo "$sigs" | wc -l` + test $num -lt $threshold || break + seen="$file $seen" + done + test $num -lt $threshold || break + + # IF no file has $threshold or better SIG matches; + # generate a new search list from all files #included from the old list + newfiles="" + for file in $files; do + test -f $file || continue + new=`egrep "$RE_inc" $file|sed "s,$RE_inc,,"';s,>.*$,,'` + newfiles=" $new $newfiles" + done + + # remove any files that have been searched previously + for file in $seen; do + newfiles=`echo "$newfiles"|sed "s, $file , ,g"` + done + + # set the search list for the next iteration + files="$newfiles" + num=0 +done + +if test $num -lt $threshold +then + echo "WARNING: cannot find signal definitions in $seen" >&2 + echo "using POSIX + ANSI signal definitions" >&2 + cat <<- _EOF_ + signal[ 1 ] = { signame = SIGHUP; + sigtext = "Hangup (POSIX)."; }; + signal[ 2 ] = { signame = SIGINT; + sigtext = "Interrupt (ANSI)."; }; + signal[ 3 ] = { signame = SIGQUIT; + sigtext = "Quit (POSIX)."; }; + signal[ 4 ] = { signame = SIGILL; + sigtext = "Illegal instruction (ANSI)."; }; + signal[ 5 ] = { signame = SIGTRAP; + sigtext = "Trace trap (POSIX)."; }; + signal[ 6 ] = { signame = SIGABRT; + sigtext = "Abort (ANSI)."; }; + signal[ 8 ] = { signame = SIGFPE; + sigtext = "Floating-point exception (ANSI)."; }; + signal[ 9 ] = { signame = SIGKILL; + sigtext = "Kill, unblockable (POSIX)."; }; + signal[ 10 ] = { signame = SIGUSR1; + sigtext = "User-defined signal 1 (POSIX)."; }; + signal[ 11 ] = { signame = SIGSEGV; + sigtext = "Segmentation violation (ANSI)."; }; + signal[ 12 ] = { signame = SIGUSR2; + sigtext = "User-defined signal 2 (POSIX)."; }; + signal[ 13 ] = { signame = SIGPIPE; + sigtext = "Broken pipe (POSIX)."; }; + signal[ 14 ] = { signame = SIGALRM; + sigtext = "Alarm clock (POSIX)."; }; + signal[ 15 ] = { signame = SIGTERM; + sigtext = "Termination (ANSI)."; }; + signal[ 17 ] = { signame = SIGCHLD; + sigtext = "Child status has changed (POSIX)."; }; + signal[ 18 ] = { signame = SIGCONT; + sigtext = "Continue (POSIX)."; }; + signal[ 19 ] = { signame = SIGSTOP; + sigtext = "Stop, unblockable (POSIX)."; }; + signal[ 20 ] = { signame = SIGTSTP; + sigtext = "Keyboard stop (POSIX)."; }; + signal[ 21 ] = { signame = SIGTTIN; + sigtext = "Background read from tty (POSIX)."; }; + signal[ 22 ] = { signame = SIGTTOU; + sigtext = "Background write to tty (POSIX)."; }; +_EOF_ + +else + echo "$sigs" | + while read SIG NUM f + do + # IF the "signal number" is octal or hex or non-numeric, + # THEN we know it is a value we are not interested in + # + case ${NUM} in + *[A-Za-z_]* ) + continue ;; + esac + + # Sometimes, there are aliases. Accept only the first. + # + if eval test ! -z \"\$HAVE_${NUM}\" + then continue ; fi + + # We also know we are not interested in super large numbers + # (e.g. SIGSTKSZ 8192) + # + if test ${NUM} -gt 127 + then continue ; fi + + eval HAVE_${NUM}=1 + f=`echo "$f" | sed -e 's;/\*[ ]*;;' -e 's;[ ]*\*/;;'` + if test -z "$f" + then f="Undescribed: SIG${SIG} (${NUM})" ; fi + + cat <<- _EOF_ + signal[ ${NUM} ] = { + signame = ${SIG}; + sigtext = "$f"; + }; + + _EOF_ + done +fi +#endshell diff --git a/compat/strsignal.h b/compat/strsignal.h new file mode 100644 index 0000000..0c30679 --- /dev/null +++ b/compat/strsignal.h @@ -0,0 +1,110 @@ +/* -*- buffer-read-only: t -*- vi: set ro: + * + * DO NOT EDIT THIS FILE (strsignal.h) + * + * It has been AutoGen-ed August 11, 2012 at 09:41:52 AM by AutoGen 5.16.2pre7 + * From the definitions strsignal.def + * and the template file strsignal + * + * Generated for a 3.1.10-1.16-desktop Linux platform + * + * strsignal copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * + * AutoGen 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. + * + * AutoGen 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/>. + */ +#ifndef MAX_SIGNAL_NUMBER +#define MAX_SIGNAL_NUMBER 32 +#define SIGNAL_IN_RANGE(s) (((unsigned)s) <= MAX_SIGNAL_NUMBER) +#define SIGNAL_NAME(s) (zSigNames + sigNameOffset[s]) +#define SIGNAL_INFO(s) (zSigInfo + sigInfoOffset[s]) + +static char const zSigNames[] = + "INVALID\0" "SIGHUP\0" "SIGINT\0" "SIGQUIT\0" "SIGILL\0" + "SIGTRAP\0" "SIGABRT\0" "SIGBUS\0" "SIGFPE\0" "SIGKILL\0" + "SIGUSR1\0" "SIGSEGV\0" "SIGUSR2\0" "SIGPIPE\0" "SIGALRM\0" + "SIGTERM\0" "SIGSTKFLT\0" "SIGCHLD\0" "SIGCONT\0" "SIGSTOP\0" + "SIGTSTP\0" "SIGTTIN\0" "SIGTTOU\0" "SIGURG\0" "SIGXCPU\0" + "SIGXFSZ\0" "SIGVTALRM\0" "SIGPROF\0" "SIGWINCH\0" "SIGIO\0" + "SIGPWR\0" "SIGSYS\0" "SIGRTMIN\0"; + +static const unsigned int sigNameOffset[] = { + 0, 8, 15, 22, 30, 37, 45, 53, 60, 67, 75, 83, 91, 99, 107, + 115, 123, 133, 141, 149, 157, 165, 173, 181, 188, 196, 204, 214, 222, 231, + 237, 244, 251 }; + +#ifndef HAVE_SYS_SIGLIST +static char const zSigInfo[] = + /* 0 */ "Signal 0 invalid\0" + /* 1 */ "Hangup (POSIX).\0" + /* 2 */ "Interrupt (ANSI).\0" + /* 3 */ "Quit (POSIX).\0" + /* 4 */ "Illegal instruction (ANSI).\0" + /* 5 */ "Trace trap (POSIX).\0" + /* 6 */ "Abort (ANSI).\0" + /* 7 */ "BUS error (4.2 BSD).\0" + /* 8 */ "Floating-point exception (ANSI).\0" + /* 9 */ "Kill, unblockable (POSIX).\0" + /* 10 */ "User-defined signal 1 (POSIX).\0" + /* 11 */ "Segmentation violation (ANSI).\0" + /* 12 */ "User-defined signal 2 (POSIX).\0" + /* 13 */ "Broken pipe (POSIX).\0" + /* 14 */ "Alarm clock (POSIX).\0" + /* 15 */ "Termination (ANSI).\0" + /* 16 */ "Stack fault.\0" + /* 17 */ "Child status has changed (POSIX).\0" + /* 18 */ "Continue (POSIX).\0" + /* 19 */ "Stop, unblockable (POSIX).\0" + /* 20 */ "Keyboard stop (POSIX).\0" + /* 21 */ "Background read from tty (POSIX).\0" + /* 22 */ "Background write to tty (POSIX).\0" + /* 23 */ "Urgent condition on socket (4.2 BSD).\0" + /* 24 */ "CPU limit exceeded (4.2 BSD).\0" + /* 25 */ "File size limit exceeded (4.2 BSD).\0" + /* 26 */ "Virtual alarm clock (4.2 BSD).\0" + /* 27 */ "Profiling alarm clock (4.2 BSD).\0" + /* 28 */ "Window size change (4.3 BSD, Sun).\0" + /* 29 */ "I/O now possible (4.2 BSD).\0" + /* 30 */ "Power failure restart (System V).\0" + /* 31 */ "Bad system call.\0" + /* 32 */ "Undescribed: SIGRTMIN (32)\0"; + +static const unsigned int sigInfoOffset[] = { + 0, 17, 33, 51, 65, 93, 113, 127, 148, 181, 208, 239, 270, 301, 322, + 343, 363, 376, 410, 428, 455, 478, 512, 545, 583, 613, 649, 680, 713, 748, + 776, 810, 827 }; + +#endif /* MAX_SIGNAL_NUMBER */ + +#ifndef HAVE_STRSIGNAL +extern char * strsignal( int signo ); +#endif + +#ifdef DEBUG_STRSIGNAL +#include <stdio.h> + +int +main( int argc, char** argv ) +{ + int sig = 0; + fputs( "Sig Sig-Name Description\n" + "=== ======== ===========\n", stdout ); + do { + printf( "%3d %-10s %s\n", sig, SIGNAL_NAME(sig), + SIGNAL_INFO(sig) ); + ++sig; + } while (SIGNAL_IN_RANGE(sig)); + return 0; +} +#endif /* DEBUG */ +#endif /* MAX_SIGNAL_NUMBER */ diff --git a/compat/strsignal.tpl b/compat/strsignal.tpl new file mode 100644 index 0000000..e017764 --- /dev/null +++ b/compat/strsignal.tpl @@ -0,0 +1,126 @@ +[= AutoGen5 template -*- Mode: html -*- + +h + +## This file is part of AutoGen. +## AutoGen Copyright (c) 1992-2012 by Bruce Korb - all rights reserved +## +## AutoGen 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. +## +## AutoGen 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/>. + +(setenv "SHELL" "/bin/sh") + +=] +[=(dne " * " "/* ")=] + * + * Generated for a [=`uname -r`=] [=`uname`=] platform + * + * strsignal copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * +[=(gpl "AutoGen" " * ")=] + */ +#ifndef MAX_SIGNAL_NUMBER +#define MAX_SIGNAL_NUMBER [= (high-lim "signal") =] +#define SIGNAL_IN_RANGE(s) (((unsigned)s) <= MAX_SIGNAL_NUMBER) +#define SIGNAL_NAME(s) (zSigNames + sigNameOffset[s]) +#define SIGNAL_INFO(s) (zSigInfo + sigInfoOffset[s])[= + +(define sig-names "\"INVALID\\0\"\n") +(define name-refs "") +(define name-ix (- (string-length sig-names) 4)) +(define tmp-text "") + +(define sig-info "") +(define info-refs "") +(define info-ix 0) + +(define add-string (lambda() + (if (exist? "signame") + (begin + (set! tmp-text (string-append "\"SIG" (get "signame") "\\0\"\n")) + (set! sig-names (string-append sig-names tmp-text)) + (set! name-refs (string-append name-refs + (sprintf "%d\n" name-ix) )) + (set! name-ix (+ name-ix (string-length tmp-text) -4)) + + (set! tmp-text (sprintf "/* %3d */ \"%s\\0\"\n" + (for-index) (get "sigtext"))) + ) + + (begin + (set! name-refs (string-append name-refs "0\n")) + (set! tmp-text (sprintf "/* %1$3d */ \"Signal %1$d invalid\\0\"\n" + (for-index))) + ) ) + + (set! sig-info (string-append sig-info tmp-text)) + (set! info-refs (string-append info-refs + (sprintf "%d\n" info-ix) )) + (set! info-ix (+ info-ix (string-length tmp-text) -14)) +)) =][= + +FOR signal (for-from 0) (for-by 1) =][= + + (add-string) =][= + +ENDFOR signal =] + +static char const zSigNames[] = +[=(shell (string-append + "columns -I4 --spread=1 <<'_EOF_'\n" + sig-names + "_EOF_" )) =]; + +static const unsigned int sigNameOffset[] = { +[=(shell (string-append + "columns -I4 -S, --spread=1 <<'_EOF_'\n" + name-refs + "_EOF_" )) =] }; + +#ifndef HAVE_SYS_SIGLIST +static char const zSigInfo[] = +[=(shell (string-append + "columns -I4 --spread=1 <<'_EOF_'\n" + sig-info + "_EOF_" )) =]; + +static const unsigned int sigInfoOffset[] = { +[=(shell (string-append + "columns -I4 -S, --spread=1 <<'_EOF_'\n" + info-refs + "_EOF_" )) =] }; + +#endif /* MAX_SIGNAL_NUMBER */ + +#ifndef HAVE_STRSIGNAL +extern char * strsignal( int signo ); +#endif + +#ifdef DEBUG_STRSIGNAL +#include <stdio.h> + +int +main( int argc, char** argv ) +{ + int sig = 0; + fputs( "Sig Sig-Name Description\n" + "=== ======== ===========\n", stdout ); + do { + printf( "%3d %-10s %s\n", sig, SIGNAL_NAME(sig), + SIGNAL_INFO(sig) ); + ++sig; + } while (SIGNAL_IN_RANGE(sig)); + return 0; +} +#endif /* DEBUG */ +#endif /* MAX_SIGNAL_NUMBER */ diff --git a/compat/unlocked-io.h b/compat/unlocked-io.h new file mode 100644 index 0000000..65bfbc4 --- /dev/null +++ b/compat/unlocked-io.h @@ -0,0 +1,136 @@ +/* Prefer faster, non-thread-safe stdio functions if available. + + Copyright (C) 2001-2004, 2009-2012 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. */ + +#ifndef UNLOCKED_IO_H +# define UNLOCKED_IO_H 1 + +/* These are wrappers for functions/macros from the GNU C library, and + from other C libraries supporting POSIX's optional thread-safe functions. + + The standard I/O functions are thread-safe. These *_unlocked ones are + more efficient but not thread-safe. That they're not thread-safe is + fine since all of the applications in this package are single threaded. + + Also, some code that is shared with the GNU C library may invoke + the *_unlocked functions directly. On hosts that lack those + functions, invoke the non-thread-safe versions instead. */ + +# include <stdio.h> + +# if HAVE_DECL_CLEARERR_UNLOCKED +# undef clearerr +# define clearerr(x) clearerr_unlocked (x) +# else +# define clearerr_unlocked(x) clearerr (x) +# endif + +# if HAVE_DECL_FEOF_UNLOCKED +# undef feof +# define feof(x) feof_unlocked (x) +# else +# define feof_unlocked(x) feof (x) +# endif + +# if HAVE_DECL_FERROR_UNLOCKED +# undef ferror +# define ferror(x) ferror_unlocked (x) +# else +# define ferror_unlocked(x) ferror (x) +# endif + +# if HAVE_DECL_FFLUSH_UNLOCKED +# undef fflush +# define fflush(x) fflush_unlocked (x) +# else +# define fflush_unlocked(x) fflush (x) +# endif + +# if HAVE_DECL_FGETS_UNLOCKED +# undef fgets +# define fgets(x,y,z) fgets_unlocked (x,y,z) +# else +# define fgets_unlocked(x,y,z) fgets (x,y,z) +# endif + +# if HAVE_DECL_FPUTC_UNLOCKED +# undef fputc +# define fputc(x,y) fputc_unlocked (x,y) +# else +# define fputc_unlocked(x,y) fputc (x,y) +# endif + +# if HAVE_DECL_FPUTS_UNLOCKED +# undef fputs +# define fputs(x,y) fputs_unlocked (x,y) +# else +# define fputs_unlocked(x,y) fputs (x,y) +# endif + +# if HAVE_DECL_FREAD_UNLOCKED +# undef fread +# define fread(w,x,y,z) fread_unlocked (w,x,y,z) +# else +# define fread_unlocked(w,x,y,z) fread (w,x,y,z) +# endif + +# if HAVE_DECL_FWRITE_UNLOCKED +# undef fwrite +# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z) +# else +# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) +# endif + +# if HAVE_DECL_GETC_UNLOCKED +# undef getc +# define getc(x) getc_unlocked (x) +# else +# define getc_unlocked(x) getc (x) +# endif + +# if HAVE_DECL_GETCHAR_UNLOCKED +# undef getchar +# define getchar() getchar_unlocked () +# else +# define getchar_unlocked() getchar () +# endif + +# if HAVE_DECL_PUTC_UNLOCKED +# undef putc +# define putc(x,y) putc_unlocked (x,y) +# else +# define putc_unlocked(x,y) putc (x,y) +# endif + +# if HAVE_DECL_PUTCHAR_UNLOCKED +# undef putchar +# define putchar(x) putchar_unlocked (x) +# else +# define putchar_unlocked(x) putchar (x) +# endif + +# undef flockfile +# define flockfile(x) ((void) 0) + +# undef ftrylockfile +# define ftrylockfile(x) 0 + +# undef funlockfile +# define funlockfile(x) ((void) 0) + +#endif /* UNLOCKED_IO_H */ diff --git a/compat/windows-config.h b/compat/windows-config.h new file mode 100644 index 0000000..ddb4ce1 --- /dev/null +++ b/compat/windows-config.h @@ -0,0 +1,156 @@ + +/** + * \file autoopts.c + * + * Time-stamp: "2012-06-15 12:31:28 bkorb" + * + * This file contains all of the routines that must be linked into + * an executable to use the generated option processing. The optional + * routines are in separately compiled modules so that they will not + * necessarily be linked in. + * + * This file is part of AutoOpts, a companion to AutoGen. + * AutoOpts is free software. + * AutoOpts is Copyright (c) 1992-2012 by Bruce Korb - all rights reserved + * + * AutoOpts is available under any one of two licenses. The license + * in use must be one of these two and the choice is under the control + * of the user of the license. + * + * The GNU Lesser General Public License, version 3 or later + * See the files "COPYING.lgplv3" and "COPYING.gplv3" + * + * The Modified Berkeley Software Distribution License + * See the file "COPYING.mbsd" + * + * These files have the following md5sums: + * + * 43b91e8ca915626ed3818ffb1b71248b pkg/libopts/COPYING.gplv3 + * 06a1a2e4760c90ea5e1dad8dfaac4d39 pkg/libopts/COPYING.lgplv3 + * 66a5cedaf62c4b2637025f049f9b826f pkg/libopts/COPYING.mbsd + */ + +#ifndef WINDOWS_CONFIG_HACKERY +#define WINDOWS_CONFIG_HACKERY 1 + +/* + * The definitions below have been stolen from NTP's config.h for Windows. + * However, they may be kept here in order to keep libopts independent from + * the NTP project. + */ +#ifndef __windows__ +# define __windows__ 4 +#endif + +/* + * Miscellaneous functions that Microsoft maps + * to other names + * + * #define inline __inline + * #define vsnprintf _vsnprintf + */ +#define snprintf _snprintf +/* + * #define stricmp _stricmp + * #define strcasecmp _stricmp + * #define isascii __isascii + * #define finite _finite + * #define random rand + * #define srandom srand + */ + +#define SIZEOF_INT 4 +#define SIZEOF_CHARP 4 +#define SIZEOF_LONG 4 +#define SIZEOF_SHORT 2 + +typedef unsigned long uintptr_t; + +/* + * # define HAVE_NET_IF_H + * # define QSORT_USES_VOID_P + * # define HAVE_SETVBUF + * # define HAVE_VSPRINTF + * # define HAVE_SNPRINTF + * # define HAVE_VSNPRINTF + * # define HAVE_PROTOTYPES /* from ntpq.mak * / + * # define HAVE_MEMMOVE + * # define HAVE_TERMIOS_H + * # define HAVE_ERRNO_H + * # define HAVE_STDARG_H + * # define HAVE_NO_NICE + * # define HAVE_MKTIME + * # define TIME_WITH_SYS_TIME + * # define HAVE_IO_COMPLETION_PORT + * # define ISC_PLATFORM_NEEDNTOP + * # define ISC_PLATFORM_NEEDPTON + * # define NEED_S_CHAR_TYPEDEF + * # define USE_PROTOTYPES /* for ntp_types.h * / + * + * #define ULONG_CONST(a) a ## UL + */ + +#define HAVE_LIMITS_H 1 +#define HAVE_STRDUP 1 +#define HAVE_STRCHR 1 +#define HAVE_FCNTL_H 1 + +/* + * VS.NET's version of wspiapi.h has a bug in it + * where it assigns a value to a variable inside + * an if statement. It should be comparing them. + * We prevent inclusion since we are not using this + * code so we don't have to see the warning messages + */ +#ifndef _WSPIAPI_H_ +#define _WSPIAPI_H_ +#endif + +/* Prevent inclusion of winsock.h in windows.h */ +#ifndef _WINSOCKAPI_ +#define _WINSOCKAPI_ +#endif + +#ifndef __RPCASYNC_H__ +#define __RPCASYNC_H__ +#endif + +/* Include Windows headers */ +#include <windows.h> +#include <winsock2.h> +#include <limits.h> + +/* + * Compatibility declarations for Windows, assuming SYS_WINNT + * has been defined. + */ +#define strdup _strdup +#define stat _stat /* struct stat from <sys/stat.h> */ +#define unlink _unlink +#define fchmod( _x, _y ); +#define ssize_t SSIZE_T + +#include <io.h> +#define open _open +#define close _close +#define read _read +#define write _write +#define lseek _lseek +#define pipe _pipe +#define dup2 _dup2 + +#define O_RDWR _O_RDWR +#define O_RDONLY _O_RDONLY +#define O_EXCL _O_EXCL + +#ifndef S_ISREG +# define S_IFREG _S_IFREG +# define S_ISREG(mode) (((mode) & S_IFREG) == S_IFREG) +#endif + +#ifndef S_ISDIR +# define S_IFDIR _S_IFDIR +# define S_ISDIR(mode) (((mode) & S_IFDIR) == S_IFDIR) +#endif + +#endif /* WINDOWS_CONFIG_HACKERY */ |