Test was erroneously failing when temp directory had a symbolic link in it (as it does on OSX).

This commit is contained in:
R. Bernstein
2010-01-17 04:28:41 -05:00
parent d9482d1ba2
commit 36ba4dbbed

View File

@@ -85,7 +85,9 @@ main(int argc, const char *argv[])
{
char *psz_tmp_subdir;
char *psz_orig_file;
char orig_file[PATH_MAX+1];
char tmp_dir[PATH_MAX+1];
char tmp_subdir[PATH_MAX+1];
char psz_file_check[PATH_MAX+1];
char *psz_last_slash;
unsigned int i_last_slash;
@@ -95,13 +97,14 @@ main(int argc, const char *argv[])
if (NULL == psz_tmp_subdir) {
exit(77);
}
psz_last_slash = strrchr(psz_tmp_subdir, MY_DIR_SEPARATOR);
if (NULL == psz_tmp_subdir) {
printf("extract parent directory from temporary directory name\n");
exit(77);
}
i_last_slash = psz_last_slash - psz_tmp_subdir + 1;
memcpy(tmp_dir, psz_tmp_subdir, i_last_slash);
cdio_realpath(psz_tmp_subdir, tmp_subdir);
psz_last_slash = strrchr(tmp_subdir, MY_DIR_SEPARATOR);
i_last_slash = psz_last_slash - tmp_subdir + 1;
memcpy(tmp_dir, tmp_subdir, i_last_slash);
tmp_dir[i_last_slash] = '\0';
printf("Temp directory is %s\n", tmp_dir);
@@ -113,8 +116,11 @@ main(int argc, const char *argv[])
if (NULL != psz_orig_file) {
FILE *fp = fopen(psz_orig_file, "w");
int rc;
char symlink_file[PATH_MAX+1];
fprintf(fp, "testing\n");
fclose(fp);
cdio_realpath(psz_orig_file, orig_file);
psz_symlink_file = get_temporary_name(NULL, "symlink file");
rc = check_rc(symlink(psz_orig_file, psz_symlink_file),
"symlink", psz_symlink_file);
@@ -122,22 +128,23 @@ main(int argc, const char *argv[])
/* Just when you thought we'd forgotten, here is our first
test! */
cdio_realpath(psz_symlink_file, psz_file_check);
if (0 != strncmp(psz_file_check, psz_orig_file, PATH_MAX)) {
if (0 != strncmp(psz_file_check, orig_file, PATH_MAX)) {
fprintf(stderr, "simple cdio_realpath failed: %s vs %s\n",
psz_file_check, psz_orig_file);
psz_file_check, orig_file);
exit(1);
}
check_rc(unlink(psz_symlink_file), "unlink", psz_symlink_file);
}
/* Make sure we handle a cyclic symbolic name, e.g. xx -> xx */
cdio_realpath(psz_symlink_file, symlink_file);
rc = check_rc(symlink(psz_symlink_file, psz_symlink_file),
"symlink", psz_symlink_file);
if (0 == rc) {
cdio_realpath(psz_symlink_file, psz_file_check);
if (0 != strncmp(psz_file_check, psz_symlink_file, PATH_MAX)) {
if (0 != strncmp(psz_file_check, symlink_file, PATH_MAX)) {
fprintf(stderr, "direct cdio_realpath cycle test failed. %s vs %s\n",
psz_file_check, psz_orig_file);
psz_file_check, symlink_file);
exit(2);
}
check_rc(unlink(psz_symlink_file), "unlink", psz_symlink_file);