diff options
author | Claudio Fontana <sick_soul@users.sourceforge.net> | 2005-12-11 13:22:29 +0000 |
---|---|---|
committer | Claudio Fontana <sick_soul@users.sourceforge.net> | 2005-12-11 13:22:29 +0000 |
commit | 5e2d8d624da4305197cce508b3bf271fd41c430a (patch) | |
tree | 4fec493a6d52d82de91b4add446c2e812713f01d /lib | |
parent | 154c7adf71bab69829954a310f3ae02837ec5e7d (diff) | |
download | idutils-5e2d8d624da4305197cce508b3bf271fd41c430a.tar.gz idutils-5e2d8d624da4305197cce508b3bf271fd41c430a.tar.bz2 idutils-5e2d8d624da4305197cce508b3bf271fd41c430a.zip |
* added inttostr module from gnulib, used in src/mkid.c to print an
off_t portably using offtostr()
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 8 | ||||
-rw-r--r-- | lib/Makefile.in | 16 | ||||
-rw-r--r-- | lib/imaxtostr.c | 3 | ||||
-rw-r--r-- | lib/intprops.h | 78 | ||||
-rw-r--r-- | lib/inttostr.c | 52 | ||||
-rw-r--r-- | lib/inttostr.h | 34 | ||||
-rw-r--r-- | lib/offtostr.c | 3 | ||||
-rw-r--r-- | lib/umaxtostr.c | 3 |
8 files changed, 189 insertions, 8 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 1f6a588..e04136e 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -8,7 +8,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=/home/claudio/src/idutils/idutils/ --lib=libgnu --source-base=lib --m4-base=m4 --aux-dir=. --macro-prefix=gl alloca alloca-opt atexit closeout error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --aux-dir=. --macro-prefix=gl alloca alloca-opt atexit closeout error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib inttostr lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies @@ -84,6 +84,12 @@ libgnu_a_SOURCES += gettext.h ## end gnulib module gettext-h +## begin gnulib module inttostr + +EXTRA_DIST += inttostr.c + +## end gnulib module inttostr + ## begin gnulib module mbchar libgnu_a_SOURCES += mbchar.h diff --git a/lib/Makefile.in b/lib/Makefile.in index 87b6838..19e3585 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -23,7 +23,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=/home/claudio/src/idutils/idutils/ --lib=libgnu --source-base=lib --m4-base=m4 --aux-dir=. --macro-prefix=gl alloca alloca-opt atexit closeout error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --aux-dir=. --macro-prefix=gl alloca alloca-opt atexit closeout error exclude exit exitfail extensions fnmatch fnmatch-gnu fpending getcwd getopt gettext gettext-h havelib inttostr lstat malloc mbchar mbuiter memchr memcpy mempcpy memset obstack pathmax quotearg realloc regex restrict stat-macros stdbool strcase strcspn strdup strnlen1 strpbrk strsep strstr xalloc xalloc-die xgetcwd SOURCES = $(libgnu_a_SOURCES) @@ -53,13 +53,14 @@ subdir = lib DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in __fpending.c \ __fpending.h alloca.c atexit.c closeout.c closeout.h error.c \ error.h exclude.c exclude.h exitfail.c exitfail.h fnmatch.c \ - getcwd.c getcwd.h getopt.c getopt1.c lstat.c lstat.h malloc.c \ - mbchar.c memchr.c memcpy.c mempcpy.c mempcpy.h memset.c \ - obstack.c obstack.h pathmax.h quotearg.c quotearg.h realloc.c \ + getcwd.c getcwd.h getopt.c getopt1.c imaxtostr.c intprops.h \ + inttostr.c inttostr.h lstat.c lstat.h malloc.c mbchar.c \ + memchr.c memcpy.c mempcpy.c mempcpy.h memset.c obstack.c \ + obstack.h offtostr.c pathmax.h quotearg.c quotearg.h realloc.c \ regcomp.c regex.c regex.h regex_internal.c regex_internal.h \ regexec.c stat-macros.h strcasecmp.c strcspn.c strdup.c \ - strdup.h strncasecmp.c strpbrk.c strsep.c strstr.c xalloc.h \ - xgetcwd.c xgetcwd.h xmalloc.c + strdup.h strncasecmp.c strpbrk.c strsep.c strstr.c umaxtostr.c \ + xalloc.h xgetcwd.c xgetcwd.h xmalloc.c ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/alloca.m4 \ $(top_srcdir)/m4/atexit.m4 $(top_srcdir)/m4/closeout.m4 \ @@ -72,6 +73,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/alloca.m4 \ $(top_srcdir)/m4/glibc2.m4 $(top_srcdir)/m4/glibc21.m4 \ $(top_srcdir)/m4/gnulib-comp.m4 $(top_srcdir)/m4/iconv.m4 \ $(top_srcdir)/m4/intdiv0.m4 $(top_srcdir)/m4/intmax.m4 \ + $(top_srcdir)/m4/intmax_t.m4 $(top_srcdir)/m4/inttostr.m4 \ $(top_srcdir)/m4/inttypes-pri.m4 $(top_srcdir)/m4/inttypes.m4 \ $(top_srcdir)/m4/inttypes_h.m4 $(top_srcdir)/m4/lcmessage.m4 \ $(top_srcdir)/m4/lib-ld.m4 $(top_srcdir)/m4/lib-link.m4 \ @@ -248,7 +250,7 @@ libgnu_a_SOURCES = exit.h gettext.h mbchar.h mbuiter.h strcase.h \ strnlen1.h strnlen1.c strpbrk.h strsep.h strstr.h xalloc-die.c libgnu_a_LIBADD = @LIBOBJS@ @ALLOCA@ EXTRA_DIST = alloca_.h fnmatch_.h fnmatch_loop.c getopt_.h \ - getopt_int.h stdbool_.h + getopt_int.h inttostr.c stdbool_.h BUILT_SOURCES = $(ALLOCA_H) $(FNMATCH_H) $(GETOPT_H) $(STDBOOL_H) SUFFIXES = MOSTLYCLEANFILES = alloca.h alloca.h-t fnmatch.h fnmatch.h-t getopt.h \ diff --git a/lib/imaxtostr.c b/lib/imaxtostr.c new file mode 100644 index 0000000..5e87ad5 --- /dev/null +++ b/lib/imaxtostr.c @@ -0,0 +1,3 @@ +#define inttostr imaxtostr +#define inttype intmax_t +#include "inttostr.c" diff --git a/lib/intprops.h b/lib/intprops.h new file mode 100644 index 0000000..34f971c --- /dev/null +++ b/lib/intprops.h @@ -0,0 +1,78 @@ +/* intprops.h -- properties of integer types + + Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert. */ + +#include <limits.h> + +/* The extra casts in the following macros work around compiler bugs, + e.g., in Cray C 5.0.3.0. */ + +/* True if the arithmetic type T is an integer type. bool counts as + an integer. */ +#define TYPE_IS_INTEGER(t) ((t) 1.5 == 1) + +/* True if negative values of the signed integer type T use two's + complement, ones' complement, or signed magnitude representation, + respectively. Much GNU code assumes two's complement, but some + people like to be portable to all possible C hosts. */ +#define TYPE_TWOS_COMPLEMENT(t) ((t) ~ (t) 0 == (t) -1) +#define TYPE_ONES_COMPLEMENT(t) ((t) ~ (t) 0 == 0) +#define TYPE_SIGNED_MAGNITUDE(t) ((t) ~ (t) 0 < (t) -1) + +/* True if the arithmetic type T is signed. */ +#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) + +/* The maximum and minimum values for the integer type T. These + macros have undefined behavior if T is signed and has padding bits. + If this is a problem for you, please let us know how to fix it for + your host. */ +#define TYPE_MINIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) 0 \ + : TYPE_SIGNED_MAGNITUDE (t) \ + ? ~ (t) 0 \ + : ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1))) +#define TYPE_MAXIMUM(t) \ + ((t) (! TYPE_SIGNED (t) \ + ? (t) -1 \ + : ~ (~ (t) 0 << (sizeof (t) * CHAR_BIT - 1)))) + +/* Return zero if T can be determined to be an unsigned type. + Otherwise, return 1. + When compiling with GCC, INT_STRLEN_BOUND uses this macro to obtain a + tighter bound. Otherwise, it overestimates the true bound by one byte + when applied to unsigned types of size 2, 4, 16, ... bytes. + The symbol signed_type_or_expr__ is private to this header file. */ +#if __GNUC__ >= 2 +# define signed_type_or_expr__(t) TYPE_SIGNED (__typeof__ (t)) +#else +# define signed_type_or_expr__(t) 1 +#endif + +/* Bound on length of the string representing an integer type or expression T. + Subtract 1 for the sign bit if T is signed; log10 (2.0) < 146/485; + add 1 for integer division truncation; add 1 more for a minus sign + if needed. */ +#define INT_STRLEN_BOUND(t) \ + ((sizeof (t) * CHAR_BIT - signed_type_or_expr__ (t)) * 146 / 485 \ + + signed_type_or_expr__ (t) + 1) + +/* Bound on buffer size needed to represent an integer type or expression T, + including the terminating null. */ +#define INT_BUFSIZE_BOUND(t) (INT_STRLEN_BOUND (t) + 1) diff --git a/lib/inttostr.c b/lib/inttostr.c new file mode 100644 index 0000000..2adcd2c --- /dev/null +++ b/lib/inttostr.c @@ -0,0 +1,52 @@ +/* inttostr.c -- convert integers to printable strings + + Copyright (C) 2001 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif +#include "inttostr.h" + +/* Convert I to a printable string in BUF, which must be at least + INT_BUFSIZE_BOUND (INTTYPE) bytes long. Return the address of the + printable string, which need not start at BUF. */ + +char * +inttostr (inttype i, char *buf) +{ + char *p = buf + INT_STRLEN_BOUND (inttype); + *p = 0; + + if (i < 0) + { + do + *--p = '0' - i % 10; + while ((i /= 10) != 0); + + *--p = '-'; + } + else + { + do + *--p = '0' + i % 10; + while ((i /= 10) != 0); + } + + return p; +} diff --git a/lib/inttostr.h b/lib/inttostr.h new file mode 100644 index 0000000..55f80ee --- /dev/null +++ b/lib/inttostr.h @@ -0,0 +1,34 @@ +/* inttostr.h -- convert integers to printable strings + + Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Paul Eggert */ + +#if HAVE_INTTYPES_H +# include <inttypes.h> +#endif +#if HAVE_STDINT_H +# include <stdint.h> +#endif + +#include <sys/types.h> + +#include "intprops.h" + +char *offtostr (off_t, char *); +char *imaxtostr (intmax_t, char *); +char *umaxtostr (uintmax_t, char *); diff --git a/lib/offtostr.c b/lib/offtostr.c new file mode 100644 index 0000000..45196e2 --- /dev/null +++ b/lib/offtostr.c @@ -0,0 +1,3 @@ +#define inttostr offtostr +#define inttype off_t +#include "inttostr.c" diff --git a/lib/umaxtostr.c b/lib/umaxtostr.c new file mode 100644 index 0000000..4f49a7f --- /dev/null +++ b/lib/umaxtostr.c @@ -0,0 +1,3 @@ +#define inttostr umaxtostr +#define inttype uintmax_t +#include "inttostr.c" |