From 03d6a25af7458283e1fe3aade4f7d612deebacbf Mon Sep 17 00:00:00 2001 From: Ashish Kumar Yadav Date: Sat, 25 Jul 2020 02:01:56 +0530 Subject: [PATCH] Improved writepid function --- dwmblocks.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/dwmblocks.c b/dwmblocks.c index 539823e..2a2dd3e 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -255,9 +255,7 @@ void writepid() { int fd; - char buf[8]; /* maximum possible pid in linux is 4194304 */ struct flock fl; - ssize_t len; fd = open(LOCKFILE, O_RDWR|O_CREAT, 0644); if (fd == -1) { @@ -280,10 +278,8 @@ writepid() perror("writepid - ftruncate"); exit(1); } - snprintf(buf, sizeof buf, "%ld", (long)getpid()); - len = strlen(buf); - if (write(fd, buf, len) != len) { - perror("writepid - write"); + if (dprintf(fd, "%ld", (long)getpid()) < 0) { + perror("writepid - dprintf"); exit(1); } }