Imported Upstream version 2.6.0
This commit is contained in:
parent
26fb71b504
commit
459aaf9392
510 changed files with 40508 additions and 18859 deletions
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
AM_CFLAGS = -I$(top_srcdir)/include
|
||||
|
||||
noinst_LIBRARIES = libcommon.a
|
||||
libcommon_a_SOURCES = common.c state.c upsconf.c ../include/nut_version.h
|
||||
libcommon_a_LIBADD = libparseconf.la
|
||||
|
||||
../include/nut_version.h: FORCE
|
||||
(cd ../include/ && $(MAKE) $(AM_MAKEFLAGS) nut_version.h)
|
||||
|
||||
FORCE:
|
||||
|
||||
noinst_LTLIBRARIES = libparseconf.la
|
||||
noinst_LTLIBRARIES = libparseconf.la libcommon.la
|
||||
libparseconf_la_SOURCES = parseconf.c
|
||||
|
||||
libcommon_la_SOURCES = common.c state.c upsconf.c ../include/nut_version.h
|
||||
# ensure inclusion of local implementation of missing systems functions
|
||||
# using LTLIBOBJS. Refer to configure.in -> AC_REPLACE_FUNCS
|
||||
libcommon_la_LIBADD = libparseconf.la @LTLIBOBJS@
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
# Makefile.in generated by automake 1.11 from Makefile.am.
|
||||
# Makefile.in generated by automake 1.11.1 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
|
||||
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
# Network UPS Tools: common
|
||||
|
||||
|
||||
VPATH = @srcdir@
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
|
|
@ -39,14 +38,16 @@ build_triplet = @build@
|
|||
host_triplet = @host@
|
||||
target_triplet = @target@
|
||||
subdir = common
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in atexit.c \
|
||||
setenv.c snprintf.c strerror.c
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_create_stdint_h.m4 \
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_compare_version.m4 \
|
||||
$(top_srcdir)/m4/ax_create_stdint_h.m4 \
|
||||
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
|
||||
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
|
||||
$(top_srcdir)/m4/lt~obsolete.m4 \
|
||||
$(top_srcdir)/m4/nut_arg_with.m4 \
|
||||
$(top_srcdir)/m4/nut_check_ipv6.m4 \
|
||||
$(top_srcdir)/m4/nut_check_asciidoc.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libgd.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libhal.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libneon.m4 \
|
||||
|
|
@ -56,6 +57,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_create_stdint_h.m4 \
|
|||
$(top_srcdir)/m4/nut_check_libusb.m4 \
|
||||
$(top_srcdir)/m4/nut_check_libwrap.m4 \
|
||||
$(top_srcdir)/m4/nut_check_os.m4 \
|
||||
$(top_srcdir)/m4/nut_config_libhal.m4 \
|
||||
$(top_srcdir)/m4/nut_report_feature.m4 \
|
||||
$(top_srcdir)/m4/nut_type_socklen_t.m4 \
|
||||
$(top_srcdir)/configure.in
|
||||
|
|
@ -65,14 +67,10 @@ mkinstalldirs = $(install_sh) -d
|
|||
CONFIG_HEADER = $(top_builddir)/include/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
LIBRARIES = $(noinst_LIBRARIES)
|
||||
ARFLAGS = cru
|
||||
libcommon_a_AR = $(AR) $(ARFLAGS)
|
||||
libcommon_a_DEPENDENCIES = libparseconf.la
|
||||
am_libcommon_a_OBJECTS = common.$(OBJEXT) state.$(OBJEXT) \
|
||||
upsconf.$(OBJEXT)
|
||||
libcommon_a_OBJECTS = $(am_libcommon_a_OBJECTS)
|
||||
LTLIBRARIES = $(noinst_LTLIBRARIES)
|
||||
libcommon_la_DEPENDENCIES = libparseconf.la @LTLIBOBJS@
|
||||
am_libcommon_la_OBJECTS = common.lo state.lo upsconf.lo
|
||||
libcommon_la_OBJECTS = $(am_libcommon_la_OBJECTS)
|
||||
libparseconf_la_LIBADD =
|
||||
am_libparseconf_la_OBJECTS = parseconf.lo
|
||||
libparseconf_la_OBJECTS = $(am_libparseconf_la_OBJECTS)
|
||||
|
|
@ -89,14 +87,16 @@ CCLD = $(CC)
|
|||
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(libcommon_a_SOURCES) $(libparseconf_la_SOURCES)
|
||||
DIST_SOURCES = $(libcommon_a_SOURCES) $(libparseconf_la_SOURCES)
|
||||
SOURCES = $(libcommon_la_SOURCES) $(libparseconf_la_SOURCES)
|
||||
DIST_SOURCES = $(libcommon_la_SOURCES) $(libparseconf_la_SOURCES)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
A2X = @A2X@
|
||||
ACLOCAL = @ACLOCAL@
|
||||
AMTAR = @AMTAR@
|
||||
AR = @AR@
|
||||
ASCIIDOC = @ASCIIDOC@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
|
|
@ -109,8 +109,10 @@ CONFPATH = @CONFPATH@
|
|||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DBLATEX = @DBLATEX@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DOC_BUILD_LIST = @DOC_BUILD_LIST@
|
||||
DRIVER_BUILD_LIST = @DRIVER_BUILD_LIST@
|
||||
DRIVER_INSTALL_TARGET = @DRIVER_INSTALL_TARGET@
|
||||
DRIVER_MAN_LIST = @DRIVER_MAN_LIST@
|
||||
|
|
@ -127,7 +129,6 @@ HAL_CALLOUTS_PATH = @HAL_CALLOUTS_PATH@
|
|||
HAL_DEVICE_MATCH_KEY = @HAL_DEVICE_MATCH_KEY@
|
||||
HAL_FDI_PATH = @HAL_FDI_PATH@
|
||||
HAL_USER = @HAL_USER@
|
||||
HAVE_GLIB_2_14 = @HAVE_GLIB_2_14@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
|
|
@ -138,22 +139,22 @@ LDFLAGS = @LDFLAGS@
|
|||
LIBGD_CFLAGS = @LIBGD_CFLAGS@
|
||||
LIBGD_LDFLAGS = @LIBGD_LDFLAGS@
|
||||
LIBHAL_CFLAGS = @LIBHAL_CFLAGS@
|
||||
LIBHAL_LDFLAGS = @LIBHAL_LDFLAGS@
|
||||
LIBHAL_LIBS = @LIBHAL_LIBS@
|
||||
LIBNEON_CFLAGS = @LIBNEON_CFLAGS@
|
||||
LIBNEON_LDFLAGS = @LIBNEON_LDFLAGS@
|
||||
LIBNEON_LIBS = @LIBNEON_LIBS@
|
||||
LIBNETSNMP_CFLAGS = @LIBNETSNMP_CFLAGS@
|
||||
LIBNETSNMP_LDFLAGS = @LIBNETSNMP_LDFLAGS@
|
||||
LIBNETSNMP_LIBS = @LIBNETSNMP_LIBS@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBPOWERMAN_CFLAGS = @LIBPOWERMAN_CFLAGS@
|
||||
LIBPOWERMAN_LDFLAGS = @LIBPOWERMAN_LDFLAGS@
|
||||
LIBPOWERMAN_LIBS = @LIBPOWERMAN_LIBS@
|
||||
LIBS = @LIBS@
|
||||
LIBSSL_CFLAGS = @LIBSSL_CFLAGS@
|
||||
LIBSSL_LDFLAGS = @LIBSSL_LDFLAGS@
|
||||
LIBSSL_LIBS = @LIBSSL_LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIBUSB_CFLAGS = @LIBUSB_CFLAGS@
|
||||
LIBUSB_LDFLAGS = @LIBUSB_LDFLAGS@
|
||||
LIBUSB_LIBS = @LIBUSB_LIBS@
|
||||
LIBWRAP_CFLAGS = @LIBWRAP_CFLAGS@
|
||||
LIBWRAP_LDFLAGS = @LIBWRAP_LDFLAGS@
|
||||
LIBWRAP_LIBS = @LIBWRAP_LIBS@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
|
|
@ -250,11 +251,12 @@ top_builddir = @top_builddir@
|
|||
top_srcdir = @top_srcdir@
|
||||
udevdir = @udevdir@
|
||||
AM_CFLAGS = -I$(top_srcdir)/include
|
||||
noinst_LIBRARIES = libcommon.a
|
||||
libcommon_a_SOURCES = common.c state.c upsconf.c ../include/nut_version.h
|
||||
libcommon_a_LIBADD = libparseconf.la
|
||||
noinst_LTLIBRARIES = libparseconf.la
|
||||
noinst_LTLIBRARIES = libparseconf.la libcommon.la
|
||||
libparseconf_la_SOURCES = parseconf.c
|
||||
libcommon_la_SOURCES = common.c state.c upsconf.c ../include/nut_version.h
|
||||
# ensure inclusion of local implementation of missing systems functions
|
||||
# using LTLIBOBJS. Refer to configure.in -> AC_REPLACE_FUNCS
|
||||
libcommon_la_LIBADD = libparseconf.la @LTLIBOBJS@
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
|
|
@ -290,13 +292,6 @@ $(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
|
|||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(am__aclocal_m4_deps):
|
||||
|
||||
clean-noinstLIBRARIES:
|
||||
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
|
||||
libcommon.a: $(libcommon_a_OBJECTS) $(libcommon_a_DEPENDENCIES)
|
||||
-rm -f libcommon.a
|
||||
$(libcommon_a_AR) libcommon.a $(libcommon_a_OBJECTS) $(libcommon_a_LIBADD)
|
||||
$(RANLIB) libcommon.a
|
||||
|
||||
clean-noinstLTLIBRARIES:
|
||||
-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
|
||||
@list='$(noinst_LTLIBRARIES)'; for p in $$list; do \
|
||||
|
|
@ -305,6 +300,8 @@ clean-noinstLTLIBRARIES:
|
|||
echo "rm -f \"$${dir}/so_locations\""; \
|
||||
rm -f "$${dir}/so_locations"; \
|
||||
done
|
||||
libcommon.la: $(libcommon_la_OBJECTS) $(libcommon_la_DEPENDENCIES)
|
||||
$(LINK) $(libcommon_la_OBJECTS) $(libcommon_la_LIBADD) $(LIBS)
|
||||
libparseconf.la: $(libparseconf_la_OBJECTS) $(libparseconf_la_DEPENDENCIES)
|
||||
$(LINK) $(libparseconf_la_OBJECTS) $(libparseconf_la_LIBADD) $(LIBS)
|
||||
|
||||
|
|
@ -314,10 +311,14 @@ mostlyclean-compile:
|
|||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/common.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/atexit.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/setenv.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/snprintf.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/strerror.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/common.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/parseconf.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/state.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/upsconf.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/state.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/upsconf.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
|
|
@ -430,7 +431,7 @@ distdir: $(DISTFILES)
|
|||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(LIBRARIES) $(LTLIBRARIES)
|
||||
all-am: Makefile $(LTLIBRARIES)
|
||||
installdirs:
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
|
|
@ -459,11 +460,11 @@ maintainer-clean-generic:
|
|||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \
|
||||
clean-noinstLTLIBRARIES mostlyclean-am
|
||||
clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
|
||||
mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -rf $(DEPDIR) ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
|
@ -509,7 +510,7 @@ install-ps-am:
|
|||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -rf $(DEPDIR) ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
|
|
@ -531,18 +532,17 @@ uninstall-am:
|
|||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
|
||||
clean-libtool clean-noinstLIBRARIES clean-noinstLTLIBRARIES \
|
||||
ctags distclean distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags 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-compile \
|
||||
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
|
||||
tags uninstall uninstall-am
|
||||
clean-libtool clean-noinstLTLIBRARIES ctags distclean \
|
||||
distclean-compile distclean-generic distclean-libtool \
|
||||
distclean-tags 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-compile mostlyclean-generic mostlyclean-libtool \
|
||||
pdf pdf-am ps ps-am tags uninstall uninstall-am
|
||||
|
||||
|
||||
../include/nut_version.h: FORCE
|
||||
|
|
|
|||
22
common/atexit.c
Normal file
22
common/atexit.c
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/* atexit() Mark Powell <medp@primagraphics.co.uk> */
|
||||
/* Implemented in terms of on_exit() for old BSD-style systems, like SunOS4 */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef HAVE_ATEXIT
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
int atexit(fn)
|
||||
void (*fn)();
|
||||
{
|
||||
#ifdef HAVE_ON_EXIT
|
||||
return on_exit(fn, 0);
|
||||
#else
|
||||
/* Choose some errno thats likely to exist on lots of systems */
|
||||
errno = EPERM;
|
||||
return (-1);
|
||||
#endif /* HAVE_ON_EXIT */
|
||||
}
|
||||
|
||||
#endif /* HAVE_ATEXIT */
|
||||
|
|
@ -33,16 +33,17 @@
|
|||
const char *UPS_VERSION = NUT_VERSION_MACRO;
|
||||
|
||||
int nut_debug_level = 0;
|
||||
int nut_log_level = 0;
|
||||
static int upslog_flags = UPSLOG_STDERR;
|
||||
|
||||
static void xbit_set(int *val, int flag)
|
||||
{
|
||||
*val = (*val |= flag);
|
||||
*val |= flag;
|
||||
}
|
||||
|
||||
static void xbit_clear(int *val, int flag)
|
||||
{
|
||||
*val = (*val ^= (*val & flag));
|
||||
*val ^= (*val & flag);
|
||||
}
|
||||
|
||||
static int xbit_test(int val, int flag)
|
||||
|
|
@ -70,6 +71,44 @@ void open_syslog(const char *progname)
|
|||
#endif
|
||||
|
||||
openlog(progname, opt, LOG_FACILITY);
|
||||
|
||||
switch (nut_log_level)
|
||||
{
|
||||
#if HAVE_SETLOGMASK && HAVE_DECL_LOG_UPTO
|
||||
case 7:
|
||||
setlogmask(LOG_UPTO(LOG_EMERG)); /* system is unusable */
|
||||
break;
|
||||
case 6:
|
||||
setlogmask(LOG_UPTO(LOG_ALERT)); /* action must be taken immediately */
|
||||
break;
|
||||
case 5:
|
||||
setlogmask(LOG_UPTO(LOG_CRIT)); /* critical conditions */
|
||||
break;
|
||||
case 4:
|
||||
setlogmask(LOG_UPTO(LOG_ERR)); /* error conditions */
|
||||
break;
|
||||
case 3:
|
||||
setlogmask(LOG_UPTO(LOG_WARNING)); /* warning conditions */
|
||||
break;
|
||||
case 2:
|
||||
setlogmask(LOG_UPTO(LOG_NOTICE)); /* normal but significant condition */
|
||||
break;
|
||||
case 1:
|
||||
setlogmask(LOG_UPTO(LOG_INFO)); /* informational */
|
||||
break;
|
||||
case 0:
|
||||
setlogmask(LOG_UPTO(LOG_DEBUG)); /* debug-level messages */
|
||||
break;
|
||||
default:
|
||||
fatalx(EXIT_FAILURE, "Invalid log level threshold");
|
||||
#else
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
upslogx(LOG_INFO, "Changing log level threshold not possible");
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* close ttys and become a daemon */
|
||||
|
|
|
|||
26
common/setenv.c
Normal file
26
common/setenv.c
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/* setenv.c Ben Collver <collver@softhome.net> */
|
||||
#ifndef HAVE_SETENV
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "common.h"
|
||||
|
||||
int nut_setenv(const char *name, const char *value, int overwrite)
|
||||
{
|
||||
char *val;
|
||||
char *buffer;
|
||||
int rv;
|
||||
|
||||
if (overwrite == 0) {
|
||||
val = getenv(name);
|
||||
if (val != NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
buffer = xmalloc(strlen(value) + strlen(name) + 2);
|
||||
strcpy(buffer, name);
|
||||
strcat(buffer, "=");
|
||||
strcat(buffer, value);
|
||||
rv = putenv(buffer); /* man putenv, do not free(buffer) */
|
||||
return (rv);
|
||||
}
|
||||
#endif
|
||||
914
common/snprintf.c
Normal file
914
common/snprintf.c
Normal file
|
|
@ -0,0 +1,914 @@
|
|||
/*
|
||||
* Copyright Patrick Powell 1995
|
||||
* This code is based on code written by Patrick Powell (papowell@astart.com)
|
||||
* It may be used for any purpose as long as this notice remains intact
|
||||
* on all source code distributions
|
||||
*/
|
||||
|
||||
/**************************************************************
|
||||
* Original:
|
||||
* Patrick Powell Tue Apr 11 09:48:21 PDT 1995
|
||||
* A bombproof version of doprnt (dopr) included.
|
||||
* Sigh. This sort of thing is always nasty do deal with. Note that
|
||||
* the version here does not include floating point...
|
||||
*
|
||||
* snprintf() is used instead of sprintf() as it does limit checks
|
||||
* for string length. This covers a nasty loophole.
|
||||
*
|
||||
* The other functions are there to prevent NULL pointers from
|
||||
* causing nast effects.
|
||||
*
|
||||
* More Recently:
|
||||
* Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43
|
||||
* This was ugly. It is still ugly. I opted out of floating point
|
||||
* numbers, but the formatter understands just about everything
|
||||
* from the normal C string format, at least as far as I can tell from
|
||||
* the Solaris 2.5 printf(3S) man page.
|
||||
*
|
||||
* Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1
|
||||
* Ok, added some minimal floating point support, which means this
|
||||
* probably requires libm on most operating systems. Don't yet
|
||||
* support the exponent (e,E) and sigfig (g,G). Also, fmtint()
|
||||
* was pretty badly broken, it just wasn't being exercised in ways
|
||||
* which showed it, so that's been fixed. Also, formated the code
|
||||
* to mutt conventions, and removed dead code left over from the
|
||||
* original. Also, there is now a builtin-test, just compile with:
|
||||
* gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm
|
||||
* and run snprintf for results.
|
||||
*
|
||||
* Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i
|
||||
* The PGP code was using unsigned hexadecimal formats.
|
||||
* Unfortunately, unsigned formats simply didn't work.
|
||||
*
|
||||
* Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8
|
||||
* The original code assumed that both snprintf() and vsnprintf() were
|
||||
* missing. Some systems only have snprintf() but not vsnprintf(), so
|
||||
* the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
|
||||
*
|
||||
* Andrew Tridgell (tridge@samba.org) Oct 1998
|
||||
* fixed handling of %.0f
|
||||
* added test for HAVE_LONG_DOUBLE
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
# include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
|
||||
|
||||
/* Define this as a fall through, HAVE_STDARG_H is probably already set */
|
||||
|
||||
#ifndef HAVE_VARARGS_H
|
||||
#define HAVE_VARARGS_H
|
||||
#endif
|
||||
|
||||
/* varargs declarations: */
|
||||
|
||||
#if defined(HAVE_STDARG_H)
|
||||
# include <stdarg.h>
|
||||
# define HAVE_STDARGS /* let's hope that works everywhere (mj) */
|
||||
# define VA_LOCAL_DECL va_list ap
|
||||
# define VA_START(f) va_start(ap, f)
|
||||
# define VA_SHIFT(v,t) ; /* no-op for ANSI */
|
||||
# define VA_END va_end(ap)
|
||||
#else
|
||||
# if defined(HAVE_VARARGS_H)
|
||||
# include <varargs.h>
|
||||
# undef HAVE_STDARGS
|
||||
# define VA_LOCAL_DECL va_list ap
|
||||
# define VA_START(f) va_start(ap) /* f is ignored! */
|
||||
# define VA_SHIFT(v,t) v = va_arg(ap,t)
|
||||
# define VA_END va_end(ap)
|
||||
# else
|
||||
/*XX ** NO VARARGS ** XX*/
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LONG_DOUBLE
|
||||
#define LDOUBLE long double
|
||||
#else
|
||||
#define LDOUBLE double
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LONG_LONG_INT
|
||||
#define LLONG long long
|
||||
#else
|
||||
#define LLONG long
|
||||
#endif
|
||||
|
||||
/*int snprintf (char *str, size_t count, const char *fmt, ...);*/
|
||||
/*int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);*/
|
||||
|
||||
static void dopr (char *buffer, size_t maxlen, const char *format,
|
||||
va_list args);
|
||||
static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max);
|
||||
static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags);
|
||||
static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
|
||||
LDOUBLE fvalue, int min, int max, int flags);
|
||||
static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
|
||||
|
||||
/*
|
||||
* dopr(): poor man's version of doprintf
|
||||
*/
|
||||
|
||||
/* format read states */
|
||||
#define DP_S_DEFAULT 0
|
||||
#define DP_S_FLAGS 1
|
||||
#define DP_S_MIN 2
|
||||
#define DP_S_DOT 3
|
||||
#define DP_S_MAX 4
|
||||
#define DP_S_MOD 5
|
||||
#define DP_S_CONV 6
|
||||
#define DP_S_DONE 7
|
||||
|
||||
/* format flags - Bits */
|
||||
#define DP_F_MINUS (1 << 0)
|
||||
#define DP_F_PLUS (1 << 1)
|
||||
#define DP_F_SPACE (1 << 2)
|
||||
#define DP_F_NUM (1 << 3)
|
||||
#define DP_F_ZERO (1 << 4)
|
||||
#define DP_F_UP (1 << 5)
|
||||
#define DP_F_UNSIGNED (1 << 6)
|
||||
|
||||
/* Conversion Flags */
|
||||
#define DP_C_SHORT 1
|
||||
#define DP_C_LONG 2
|
||||
#define DP_C_LDOUBLE 3
|
||||
#define DP_C_LLONG 4
|
||||
|
||||
#define char_to_int(p) ((p)- '0')
|
||||
#define MAX(p,q) (((p) >= (q)) ? (p) : (q))
|
||||
|
||||
static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
|
||||
{
|
||||
char ch;
|
||||
LLONG value;
|
||||
LDOUBLE fvalue;
|
||||
char *strvalue;
|
||||
int min;
|
||||
int max;
|
||||
int state;
|
||||
int flags;
|
||||
int cflags;
|
||||
size_t currlen;
|
||||
|
||||
state = DP_S_DEFAULT;
|
||||
currlen = flags = cflags = min = 0;
|
||||
max = -1;
|
||||
ch = *format++;
|
||||
|
||||
while (state != DP_S_DONE)
|
||||
{
|
||||
if ((ch == '\0') || (currlen >= maxlen))
|
||||
state = DP_S_DONE;
|
||||
|
||||
switch(state)
|
||||
{
|
||||
case DP_S_DEFAULT:
|
||||
if (ch == '%')
|
||||
state = DP_S_FLAGS;
|
||||
else
|
||||
dopr_outch (buffer, &currlen, maxlen, ch);
|
||||
ch = *format++;
|
||||
break;
|
||||
case DP_S_FLAGS:
|
||||
switch (ch)
|
||||
{
|
||||
case '-':
|
||||
flags |= DP_F_MINUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '+':
|
||||
flags |= DP_F_PLUS;
|
||||
ch = *format++;
|
||||
break;
|
||||
case ' ':
|
||||
flags |= DP_F_SPACE;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '#':
|
||||
flags |= DP_F_NUM;
|
||||
ch = *format++;
|
||||
break;
|
||||
case '0':
|
||||
flags |= DP_F_ZERO;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
state = DP_S_MIN;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DP_S_MIN:
|
||||
if (isdigit((unsigned char)ch))
|
||||
{
|
||||
min = 10*min + char_to_int (ch);
|
||||
ch = *format++;
|
||||
}
|
||||
else if (ch == '*')
|
||||
{
|
||||
min = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_DOT;
|
||||
}
|
||||
else
|
||||
state = DP_S_DOT;
|
||||
break;
|
||||
case DP_S_DOT:
|
||||
if (ch == '.')
|
||||
{
|
||||
state = DP_S_MAX;
|
||||
ch = *format++;
|
||||
}
|
||||
else
|
||||
state = DP_S_MOD;
|
||||
break;
|
||||
case DP_S_MAX:
|
||||
if (isdigit((unsigned char)ch))
|
||||
{
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
max = 10*max + char_to_int (ch);
|
||||
ch = *format++;
|
||||
}
|
||||
else if (ch == '*')
|
||||
{
|
||||
max = va_arg (args, int);
|
||||
ch = *format++;
|
||||
state = DP_S_MOD;
|
||||
}
|
||||
else
|
||||
state = DP_S_MOD;
|
||||
break;
|
||||
case DP_S_MOD:
|
||||
switch (ch)
|
||||
{
|
||||
case 'h':
|
||||
cflags = DP_C_SHORT;
|
||||
ch = *format++;
|
||||
break;
|
||||
case 'l':
|
||||
cflags = DP_C_LONG;
|
||||
ch = *format++;
|
||||
if (ch == 'l') { /* It's a long long */
|
||||
cflags = DP_C_LLONG;
|
||||
ch = *format++;
|
||||
}
|
||||
break;
|
||||
case 'L':
|
||||
cflags = DP_C_LDOUBLE;
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
state = DP_S_CONV;
|
||||
break;
|
||||
case DP_S_CONV:
|
||||
switch (ch)
|
||||
{
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = va_arg (args, long int);
|
||||
else if (cflags == DP_C_LLONG)
|
||||
value = va_arg (args, LLONG);
|
||||
else
|
||||
value = va_arg (args, int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'o':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = (long)va_arg (args, unsigned long int);
|
||||
else if (cflags == DP_C_LLONG)
|
||||
value = (long)va_arg (args, unsigned LLONG);
|
||||
else
|
||||
value = (long)va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
|
||||
break;
|
||||
case 'u':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = (long)va_arg (args, unsigned long int);
|
||||
else if (cflags == DP_C_LLONG)
|
||||
value = (LLONG)va_arg (args, unsigned LLONG);
|
||||
else
|
||||
value = (long)va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
|
||||
break;
|
||||
case 'X':
|
||||
flags |= DP_F_UP;
|
||||
case 'x':
|
||||
flags |= DP_F_UNSIGNED;
|
||||
if (cflags == DP_C_SHORT)
|
||||
value = va_arg (args, unsigned short int);
|
||||
else if (cflags == DP_C_LONG)
|
||||
value = (long)va_arg (args, unsigned long int);
|
||||
else if (cflags == DP_C_LLONG)
|
||||
value = (LLONG)va_arg (args, unsigned LLONG);
|
||||
else
|
||||
value = (long)va_arg (args, unsigned int);
|
||||
fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
|
||||
break;
|
||||
case 'f':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg (args, LDOUBLE);
|
||||
else
|
||||
fvalue = va_arg (args, double);
|
||||
/* um, floating point? */
|
||||
fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
|
||||
break;
|
||||
case 'E':
|
||||
flags |= DP_F_UP;
|
||||
case 'e':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg (args, LDOUBLE);
|
||||
else
|
||||
fvalue = va_arg (args, double);
|
||||
break;
|
||||
case 'G':
|
||||
flags |= DP_F_UP;
|
||||
case 'g':
|
||||
if (cflags == DP_C_LDOUBLE)
|
||||
fvalue = va_arg (args, LDOUBLE);
|
||||
else
|
||||
fvalue = va_arg (args, double);
|
||||
break;
|
||||
case 'c':
|
||||
dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
|
||||
break;
|
||||
case 's':
|
||||
strvalue = va_arg (args, char *);
|
||||
if (max < 0)
|
||||
max = maxlen; /* ie, no max */
|
||||
fmtstr (buffer, &currlen, maxlen, strvalue, flags, min, max);
|
||||
break;
|
||||
case 'p':
|
||||
strvalue = va_arg (args, void *);
|
||||
fmtint (buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags);
|
||||
break;
|
||||
case 'n':
|
||||
if (cflags == DP_C_SHORT)
|
||||
{
|
||||
short int *num;
|
||||
num = va_arg (args, short int *);
|
||||
*num = currlen;
|
||||
}
|
||||
else if (cflags == DP_C_LONG)
|
||||
{
|
||||
long int *num;
|
||||
num = va_arg (args, long int *);
|
||||
*num = (long int)currlen;
|
||||
}
|
||||
else if (cflags == DP_C_LLONG)
|
||||
{
|
||||
LLONG *num;
|
||||
num = va_arg (args, LLONG *);
|
||||
*num = (LLONG)currlen;
|
||||
}
|
||||
else
|
||||
{
|
||||
int *num;
|
||||
num = va_arg (args, int *);
|
||||
*num = currlen;
|
||||
}
|
||||
break;
|
||||
case '%':
|
||||
dopr_outch (buffer, &currlen, maxlen, ch);
|
||||
break;
|
||||
case 'w':
|
||||
/* not supported yet, treat as next char */
|
||||
ch = *format++;
|
||||
break;
|
||||
default:
|
||||
/* Unknown, skip */
|
||||
break;
|
||||
}
|
||||
ch = *format++;
|
||||
state = DP_S_DEFAULT;
|
||||
flags = cflags = min = 0;
|
||||
max = -1;
|
||||
break;
|
||||
case DP_S_DONE:
|
||||
break;
|
||||
default:
|
||||
/* hmm? */
|
||||
break; /* some picky compilers need this */
|
||||
}
|
||||
}
|
||||
if (currlen < maxlen - 1)
|
||||
buffer[currlen] = '\0';
|
||||
else
|
||||
buffer[maxlen - 1] = '\0';
|
||||
}
|
||||
|
||||
static void fmtstr (char *buffer, size_t *currlen, size_t maxlen,
|
||||
char *value, int flags, int min, int max)
|
||||
{
|
||||
int padlen, strln; /* amount to pad */
|
||||
int cnt = 0;
|
||||
|
||||
if (value == 0)
|
||||
{
|
||||
value = "<NULL>";
|
||||
}
|
||||
|
||||
for (strln = 0; value[strln]; ++strln); /* strlen */
|
||||
padlen = min - strln;
|
||||
if (padlen < 0)
|
||||
padlen = 0;
|
||||
if (flags & DP_F_MINUS)
|
||||
padlen = -padlen; /* Left Justify */
|
||||
|
||||
while ((padlen > 0) && (cnt < max))
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--padlen;
|
||||
++cnt;
|
||||
}
|
||||
while (*value && (cnt < max))
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, *value++);
|
||||
++cnt;
|
||||
}
|
||||
while ((padlen < 0) && (cnt < max))
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++padlen;
|
||||
++cnt;
|
||||
}
|
||||
}
|
||||
|
||||
/* Have to handle DP_F_NUM (ie 0x and 0 alternates) */
|
||||
|
||||
static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
|
||||
long value, int base, int min, int max, int flags)
|
||||
{
|
||||
int signvalue = 0;
|
||||
unsigned long uvalue;
|
||||
char convert[20];
|
||||
int place = 0;
|
||||
int spadlen = 0; /* amount to space pad */
|
||||
int zpadlen = 0; /* amount to zero pad */
|
||||
int caps = 0;
|
||||
|
||||
if (max < 0)
|
||||
max = 0;
|
||||
|
||||
uvalue = value;
|
||||
|
||||
if(!(flags & DP_F_UNSIGNED))
|
||||
{
|
||||
if( value < 0 ) {
|
||||
signvalue = '-';
|
||||
uvalue = -value;
|
||||
}
|
||||
else
|
||||
if (flags & DP_F_PLUS) /* Do a sign (+/i) */
|
||||
signvalue = '+';
|
||||
else
|
||||
if (flags & DP_F_SPACE)
|
||||
signvalue = ' ';
|
||||
}
|
||||
|
||||
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
|
||||
|
||||
do {
|
||||
convert[place++] =
|
||||
(caps? "0123456789ABCDEF":"0123456789abcdef")
|
||||
[uvalue % (unsigned)base ];
|
||||
uvalue = (uvalue / (unsigned)base );
|
||||
} while(uvalue && (place < 20));
|
||||
if (place == 20) place--;
|
||||
convert[place] = 0;
|
||||
|
||||
zpadlen = max - place;
|
||||
spadlen = min - MAX (max, place) - (signvalue ? 1 : 0);
|
||||
if (zpadlen < 0) zpadlen = 0;
|
||||
if (spadlen < 0) spadlen = 0;
|
||||
if (flags & DP_F_ZERO)
|
||||
{
|
||||
zpadlen = MAX(zpadlen, spadlen);
|
||||
spadlen = 0;
|
||||
}
|
||||
if (flags & DP_F_MINUS)
|
||||
spadlen = -spadlen; /* Left Justifty */
|
||||
|
||||
#ifdef DEBUG_SNPRINTF
|
||||
printf("zpad: %d, spad: %d, min: %d, max: %d, place: %d\n",
|
||||
zpadlen, spadlen, min, max, place);
|
||||
#endif
|
||||
|
||||
/* Spaces */
|
||||
while (spadlen > 0)
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--spadlen;
|
||||
}
|
||||
|
||||
/* Sign */
|
||||
if (signvalue)
|
||||
dopr_outch (buffer, currlen, maxlen, signvalue);
|
||||
|
||||
/* Zeros */
|
||||
if (zpadlen > 0)
|
||||
{
|
||||
while (zpadlen > 0)
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, '0');
|
||||
--zpadlen;
|
||||
}
|
||||
}
|
||||
|
||||
/* Digits */
|
||||
while (place > 0)
|
||||
dopr_outch (buffer, currlen, maxlen, convert[--place]);
|
||||
|
||||
/* Left Justified spaces */
|
||||
while (spadlen < 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++spadlen;
|
||||
}
|
||||
}
|
||||
|
||||
static LDOUBLE abs_val (LDOUBLE value)
|
||||
{
|
||||
LDOUBLE result = value;
|
||||
|
||||
if (value < 0)
|
||||
result = -value;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static LDOUBLE pow10 (int exp)
|
||||
{
|
||||
LDOUBLE result = 1;
|
||||
|
||||
while (exp)
|
||||
{
|
||||
result *= 10;
|
||||
exp--;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static long round (LDOUBLE value)
|
||||
{
|
||||
long intpart;
|
||||
|
||||
intpart = (long)value;
|
||||
value = value - intpart;
|
||||
if (value >= 0.5)
|
||||
intpart++;
|
||||
|
||||
return intpart;
|
||||
}
|
||||
|
||||
static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
|
||||
LDOUBLE fvalue, int min, int max, int flags)
|
||||
{
|
||||
int signvalue = 0;
|
||||
LDOUBLE ufvalue;
|
||||
#ifndef HAVE_FCVT
|
||||
char iconvert[20];
|
||||
char fconvert[20];
|
||||
#else
|
||||
char iconvert[311];
|
||||
char fconvert[311];
|
||||
char *result;
|
||||
int dec_pt, sig;
|
||||
int r_length;
|
||||
# ifdef HAVE_FCVTL
|
||||
extern char *fcvtl(long double value, int ndigit, int *decpt, int *sign);
|
||||
# else
|
||||
extern char *fcvt(double value, int ndigit, int *decpt, int *sign);
|
||||
# endif
|
||||
#endif
|
||||
int iplace = 0;
|
||||
int fplace = 0;
|
||||
int padlen = 0; /* amount to pad */
|
||||
int zpadlen = 0;
|
||||
int caps = 0;
|
||||
long intpart;
|
||||
long fracpart;
|
||||
|
||||
/*
|
||||
* AIX manpage says the default is 0, but Solaris says the default
|
||||
* is 6, and sprintf on AIX defaults to 6
|
||||
*/
|
||||
if (max < 0)
|
||||
max = 6;
|
||||
|
||||
ufvalue = abs_val (fvalue);
|
||||
|
||||
if (fvalue < 0)
|
||||
signvalue = '-';
|
||||
else
|
||||
if (flags & DP_F_PLUS) /* Do a sign (+/i) */
|
||||
signvalue = '+';
|
||||
else
|
||||
if (flags & DP_F_SPACE)
|
||||
signvalue = ' ';
|
||||
|
||||
#if 0
|
||||
if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_FCVT
|
||||
intpart = (long)ufvalue;
|
||||
|
||||
/*
|
||||
* Sorry, we only support 9 digits past the decimal because of our
|
||||
* conversion method
|
||||
*/
|
||||
if (max > 9)
|
||||
max = 9;
|
||||
|
||||
/* We "cheat" by converting the fractional part to integer by
|
||||
* multiplying by a factor of 10
|
||||
*/
|
||||
fracpart = round ((pow10 (max)) * (ufvalue - intpart));
|
||||
|
||||
if (fracpart >= pow10 (max))
|
||||
{
|
||||
intpart++;
|
||||
fracpart -= pow10 (max);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_SNPRINTF
|
||||
printf("fmtfp: %g %d.%d min=%d max=%d\n",
|
||||
(double)fvalue, intpart, fracpart, min, max);
|
||||
#endif
|
||||
|
||||
/* Convert integer part */
|
||||
do {
|
||||
iconvert[iplace++] =
|
||||
(caps? "0123456789ABCDEF":"0123456789abcdef")[intpart % 10];
|
||||
intpart = (intpart / 10);
|
||||
} while(intpart && (iplace < 20));
|
||||
if (iplace == 20) iplace--;
|
||||
iconvert[iplace] = 0;
|
||||
|
||||
/* Convert fractional part */
|
||||
do {
|
||||
fconvert[fplace++] =
|
||||
(caps? "0123456789ABCDEF":"0123456789abcdef")[fracpart % 10];
|
||||
fracpart = (fracpart / 10);
|
||||
} while(fracpart && (fplace < 20));
|
||||
if (fplace == 20) fplace--;
|
||||
fconvert[fplace] = 0;
|
||||
#else /* use fcvt() */
|
||||
if (max > 310)
|
||||
max = 310;
|
||||
# ifdef HAVE_FCVTL
|
||||
result = fcvtl(ufvalue, max, &dec_pt, &sig);
|
||||
# else
|
||||
result = fcvt(ufvalue, max, &dec_pt, &sig);
|
||||
# endif
|
||||
|
||||
r_length = strlen(result);
|
||||
|
||||
/*
|
||||
* Fix broken fcvt implementation returns..
|
||||
*/
|
||||
|
||||
if (r_length == 0)
|
||||
{
|
||||
result[0] = '0';
|
||||
result[1] = '\0';
|
||||
r_length = 1;
|
||||
}
|
||||
|
||||
if ( r_length < dec_pt )
|
||||
dec_pt = r_length;
|
||||
|
||||
if (dec_pt <= 0) {
|
||||
iplace = 1;
|
||||
iconvert[0] = '0';
|
||||
iconvert[1] = '\0';
|
||||
|
||||
fplace = 0;
|
||||
|
||||
while(r_length)
|
||||
fconvert[fplace++] = result[--r_length];
|
||||
|
||||
while ((dec_pt < 0) && (fplace < max)) {
|
||||
fconvert[fplace++] = '0';
|
||||
dec_pt++;
|
||||
}
|
||||
} else {
|
||||
int c;
|
||||
|
||||
iplace=0;
|
||||
for(c=dec_pt; c; iconvert[iplace++] = result[--c])
|
||||
;
|
||||
iconvert[iplace] = '\0';
|
||||
|
||||
result += dec_pt;
|
||||
fplace = 0;
|
||||
|
||||
for(c=(r_length-dec_pt); c; fconvert[fplace++] = result[--c])
|
||||
;
|
||||
}
|
||||
#endif /* fcvt */
|
||||
|
||||
/* -1 for decimal point, another -1 if we are printing a sign */
|
||||
padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0);
|
||||
zpadlen = max - fplace;
|
||||
if (zpadlen < 0)
|
||||
zpadlen = 0;
|
||||
if (padlen < 0)
|
||||
padlen = 0;
|
||||
if (flags & DP_F_MINUS)
|
||||
padlen = -padlen; /* Left Justifty */
|
||||
|
||||
if ((flags & DP_F_ZERO) && (padlen > 0))
|
||||
{
|
||||
if (signvalue)
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, signvalue);
|
||||
--padlen;
|
||||
signvalue = 0;
|
||||
}
|
||||
while (padlen > 0)
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, '0');
|
||||
--padlen;
|
||||
}
|
||||
}
|
||||
while (padlen > 0)
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
--padlen;
|
||||
}
|
||||
if (signvalue)
|
||||
dopr_outch (buffer, currlen, maxlen, signvalue);
|
||||
|
||||
while (iplace > 0)
|
||||
dopr_outch (buffer, currlen, maxlen, iconvert[--iplace]);
|
||||
|
||||
|
||||
#ifdef DEBUG_SNPRINTF
|
||||
printf("fmtfp: fplace=%d zpadlen=%d\n", fplace, zpadlen);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Decimal point. This should probably use locale to find the correct
|
||||
* char to print out.
|
||||
*/
|
||||
if (max > 0) {
|
||||
dopr_outch (buffer, currlen, maxlen, '.');
|
||||
|
||||
while (fplace > 0)
|
||||
dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
|
||||
}
|
||||
|
||||
while (zpadlen > 0)
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, '0');
|
||||
--zpadlen;
|
||||
}
|
||||
|
||||
while (padlen < 0)
|
||||
{
|
||||
dopr_outch (buffer, currlen, maxlen, ' ');
|
||||
++padlen;
|
||||
}
|
||||
}
|
||||
|
||||
static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c)
|
||||
{
|
||||
if (*currlen < maxlen)
|
||||
buffer[(*currlen)++] = c;
|
||||
}
|
||||
#endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */
|
||||
|
||||
#ifndef HAVE_VSNPRINTF
|
||||
int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
|
||||
{
|
||||
str[0] = 0;
|
||||
dopr(str, count, fmt, args);
|
||||
return(strlen(str));
|
||||
}
|
||||
#endif /* !HAVE_VSNPRINTF */
|
||||
|
||||
#ifndef HAVE_SNPRINTF
|
||||
/* VARARGS3 */
|
||||
#ifdef HAVE_STDARGS
|
||||
int snprintf (char *str,size_t count,const char *fmt,...)
|
||||
#else
|
||||
int snprintf (va_alist) va_dcl
|
||||
#endif
|
||||
{
|
||||
#ifndef HAVE_STDARGS
|
||||
char *str;
|
||||
size_t count;
|
||||
char *fmt;
|
||||
#endif
|
||||
VA_LOCAL_DECL;
|
||||
|
||||
VA_START (fmt);
|
||||
VA_SHIFT (str, char *);
|
||||
VA_SHIFT (count, size_t );
|
||||
VA_SHIFT (fmt, char *);
|
||||
(void) vsnprintf(str, count, fmt, ap);
|
||||
VA_END;
|
||||
return(strlen(str));
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
/* keep compilers happy about empty files */
|
||||
void dummy_snprintf(void) {}
|
||||
#endif /* !HAVE_SNPRINTF */
|
||||
|
||||
#ifdef TEST_SNPRINTF
|
||||
#ifndef LONG_STRING
|
||||
#define LONG_STRING 1024
|
||||
#endif
|
||||
int main (void)
|
||||
{
|
||||
char buf1[LONG_STRING];
|
||||
char buf2[LONG_STRING];
|
||||
char *fp_fmt[] = {
|
||||
"%-1.5f",
|
||||
"%1.5f",
|
||||
"%123.9f",
|
||||
"%10.5f",
|
||||
"% 10.5f",
|
||||
"%+22.9f",
|
||||
"%+4.9f",
|
||||
"%01.3f",
|
||||
"%4f",
|
||||
"%3.1f",
|
||||
"%3.2f",
|
||||
"%.0f",
|
||||
"%.1f",
|
||||
NULL
|
||||
};
|
||||
double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996,
|
||||
0.9996, 1.996, 4.136, 6442452944.1234, 0};
|
||||
char *int_fmt[] = {
|
||||
"%-1.5d",
|
||||
"%1.5d",
|
||||
"%123.9d",
|
||||
"%5.5d",
|
||||
"%10.5d",
|
||||
"% 10.5d",
|
||||
"%+22.33d",
|
||||
"%01.3d",
|
||||
"%4d",
|
||||
NULL
|
||||
};
|
||||
long int_nums[] = { -1, 134, 91340, 341, 0203, 0};
|
||||
int x, y;
|
||||
int fail = 0;
|
||||
int num = 0;
|
||||
|
||||
printf ("Testing snprintf format codes against system sprintf...\n");
|
||||
|
||||
for (x = 0; fp_fmt[x] != NULL ; x++)
|
||||
for (y = 0; fp_nums[y] != 0 ; y++)
|
||||
{
|
||||
snprintf (buf1, sizeof (buf1), fp_fmt[x], fp_nums[y]);
|
||||
sprintf (buf2, fp_fmt[x], fp_nums[y]);
|
||||
if (strcmp (buf1, buf2))
|
||||
{
|
||||
printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n",
|
||||
fp_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
|
||||
for (x = 0; int_fmt[x] != NULL ; x++)
|
||||
for (y = 0; int_nums[y] != 0 ; y++)
|
||||
{
|
||||
snprintf (buf1, sizeof (buf1), int_fmt[x], int_nums[y]);
|
||||
sprintf (buf2, int_fmt[x], int_nums[y]);
|
||||
if (strcmp (buf1, buf2))
|
||||
{
|
||||
printf("snprintf doesn't match Format: %s\n\tsnprintf = %s\n\tsprintf = %s\n",
|
||||
int_fmt[x], buf1, buf2);
|
||||
fail++;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
printf ("%d tests failed out of %d.\n", fail, num);
|
||||
}
|
||||
#endif /* SNPRINTF_TEST */
|
||||
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
#include "state.h"
|
||||
#include "parseconf.h"
|
||||
|
||||
static void val_escape(struct st_tree_t *node)
|
||||
static void val_escape(st_tree_t *node)
|
||||
{
|
||||
char etmp[ST_MAX_VALUE_LEN];
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ static void val_escape(struct st_tree_t *node)
|
|||
node->val = node->safe;
|
||||
}
|
||||
|
||||
static void st_tree_enum_free(struct enum_t *list)
|
||||
static void st_tree_enum_free(enum_t *list)
|
||||
{
|
||||
if (!list) {
|
||||
return;
|
||||
|
|
@ -66,7 +66,7 @@ static void st_tree_enum_free(struct enum_t *list)
|
|||
}
|
||||
|
||||
/* free all memory associated with a node */
|
||||
static void st_tree_node_free(struct st_tree_t *node)
|
||||
static void st_tree_node_free(st_tree_t *node)
|
||||
{
|
||||
free(node->var);
|
||||
free(node->raw);
|
||||
|
|
@ -82,7 +82,7 @@ static void st_tree_node_free(struct st_tree_t *node)
|
|||
}
|
||||
|
||||
/* add a subtree to another subtree */
|
||||
static void st_tree_node_add(struct st_tree_t **nptr, struct st_tree_t *sptr)
|
||||
static void st_tree_node_add(st_tree_t **nptr, st_tree_t *sptr)
|
||||
{
|
||||
if (!sptr) {
|
||||
return;
|
||||
|
|
@ -90,7 +90,7 @@ static void st_tree_node_add(struct st_tree_t **nptr, struct st_tree_t *sptr)
|
|||
|
||||
while (*nptr) {
|
||||
|
||||
struct st_tree_t *node = *nptr;
|
||||
st_tree_t *node = *nptr;
|
||||
|
||||
if (strcasecmp(node->var, sptr->var) > 0) {
|
||||
nptr = &node->left;
|
||||
|
|
@ -110,11 +110,11 @@ static void st_tree_node_add(struct st_tree_t **nptr, struct st_tree_t *sptr)
|
|||
}
|
||||
|
||||
/* remove a variable from a tree */
|
||||
int state_delinfo(struct st_tree_t **nptr, const char *var)
|
||||
int state_delinfo(st_tree_t **nptr, const char *var)
|
||||
{
|
||||
while (*nptr) {
|
||||
|
||||
struct st_tree_t *node = *nptr;
|
||||
st_tree_t *node = *nptr;
|
||||
|
||||
if (strcasecmp(node->var, var) > 0) {
|
||||
nptr = &node->left;
|
||||
|
|
@ -142,11 +142,11 @@ int state_delinfo(struct st_tree_t **nptr, const char *var)
|
|||
|
||||
/* interface */
|
||||
|
||||
int state_setinfo(struct st_tree_t **nptr, const char *var, const char *val)
|
||||
int state_setinfo(st_tree_t **nptr, const char *var, const char *val)
|
||||
{
|
||||
while (*nptr) {
|
||||
|
||||
struct st_tree_t *node = *nptr;
|
||||
st_tree_t *node = *nptr;
|
||||
|
||||
if (strcasecmp(node->var, var) > 0) {
|
||||
nptr = &node->left;
|
||||
|
|
@ -193,9 +193,9 @@ int state_setinfo(struct st_tree_t **nptr, const char *var, const char *val)
|
|||
return 1; /* added */
|
||||
}
|
||||
|
||||
static int st_tree_enum_add(struct enum_t **list, const char *enc)
|
||||
static int st_tree_enum_add(enum_t **list, const char *enc)
|
||||
{
|
||||
struct enum_t *item;
|
||||
enum_t *item;
|
||||
|
||||
while (*list) {
|
||||
|
||||
|
|
@ -217,9 +217,9 @@ static int st_tree_enum_add(struct enum_t **list, const char *enc)
|
|||
return 1; /* added */
|
||||
}
|
||||
|
||||
int state_addenum(struct st_tree_t *root, const char *var, const char *val)
|
||||
int state_addenum(st_tree_t *root, const char *var, const char *val)
|
||||
{
|
||||
struct st_tree_t *sttmp;
|
||||
st_tree_t *sttmp;
|
||||
char enc[ST_MAX_VALUE_LEN];
|
||||
|
||||
/* find the tree node for var */
|
||||
|
|
@ -237,9 +237,9 @@ int state_addenum(struct st_tree_t *root, const char *var, const char *val)
|
|||
return st_tree_enum_add(&sttmp->enum_list, enc);
|
||||
}
|
||||
|
||||
int state_setaux(struct st_tree_t *root, const char *var, const char *auxs)
|
||||
int state_setaux(st_tree_t *root, const char *var, const char *auxs)
|
||||
{
|
||||
struct st_tree_t *sttmp;
|
||||
st_tree_t *sttmp;
|
||||
int aux;
|
||||
|
||||
/* find the tree node for var */
|
||||
|
|
@ -263,9 +263,9 @@ int state_setaux(struct st_tree_t *root, const char *var, const char *auxs)
|
|||
return 1;
|
||||
}
|
||||
|
||||
const char *state_getinfo(struct st_tree_t *root, const char *var)
|
||||
const char *state_getinfo(st_tree_t *root, const char *var)
|
||||
{
|
||||
struct st_tree_t *sttmp;
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
|
@ -277,9 +277,9 @@ const char *state_getinfo(struct st_tree_t *root, const char *var)
|
|||
return sttmp->val;
|
||||
}
|
||||
|
||||
int state_getflags(struct st_tree_t *root, const char *var)
|
||||
int state_getflags(st_tree_t *root, const char *var)
|
||||
{
|
||||
struct st_tree_t *sttmp;
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
|
@ -291,9 +291,9 @@ int state_getflags(struct st_tree_t *root, const char *var)
|
|||
return sttmp->flags;
|
||||
}
|
||||
|
||||
int state_getaux(struct st_tree_t *root, const char *var)
|
||||
int state_getaux(st_tree_t *root, const char *var)
|
||||
{
|
||||
struct st_tree_t *sttmp;
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
|
@ -305,9 +305,9 @@ int state_getaux(struct st_tree_t *root, const char *var)
|
|||
return sttmp->aux;
|
||||
}
|
||||
|
||||
const struct enum_t *state_getenumlist(struct st_tree_t *root, const char *var)
|
||||
const enum_t *state_getenumlist(st_tree_t *root, const char *var)
|
||||
{
|
||||
struct st_tree_t *sttmp;
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
|
@ -319,10 +319,10 @@ const struct enum_t *state_getenumlist(struct st_tree_t *root, const char *var)
|
|||
return sttmp->enum_list;
|
||||
}
|
||||
|
||||
void state_setflags(struct st_tree_t *root, const char *var, int numflags, char **flag)
|
||||
void state_setflags(st_tree_t *root, const char *var, int numflags, char **flag)
|
||||
{
|
||||
int i;
|
||||
struct st_tree_t *sttmp;
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
|
@ -351,9 +351,9 @@ void state_setflags(struct st_tree_t *root, const char *var, int numflags, char
|
|||
}
|
||||
}
|
||||
|
||||
int state_addcmd(struct cmdlist_t **list, const char *cmd)
|
||||
int state_addcmd(cmdlist_t **list, const char *cmd)
|
||||
{
|
||||
struct cmdlist_t *item;
|
||||
cmdlist_t *item;
|
||||
|
||||
while (*list) {
|
||||
|
||||
|
|
@ -380,7 +380,7 @@ int state_addcmd(struct cmdlist_t **list, const char *cmd)
|
|||
return 1; /* added */
|
||||
}
|
||||
|
||||
void state_infofree(struct st_tree_t *node)
|
||||
void state_infofree(st_tree_t *node)
|
||||
{
|
||||
if (!node) {
|
||||
return;
|
||||
|
|
@ -392,7 +392,7 @@ void state_infofree(struct st_tree_t *node)
|
|||
st_tree_node_free(node);
|
||||
}
|
||||
|
||||
void state_cmdfree(struct cmdlist_t *list)
|
||||
void state_cmdfree(cmdlist_t *list)
|
||||
{
|
||||
if (!list) {
|
||||
return;
|
||||
|
|
@ -404,11 +404,11 @@ void state_cmdfree(struct cmdlist_t *list)
|
|||
free(list);
|
||||
}
|
||||
|
||||
int state_delcmd(struct cmdlist_t **list, const char *cmd)
|
||||
int state_delcmd(cmdlist_t **list, const char *cmd)
|
||||
{
|
||||
while (*list) {
|
||||
|
||||
struct cmdlist_t *item = *list;
|
||||
cmdlist_t *item = *list;
|
||||
|
||||
if (strcasecmp(item->name, cmd) > 0) {
|
||||
/* not found */
|
||||
|
|
@ -433,11 +433,11 @@ int state_delcmd(struct cmdlist_t **list, const char *cmd)
|
|||
return 0; /* not found */
|
||||
}
|
||||
|
||||
static int st_tree_del_enum(struct enum_t **list, const char *val)
|
||||
static int st_tree_del_enum(enum_t **list, const char *val)
|
||||
{
|
||||
while (*list) {
|
||||
|
||||
struct enum_t *item = *list;
|
||||
enum_t *item = *list;
|
||||
|
||||
/* if this is not the right value, go on to the next */
|
||||
if (strcasecmp(item->val, val)) {
|
||||
|
|
@ -457,9 +457,9 @@ static int st_tree_del_enum(struct enum_t **list, const char *val)
|
|||
return 0; /* not found */
|
||||
}
|
||||
|
||||
int state_delenum(struct st_tree_t *root, const char *var, const char *val)
|
||||
int state_delenum(st_tree_t *root, const char *var, const char *val)
|
||||
{
|
||||
struct st_tree_t *sttmp;
|
||||
st_tree_t *sttmp;
|
||||
|
||||
/* find the tree node for var */
|
||||
sttmp = state_tree_find(root, var);
|
||||
|
|
@ -471,7 +471,7 @@ int state_delenum(struct st_tree_t *root, const char *var, const char *val)
|
|||
return st_tree_del_enum(&sttmp->enum_list, val);
|
||||
}
|
||||
|
||||
struct st_tree_t *state_tree_find(struct st_tree_t *node, const char *var)
|
||||
st_tree_t *state_tree_find(st_tree_t *node, const char *var)
|
||||
{
|
||||
while (node) {
|
||||
|
||||
|
|
|
|||
503
common/strerror.c
Normal file
503
common/strerror.c
Normal file
|
|
@ -0,0 +1,503 @@
|
|||
/* strerror() Mark Powell <medp@primagraphics.co.uk> */
|
||||
/* Simple implementation derived from libiberty */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
char *strerror(int errnum)
|
||||
{
|
||||
static char buf[32];
|
||||
|
||||
switch (errnum) {
|
||||
#if defined (EPERM)
|
||||
case EPERM:
|
||||
return "Not owner";
|
||||
#endif
|
||||
#if defined (ENOENT)
|
||||
case ENOENT:
|
||||
return "No such file or directory";
|
||||
#endif
|
||||
#if defined (ESRCH)
|
||||
case ESRCH:
|
||||
return "No such process";
|
||||
#endif
|
||||
#if defined (EINTR)
|
||||
case EINTR:
|
||||
return "Interrupted system call";
|
||||
#endif
|
||||
#if defined (EIO)
|
||||
case EIO:
|
||||
return "I/O error";
|
||||
#endif
|
||||
#if defined (ENXIO)
|
||||
case ENXIO:
|
||||
return "No such device or address";
|
||||
#endif
|
||||
#if defined (E2BIG)
|
||||
return "Arg list too long";
|
||||
#endif
|
||||
#if defined (ENOEXEC)
|
||||
case ENOEXEC:
|
||||
return "Exec format error";
|
||||
#endif
|
||||
#if defined (EBADF)
|
||||
case EBADF:
|
||||
return "Bad file number";
|
||||
#endif
|
||||
#if defined (ECHILD)
|
||||
case ECHILD:
|
||||
return "No child processes";
|
||||
#endif
|
||||
#if defined (EWOULDBLOCK) /* Put before EAGAIN, sometimes aliased */
|
||||
case EWOULDBLOCK:
|
||||
return "Operation would block";
|
||||
#endif
|
||||
#if defined (EAGAIN)
|
||||
#if defined (EWOULDBLOCK) && EAGAIN != EWOULDBLOCK
|
||||
case EAGAIN:
|
||||
return "No more processes";
|
||||
#endif
|
||||
#endif
|
||||
#if defined (ENOMEM)
|
||||
case ENOMEM:
|
||||
return "Not enough space";
|
||||
#endif
|
||||
#if defined (EACCES)
|
||||
case EACCES:
|
||||
return "Permission denied";
|
||||
#endif
|
||||
#if defined (EFAULT)
|
||||
case EFAULT:
|
||||
return "Bad address";
|
||||
#endif
|
||||
#if defined (ENOTBLK)
|
||||
case ENOTBLK:
|
||||
return "Block device required";
|
||||
#endif
|
||||
#if defined (EBUSY)
|
||||
case EBUSY:
|
||||
return "Device busy";
|
||||
#endif
|
||||
#if defined (EEXIST)
|
||||
case EEXIST:
|
||||
return "File exists";
|
||||
#endif
|
||||
#if defined (EXDEV)
|
||||
case EXDEV:
|
||||
return "Cross-device link";
|
||||
#endif
|
||||
#if defined (ENODEV)
|
||||
case ENODEV:
|
||||
return "No such device";
|
||||
#endif
|
||||
#if defined (ENOTDIR)
|
||||
case ENOTDIR:
|
||||
return "Not a directory";
|
||||
#endif
|
||||
#if defined (EISDIR)
|
||||
case EISDIR:
|
||||
return "Is a directory";
|
||||
#endif
|
||||
#if defined (EINVAL)
|
||||
case EINVAL:
|
||||
return "Invalid argument";
|
||||
#endif
|
||||
#if defined (ENFILE)
|
||||
case ENFILE:
|
||||
return "File table overflow";
|
||||
#endif
|
||||
#if defined (EMFILE)
|
||||
case EMFILE:
|
||||
return "Too many open files";
|
||||
#endif
|
||||
#if defined (ENOTTY)
|
||||
case ENOTTY:
|
||||
return "Not a typewriter";
|
||||
#endif
|
||||
#if defined (ETXTBSY)
|
||||
case ETXTBSY:
|
||||
return "Text file busy";
|
||||
#endif
|
||||
#if defined (EFBIG)
|
||||
case EFBIG:
|
||||
return "File too large";
|
||||
#endif
|
||||
#if defined (ENOSPC)
|
||||
case ENOSPC:
|
||||
return "No space left on device";
|
||||
#endif
|
||||
#if defined (ESPIPE)
|
||||
case ESPIPE:
|
||||
return "Illegal seek";
|
||||
#endif
|
||||
#if defined (EROFS)
|
||||
case EROFS:
|
||||
return "Read-only file system";
|
||||
#endif
|
||||
#if defined (EMLINK)
|
||||
case EMLINK:
|
||||
return "Too many links";
|
||||
#endif
|
||||
#if defined (EPIPE)
|
||||
case EPIPE:
|
||||
return "Broken pipe";
|
||||
#endif
|
||||
#if defined (EDOM)
|
||||
case EDOM:
|
||||
return "Math argument out of domain of func";
|
||||
#endif
|
||||
#if defined (ERANGE)
|
||||
case ERANGE:
|
||||
return "Math result not representable";
|
||||
#endif
|
||||
#if defined (ENOMSG)
|
||||
case ENOMSG:
|
||||
return "No message of desired type";
|
||||
#endif
|
||||
#if defined (EIDRM)
|
||||
case EIDRM:
|
||||
return "Identifier removed";
|
||||
#endif
|
||||
#if defined (ECHRNG)
|
||||
case ECHRNG:
|
||||
return "Channel number out of range";
|
||||
#endif
|
||||
#if defined (EL2NSYNC)
|
||||
return "Level 2 not synchronized";
|
||||
#endif
|
||||
#if defined (EL3HLT)
|
||||
return "Level 3 halted";
|
||||
#endif
|
||||
#if defined (EL3RST)
|
||||
return "Level 3 reset";
|
||||
#endif
|
||||
#if defined (ELNRNG)
|
||||
case ELNRNG:
|
||||
return "Link number out of range";
|
||||
#endif
|
||||
#if defined (EUNATCH)
|
||||
case EUNATCH:
|
||||
return "Protocol driver not attached";
|
||||
#endif
|
||||
#if defined (ENOCSI)
|
||||
case ENOCSI:
|
||||
return "No CSI structure available";
|
||||
#endif
|
||||
#if defined (EL2HLT)
|
||||
return "Level 2 halted";
|
||||
#endif
|
||||
#if defined (EDEADLK)
|
||||
case EDEADLK:
|
||||
return "Deadlock condition";
|
||||
#endif
|
||||
#if defined (ENOLCK)
|
||||
case ENOLCK:
|
||||
return "No record locks available";
|
||||
#endif
|
||||
#if defined (EBADE)
|
||||
case EBADE:
|
||||
return "Invalid exchange";
|
||||
#endif
|
||||
#if defined (EBADR)
|
||||
case EBADR:
|
||||
return "Invalid request descriptor";
|
||||
#endif
|
||||
#if defined (EXFULL)
|
||||
case EXFULL:
|
||||
return "Exchange full";
|
||||
#endif
|
||||
#if defined (ENOANO)
|
||||
case ENOANO:
|
||||
return "No anode";
|
||||
#endif
|
||||
#if defined (EBADRQC)
|
||||
case EBADRQC:
|
||||
return "Invalid request code";
|
||||
#endif
|
||||
#if defined (EBADSLT)
|
||||
case EBADSLT:
|
||||
return "Invalid slot";
|
||||
#endif
|
||||
#if defined (EDEADLOCK)
|
||||
case EDEADLOCK:
|
||||
return "File locking deadlock error";
|
||||
#endif
|
||||
#if defined (EBFONT)
|
||||
case EBFONT:
|
||||
return "Bad font file format";
|
||||
#endif
|
||||
#if defined (ENOSTR)
|
||||
case ENOSTR:
|
||||
return "Device not a stream";
|
||||
#endif
|
||||
#if defined (ENODATA)
|
||||
case ENODATA:
|
||||
return "No data available";
|
||||
#endif
|
||||
#if defined (ETIME)
|
||||
case ETIME:
|
||||
return "Timer expired";
|
||||
#endif
|
||||
#if defined (ENOSR)
|
||||
case ENOSR:
|
||||
return "Out of streams resources";
|
||||
#endif
|
||||
#if defined (ENONET)
|
||||
case ENONET:
|
||||
return "Machine is not on the network";
|
||||
#endif
|
||||
#if defined (ENOPKG)
|
||||
case ENOPKG:
|
||||
return "Package not installed";
|
||||
#endif
|
||||
#if defined (EREMOTE)
|
||||
case EREMOTE:
|
||||
return "Object is remote";
|
||||
#endif
|
||||
#if defined (ENOLINK)
|
||||
case ENOLINK:
|
||||
return "Link has been severed";
|
||||
#endif
|
||||
#if defined (EADV)
|
||||
case EADV:
|
||||
return "Advertise error";
|
||||
#endif
|
||||
#if defined (ESRMNT)
|
||||
case ESRMNT:
|
||||
return "Srmount error";
|
||||
#endif
|
||||
#if defined (ECOMM)
|
||||
case ECOMM:
|
||||
return "Communication error on send";
|
||||
#endif
|
||||
#if defined (EPROTO)
|
||||
case EPROTO:
|
||||
return "Protocol error";
|
||||
#endif
|
||||
#if defined (EMULTIHOP)
|
||||
case EMULTIHOP:
|
||||
return "Multihop attempted";
|
||||
#endif
|
||||
#if defined (EDOTDOT)
|
||||
case EDOTDOT:
|
||||
return "RFS specific error";
|
||||
#endif
|
||||
#if defined (EBADMSG)
|
||||
case EBADMSG:
|
||||
return "Not a data message";
|
||||
#endif
|
||||
#if defined (ENAMETOOLONG)
|
||||
case ENAMETOOLONG:
|
||||
return "File name too long";
|
||||
#endif
|
||||
#if defined (EOVERFLOW)
|
||||
case EOVERFLOW:
|
||||
return "Value too large for defined data type";
|
||||
#endif
|
||||
#if defined (ENOTUNIQ)
|
||||
case ENOTUNIQ:
|
||||
return "Name not unique on network";
|
||||
#endif
|
||||
#if defined (EBADFD)
|
||||
case EBADFD:
|
||||
return "File descriptor in bad state";
|
||||
#endif
|
||||
#if defined (EREMCHG)
|
||||
case EREMCHG:
|
||||
return "Remote address changed";
|
||||
#endif
|
||||
#if defined (ELIBACC)
|
||||
case ELIBACC:
|
||||
return "Can not access a needed shared library";
|
||||
#endif
|
||||
#if defined (ELIBBAD)
|
||||
case ELIBBAD:
|
||||
return "Accessing a corrupted shared library";
|
||||
#endif
|
||||
#if defined (ELIBSCN)
|
||||
case ELIBSCN:
|
||||
return ".lib section in a.out corrupted";
|
||||
#endif
|
||||
#if defined (ELIBMAX)
|
||||
case ELIBMAX:
|
||||
return "Attempting to link in too many shared libraries";
|
||||
#endif
|
||||
#if defined (ELIBEXEC)
|
||||
case ELIBEXEC:
|
||||
return "Cannot exec a shared library directly";
|
||||
#endif
|
||||
#if defined (EILSEQ)
|
||||
case EILSEQ:
|
||||
return "Illegal byte sequence";
|
||||
#endif
|
||||
#if defined (ENOSYS)
|
||||
case ENOSYS:
|
||||
return "Operation not applicable";
|
||||
#endif
|
||||
#if defined (ELOOP)
|
||||
case ELOOP:
|
||||
return "Too many symbolic links encountered";
|
||||
#endif
|
||||
#if defined (ERESTART)
|
||||
case ERESTART:
|
||||
return "Interrupted system call should be restarted";
|
||||
#endif
|
||||
#if defined (ESTRPIPE)
|
||||
case ESTRPIPE:
|
||||
return "Streams pipe error";
|
||||
#endif
|
||||
#if defined (ENOTEMPTY)
|
||||
case ENOTEMPTY:
|
||||
return "Directory not empty";
|
||||
#endif
|
||||
#if defined (EUSERS)
|
||||
case EUSERS:
|
||||
return "Too many users";
|
||||
#endif
|
||||
#if defined (ENOTSOCK)
|
||||
case ENOTSOCK:
|
||||
return "Socket operation on non-socket";
|
||||
#endif
|
||||
#if defined (EDESTADDRREQ)
|
||||
case EDESTADDRREQ:
|
||||
return "Destination address required";
|
||||
#endif
|
||||
#if defined (EMSGSIZE)
|
||||
case EMSGSIZE:
|
||||
return "Message too long";
|
||||
#endif
|
||||
#if defined (EPROTOTYPE)
|
||||
case EPROTOTYPE:
|
||||
return "Protocol wrong type for socket";
|
||||
#endif
|
||||
#if defined (ENOPROTOOPT)
|
||||
case ENOPROTOOPT:
|
||||
return "Protocol not available";
|
||||
#endif
|
||||
#if defined (EPROTONOSUPPORT)
|
||||
case EPROTONOSUPPORT:
|
||||
return "Protocol not supported";
|
||||
#endif
|
||||
#if defined (ESOCKTNOSUPPORT)
|
||||
case ESOCKTNOSUPPORT:
|
||||
return "Socket type not supported";
|
||||
#endif
|
||||
#if defined (EOPNOTSUPP)
|
||||
case EOPNOTSUPP:
|
||||
return "Operation not supported on transport endpoint";
|
||||
#endif
|
||||
#if defined (EPFNOSUPPORT)
|
||||
case EPFNOSUPPORT:
|
||||
return "Protocol family not supported";
|
||||
#endif
|
||||
#if defined (EAFNOSUPPORT)
|
||||
case EAFNOSUPPORT:
|
||||
return "Address family not supported by protocol";
|
||||
#endif
|
||||
#if defined (EADDRINUSE)
|
||||
case EADDRINUSE:
|
||||
return "Address already in use";
|
||||
#endif
|
||||
#if defined (EADDRNOTAVAIL)
|
||||
case EADDRNOTAVAIL:
|
||||
return "Cannot assign requested address";
|
||||
#endif
|
||||
#if defined (ENETDOWN)
|
||||
case ENETDOWN:
|
||||
return "Network is down";
|
||||
#endif
|
||||
#if defined (ENETUNREACH)
|
||||
case ENETUNREACH:
|
||||
return "Network is unreachable";
|
||||
#endif
|
||||
#if defined (ENETRESET)
|
||||
case ENETRESET:
|
||||
return "Network dropped connection because of reset";
|
||||
#endif
|
||||
#if defined (ECONNABORTED)
|
||||
case ECONNABORTED:
|
||||
return "Software caused connection abort";
|
||||
#endif
|
||||
#if defined (ECONNRESET)
|
||||
case ECONNRESET:
|
||||
return "Connection reset by peer";
|
||||
#endif
|
||||
#if defined (ENOBUFS)
|
||||
case ENOBUFS:
|
||||
return "No buffer space available";
|
||||
#endif
|
||||
#if defined (EISCONN)
|
||||
case EISCONN:
|
||||
return "Transport endpoint is already connected";
|
||||
#endif
|
||||
#if defined (ENOTCONN)
|
||||
case ENOTCONN:
|
||||
return "Transport endpoint is not connected";
|
||||
#endif
|
||||
#if defined (ESHUTDOWN)
|
||||
case ESHUTDOWN:
|
||||
return "Cannot send after transport endpoint shutdown";
|
||||
#endif
|
||||
#if defined (ETOOMANYREFS)
|
||||
case ETOOMANYREFS:
|
||||
return "Too many references: cannot splice";
|
||||
#endif
|
||||
#if defined (ETIMEDOUT)
|
||||
case ETIMEDOUT:
|
||||
return "Connection timed out";
|
||||
#endif
|
||||
#if defined (ECONNREFUSED)
|
||||
case ECONNREFUSED:
|
||||
return "Connection refused";
|
||||
#endif
|
||||
#if defined (EHOSTDOWN)
|
||||
case EHOSTDOWN:
|
||||
return "Host is down";
|
||||
#endif
|
||||
#if defined (EHOSTUNREACH)
|
||||
case EHOSTUNREACH:
|
||||
return "No route to host";
|
||||
#endif
|
||||
#if defined (EALREADY)
|
||||
case EALREADY:
|
||||
return "Operation already in progress";
|
||||
#endif
|
||||
#if defined (EINPROGRESS)
|
||||
case EINPROGRESS:
|
||||
return "Operation now in progress";
|
||||
#endif
|
||||
#if defined (ESTALE)
|
||||
case ESTALE:
|
||||
return "Stale NFS file handle";
|
||||
#endif
|
||||
#if defined (EUCLEAN)
|
||||
case EUCLEAN:
|
||||
return "Structure needs cleaning";
|
||||
#endif
|
||||
#if defined (ENOTNAM)
|
||||
case ENOTNAM:
|
||||
return "Not a XENIX named type file";
|
||||
#endif
|
||||
#if defined (ENAVAIL)
|
||||
case ENAVAIL:
|
||||
return "No XENIX semaphores available";
|
||||
#endif
|
||||
#if defined (EISNAM)
|
||||
case EISNAM:
|
||||
return "Is a named type file";
|
||||
#endif
|
||||
#if defined (EREMOTEIO)
|
||||
case EREMOTEIO:
|
||||
return "Remote I/O error";
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Fallback: just print the error number */
|
||||
snprintf(buf, sizeof(buf), "Error %d", errnum);
|
||||
return buf;
|
||||
}
|
||||
|
||||
#endif /* HAVE_STRERROR */
|
||||
Loading…
Add table
Add a link
Reference in a new issue