Fix list management in stdio_set_driver_enabled so drivers can be freely added and removed (#822)
This commit is contained in:
parent
04c68c554b
commit
60a6fea534
@ -180,20 +180,19 @@ int _write(int handle, char *buffer, int length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void stdio_set_driver_enabled(stdio_driver_t *driver, bool enable) {
|
void stdio_set_driver_enabled(stdio_driver_t *driver, bool enable) {
|
||||||
stdio_driver_t *prev = drivers;
|
stdio_driver_t **prev = &drivers;
|
||||||
for (stdio_driver_t *d = drivers; d; d = d->next) {
|
while (*prev) {
|
||||||
if (d == driver) {
|
if (*prev == driver) {
|
||||||
if (!enable) {
|
if (!enable) {
|
||||||
prev->next = d->next;
|
*prev = driver->next;
|
||||||
driver->next = NULL;
|
driver->next = NULL;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prev = d;
|
prev = &(*prev)->next;
|
||||||
}
|
}
|
||||||
if (enable) {
|
if (enable) {
|
||||||
if (prev) prev->next = driver;
|
*prev = driver;
|
||||||
else drivers = driver;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user