]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj-sub: use modern C
authorBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 28 Oct 2021 09:35:43 +0000 (11:35 +0200)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Thu, 28 Oct 2021 09:35:43 +0000 (11:35 +0200)
Use O_APPEND instead of lseek,
Use dprintf instead of writen

src/mlmmj-sub.c

index 6f6d483c79fe7c35e9a134ee14ec258b41c1cda6..f51b1e95db600a211c78783b6343fbae1ab30cd1 100644 (file)
@@ -524,7 +524,6 @@ static void subscribe_type(struct mlmmj_list *list,
        char *sublockname = NULL;
        int groupwritable = 0, sublockfd,  subfilefd;
        struct stat st;
-       size_t len;
        int subdirfd = -1;
 
        switch(typesub) {
@@ -570,7 +569,7 @@ static void subscribe_type(struct mlmmj_list *list,
                exit(EXIT_FAILURE);
        }
 
-       subfilefd = openat(subdirfd, chstr, O_RDWR|O_CREAT|O_EXLOCK,
+       subfilefd = openat(subdirfd, chstr, O_RDWR|O_CREAT|O_EXLOCK|O_APPEND,
                                S_IRUSR|S_IWUSR|groupwritable);
        if(subfilefd == -1) {
                log_error(LOG_ARGS, "Could not open '%s/%s/%s'", list->dir, chstr);
@@ -578,11 +577,7 @@ static void subscribe_type(struct mlmmj_list *list,
                exit(EXIT_FAILURE);
        }
 
-       lseek(subfilefd, 0L, SEEK_END);
-       len = strlen(address);
-       address[len] = '\n';
-       writen(subfilefd, address, len + 1);
-       address[len] = 0;
+       dprintf(subfilefd, "%s\n", address);
        close(subfilefd);
        close(sublockfd);
        unlinkat(subdirfd, sublockname, 0);