/src/httpd/srclib/apr/file_io/unix/printf.c
Line | Count | Source (jump to first uncovered line) |
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 | | |
31 | | static int file_printf_flush(apr_vformatter_buff_t *buff) |
32 | 0 | { |
33 | 0 | struct apr_file_printf_data *data = (struct apr_file_printf_data *)buff; |
34 | |
|
35 | 0 | if (apr_file_write_full(data->fptr, data->buf, |
36 | 0 | data->vbuff.curpos - data->buf, NULL)) { |
37 | 0 | return -1; |
38 | 0 | } |
39 | | |
40 | 0 | data->vbuff.curpos = data->buf; |
41 | 0 | return 0; |
42 | 0 | } |
43 | | |
44 | | APR_DECLARE_NONSTD(int) apr_file_printf(apr_file_t *fptr, |
45 | | const char *format, ...) |
46 | 0 | { |
47 | 0 | struct apr_file_printf_data data; |
48 | 0 | va_list ap; |
49 | 0 | int count; |
50 | | |
51 | | /* don't really need a HUGE_STRING_LEN anymore */ |
52 | 0 | data.buf = malloc(HUGE_STRING_LEN); |
53 | 0 | if (data.buf == NULL) { |
54 | 0 | return -1; |
55 | 0 | } |
56 | 0 | data.vbuff.curpos = data.buf; |
57 | 0 | data.vbuff.endpos = data.buf + HUGE_STRING_LEN; |
58 | 0 | data.fptr = fptr; |
59 | 0 | va_start(ap, format); |
60 | 0 | count = apr_vformatter(file_printf_flush, |
61 | 0 | (apr_vformatter_buff_t *)&data, format, ap); |
62 | | /* apr_vformatter does not call flush for the last bits */ |
63 | 0 | if (count >= 0) file_printf_flush((apr_vformatter_buff_t *)&data); |
64 | |
|
65 | 0 | va_end(ap); |
66 | |
|
67 | 0 | free(data.buf); |
68 | |
|
69 | 0 | return count; |
70 | 0 | } |