I'm learning about kernel modules communicating with user level programs and originally was opening a file with
FILE *pFile = fopen(...)
and writing to it with
char *str = malloc(10);
fputs(str, pFile);
However now I need to use functionality in #include <fcntl.h>
to attempt some asynchronous notifications and the example I have instead uses
int pFile;
pFile = open("/dev/mymodule", O_RDWR);
I think that I can no longer use fputs()
or fgets()
because it requires a FILE *ptr
and I have an int
instead now. I think I'm supposed to use write()
and read()
instead.
Is this how it would work?
write(pFile, str, sizeof(str));
char line[256];
while (read(pFile, line, 256) != NULL) {
printf("%s", line);
}