1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

refactor: use strtok_r() instead of strtok()

This commit is contained in:
Steffen Vogel 2019-02-18 01:12:30 +01:00
parent aa14147fd9
commit 54425dcfe9
2 changed files with 10 additions and 10 deletions

View file

@ -70,7 +70,7 @@ int kernel_get_page_size()
int kernel_get_hugepage_size()
{
#ifdef __linux__
char *key, *value, *unit, *line = NULL;
char *key, *value, *unit, *line = NULL, *lasts;
int sz = -1;
size_t len = 0;
FILE *f;
@ -80,9 +80,9 @@ int kernel_get_hugepage_size()
return -1;
while (getline(&line, &len, f) != -1) {
key = strtok(line, ": ");
value = strtok(NULL, " ");
unit = strtok(NULL, "\n");
key = strtok_r(line, ": ", &lasts);
value = strtok_r(NULL, " ", &lasts);
unit = strtok_r(NULL, "\n", &lasts);
if (!strcmp(key, "Hugepagesize") && !strcmp(unit, "kB")) {
sz = strtoul(value, NULL, 10) * 1024;
@ -175,7 +175,7 @@ int kernel_module_loaded(const char *module)
int kernel_get_cmdline_param(const char *param, char *buf, size_t len)
{
int ret;
char cmdline[512];
char cmdline[512], *lasts;
FILE *f = fopen(PROCFS_PATH "/cmdline", "r");
if (!f)
@ -184,7 +184,7 @@ int kernel_get_cmdline_param(const char *param, char *buf, size_t len)
if (!fgets(cmdline, sizeof(cmdline), f))
goto out;
char *tok = strtok(cmdline, " \t");
char *tok = strtok_r(cmdline, " \t", &lasts);
do {
char key[128], value[128];
@ -202,7 +202,7 @@ int kernel_get_cmdline_param(const char *param, char *buf, size_t len)
return 0; /* found */
}
}
} while((tok = strtok(NULL, " \t")));
} while ((tok = strtok_r(NULL, " \t", &lasts)));
out:
fclose(f);

View file

@ -353,7 +353,7 @@ int vfio_pci_reset(struct vfio_device *d)
int vfio_pci_msi_find(struct vfio_device *d, int nos[32])
{
int ret, idx, irq;
char *end, *col, *last, line[1024], name[13];
char *end, *col, *last, *lasts, line[1024], name[13];
FILE *f;
f = fopen("/proc/interrupts", "r");
@ -365,7 +365,7 @@ int vfio_pci_msi_find(struct vfio_device *d, int nos[32])
/* For each line in /proc/interruipts */
while (fgets(line, sizeof(line), f)) {
col = strtok(line, " ");
col = strtok_r(line, " ", &lasts);
/* IRQ number is in first column */
irq = strtol(col, &end, 10);
@ -375,7 +375,7 @@ int vfio_pci_msi_find(struct vfio_device *d, int nos[32])
/* Find last column of line */
do {
last = col;
} while ((col = strtok(NULL, " ")));
} while ((col = strtok_r(NULL, " ", &lasts)));
ret = sscanf(last, "vfio-msi[%u](%12[0-9:])", &idx, name);