1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-11-03 04:17:18 -05:00

Use a better \n and \r trimming idiom after fgets().

git-svn-id: https://svn.xiph.org/trunk/ezstream@13457 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
moritz 2007-08-08 13:04:49 +00:00
parent 539100e6fc
commit 086b61a190
2 changed files with 6 additions and 12 deletions

View File

@ -533,10 +533,8 @@ metadata_program_update(metadata_t *md, enum metadata_request md_req)
printf("%s: Warning: Metadata string received via '%s' is too long and has been truncated\n",
__progname, command);
if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\r')
buf[strlen(buf) - 1] = '\0';
buf[strcspn(buf, "\n")] = '\0';
buf[strcspn(buf, "\r")] = '\0';
switch (md_req) {
case METADATA_STRING:

View File

@ -171,10 +171,8 @@ playlist_read(const char *filename)
continue;
/* Trim any trailing newlines and carriage returns. */
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\r')
buf[strlen(buf) - 1] = '\0';
buf[strcspn(buf, "\n")] = '\0';
buf[strcspn(buf, "\r")] = '\0';
/* Skip lines that are empty after the trimming. */
if (buf[0] == '\0')
@ -521,10 +519,8 @@ playlist_run_program(playlist_t *pl)
return (NULL);
}
if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = '\0';
if (buf[0] != '\0' && buf[strlen(buf) - 1] == '\r')
buf[strlen(buf) - 1] = '\0';
buf[strcspn(buf, "\n")] = '\0';
buf[strcspn(buf, "\r")] = '\0';
if (buf[0] == '\0') {
printf("%s: Empty line received from program '%s'\n",
__progname, pl->filename);