vere: trim trailing whitespace from pace file

This commit is contained in:
Joe Bryan 2022-05-27 12:27:14 -04:00
parent 83fdfa99c3
commit 45e3609da7
2 changed files with 12 additions and 3 deletions

View File

@ -21,6 +21,7 @@
# ifndef _XOPEN_SOURCE
# define _XOPEN_SOURCE 700
# endif
# include <ctype.h>
# include <inttypes.h>
# include <stdlib.h>
# include <string.h>
@ -38,6 +39,7 @@
# include <sys/sendfile.h>
# elif defined(U3_OS_osx)
# include <ctype.h>
# include <inttypes.h>
# include <stdlib.h>
# include <string.h>
@ -58,6 +60,7 @@
# include <copyfile.h>
# elif defined(U3_OS_bsd)
# include <ctype.h>
# include <inttypes.h>
# include <stdlib.h>
# include <string.h>
@ -77,6 +80,7 @@
# define signal mingw_has_no_usable_signal
# define raise mingw_has_no_usable_raise
# define _POSIX
# include <ctype.h>
# include <inttypes.h>
# include <stdlib.h>
# include <string.h>

View File

@ -321,16 +321,21 @@ _king_get_pace(void)
len_w = buf_u.st_size;
pat_c = c3_malloc(len_w + 1);
red_w = read(fid_i, pat_c, len_w);
pat_c[len_w] = 0;
close(fid_i);
if ( len_w != red_w ) {
c3_free(pat_c);
u3l_log("unable to read pace file, "
"falling back to default (\"live\")\n");
return strdup("live");
}
// XX trim pat_c ?
//
pat_c[len_w] = 0;
while ( len_w-- && isspace(pat_c[len_w]) ) {
pat_c[len_w] = 0;
}
return pat_c;
}