-
Notifications
You must be signed in to change notification settings - Fork 0
/
vlib_sfhelper.c
53 lines (43 loc) · 920 Bytes
/
vlib_sfhelper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// SPDX-License-Identifier: EPL-1.0
/*
* Copyright IBM Corp. 2003,2010
*
* Authors: Sven Schuetz <[email protected]>
*
* File: vlib_sfhelper.c
*
* Description:
* sysfs helper functions to hide the resource access
*
*/
#include "vlib.h"
sfhelper_dir *sfhelper_opendir(char *dirname)
{
return (sfhelper_dir *)(opendir(dirname));
}
void sfhelper_closedir(sfhelper_dir *dir)
{
closedir((DIR *)dir);
}
char *sfhelper_getNextDirEnt(sfhelper_dir *dir)
{
struct dirent *direntry;
while (direntry = readdir(dir))
return direntry->d_name;
return NULL;
}
int sfhelper_getProperty(char *dir, char *name, char *result)
{
FILE *fd;
char path[PATH_MAX];
snprintf(path, PATH_MAX, "%s/%s", dir, name);
fd = fopen(path, "r");
if (!fd)
return 0;
if (fgets(result, ATTR_MAX, fd) == NULL)
return -1;
fclose(fd);
if (result[strlen(result) - 1] == '\n')
result[strlen(result) - 1] = '\0';
return 0;
}