Krolyxon
Commit de3d782

Branches

Refs →

nsxivde3d782

Compiler independent buffer alignment

Author
Bert Münnich
Date
2017-05-17 20:15 +0200
Parent
0e1a85d
Commit
de3d7827ce13a52b1bcf3b72e9dc2ee89152dea6

+7 −3

1 file changed

  1. M autoreload_inotify.c +7 −3
M autoreload_inotify.c View
@@ -56,22 +56,26 @@ static void arl_setup_dir(arl_t *arl, const char *filepath)
5656 free(dntmp);
5757 }
5858
59+union {
60+ char d[4096]; /* aligned buffer */
61+ struct inotify_event e;
62+} buf;
63+
5964 bool arl_handle(arl_t *arl, const char *filepath)
6065 {
6166 bool reload = false;
62− char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
6367 char *ptr;
6468 const struct inotify_event *event;
6569
6670 for (;;) {
67− ssize_t len = read(arl->fd, buf, sizeof(buf));
71+ ssize_t len = read(arl->fd, buf.d, sizeof(buf.d));
6872
6973 if (len == -1) {
7074 if (errno == EINTR)
7175 continue;
7276 break;
7377 }
74− for (ptr = buf; ptr < buf + len; ptr += sizeof(*event) + event->len) {
78+ for (ptr = buf.d; ptr < buf.d + len; ptr += sizeof(*event) + event->len) {
7579 event = (const struct inotify_event*) ptr;
7680
7781 /* events from watching the file itself */