apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: apr/strings apr_strings.c
Date Thu, 10 May 2001 18:05:23 GMT
brane       01/05/10 11:05:22

  Modified:    strings  apr_strings.c
  Log:
  * apr_pstrndup: Check string length with memchr instead of strlen so
    that s doesn't have to be null-terminated.
  * Provide memchr implementation if !APR_HAS_MEMCHR.
  
  Revision  Changes    Path
  1.13      +18 -4     apr/strings/apr_strings.c
  
  Index: apr_strings.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_strings.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- apr_strings.c	2001/02/23 03:59:56	1.12
  +++ apr_strings.c	2001/05/10 18:05:18	1.13
  @@ -54,6 +54,7 @@
   
   #include "apr.h"
   #include "apr_strings.h"
  +#include "apr_general.h"
   #include "apr_private.h"
   #include "apr_lib.h"
   #ifdef HAVE_STDDEF_H
  @@ -83,14 +84,14 @@
   APR_DECLARE(char *) apr_pstrndup(apr_pool_t *a, const char *s, apr_size_t n)
   {
       char *res;
  -    apr_size_t len;
  +    const char *end;
   
       if (s == NULL) {
           return NULL;
       }
  -    len = strlen(s);
  -    if (len < n)
  -        n = len;
  +    end = memchr(s, '\0', n);
  +    if (end != NULL)
  +        n = end - s;
       res = apr_palloc(a, n + 1);
       memcpy(res, s, n);
       res[n] = '\0';
  @@ -147,3 +148,16 @@
       return res;
   }
   
  +#if (!APR_HAVE_MEMCHR)
  +void *memchr(const void *s, int c, size_t n)
  +{
  +    const char *cp;
  +
  +    for (cp = s; n > 0; n--, cp++) {
  +        if (*cp == c)
  +            return (char *) cp; /* Casting away the const here */
  +    }
  +
  +    return NULL;
  +}
  +#endif
  
  
  

Mime
View raw message