updateblock - nullterminate

This commit is contained in:
Ashish Kumar Yadav 2021-02-09 12:34:20 +05:30
parent 452d7850c2
commit 161e0f5615
5 changed files with 7 additions and 7 deletions

View file

@ -23,7 +23,6 @@
delivered first. */ delivered first. */
/* pathu - path of the program whose output is used as status text of the block /* pathu - path of the program whose output is used as status text of the block
(output of the program should end in a null or newline character)
* pathc - path of the program used for handling clicks on the block */ * pathc - path of the program used for handling clicks on the block */
/* 1 interval = INTERVALs seconds, INTERVALn nanoseconds */ /* 1 interval = INTERVALs seconds, INTERVALn nanoseconds */

View file

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/sh
ICON=" " ICON=" "
read -r capacity </sys/class/power_supply/BAT0/capacity read -r capacity </sys/class/power_supply/BAT0/capacity
printf "$ICON%s%%\n" "$capacity" printf "$ICON%s%%" "$capacity"

View file

@ -1,3 +1,3 @@
#!/bin/sh #!/bin/sh
ICON=" " ICON=" "
printf "$ICON%s\n" "$(date '+%a, %b %d, %R')" printf "$ICON%s" "$(date '+%a, %b %d, %R')"

View file

@ -9,7 +9,7 @@ read -r temp </sys/class/thermal/thermal_zone0/temp
temp=${temp%???} temp=${temp%???}
if [ "$temp" -lt "$crit" ] ; then if [ "$temp" -lt "$crit" ] ; then
printf "$ICONn%s°C\n" "$temp" printf "$ICONn%s°C" "$temp"
else else
printf "$ICONc%s°C\n" "$temp" printf "$ICONc%s°C" "$temp"
fi fi

View file

@ -234,6 +234,7 @@ updateblock(Block *block, int sigval)
exit(1); exit(1);
} }
close(fd[0]); close(fd[0]);
block->curcmdout[block->curcmdout[trd - 1] == '\n' ? trd - 1 : trd] = '\0';
} }
} }
} }
@ -249,7 +250,7 @@ updatestatus()
/* checking half of the function */ /* checking half of the function */
for (; block->pathu; block++) { for (; block->pathu; block++) {
c = block->curcmdout, p = block->prvcmdout; c = block->curcmdout, p = block->prvcmdout;
for (; *c == *p && *c != '\n' && *c != '\0'; c++, p++); for (; *c != '\0' && *c == *p; c++, p++);
s += c - block->curcmdout; s += c - block->curcmdout;
if (*c != *p) if (*c != *p)
goto update; goto update;
@ -265,7 +266,7 @@ updatestatus()
for (; block->pathu; block++) { for (; block->pathu; block++) {
c = block->curcmdout, p = block->prvcmdout; c = block->curcmdout, p = block->prvcmdout;
update: update:
for (; *p = *c, *c != '\n' && *c != '\0'; c++, p++) for (; (*p = *c) != '\0'; c++, p++)
*(s++) = *c; *(s++) = *c;
if (c == block->curcmdout) if (c == block->curcmdout)
continue; continue;