You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@locus.apache.org on 2000/09/13 01:15:36 UTC
cvs commit: apache-2.0/src/lib/apr/test testsf.c
trawick 00/09/12 16:15:36
Modified: src CHANGES
src/lib/apr/file_io/unix readwrite.c
src/lib/apr/test testsf.c
Log:
apr_putc(), apr_puts() for Unix: handle buffered files and interrupted
writes.
apr_flush() for Unix: handle interrupted writes.
A test program was modified to drive apr_putc() and apr_puts() on
buffered files.
Revision Changes Path
1.224 +4 -0 apache-2.0/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apache-2.0/src/CHANGES,v
retrieving revision 1.223
retrieving revision 1.224
diff -u -r1.223 -r1.224
--- CHANGES 2000/09/12 17:46:38 1.223
+++ CHANGES 2000/09/12 23:15:35 1.224
@@ -1,4 +1,7 @@
Changes with Apache 2.0a7
+ *) apr_putc(), apr_puts() for Unix: handle buffered files and interrupted
+ writes. apr_flush() for Unix: handle interrupted writes.
+ [Jeff Trawick]
*) NameVirtualHost can now take "*" as an argument instead of
an IP address. This allows you to create a purely name-based
@@ -17,6 +20,7 @@
EOS, by utilizing a flag in the request_rec.
[Ryan Bloom]
+>>>>>>> 1.223
*) apr_put_os_file() now sets up the unget byte appropriately on Unix
and Win32. Previously, the first read from an apr_file_t set up via
apr_put_os_file() would return a '\0'. [Jeff Trawick]
1.59 +13 -20 apache-2.0/src/lib/apr/file_io/unix/readwrite.c
Index: readwrite.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/readwrite.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- readwrite.c 2000/08/06 06:07:04 1.58
+++ readwrite.c 2000/09/12 23:15:36 1.59
@@ -298,10 +298,9 @@
apr_status_t apr_putc(char ch, apr_file_t *thefile)
{
- if (write(thefile->filedes, &ch, 1) != 1) {
- return errno;
- }
- return APR_SUCCESS;
+ apr_ssize_t nbytes = 1;
+
+ return apr_write(thefile, &ch, &nbytes);
}
apr_status_t apr_ungetc(char ch, apr_file_t *thefile)
@@ -319,32 +318,26 @@
apr_status_t apr_puts(const char *str, apr_file_t *thefile)
{
- ssize_t rv;
- int len;
+ apr_ssize_t nbytes = strlen(str);
- len = strlen(str);
- rv = write(thefile->filedes, str, len);
- if (rv != len) {
- return errno;
- }
- return APR_SUCCESS;
+ return apr_write(thefile, str, &nbytes);
}
apr_status_t apr_flush(apr_file_t *thefile)
{
if (thefile->buffered) {
apr_int64_t written = 0;
- int rc = 0;
if (thefile->direction == 1 && thefile->bufpos) {
- written= write(thefile->filedes, thefile->buffer, thefile->bufpos);
+ do {
+ written = write(thefile->filedes, thefile->buffer, thefile->bufpos);
+ } while (written == (apr_int64_t)-1 && errno == EINTR);
+ if (written == (apr_int64_t)-1) {
+ return errno;
+ }
thefile->filePtr += written;
-
- if (rc == 0)
- thefile->bufpos = 0;
+ thefile->bufpos = 0;
}
-
- return rc;
}
/* There isn't anything to do if we aren't buffering the output
* so just return success.
@@ -385,7 +378,7 @@
APR_EXPORT(int) apr_fprintf(apr_file_t *fptr, const char *format, ...)
{
- int cc;
+ apr_status_t cc;
va_list ap;
char *buf;
int len;
1.8 +17 -7 apache-2.0/src/lib/apr/test/testsf.c
Index: testsf.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/test/testsf.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- testsf.c 2000/08/06 06:07:29 1.7
+++ testsf.c 2000/09/12 23:15:36 1.8
@@ -129,7 +129,6 @@
apr_status_t rv;
char buf[120];
int i;
- apr_ssize_t nbytes;
apr_finfo_t finfo;
printf("Creating a test file...\n");
@@ -143,13 +142,24 @@
}
buf[0] = FILE_DATA_CHAR;
+ buf[1] = '\0';
for (i = 0; i < FILE_LENGTH; i++) {
- nbytes = 1;
- rv = apr_write(f, buf, &nbytes);
- if (rv) {
- fprintf(stderr, "apr_write()->%d/%s\n",
- rv, apr_strerror(rv, buf, sizeof buf));
- exit(1);
+ /* exercise apr_putc() and apr_puts() on buffered files */
+ if ((i % 2) == 0) {
+ rv = apr_putc(buf[0], f);
+ if (rv) {
+ fprintf(stderr, "apr_putc()->%d/%s\n",
+ rv, apr_strerror(rv, buf, sizeof buf));
+ exit(1);
+ }
+ }
+ else {
+ rv = apr_puts(buf, f);
+ if (rv) {
+ fprintf(stderr, "apr_puts()->%d/%s\n",
+ rv, apr_strerror(rv, buf, sizeof buf));
+ exit(1);
+ }
}
}