about summary refs log tree commit diff
path: root/lib/util
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-12-27 22:31:01 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-12-27 22:31:01 +0000
commitdcde1624d79c372394e65c99771fe64a28a82ee5 (patch)
tree6ef16add2693ae8d966c79bbdc570fc2a3c0acdb /lib/util
parentb9310d8e36427001a9e67fafa2462616d1f6bfff (diff)
downloadnetpbm-mirror-dcde1624d79c372394e65c99771fe64a28a82ee5.tar.gz
netpbm-mirror-dcde1624d79c372394e65c99771fe64a28a82ee5.tar.xz
netpbm-mirror-dcde1624d79c372394e65c99771fe64a28a82ee5.zip
Release 10.41.00
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@499 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/util')
-rw-r--r--lib/util/Makefile2
-rw-r--r--lib/util/mallocvar.h2
-rw-r--r--lib/util/nstring.c40
-rw-r--r--lib/util/nstring.h5
4 files changed, 47 insertions, 2 deletions
diff --git a/lib/util/Makefile b/lib/util/Makefile
index d770555f..49396010 100644
--- a/lib/util/Makefile
+++ b/lib/util/Makefile
@@ -17,7 +17,7 @@ all: $(UTILOBJECTS)
 
 include $(SRCDIR)/Makefile.common
 
-INCLUDES = -I $(BUILDDIR) -I $(SRCDIR)/$(SUBDIR)/..
+INCLUDES = -I$(SRCDIR)/$(SUBDIR) -I. -Iimportinc
 
 $(UTILOBJECTS):%.o:%.c importinc
 	$(CC) -c $(INCLUDES) -DNDEBUG $(CPPFLAGS) $(CFLAGS) $(CFLAGS_SHLIB) \
diff --git a/lib/util/mallocvar.h b/lib/util/mallocvar.h
index e5b7b1ea..b750e177 100644
--- a/lib/util/mallocvar.h
+++ b/lib/util/mallocvar.h
@@ -83,7 +83,7 @@ reallocProduct(void **      const blockP,
     arrayName = array; \
 } while (0)
 
-#define REALLOCARRAY(arrayName, nElements) { \
+#define REALLOCARRAY(arrayName, nElements) do { \
     void * array; \
     array = arrayName; \
     reallocProduct(&array, nElements, sizeof(arrayName[0])); \
diff --git a/lib/util/nstring.c b/lib/util/nstring.c
index feb8215e..0fa78c7a 100644
--- a/lib/util/nstring.c
+++ b/lib/util/nstring.c
@@ -915,3 +915,43 @@ strishex(const char * const subject) {
 
     return retval;
 }
+
+
+
+void
+interpret_uint(const char *   const string,
+               unsigned int * const valueP,
+               const char **  const errorP) {
+
+    if (string[0] == '\0')
+        asprintfN(errorP, "Null string.");
+    else {
+        /* strtoul() does a bizarre thing where if the number is out
+           of range, it returns a clamped value but tells you about it
+           by setting errno = ERANGE.  If it is not out of range,
+           strtoul() leaves errno alone.
+        */
+        char * tail;
+        unsigned long ulongValue;
+        
+        errno = 0;  /* So we can tell if strtoul() overflowed */
+
+        ulongValue = strtoul(string, &tail, 10);
+
+        if (tail[0] != '\0')
+            asprintfN(errorP, "Non-digit stuff in string: %s", tail);
+        else if (errno == ERANGE)
+            asprintfN(errorP, "Number too large");
+        else if (ulongValue > UINT_MAX)
+            asprintfN(errorP, "Number too large");
+        else if (string[0] == '-')
+            asprintfN(errorP, "Negative number");
+            /* Sleazy code; string may have leading spaces. */
+        else {
+            *valueP = ulongValue;
+            *errorP = NULL;
+        }
+    }
+}
+
+
diff --git a/lib/util/nstring.h b/lib/util/nstring.h
index 9d61cfa5..1e5ca4c3 100644
--- a/lib/util/nstring.h
+++ b/lib/util/nstring.h
@@ -183,6 +183,11 @@ memmemN(const void * const haystackArg,
 bool
 strishex(const char * const subject);
 
+void
+interpret_uint(const char *   const string,
+               unsigned int * const valueP,
+               const char **  const errorP);
+
 #ifdef __cplusplus
 }
 #endif