You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by co...@apache.org on 2005/10/12 14:20:14 UTC
svn commit: r314856 - /apr/apr/trunk/file_io/win32/readwrite.c
Author: colm
Date: Wed Oct 12 05:20:05 2005
New Revision: 314856
URL: http://svn.apache.org/viewcvs?rev=314856&view=rev
Log:
Port r76283, the vformatter logic for unix/readwrite.c to handle arbitrary length strings, to the win32 code; one less test failure.
Modified:
apr/apr/trunk/file_io/win32/readwrite.c
Modified: apr/apr/trunk/file_io/win32/readwrite.c
URL: http://svn.apache.org/viewcvs/apr/apr/trunk/file_io/win32/readwrite.c?rev=314856&r1=314855&r2=314856&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/readwrite.c (original)
+++ apr/apr/trunk/file_io/win32/readwrite.c Wed Oct 12 05:20:05 2005
@@ -474,32 +474,47 @@
}
}
-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;
+}