I have a userspace application which interacts with a kernel-space driver in a Linux environment. The driver, in this case, is an LED driver. In typical *nix fashion, the driver exposes a file in
value. When the value of
value exceeds a threshold, the LED turns on.
So, my question is, what is the best-practice way of updating
value from user-space in C?
My current approach is to simply write to the file, with a hardcoded filepath:
int value = 0; FILE *fp; /* update value here... */ fp = fopen("/sys/class/leds/actled1:green/value", "w"); if(fp != NULL) fprintf(fp, "%d", value); fclose(fp);
Is there a better way to do this? It seems that there should be a standard POSIX C api for this, perhaps one that allows for driver lookup (so that I don't need to hard-code the filepath).