apr_brigade_puts


※上記の広告は60日以上更新のないWIKIに表示されています。更新することで広告が下部へ移動します。

srclib/apr-util/include/apr_buckets.h
/**
 * This function writes a string into a bucket brigade.
 * @param bb The bucket brigade to add to
 * @param flush The flush function to use if the brigade is full
 * @param ctx The structure to pass to the flush function
 * @param str The string to add
 * @return APR_SUCCESS or error code
 */
APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *bb,
                                          apr_brigade_flush flush, void *ctx,
                                          const char *str);


srclib/apr-util/buckets/apr_brigade.c
APU_DECLARE(apr_status_t) apr_brigade_puts(apr_bucket_brigade *bb,
                                          apr_brigade_flush flush, void *ctx,
                                          const char *str)
{
   apr_size_t len = strlen(str);
   apr_bucket *bkt = APR_BRIGADE_LAST(bb);
   if (!APR_BRIGADE_EMPTY(bb) && APR_BUCKET_IS_HEAP(bkt)) {
       /* If there is enough space available in a heap bucket
        * at the end of the brigade, copy the string directly
        * into the heap bucket
        */
       apr_bucket_heap *h = bkt->data;
       apr_size_t bytes_avail = h->alloc_len - bkt->length;

       if (bytes_avail >= len) {
           char *buf = h->base + bkt->start + bkt->length;
           memcpy(buf, str, len);
           bkt->length += len;
           return APR_SUCCESS;
       }
   }

   /* If the string could not be copied into an existing heap
    * bucket, delegate the work to apr_brigade_write(), which
    * knows how to grow the brigade
    */
   return apr_brigade_write(bb, flush, ctx, str, len);
}