From: Baptiste Daroussin Date: Thu, 28 Oct 2021 09:35:43 +0000 (+0200) Subject: mlmmj-sub: use modern C X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3c6cc8780a90321f184080f93a93cba047dff4a4;p=thirdparty%2Fmlmmj.git mlmmj-sub: use modern C Use O_APPEND instead of lseek, Use dprintf instead of writen --- diff --git a/src/mlmmj-sub.c b/src/mlmmj-sub.c index 6f6d483c..f51b1e95 100644 --- a/src/mlmmj-sub.c +++ b/src/mlmmj-sub.c @@ -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);