        -:    0:Source:/home/dsg/apr_trunk/file_io/unix/printf.c
        -:    0:Graph:./file_io/unix/.libs/printf.gcno
        -:    0:Data:./file_io/unix/.libs/printf.gcda
        -:    0:Runs:346
        -:    1:/* Licensed to the Apache Software Foundation (ASF) under one or more
        -:    2: * contributor license agreements.  See the NOTICE file distributed with
        -:    3: * this work for additional information regarding copyright ownership.
        -:    4: * The ASF licenses this file to You under the Apache License, Version 2.0
        -:    5: * (the "License"); you may not use this file except in compliance with
        -:    6: * the License.  You may obtain a copy of the License at
        -:    7: *
        -:    8: *     http://www.apache.org/licenses/LICENSE-2.0
        -:    9: *
        -:   10: * Unless required by applicable law or agreed to in writing, software
        -:   11: * distributed under the License is distributed on an "AS IS" BASIS,
        -:   12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        -:   13: * See the License for the specific language governing permissions and
        -:   14: * limitations under the License.
        -:   15: */
        -:   16:
        -:   17:#include "apr_file_io.h"
        -:   18:#include "apr_strings.h"
        -:   19:#include "apr_lib.h"
        -:   20:
        -:   21:#if APR_HAVE_STDLIB_H
        -:   22:#include <stdlib.h>
        -:   23:#endif
        -:   24:
        -:   25:struct apr_file_printf_data {
        -:   26:    apr_vformatter_buff_t vbuff;
        -:   27:    apr_file_t *fptr;
        -:   28:    char *buf;
        -:   29:};
        -:   30:
       22:   31:static int file_printf_flush(apr_vformatter_buff_t *buff)
        -:   32:{
       22:   33:    struct apr_file_printf_data *data = (struct apr_file_printf_data *)buff;
        -:   34:
       22:   35:    if (apr_file_write_full(data->fptr, data->buf,
       22:   36:                            data->vbuff.curpos - data->buf, NULL)) {
    #####:   37:        return -1;
        -:   38:    }
        -:   39:
       22:   40:    data->vbuff.curpos = data->buf;
       22:   41:    return 0;
        -:   42:}
        -:   43:
       20:   44:APR_DECLARE_NONSTD(int) apr_file_printf(apr_file_t *fptr,
        -:   45:                                        const char *format, ...)
        -:   46:{
        -:   47:    struct apr_file_printf_data data;
        -:   48:    va_list ap;
        -:   49:    int count;
        -:   50:
        -:   51:    /* don't really need a HUGE_STRING_LEN anymore */
       20:   52:    data.buf = malloc(HUGE_STRING_LEN);
       20:   53:    if (data.buf == NULL) {
    #####:   54:        return -1;
        -:   55:    }
       20:   56:    data.vbuff.curpos = data.buf;
       20:   57:    data.vbuff.endpos = data.buf + HUGE_STRING_LEN;
       20:   58:    data.fptr = fptr;
       20:   59:    va_start(ap, format);
       20:   60:    count = apr_vformatter(file_printf_flush,
        -:   61:                           (apr_vformatter_buff_t *)&data, format, ap);
        -:   62:    /* apr_vformatter does not call flush for the last bits */
       20:   63:    if (count >= 0) file_printf_flush((apr_vformatter_buff_t *)&data);
        -:   64:
       20:   65:    va_end(ap);
        -:   66:
       20:   67:    free(data.buf);
        -:   68:
       20:   69:    return count;
        -:   70:}
