fanotify.3: Pass array to read(2) directly instead of a pointer to it
PATCH 1/1 fanotify.3: Pass array to read(2) directly instead of a pointer to it
It doesn't make any sense to pass a pointer to the array to read(2).
It might make sense to pass a pointer to the first element of the array, but that is already implicitly done when passing the array, which decays to that pointer, so it's simpler to pass the array.
And anyway, the cast was unneeded, as any pointer is implicitly casted to void *.
--- man7/fanotify.7 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
man7/fanotify.7 +2 -2
@@ -818,7 +818,7 @@ handle_events(int fd) /* Read some events */ - len = read(fd, (void *) &buf, sizeof(buf)); + len = read(fd, buf, sizeof(buf)); if (len == \-1 && errno != EAGAIN) { perror("read"); exit(EXIT_FAILURE);
@@ -1111,7 +1111,7 @@ main(int argc, char **argv) /* Read events from the event queue into a buffer */ - len = read(fd, (void *) &events_buf, sizeof(events_buf)); + len = read(fd, events_buf, sizeof(events_buf)); if (len == \-1 && errno != EAGAIN) { perror("read"); exit(EXIT_FAILURE);
Signature · 1 line
2.28.0
Hi Michael,
I had a typo in the subject. It's fanotify.7; please fix it when applying the patch.
Cheers,
Alex
Quoted 37 lines · Alejandro Colomar
It doesn't make any sense to pass a pointer to the array to read(2).
It might make sense to pass a pointer to the first element of the array, but that is already implicitly done when passing the array, which decays to that pointer, so it's simpler to pass the array.
And anyway, the cast was unneeded, as any pointer is implicitly casted to
void *.Signed-off-by Alejandro Colomar <[email protected]>--- man7/fanotify.7 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)man7/fanotify.7 +2
-2@@ -818,7 +818,7 @@ handle_events(int fd) /* Read some events */ - len = read(fd, (void *) &buf, sizeof(buf)); + len = read(fd, buf, sizeof(buf)); if (len == \-1 && errno != EAGAIN) { perror("read"); exit(EXIT_FAILURE);@@ -1111,7 +1111,7 @@ main(int argc, char **argv) /* Read events from the event queue into a buffer */ - len = read(fd, (void *) &events_buf, sizeof(events_buf)); + len = read(fd, events_buf, sizeof(events_buf)); if (len == \-1 && errno != EAGAIN) { perror("read"); exit(EXIT_FAILURE);
Quoted 4 lines · Alejandro Colomar
Hi Michael,
I had a typo in the subject. It's fanotify.7; please fix it when applying the patch.
Patch applied. and title line fixed.
Thanks, Alex.
Cheers,
Michael
Quoted 38 lines · Alejandro Colomar
Quoted 37 lines
It doesn't make any sense to pass a pointer to the array to read(2).
It might make sense to pass a pointer to the first element of the array, but that is already implicitly done when passing the array, which decays to that pointer, so it's simpler to pass the array.
And anyway, the cast was unneeded, as any pointer is implicitly casted to
void *.Signed-off-by Alejandro Colomar <[email protected]>--- man7/fanotify.7 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)man7/fanotify.7 +2
-2@@ -818,7 +818,7 @@ handle_events(int fd) /* Read some events */ - len = read(fd, (void *) &buf, sizeof(buf)); + len = read(fd, buf, sizeof(buf)); if (len == \-1 && errno != EAGAIN) { perror("read"); exit(EXIT_FAILURE);@@ -1111,7 +1111,7 @@ main(int argc, char **argv) /* Read events from the event queue into a buffer */ - len = read(fd, (void *) &events_buf, sizeof(events_buf)); + len = read(fd, events_buf, sizeof(events_buf)); if (len == \-1 && errno != EAGAIN) { perror("read"); exit(EXIT_FAILURE);
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/