Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/illiliti/libdemi
Device enumeration, monitoring and introspecting library
https://github.com/illiliti/libdemi
Last synced: 5 days ago
JSON representation
Device enumeration, monitoring and introspecting library
- Host: GitHub
- URL: https://github.com/illiliti/libdemi
- Owner: illiliti
- License: isc
- Created: 2021-10-11T16:52:27.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-28T17:48:04.000Z (over 2 years ago)
- Last Synced: 2024-05-08T20:04:19.173Z (6 months ago)
- Language: C
- Size: 113 KB
- Stars: 7
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-systemd - libdemi
- awesome-systemd - libdemi
README
# libdemi
**!!! EXPERIMENTAL !!!**
Device enumeration, monitoring and introspecting library
## Showcase
```c
#include
#include
#include
#includeint main(void)
{
// Initialize demi file descriptor with no/zero flags.
// Optionally, DEMI_CLOEXEC and DEMI_NONBLOCK can be bitwise ORed in flags
// to atomically set close-on-exec flag and nonblocking mode respectively.
int fd = demi_init(0);if (fd == -1) {
return EXIT_FAILURE;
}struct demi_event de;
// Read pending event. This call will block since DEMI_NONBLOCK was not set.
while (demi_read(fd, &de) != -1) {
// de_devname might not contain devname, indicating that the event shall be ignored.
if (de.de_devname[0] == '\0') {
continue;
}// Prepend /dev/ to devname, so that we have full path to devnode.
char devnode[sizeof(de.de_devname) + sizeof("/dev/")];
snprintf(devnode, sizeof(devnode), "/dev/%s", de.de_devname);// Print devnode and code of event type.
printf("%s (code %d)\n", devnode, de.de_type);
}// Do not forget to close file descriptor when you are done.
close(fd);
return EXIT_SUCCESS;
}
```## See also
https://github.com/illiliti/kiss-libdemi