(wrong string) ünnich

From: <git_AT_suckless.org>
Date: Wed, 17 May 2017 20:26:18 +0200 (CEST)

commit 9ac8fc62dfc8061c6bc1f973454ba10228acfbf2
Author: Bert Münnich <ber.t_AT_posteo.de>
AuthorDate: Wed May 17 20:12:22 2017 +0200
Commit: Bert Münnich <ber.t_AT_posteo.de>
CommitDate: Wed May 17 20:12:22 2017 +0200

    Fix code-style in autoreload_inotify.c

diff --git a/autoreload_inotify.c b/autoreload_inotify.c
index 383e42b..b536c2a 100644
--- a/autoreload_inotify.c
+++ b/autoreload_inotify.c
_AT_@ -27,9 +27,8 @@
 
 CLEANUP void arl_cleanup(arl_t *arl)
 {
- if (arl->fd != -1 && arl->wd != -1)
- {
- if(inotify_rm_watch(arl->fd, arl->wd))
+ if (arl->fd != -1 && arl->wd != -1) {
+ if (inotify_rm_watch(arl->fd, arl->wd))
                         error(0, 0, "Failed to remove inotify watch.");
         }
 }
_AT_@ -38,8 +37,7 @@ static void arl_setup_dir(arl_t *arl, const char *filepath)
 {
         char *dntmp, *dn;
 
- if (arl->fd == -1)
- {
+ if (arl->fd == -1) {
                 error(0, 0, "Uninitialized, could not add inotify watch on directory.");
                 return;
         }
_AT_@ -49,9 +47,10 @@ static void arl_setup_dir(arl_t *arl, const char *filepath)
         dn = (char*) dirname(dntmp);
 
         /* this is not one-shot as other stuff may be created too
- note: we won't handle deletion of the directory itself,
- this is a design decision */
- arl->wd = inotify_add_watch(arl->fd, dn,IN_CREATE);
+ * note: we won't handle deletion of the directory itself,
+ * this is a design decision
+ */
+ arl->wd = inotify_add_watch(arl->fd, dn, IN_CREATE);
         if (arl->wd == -1)
                 error(0, 0, "Failed to add inotify watch on directory '%s'.", dn);
         else
_AT_@ -63,52 +62,40 @@ static void arl_setup_dir(arl_t *arl, const char *filepath)
 bool arl_handle(arl_t *arl, const char *filepath)
 {
         bool reload = false;
- ssize_t len;
         char buf[4096] __attribute__ ((aligned(__alignof__(struct inotify_event))));
- const struct inotify_event *event;
         char *ptr;
- char *fntmp, *fn;
+ const struct inotify_event *event;
+
+ ssize_t len = read(arl->fd, buf, sizeof(buf));
 
- len = read(arl->fd, buf, sizeof buf);
- if (len == -1)
- {
+ if (len == -1) {
                 error(0, 0, "Failed to read inotify events.");
                 return false;
         }
-
- for (ptr = buf; ptr < buf + len;
- ptr += sizeof(struct inotify_event) + event->len)
- {
-
- event = (const struct inotify_event *) ptr;
+ for (ptr = buf; ptr < buf + len; ptr += sizeof(*event) + event->len) {
+ event = (const struct inotify_event*) ptr;
 
                 /* events from watching the file itself */
- if (event->mask & IN_CLOSE_WRITE)
- {
+ if (event->mask & IN_CLOSE_WRITE) {
                         reload = true;
                 }
-
                 if (event->mask & IN_DELETE_SELF)
                         arl_setup_dir(arl, filepath);
 
                 /* events from watching the file's directory */
- if (event->mask & IN_CREATE)
- {
- fntmp = strdup(filepath);
- fn = basename(fntmp);
+ if (event->mask & IN_CREATE) {
+ char *fntmp = strdup(filepath);
+ char *fn = basename(fntmp);
 
- if (0 == strcmp(event->name, fn))
- {
+ if (STREQ(event->name, fn)) {
                                 /* this is the file we're looking for */
 
                                 /* cleanup, this has not been one-shot */
- if (arl->watching_dir)
- {
- if(inotify_rm_watch(arl->fd, arl->wd))
+ if (arl->watching_dir) {
+ if (inotify_rm_watch(arl->fd, arl->wd))
                                                 error(0, 0, "Failed to remove inotify watch.");
                                         arl->watching_dir = false;
                                 }
-
                                 reload = true;
                         }
                         free(fntmp);
_AT_@ -128,22 +115,20 @@ void arl_init(arl_t *arl)
 
 void arl_setup(arl_t *arl, const char *filepath)
 {
- if (arl->fd == -1)
- {
+ if (arl->fd == -1) {
                 error(0, 0, "Uninitialized, could not add inotify watch.");
                 return;
         }
 
         /* may have switched from a deleted to another image */
- if (arl->watching_dir)
- {
+ if (arl->watching_dir) {
                 if (inotify_rm_watch(arl->fd, arl->wd))
                         error(0, 0, "Failed to remove inotify watch.");
                 arl->watching_dir = false;
         }
 
         arl->wd = inotify_add_watch(arl->fd, filepath,
- IN_ONESHOT | IN_CLOSE_WRITE | IN_DELETE_SELF);
+ IN_ONESHOT | IN_CLOSE_WRITE | IN_DELETE_SELF);
         if (arl->wd == -1)
                 error(0, 0, "Failed to add inotify watch on file '%s'.", filepath);
 }
Received on Wed May 17 2017 - 20:26:18 CEST

This archive was generated by hypermail 2.3.0 : Wed May 17 2017 - 20:36:40 CEST