X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dwmblocks.c;h=e3e34a18878b825764c83ebf107ff53165f01302;hb=3d308cafb0f3a56e9247e6a9aaf9da6e279a5bc6;hp=5abd10d2515604d4784d18938eccecb74e0c2027;hpb=416a36d63642b7261d347e29eb2b6cdddf8dba77;p=dwmblocks.git diff --git a/dwmblocks.c b/dwmblocks.c index 5abd10d..e3e34a1 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -50,16 +50,17 @@ static void (*writestatus) () = setroot; void getcmd(const Block *block, char *output) { strcpy(output, block->icon); - char *cmd = block->command; - FILE *cmdf = popen(cmd,"r"); + FILE *cmdf = popen(block->command, "r"); if (!cmdf) return; - char c; int i = strlen(block->icon); fgets(output+i, CMDLENGTH-i-delimLen, cmdf); i = strlen(output); - if (delim[0] != '\0' && --i) - strncpy(output+i, delim, delimLen); + if (delim[0] != '\0') { + //only chop off newline if one is present at the end + i = output[i-1] == '\n' ? i-1 : i; + strncpy(output+i, delim, delimLen); + } else output[i++] = '\0'; pclose(cmdf); @@ -177,7 +178,8 @@ int main(int argc, char** argv) else if (!strcmp("-p",argv[i])) writestatus = pstdout; } - delim[MIN(delimLen, strlen(delim))] = '\0'; + delimLen = MIN(delimLen, strlen(delim)); + delim[delimLen++] = '\0'; signal(SIGTERM, termhandler); signal(SIGINT, termhandler); statusloop();