nsxivde3d782
Compiler independent buffer alignment
+7 −3
1 file changed
- M autoreload_inotify.c +7 −3
| @@ -56,22 +56,26 @@ static void arl_setup_dir(arl_t *arl, const char *filepath) | |||
| 56 | 56 | free(dntmp); | |
| 57 | 57 | } | |
| 58 | 58 | ||
| 59 | + | union { | |
| 60 | + | char d[4096]; /* aligned buffer */ | |
| 61 | + | struct inotify_event e; | |
| 62 | + | } buf; | |
| 63 | + | ||
| 59 | 64 | bool arl_handle(arl_t *arl, const char *filepath) | |
| 60 | 65 | { | |
| 61 | 66 | bool reload = false; | |
| 62 | − | char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event)))); | |
| 63 | 67 | char *ptr; | |
| 64 | 68 | const struct inotify_event *event; | |
| 65 | 69 | ||
| 66 | 70 | for (;;) { | |
| 67 | − | ssize_t len = read(arl->fd, buf, sizeof(buf)); | |
| 71 | + | ssize_t len = read(arl->fd, buf.d, sizeof(buf.d)); | |
| 68 | 72 | ||
| 69 | 73 | if (len == -1) { | |
| 70 | 74 | if (errno == EINTR) | |
| 71 | 75 | continue; | |
| 72 | 76 | break; | |
| 73 | 77 | } | |
| 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) { | |
| 75 | 79 | event = (const struct inotify_event*) ptr; | |
| 76 | 80 | ||
| 77 | 81 | /* events from watching the file itself */ | |