summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES6
-rw-r--r--file_io/os2/readwrite.c6
-rw-r--r--file_io/unix/readwrite.c9
-rw-r--r--file_io/win32/readwrite.c6
-rw-r--r--include/apr_file_io.h5
-rw-r--r--test/testfile.c11
6 files changed, 34 insertions, 9 deletions
diff --git a/CHANGES b/CHANGES
index 3bd68a8e9..d5def9ddb 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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]
diff --git a/file_io/os2/readwrite.c b/file_io/os2/readwrite.c
index 20c298742..6121ebc5a 100644
--- a/file_io/os2/readwrite.c
+++ b/file_io/os2/readwrite.c
@@ -349,6 +349,12 @@ APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
}
}
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;
}
diff --git a/file_io/unix/readwrite.c b/file_io/unix/readwrite.c
index db412ec06..c7782a35b 100644
--- a/file_io/unix/readwrite.c
+++ b/file_io/unix/readwrite.c
@@ -330,6 +330,7 @@ APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
{
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 @@ APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
/* 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;
}
diff --git a/file_io/win32/readwrite.c b/file_io/win32/readwrite.c
index c54878a52..6c023b484 100644
--- a/file_io/win32/readwrite.c
+++ b/file_io/win32/readwrite.c
@@ -458,6 +458,12 @@ APR_DECLARE(apr_status_t) apr_file_gets(char *str, int len, apr_file_t *thefile)
}
}
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;
}
diff --git a/include/apr_file_io.h b/include/apr_file_io.h
index 6a2800b5a..3a4fcbd4b 100644
--- a/include/apr_file_io.h
+++ b/include/apr_file_io.h
@@ -451,10 +451,7 @@ APR_DECLARE(apr_status_t) apr_file_ungetc(char ch, apr_file_t *thefile);
* @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);
diff --git a/test/testfile.c b/test/testfile.c
index 4dd30e725..0c350f46e 100644
--- a/test/testfile.c
+++ b/test/testfile.c
@@ -372,12 +372,15 @@ static void test_gets(CuTest *tc)
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);
}