Get rid of size member of Odr_oct
[yaz-moved-to-github.git] / src / odr_mem.c
index 88f012c..52d850b 100644 (file)
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
+ * Copyright (C) 1995-2013 Index Data
  * See the file LICENSE for details.
  */
 /**
@@ -67,7 +67,9 @@ Odr_oct *odr_create_Odr_oct(ODR o, const unsigned char *buf, int sz)
     Odr_oct *p = (Odr_oct *) odr_malloc(o, sizeof(Odr_oct));
     p->buf = (unsigned char *) odr_malloc(o, sz);
     memcpy(p->buf, buf, sz);
+#if OCT_SIZE
     p->size = sz;
+#endif
     p->len = sz;
     return p;
 }
@@ -96,7 +98,7 @@ int odr_grow_block(ODR b, int min_bytes)
     return 0;
 }
 
-int odr_write(ODR o, unsigned char *buf, int bytes)
+int odr_write2(ODR o, const char *buf, int bytes)
 {
     if (o->pos + bytes >= o->size && odr_grow_block(o, bytes))
     {
@@ -110,6 +112,11 @@ int odr_write(ODR o, unsigned char *buf, int bytes)
     return 0;
 }
 
+int odr_write(ODR o, unsigned char *buf, int bytes)
+{
+    return odr_write2(o, (char *) buf, bytes);
+}
+
 int odr_seek(ODR o, int whence, int offset)
 {
     if (whence == ODR_S_CUR)
@@ -125,21 +132,26 @@ int odr_seek(ODR o, int whence, int offset)
     return 0;
 }
 
-Odr_int odr_atoi(const char *s)
+Odr_int odr_strtol(const char *nptr, char **endptr, int base)
 {
 #if NMEM_64
-    char *endptr;
 #if WIN32
-    return _strtoui64(s, &endptr, 10);
+    return _strtoui64(nptr, endptr, base);
 #else
-    return strtoll(s, &endptr, 10);
+    return strtoll(nptr, endptr, base);
 #endif
 
 #else
-    return atoi(s);
+    return strtol(nptr, endptr, base);
 #endif
 }
 
+Odr_int odr_atoi(const char *s)
+{
+    char *endptr;
+    return odr_strtol(s, &endptr, 10);
+}
+
 /*
  * Local variables:
  * c-basic-offset: 4