diff options
author | Joe Orton <jorton@apache.org> | 2019-06-25 14:21:56 +0000 |
---|---|---|
committer | Joe Orton <jorton@apache.org> | 2019-06-25 14:21:56 +0000 |
commit | 864ce9d1b1784c31386a7a5ff568e78f56a0a75f (patch) | |
tree | 75ac7cea477231ea31a07f15b37a47a6cd5e010b /test | |
parent | e0f71494adc916c15fca5038ac1e45b77113168c (diff) | |
download | apr-864ce9d1b1784c31386a7a5ff568e78f56a0a75f.tar.gz |
Add apr_dir_pread(), a variant of apr_dir_read() which allows callers
to read a directory with constant memory consumption:
* include/apr_file_info.h: Add warning on memory consumption for
apr_dir_read; declare apr_dir_pread.
* file_io/unix/dir.c (apr_dir_pread): Rename from apr_dir_read and
take pool argument. (apr_dir_read): Reimplement using it.
* file_io/win32/dir.c, file_io/os2/dir.c: Likewise, but untested.
* test/testdir.c (test_pread) [APR_POOL_DEBUG]: Add test case.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1862071 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r-- | test/testdir.c | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/test/testdir.c b/test/testdir.c index 21876be5d..bb3399cbf 100644 --- a/test/testdir.c +++ b/test/testdir.c @@ -430,6 +430,36 @@ static void test_readmore_info(abts_case* tc, void* data) ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); } +#if APR_POOL_DEBUG +static void test_pread(abts_case *tc, void *data) +{ + apr_dir_t *dir; + apr_finfo_t finfo; + apr_size_t before, after; + apr_pool_t *subp; + + APR_ASSERT_SUCCESS(tc, "apr_dir_open failed", apr_dir_open(&dir, "data", p)); + + apr_pool_create(&subp, p); + + before = apr_pool_num_bytes(p, 0); + + APR_ASSERT_SUCCESS(tc, "apr_dir_read failed", + apr_dir_pread(&finfo, APR_FINFO_DIRENT, dir, subp)); + + after = apr_pool_num_bytes(p, 0); + + ABTS_PTR_EQUAL(tc, finfo.pool, subp); + + apr_pool_destroy(subp); + + APR_ASSERT_SUCCESS(tc, "apr_dir_close failed", apr_dir_close(dir)); + + ABTS_INT_EQUAL(tc, before, after); + +} +#endif + abts_suite *testdir(abts_suite *suite) { suite = ADD_SUITE(suite) @@ -451,7 +481,10 @@ abts_suite *testdir(abts_suite *suite) abts_run_test(suite, test_closedir, NULL); abts_run_test(suite, test_uncleared_errno, NULL); abts_run_test(suite, test_readmore_info, NULL); - +#if APR_POOL_DEBUG + abts_run_test(suite, test_pread, NULL); +#endif + return suite; } |