trawick 2003/04/30 20:16:30
Modified: . CHANGES
file_io/os2 readwrite.c
file_io/unix readwrite.c
file_io/win32 readwrite.c
include apr_file_io.h
test testfile.c
Log:
apr_file_gets(): Return APR_SUCCESS if any characters are
returned. Any I/O errors or EOF will be reported on the
next call. Callers that are coded to expect returned
data + APR_EOF when there is no final newline are affected
by this change.
Revision Changes Path
1.405 +6 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.404
retrieving revision 1.405
diff -u -r1.404 -r1.405
--- CHANGES 21 Apr 2003 22:36:55 -0000 1.404
+++ CHANGES 1 May 2003 03:16:29 -0000 1.405
@@ -1,5 +1,11 @@
Changes with APR 0.9.4
+ *) apr_file_gets(): Return APR_SUCCESS if any characters are
+ returned. Any I/O errors or EOF will be reported on the
+ next call. Callers that are coded to expect returned
+ data + APR_EOF when there is no final newline are affected
+ by this change. [Jeff Trawick]
+
*) apr_proc_create() on Unix: Make the APR_SHELLCMD mode work
when there is more than one program argument passed in.
[Jeff Trawick]
1.58 +6 -0 apr/file_io/os2/readwrite.c
Index: readwrite.c
===================================================================
RCS file: /home/cvs/apr/file_io/os2/readwrite.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- readwrite.c 4 Mar 2003 22:19:38 -0000 1.57
+++ readwrite.c 1 May 2003 03:16:29 -0000 1.58
@@ -349,6 +349,12 @@
}
}
str[i] = 0;
+ if (i > 0) {
+ /* we stored chars; don't report EOF or any other errors;
+ * the app will find out about that on the next call
+ */
+ return APR_SUCCESS;
+ }
return rv;
}
1.85 +8 -1 apr/file_io/unix/readwrite.c
Index: readwrite.c
===================================================================
RCS file: /home/cvs/apr/file_io/unix/readwrite.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -r1.84 -r1.85
--- readwrite.c 7 Jan 2003 00:52:53 -0000 1.84
+++ readwrite.c 1 May 2003 03:16:29 -0000 1.85
@@ -330,6 +330,7 @@
{
apr_status_t rv = APR_SUCCESS; /* get rid of gcc warning */
apr_size_t nbytes;
+ const char *str_start = str;
char *final = str + len - 1;
if (len <= 1) {
@@ -353,7 +354,13 @@
/* We must store a terminating '\0' if we've stored any chars. We can
* get away with storing it if we hit an error first.
*/
- *str = '\0';
+ *str = '\0';
+ if (str > str_start) {
+ /* we stored chars; don't report EOF or any other errors;
+ * the app will find out about that on the next call
+ */
+ return APR_SUCCESS;
+ }
return rv;
}
1.79 +6 -0 apr/file_io/win32/readwrite.c
Index: readwrite.c
===================================================================
RCS file: /home/cvs/apr/file_io/win32/readwrite.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- readwrite.c 4 Mar 2003 22:19:38 -0000 1.78
+++ readwrite.c 1 May 2003 03:16:30 -0000 1.79
@@ -458,6 +458,12 @@
}
}
str[i] = 0;
+ if (i > 0) {
+ /* we stored chars; don't report EOF or any other errors;
+ * the app will find out about that on the next call
+ */
+ return APR_SUCCESS;
+ }
return rv;
}
1.139 +1 -4 apr/include/apr_file_io.h
Index: apr_file_io.h
===================================================================
RCS file: /home/cvs/apr/include/apr_file_io.h,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -r1.138 -r1.139
--- apr_file_io.h 3 Apr 2003 23:20:05 -0000 1.138
+++ apr_file_io.h 1 May 2003 03:16:30 -0000 1.139
@@ -451,10 +451,7 @@
* @param str The buffer to store the string in.
* @param len The length of the string
* @param thefile The file descriptor to read from
- * @remark APR_EOF will be returned if some characters are read but the end
- * of file is reached before a newline is read.
- * @remark The buffer will be '\0'-terminated if any characters are stored,
- * even if something other than APR_SUCCESS is returned.
+ * @remark The buffer will be '\0'-terminated if any characters are stored.
*/
APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t
*thefile);
1.69 +7 -4 apr/test/testfile.c
Index: testfile.c
===================================================================
RCS file: /home/cvs/apr/test/testfile.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -r1.68 -r1.69
--- testfile.c 29 Apr 2003 20:32:06 -0000 1.68
+++ testfile.c 1 May 2003 03:16:30 -0000 1.69
@@ -372,12 +372,15 @@
CuAssertIntEquals(tc, APR_SUCCESS, rv);
rv = apr_file_gets(str, 256, f);
- /* Only one line in the test file, so we should get the EOF on the first
- * call to gets.
+ /* Only one line in the test file, so APR will encounter EOF on the first
+ * call to gets, but we should get APR_SUCCESS on this call and
+ * APR_EOF on the next.
*/
- CuAssertIntEquals(tc, APR_EOF, rv);
+ CuAssertIntEquals(tc, APR_SUCCESS, rv);
CuAssertStrEquals(tc, TESTSTR, str);
-
+ rv = apr_file_gets(str, 256, f);
+ CuAssertIntEquals(tc, APR_EOF, rv);
+ CuAssertStrEquals(tc, "", str);
apr_file_close(f);
}