apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/strings apr_strings.c
Date Sun, 02 Dec 2001 09:20:23 GMT
wrowe       01/12/02 01:20:23

  Modified:    include  apr_strings.h
               strings  apr_strings.c
  Log:
    This patch adds a function apr_strmemdup(), which works like
    apr_pstrndup() except that it's optimized for the case where
    the caller can guarantee that the length of the supplied string
    is >= 'n'
  
  Submitted by: Brian Pane <bpane@pacbell.net>
  
  Revision  Changes    Path
  1.23      +14 -0     apr/include/apr_strings.h
  
  Index: apr_strings.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_strings.h,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- apr_strings.h	2001/08/24 17:55:45	1.22
  +++ apr_strings.h	2001/12/02 09:20:23	1.23
  @@ -128,6 +128,20 @@
   APR_DECLARE(char *) apr_pstrdup(apr_pool_t *p, const char *s);
   
   /**
  + * Create a null-terminated string by making a copy of a sequence
  + * of characters and appending a null byte
  + * @param p The pool to allocate out of
  + * @param s The block of characters to duplicate
  + * @param n The number of characters to duplicate
  + * @return The new string
  + * @remark This is a faster alternative to apr_pstrndup, for use
  + *         when you know that the string being duplicated really
  + *         has 'n' or more characters.  If the string might contain
  + *         fewer characters, use apr_pstrndup.
  + */
  +APR_DECLARE(char *) apr_pstrmemdup(apr_pool_t *p, const char *s, apr_size_t n);
  +
  +/**
    * duplicate the first n characters of a string into memory allocated 
    * out of a pool; the new string will be '\0'-terminated
    * @param p The pool to allocate out of
  
  
  
  1.23      +13 -0     apr/strings/apr_strings.c
  
  Index: apr_strings.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_strings.c,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- apr_strings.c	2001/09/28 04:11:20	1.22
  +++ apr_strings.c	2001/12/02 09:20:23	1.23
  @@ -99,6 +99,19 @@
       return res;
   }
   
  +APR_DECLARE(char *) apr_pstrmemdup(apr_pool_t *a, const char *s, apr_size_t n)
  +{
  +    char *res;
  +
  +    if (s == NULL) {
  +        return NULL;
  +    }
  +    res = apr_palloc(a, n + 1);
  +    memcpy(res, s, n);
  +    res[n] = '\0';
  +    return res;
  +}
  +
   APR_DECLARE(void *) apr_pmemdup(apr_pool_t *a, const void *m, apr_size_t n)
   {
       void *res;
  
  
  

Mime
View raw message