I try to read some data from one fd, but failed with error message"Invalid argument!".
struct inotify_event eventHdr;
int head_read_len = (int)read(ctx->fd, (void *)&eventHdr, sizeof(inotify_event));
if(head_read_len == -1){
_debug("read eventHdr failed!!!!\n");
perror("read eventHdr!"); //Print "Invalid argument."
}
else{
_debug("read eventHdr succeed!!!!, head_read_len:%d, name:%s\n", head_read_len, eventHdr.name);
lseek(ctx->fd, SEEK_CUR, -head_read_len);
}
Notes:
The
struct inotify_event
is used for inotify system call, man inotify for more details.fd
is guaranteed to be a valid inotify file descriptor.
What seems to be the problem? Any valuable insights?