diff options
author | Dan Fandrich <dan@coneharvesters.com> | 2010-04-06 22:51:05 -0700 |
---|---|---|
committer | Dan Fandrich <dan@coneharvesters.com> | 2010-04-15 10:51:03 -0700 |
commit | f38510f4b59edad8ae6e8f1535ea3ffcd31fa5d4 (patch) | |
tree | 54c1a00f41cd486229d7d51c24aaae462b71a4f1 /tests/libtest/lib525.c | |
parent | 689b6929c311f85aad8ca46add161384bbe0a654 (diff) | |
download | curl-f38510f4b59edad8ae6e8f1535ea3ffcd31fa5d4.tar.gz |
Eliminated an unlikely race condition in some tests.
Based on a patch from the FreeBSD ports by Peter Pentchev.
Diffstat (limited to 'tests/libtest/lib525.c')
-rw-r--r-- | tests/libtest/lib525.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/tests/libtest/lib525.c b/tests/libtest/lib525.c index d2542577b..ade637012 100644 --- a/tests/libtest/lib525.c +++ b/tests/libtest/lib525.c @@ -40,14 +40,6 @@ int test(char *URL) return -1; } - /* get the file size of the local file */ - hd = open(libtest_arg2, O_RDONLY) ; - fstat(hd, &file_info); - close(hd) ; - - /* get a FILE * of the same file, could also be made with - fdopen() from the previous descriptor, but hey this is just - an example! */ hd_src = fopen(libtest_arg2, "rb"); if(NULL == hd_src) { error = ERRNO; @@ -57,6 +49,18 @@ int test(char *URL) return TEST_ERR_MAJOR_BAD; } + /* get the file size of the local file */ + hd = fstat(fileno(hd_src), &file_info); + if(hd == -1) { + /* can't open file, bail out */ + error = ERRNO; + fprintf(stderr, "fstat() failed with error: %d %s\n", + error, strerror(error)); + fprintf(stderr, "ERROR: cannot open file %s\n", libtest_arg2); + fclose(hd_src); + return -1; + } + if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); fclose(hd_src); |