ATF_TC_BODY(path_to_absolute, tc) { const char *names[] = { ".", "dir", NULL }; const char **n; ATF_REQUIRE(mkdir("dir", 0755) != -1); for (n = names; *n != NULL; n++) { atf_fs_path_t p, p2; atf_fs_stat_t st1, st2; RE(atf_fs_path_init_fmt(&p, "%s", *n)); RE(atf_fs_stat_init(&st1, &p)); printf("Relative path: %s\n", atf_fs_path_cstring(&p)); RE(atf_fs_path_to_absolute(&p, &p2)); printf("Absolute path: %s\n", atf_fs_path_cstring(&p2)); ATF_REQUIRE(atf_fs_path_is_absolute(&p2)); RE(atf_fs_stat_init(&st2, &p2)); ATF_REQUIRE_EQ(atf_fs_stat_get_device(&st1), atf_fs_stat_get_device(&st2)); ATF_REQUIRE_EQ(atf_fs_stat_get_inode(&st1), atf_fs_stat_get_inode(&st2)); atf_fs_stat_fini(&st2); atf_fs_stat_fini(&st1); atf_fs_path_fini(&p2); atf_fs_path_fini(&p); printf("\n"); } }
static atf_error_t handle_srcdir(struct params *p) { atf_error_t err; atf_dynstr_t leafname; atf_fs_path_t exe, srcdir; bool b; err = atf_fs_path_copy(&srcdir, &p->m_srcdir); if (atf_is_error(err)) goto out; if (!atf_fs_path_is_absolute(&srcdir)) { atf_fs_path_t srcdirabs; err = atf_fs_path_to_absolute(&srcdir, &srcdirabs); if (atf_is_error(err)) goto out_srcdir; atf_fs_path_fini(&srcdir); srcdir = srcdirabs; } err = atf_fs_path_leaf_name(&srcdir, &leafname); if (atf_is_error(err)) goto out_srcdir; else { const bool libs = atf_equal_dynstr_cstring(&leafname, ".libs"); atf_dynstr_fini(&leafname); if (libs) { err = srcdir_strip_libtool(&srcdir); if (atf_is_error(err)) goto out; } } err = atf_fs_path_copy(&exe, &srcdir); if (atf_is_error(err)) goto out_srcdir; err = atf_fs_path_append_fmt(&exe, "%s", progname); if (atf_is_error(err)) goto out_exe; err = atf_fs_exists(&exe, &b); if (!atf_is_error(err)) { if (b) { err = atf_map_insert(&p->m_config, "srcdir", strdup(atf_fs_path_cstring(&srcdir)), true); } else { err = user_error("Cannot find the test program in the source " "directory `%s'", atf_fs_path_cstring(&srcdir)); } } out_exe: atf_fs_path_fini(&exe); out_srcdir: atf_fs_path_fini(&srcdir); out: return err; }