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>
This commit is contained in:
Thomas Wood
2015-09-23 16:52:24 +01:00
parent 1ea96af776
commit 6c89204da7
4 changed files with 35 additions and 45 deletions
+31
View File
@@ -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
*/
+1
View File
@@ -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: