summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrooneg <rooneg@13f79535-47bb-0310-9956-ffa450edef68>2006-01-26 21:44:59 +0000
committerrooneg <rooneg@13f79535-47bb-0310-9956-ffa450edef68>2006-01-26 21:44:59 +0000
commit2f41c8e0925b1826c4a6b450823118cd08818dc8 (patch)
tree892a833e833bdeebc8e363146e51224746d54ad1
parentdd70cf1ab46a0311247c5617c4937bd1c63cf762 (diff)
downloadlibapr-2f41c8e0925b1826c4a6b450823118cd08818dc8.tar.gz
Merge r314856 to 0.9.x.
Original log message: Port r76283, the vformatter logic for unix/readwrite.c to handle arbitrary length strings, to the win32 code; one less test failure. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/0.9.x@372616 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--file_io/win32/readwrite.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/file_io/win32/readwrite.c b/file_io/win32/readwrite.c
index ea7dd4534..c3352defa 100644
--- a/file_io/win32/readwrite.c
+++ b/file_io/win32/readwrite.c
@@ -451,32 +451,47 @@ APR_DECLARE(apr_status_t) apr_file_flush(apr_file_t *thefile)
}
}
-static int printf_flush(apr_vformatter_buff_t *vbuff)
+struct apr_file_printf_data {
+ apr_vformatter_buff_t vbuff;
+ apr_file_t *fptr;
+ char *buf;
+};
+
+static int file_printf_flush(apr_vformatter_buff_t *buff)
{
- /* I would love to print this stuff out to the file, but I will
- * get that working later. :) For now, just return.
- */
- return -1;
+ struct apr_file_printf_data *data = (struct apr_file_printf_data *)buff;
+
+ if (apr_file_write_full(data->fptr, data->buf,
+ data->vbuff.curpos - data->buf, NULL)) {
+ return -1;
+ }
+
+ data->vbuff.curpos = data->buf;
+ return 0;
}
APR_DECLARE_NONSTD(int) apr_file_printf(apr_file_t *fptr,
const char *format, ...)
{
- int cc;
+ struct apr_file_printf_data data;
va_list ap;
- char *buf;
- int len;
+ int count;
- buf = malloc(HUGE_STRING_LEN);
- if (buf == NULL) {
+ data.buf = malloc(HUGE_STRING_LEN);
+ if (data.buf == NULL) {
return 0;
}
+ data.vbuff.curpos = data.buf;
+ data.vbuff.endpos = data.buf + HUGE_STRING_LEN;
+ data.fptr = fptr;
va_start(ap, format);
- len = apr_vsnprintf(buf, HUGE_STRING_LEN, format, ap);
- cc = apr_file_puts(buf, fptr);
- va_end(ap);
- free(buf);
- return (cc == APR_SUCCESS) ? len : -1;
-}
+ count = apr_vformatter(file_printf_flush,
+ (apr_vformatter_buff_t *)&data, format, ap);
+ /* apr_vformatter does not call flush for the last bits */
+ if (count >= 0) file_printf_flush((apr_vformatter_buff_t *)&data);
+ va_end(ap);
+ free(data.buf);
+ return count;
+}