More robust pjlib file test: it shouldn't leave the file on the disk if the test fails

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@957 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
Benny Prijono 2007-02-17 00:13:11 +00:00
parent 0deef106f1
commit c77fd57bc1
1 changed files with 14 additions and 2 deletions

View File

@ -28,7 +28,7 @@
static char buffer[11] = {'H', 'e', 'l', 'l', 'o', ' ', static char buffer[11] = {'H', 'e', 'l', 'l', 'o', ' ',
'W', 'o', 'r', 'l', 'd' }; 'W', 'o', 'r', 'l', 'd' };
int file_test(void) static int file_test_internal(void)
{ {
enum { FILE_MAX_AGE = 1000 }; enum { FILE_MAX_AGE = 1000 };
pj_oshandle_t fd = 0; pj_oshandle_t fd = 0;
@ -89,9 +89,9 @@ int file_test(void)
if (stat.size != sizeof(buffer)) if (stat.size != sizeof(buffer))
return -70; return -70;
#if INCLUDE_FILE_TIME_TEST
/* Check file creation time >= start_time. */ /* Check file creation time >= start_time. */
if (!PJ_TIME_VAL_GTE(stat.ctime, start_time)) if (!PJ_TIME_VAL_GTE(stat.ctime, start_time))
#if INCLUDE_FILE_TIME_TEST
return -80; return -80;
/* Check file creation time is not much later. */ /* Check file creation time is not much later. */
PJ_TIME_VAL_SUB(stat.ctime, start_time); PJ_TIME_VAL_SUB(stat.ctime, start_time);
@ -206,6 +206,18 @@ int file_test(void)
return PJ_SUCCESS; return PJ_SUCCESS;
} }
int file_test(void)
{
int rc = file_test_internal();
/* Delete test file if exists. */
if (pj_file_exists(FILENAME))
pj_file_delete(FILENAME);
return rc;
}
#else #else
int dummy_file_test; int dummy_file_test;
#endif #endif