summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Wood <thomas.wood@intel.com>2015-09-23 16:52:24 +0100
committerThomas Wood <thomas.wood@intel.com>2015-09-24 14:24:18 +0100
commit6c89204da77a721c9f6c2c77908ca9502a246df8 (patch)
treeb189c79537dc5376639c94ae5cdade48c314963d /lib
parent1ea96af776a853303240fe6ec414aeed3316c24b (diff)
lib: add igt_debugfs_search
Add igt_debugfs_search to search each line in a debugfs file for a specified substring. Signed-off-by: Thomas Wood <thomas.wood@intel.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/igt_debugfs.c31
-rw-r--r--lib/igt_debugfs.h1
2 files changed, 32 insertions, 0 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c
index 5c132795..c603369e 100644
--- a/lib/igt_debugfs.c
+++ b/lib/igt_debugfs.c
@@ -212,6 +212,37 @@ void __igt_debugfs_read(const char *filename, char *buf, int buf_size)
igt_assert(fclose(file) == 0);
}
+/**
+ * igt_debugfs_search:
+ * @filename: file name
+ * @substring: string to search for in @filename
+ *
+ * Searches each line in @filename for the substring specified in @substring.
+ *
+ * Returns: True if the @substring is found to occur in @filename
+ */
+bool igt_debugfs_search(const char *filename, const char *substring)
+{
+ FILE *file;
+ size_t n = 0;
+ char *line = NULL;
+ bool matched = false;
+
+ file = igt_debugfs_fopen(filename, O_RDONLY);
+ igt_assert(file);
+
+ while (getline(&line, &n, file) >= 0) {
+ matched = (strstr(line, substring) != NULL);
+ if (matched)
+ break;
+ }
+
+ free(line);
+ fclose(file);
+
+ return matched;
+}
+
/*
* Pipe CRC
*/
diff --git a/lib/igt_debugfs.h b/lib/igt_debugfs.h
index 78cb5e1c..ee9ff40c 100644
--- a/lib/igt_debugfs.h
+++ b/lib/igt_debugfs.h
@@ -35,6 +35,7 @@ int igt_debugfs_open(const char *filename, int mode);
FILE *igt_debugfs_fopen(const char *filename,
const char *mode);
void __igt_debugfs_read(const char *filename, char *buf, int buf_size);
+bool igt_debugfs_search(const char *filename, const char *substring);
/**
* igt_debugfs_read: