return buf;
}
+/**
+ * Get the directory separator to append to a path
+ */
+static const char* get_separator(const char *path)
+{
+ if (streq(path, DIRECTORY_SEPARATOR))
+ { /* root directory on Unix file system, no separator */
+ return "";
+ }
+ else
+ { /* non-root or Windows path, use system specific separator */
+ return DIRECTORY_SEPARATOR;
+ }
+}
+
METHOD(attest_db_t, set_component, bool,
private_attest_db_t *this, char *comp, bool create)
{
return FALSE;
}
- /* remove trailing '/' character if not root directory */
+ /* remove trailing '/' or '\' character if not root directory */
len = strlen(dir);
- if (len > 1 && dir[len-1] == '/')
+ if (len > 1 && dir[len-1] == DIRECTORY_SEPARATOR[0])
{
dir[len-1] = '\0';
}
private_attest_db_t *this, char *file, bool create)
{
int fid;
- char *sep;
enumerator_t *e;
if (this->file)
{
return TRUE;
}
- sep = streq(this->dir, "/") ? "" : "/";
e = this->db->query(this->db, "SELECT id FROM files "
"WHERE dir = ? AND name = ?",
DB_INT, this->did, DB_TEXT, file, DB_INT);
if (!create)
{
- printf("file '%s%s%s' not found in database\n", this->dir, sep, file);
+ printf("file '%s%s%s' not found in database\n",
+ this->dir, get_separator(this->dir), file);
return FALSE;
}
{
this->fid = fid;
}
- printf("file '%s%s%s' %sinserted into database\n", this->dir, sep, file,
- this->fid ? "" : "could not be ");
+ printf("file '%s%s%s' %sinserted into database\n", this->dir,
+ get_separator(this->dir), file, this->fid ? "" : "could not be ");
return this->fid > 0;
}
printf("%d %N value%s found for file '%s%s%s'\n", count,
pts_meas_algorithm_names, this->algo,
(count == 1) ? "" : "s", this->dir,
- streq(this->dir, "/") ? "" : "/", this->file);
+ get_separator(this->dir), this->file);
}
}
else if (this->file)
*/
static bool add_hash(private_attest_db_t *this)
{
- char *pathname, *filename, *sep, *label;
+ char *pathname, *filename, *label;
+ const char *sep;
pts_file_meas_t *measurements;
chunk_t measurement;
hasher_t *hasher = NULL;
{
this->meas_dir = strdup(this->dir);
}
- sep = streq(this->meas_dir, "/") ? "" : "/";
+ sep = get_separator(this->meas_dir);
if (this->fid)
{
DB_UINT, this->algo, DB_UINT, this->pid,
DB_UINT, this->fid) > 0;
- printf("%4d: %s%s%s\n", this->fid, this->dir,
- streq(this->dir, "/") ? "" : "/", this->file);
+ printf("%4d: %s%s%s\n", this->fid, this->dir, get_separator(this->dir),
+ this->file);
printf("%N value for product '%s' %sdeleted from database\n",
pts_meas_algorithm_names, this->algo, this->product,
success ? "" : "could not be ");
DB_UINT, this->fid) > 0;
printf("file '%s%s%s' %sdeleted from database\n", this->dir,
- streq(this->dir, "/") ? "" : "/", this->file,
+ get_separator(this->dir), this->file,
success ? "" : "could not be ");
return success;
}