You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by be...@apache.org on 2001/02/11 17:18:09 UTC

cvs commit: apr/strings apr_strings.c

ben         01/02/11 08:18:09

  Modified:    include  apr_strings.h
               strings  apr_strings.c
  Log:
  Add memdup function.
  
  Revision  Changes    Path
  1.11      +12 -2     apr/include/apr_strings.h
  
  Index: apr_strings.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_strings.h,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- apr_strings.h	2001/02/11 00:12:11	1.10
  +++ apr_strings.h	2001/02/11 16:18:08	1.11
  @@ -120,7 +120,7 @@
   /**
    * duplicate a string into memory allocated out of a pool
    * @param p The pool to allocate out of
  - * @param s The string to allocate
  + * @param s The string to duplicate
    * @return The new string
    * @deffunc char *apr_pstrdup(apr_pool_t *p, const char *s)
    */
  @@ -130,12 +130,22 @@
    * 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
  - * @param s The string to allocate
  + * @param s The string to duplicate
    * @param n The number of characters to duplicate
    * @return The new string
    * @deffunc char *apr_pstrndup(apr_pool_t *p, const char *s, apr_size_t n)
    */
   APR_DECLARE(char *) apr_pstrndup(apr_pool_t *p, const char *s, apr_size_t n);
  +
  +/**
  + * Duplicate a block of memory.
  + *
  + * @param p The pool to allocate from
  + * @param m The memory to duplicate
  + * @param n The number of bytes to duplicate
  + * @return The new block of memory
  + */
  +APR_DECLARE(void *) apr_memdup(apr_pool_t *p, const void *m, apr_size_t n);
   
   /**
    * Concatenate multiple strings, allocating memory out a pool
  
  
  
  1.8       +11 -0     apr/strings/apr_strings.c
  
  Index: apr_strings.c
  ===================================================================
  RCS file: /home/cvs/apr/strings/apr_strings.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- apr_strings.c	2001/01/28 08:18:32	1.7
  +++ apr_strings.c	2001/02/11 16:18:09	1.8
  @@ -93,6 +93,17 @@
       return res;
   }
   
  +APR_DECLARE(void *) apr_memdup(apr_pool_t *a, const void *m, apr_size_t n)
  +{
  +    void *res;
  +
  +    if(m == NULL)
  +	return NULL;
  +    res = apr_palloc(a, n);
  +    memcpy(res, m, n);
  +    return res;
  +}
  +
   APR_DECLARE_NONSTD(char *) apr_pstrcat(apr_pool_t *a, ...)
   {
       char *cp, *argp, *res;
  
  
  

Re: cvs commit: apr/strings apr_strings.c

Posted by Greg Stein <gs...@lyra.org>.
On Sun, Feb 11, 2001 at 09:40:04AM -0800, Cliff Woolley wrote:
> 
> --- ben@apache.org wrote:
> >   +APR_DECLARE(void *) apr_memdup(apr_pool_t *a, const void *m, apr_size_t n)
> >   +{
> >   +    void *res;
> >   +
> >   +    if(m == NULL)
> >   +	return NULL;
> >   +    res = apr_palloc(a, n);
> >   +    memcpy(res, m, n);
> >   +    return res;
> >   +}
> >   +
> 
> Nice.  Minor question, though: why is this called "apr_memdup" instead of "apr_pmemdup"? 
> I thought all of the "like the standard function, but into a pool instead of the heap"
> functions were prefixed with a 'p'.

You're right. I've just changed it.

> Also, should it check for failure of apr_palloc, or is that being too anal?

We never check for failure to alloc. The program terminates instead.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: cvs commit: apr/strings apr_strings.c

Posted by Cliff Woolley <cl...@yahoo.com>.
--- ben@apache.org wrote:
>   +APR_DECLARE(void *) apr_memdup(apr_pool_t *a, const void *m, apr_size_t n)
>   +{
>   +    void *res;
>   +
>   +    if(m == NULL)
>   +	return NULL;
>   +    res = apr_palloc(a, n);
>   +    memcpy(res, m, n);
>   +    return res;
>   +}
>   +

Nice.  Minor question, though: why is this called "apr_memdup" instead of "apr_pmemdup"? 
I thought all of the "like the standard function, but into a pool instead of the heap"
functions were prefixed with a 'p'.

Also, should it check for failure of apr_palloc, or is that being too anal?

--Cliff


__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/