diff options
author | mykola.salomatin <mykola.salomatin@globallogic.com> | 2020-12-18 19:26:10 +0200 |
---|---|---|
committer | mykola.salomatin <mykola.salomatin@globallogic.com> | 2020-12-18 19:26:10 +0200 |
commit | e3e2005d248b42fabf09f77dec713a052bd0aa3b (patch) | |
tree | 5e727fefac3d24a01550afba18522e4637008495 /include/Utility | |
parent | 0dbb4ef906dad01bce313f7de51ad2253599ca97 (diff) | |
download | mts-io-sysfs-e3e2005d248b42fabf09f77dec713a052bd0aa3b.tar.gz mts-io-sysfs-e3e2005d248b42fabf09f77dec713a052bd0aa3b.tar.bz2 mts-io-sysfs-e3e2005d248b42fabf09f77dec713a052bd0aa3b.zip |
[MTX-3769] Conduit 300: New Capability - TPM
Diffstat (limited to 'include/Utility')
-rw-r--r-- | include/Utility/Utility.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/Utility/Utility.h b/include/Utility/Utility.h index bd6019e..4fb54df 100644 --- a/include/Utility/Utility.h +++ b/include/Utility/Utility.h @@ -3,6 +3,7 @@ #include "General.h" #include "Version.h" +#include <glob.h> /********************************************************************** * COPYRIGHT 2020 MULTI-TECH SYSTEMS, INC. @@ -56,4 +57,26 @@ inline mode_t fileType(std::string file) { } } +/* + findFileGlob() function has been added for generic file name search. + For example: one device has file /dev/tpm0, another one has /dev/tpm3. + And as a search parameter, you can specify the filepath with wildcard, + findFileGlob("/dev/tpm*"). The function will find the required file. +*/ + +inline mode_t findFileGlob(std::string file) { + struct stat buf = {}; + glob_t gl; + mode_t result = -1; + + if (0 == glob(file.c_str(), 0, NULL, &gl)) { + if (0 < gl.gl_pathc && 0 == stat(gl.gl_pathv[0], &buf)) { + result = buf.st_mode & S_IFMT; + } + globfree(&gl); + } + + return result; +} + #endif /* UTILITIES_H_ */ |