libpts: Use path_base|dirname()
This commit is contained in:
@@ -266,19 +266,20 @@ static void do_args(int argc, char *argv[])
|
||||
continue;
|
||||
case 'F':
|
||||
{
|
||||
char *path = strdup(optarg);
|
||||
char *dir = dirname(path);
|
||||
char *file = basename(optarg);
|
||||
char *dir = path_dirname(optarg);
|
||||
char *file = path_basename(optarg);
|
||||
|
||||
if (*dir != '.')
|
||||
{
|
||||
if (!attest->set_directory(attest, dir, op == OP_ADD))
|
||||
{
|
||||
free(path);
|
||||
free(file);
|
||||
free(dir);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
free(path);
|
||||
free(file);
|
||||
free(dir);
|
||||
if (!attest->set_file(attest, file, op == OP_ADD))
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
@@ -627,7 +627,7 @@ METHOD(pts_t, get_metadata, pts_file_meta_t*,
|
||||
metadata->destroy(metadata);
|
||||
return NULL;
|
||||
}
|
||||
entry->filename = strdup(basename(pathname));
|
||||
entry->filename = path_basename(pathname);
|
||||
metadata->add(metadata, entry);
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ METHOD(pts_database_t, check_file_measurement, status_t,
|
||||
enumerator_t *e;
|
||||
chunk_t hash;
|
||||
status_t status = NOT_FOUND;
|
||||
char *path, *dir, *file;
|
||||
char *dir, *file;
|
||||
|
||||
if (strlen(filename) < 1)
|
||||
{
|
||||
@@ -257,9 +257,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
|
||||
}
|
||||
|
||||
/* separate filename into directory and basename components */
|
||||
path = strdup(filename);
|
||||
dir = dirname(path);
|
||||
file = basename(filename);
|
||||
dir = path_dirname(filename);
|
||||
file = path_basename(filename);
|
||||
|
||||
if (*dir == '.')
|
||||
{ /* relative pathname */
|
||||
@@ -281,7 +280,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
|
||||
DB_TEXT, dir, DB_INT);
|
||||
if (!e)
|
||||
{
|
||||
free(path);
|
||||
free(file);
|
||||
free(dir);
|
||||
return FAILED;
|
||||
}
|
||||
dir_found = e->enumerate(e, &did);
|
||||
@@ -289,7 +289,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
|
||||
|
||||
if (!dir_found)
|
||||
{
|
||||
free(path);
|
||||
free(file);
|
||||
free(dir);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -301,7 +302,8 @@ METHOD(pts_database_t, check_file_measurement, status_t,
|
||||
DB_TEXT, product, DB_INT, did, DB_TEXT, file, DB_INT, algo,
|
||||
DB_BLOB);
|
||||
}
|
||||
free(path);
|
||||
free(file);
|
||||
free(dir);
|
||||
|
||||
if (!e)
|
||||
{
|
||||
|
||||
@@ -341,9 +341,10 @@ pts_file_meas_t *pts_file_meas_create_from_path(u_int16_t request_id,
|
||||
success = FALSE;
|
||||
goto end;
|
||||
}
|
||||
filename = use_rel_name ? basename(pathname) : pathname;
|
||||
filename = use_rel_name ? path_basename(pathname) : strdup(pathname);
|
||||
DBG2(DBG_PTS, " %#B for '%s'", &measurement, filename);
|
||||
add(this, filename, measurement);
|
||||
free(filename);
|
||||
}
|
||||
|
||||
end:
|
||||
|
||||
Reference in New Issue
Block a user