You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2004/05/24 11:33:27 UTC
cvs commit: apr/test teststr.c
jorton 2004/05/24 02:33:27
Modified: . CHANGES configure.in
include apr_strings.h
include/arch/netware apr_private.h
include/arch/win32 apr_private.h
strings apr_strings.c
test teststr.c
Log:
* configure.in, include/arch/win32/apr_private.h,
include/arch/netware/apr_private.h: Define APR_OFF_T_STRFN.
* include/apr_strings.h, strings/apr_strings.c: Add apr_strtoff()
function.
* test/teststr.c (string_strtoff): Add test.
Submitted by: André Malo, Joe Orton
Revision Changes Path
1.470 +3 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.469
retrieving revision 1.470
diff -d -u -r1.469 -r1.470
--- CHANGES 21 May 2004 22:21:13 -0000 1.469
+++ CHANGES 24 May 2004 09:33:25 -0000 1.470
@@ -7,6 +7,9 @@
Changes with APR 1.0
+ *) Add apr_strtoff() function for converting numeric strings into
+ apr_off_t values. [Andr� Malo <nd perlig.de>, Joe Orton]
+
*) Fix stack overflow with IPv6 apr_socket_accept() on Win32.
PR 28471. [inoue <inoue ariel-networks.com>]
1.581 +11 -0 apr/configure.in
Index: configure.in
===================================================================
RCS file: /home/cvs/apr/configure.in,v
retrieving revision 1.580
retrieving revision 1.581
diff -d -u -r1.580 -r1.581
--- configure.in 20 May 2004 14:53:21 -0000 1.580
+++ configure.in 24 May 2004 09:33:26 -0000 1.581
@@ -1222,6 +1222,7 @@
# LFS is go!
off_t_fmt='#define APR_OFF_T_FMT APR_INT64_T_FMT'
off_t_value='off64_t'
+ off_t_strfn='apr_strtoi64'
elif test "${ac_cv_sizeof_off_t}x${ac_cv_sizeof_long}" = "4x4"; then
# Special case: off_t may change size with _FILE_OFFSET_BITS
# on 32-bit systems with LFS support. To avoid compatibility
@@ -1229,16 +1230,20 @@
# hard-code apr_off_t to long.
off_t_value=long
off_t_fmt='#define APR_OFF_T_FMT "ld"'
+ off_t_strfn='strtol'
elif test "$ac_cv_type_off_t" = "yes"; then
off_t_value=off_t
# off_t is more commonly a long than an int; prefer that case
# where int and long are the same size.
if test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_long"; then
off_t_fmt='#define APR_OFF_T_FMT "ld"'
+ off_t_strfn='strtol'
elif test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_int"; then
off_t_fmt='#define APR_OFF_T_FMT "d"'
+ off_t_strfn='strtoi'
elif test "$ac_cv_sizeof_off_t" = "$ac_cv_sizeof_long_long"; then
off_t_fmt='#define APR_OFF_T_FMT APR_INT64_T_FMT'
+ off_t_strfn='apr_strtoi64'
else
AC_ERROR([could not determine the size of off_t])
fi
@@ -1246,6 +1251,7 @@
# Fallback on int
off_t_value=apr_int32_t
off_t_fmt=d
+ off_t_strfn='strtoi'
fi
AC_MSG_RESULT($off_t_value)
@@ -1346,6 +1352,11 @@
AC_SUBST(have_memchr)
AC_SUBST(have_int64_strfn)
AC_SUBST(int64_strfn)
+if test "$off_t_strfn" = "apr_strtoi64" && test "$have_int64_strfn" = "1"; then
+ off_t_strfn=$int64_strfn
+fi
+AC_DEFINE_UNQUOTED(APR_OFF_T_STRFN, [$off_t_strfn],
+ [Define as function used for conversion of strings to apr_off_t])
dnl ----------------------------- Checking for DSO support
echo "${nl}Checking for DSO..."
1.39 +17 -0 apr/include/apr_strings.h
Index: apr_strings.h
===================================================================
RCS file: /home/cvs/apr/include/apr_strings.h,v
retrieving revision 1.38
retrieving revision 1.39
diff -d -u -r1.38 -r1.39
--- apr_strings.h 17 May 2004 20:09:59 -0000 1.38
+++ apr_strings.h 24 May 2004 09:33:26 -0000 1.39
@@ -296,6 +296,23 @@
APR_DECLARE(char *) apr_off_t_toa(apr_pool_t *p, apr_off_t n);
/**
+ * Convert a numeric string into an apr_off_t numeric value.
+ * @param offset The value of the parsed string.
+ * @param buf The string to parse. It may contain optional whitespace,
+ * followed by an optional '+' (positive, default) or '-' (negative)
+ * character, followed by an optional '0x' prefix if base is 0 or 16,
+ * followed by numeric digits appropriate for base.
+ * @param end A pointer to the end of the valid character in buf. If
+ * not NULL, it is set to the first invalid character in buf.
+ * @param base A numeric base in the range between 2 and 36 inclusive,
+ * or 0. If base is zero, buf will be treated as base ten unless its
+ * digits are prefixed with '0x', in which case it will be treated as
+ * base 16.
+ */
+APR_DECLARE(apr_status_t) apr_strtoff(apr_off_t *offset, const char *buf,
+ char **end, int base);
+
+/**
* parse a numeric string into a 64-bit numeric value
* @param buf The string to parse. It may contain optional whitespace,
* followed by an optional '+' (positive, default) or '-' (negative)
1.23 +6 -0 apr/include/arch/netware/apr_private.h
Index: apr_private.h
===================================================================
RCS file: /home/cvs/apr/include/arch/netware/apr_private.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -d -u -r1.22 -r1.23
--- apr_private.h 13 Feb 2004 09:38:29 -0000 1.22
+++ apr_private.h 24 May 2004 09:33:26 -0000 1.23
@@ -156,6 +156,12 @@
#undef malloc
#define malloc(x) library_malloc(gLibHandle,x)
+#if APR_HAS_LARGE_FILES
+#define APR_OFF_T_STRFN strtoll
+#else
+#define APR_OFF_T_STRFN strtol
+#endif
+
/*
* Include common private declarations.
*/
1.36 +10 -0 apr/include/arch/win32/apr_private.h
Index: apr_private.h
===================================================================
RCS file: /home/cvs/apr/include/arch/win32/apr_private.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -d -u -r1.35 -r1.36
--- apr_private.h 13 Feb 2004 09:38:31 -0000 1.35
+++ apr_private.h 24 May 2004 09:33:26 -0000 1.36
@@ -143,6 +143,16 @@
#define HAVE_GETNAMEINFO 1
#endif
+#if APR_HAS_LARGE_FILES
+#if APR_HAVE_INT64_STRFN
+#define APR_OFF_T_STRFN APR_INT64_STRFN
+#else
+#define APR_OFF_T_STRFN apr_strtoi64
+#endif
+#else
+#define APR_OFF_T_STRFN strtoi
+#endif
+
/*
* Include common private declarations.
*/
1.45 +8 -0 apr/strings/apr_strings.c
Index: apr_strings.c
===================================================================
RCS file: /home/cvs/apr/strings/apr_strings.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -d -u -r1.44 -r1.45
--- apr_strings.c 4 Apr 2004 14:54:17 -0000 1.44
+++ apr_strings.c 24 May 2004 09:33:27 -0000 1.45
@@ -233,6 +233,14 @@
#define INT64_MIN (-APR_INT64_C(0x7fffffffffffffff) - APR_INT64_C(1))
#endif
+APR_DECLARE(apr_status_t) apr_strtoff(apr_off_t *offset, const char *nptr,
+ char **endptr, int base)
+{
+ errno = 0;
+ *offset = APR_OFF_T_STRFN(nptr, endptr, base);
+ return APR_FROM_OS_ERROR(errno);
+}
+
APR_DECLARE(apr_int64_t) apr_strtoi64(const char *nptr, char **endptr, int base)
{
#if (APR_HAVE_INT64_STRFN)
1.22 +15 -0 apr/test/teststr.c
Index: teststr.c
===================================================================
RCS file: /home/cvs/apr/test/teststr.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -d -u -r1.21 -r1.22
--- teststr.c 14 May 2004 14:43:22 -0000 1.21
+++ teststr.c 24 May 2004 09:33:27 -0000 1.22
@@ -246,6 +246,20 @@
}
}
+static void string_strtoff(abts_case *tc, void *data)
+{
+ apr_off_t off;
+
+ ABTS_ASSERT(tc, "strtoff fails on out-of-range integer",
+ apr_strtoff(&off, "999999999999999999999999999999",
+ NULL, 10) != APR_SUCCESS);
+
+ ABTS_ASSERT(tc, "strtoff does not fail on 1234",
+ apr_strtoff(&off, "1234", NULL, 10) == APR_SUCCESS);
+
+ ABTS_ASSERT(tc, "strtoff parsed 1234 correctly,", off == 1234);
+}
+
abts_suite *teststr(abts_suite *suite)
{
suite = ADD_SUITE(suite)
@@ -257,6 +271,7 @@
abts_run_test(suite, string_error, NULL);
abts_run_test(suite, string_long, NULL);
abts_run_test(suite, string_strtoi64, NULL);
+ abts_run_test(suite, string_strtoff, NULL);
return suite;
}