[xiph-commits] r13457 - trunk/ezstream/src
moritz at svn.xiph.org
moritz at svn.xiph.org
Wed Aug 8 06:04:50 PDT 2007
Author: moritz
Date: 2007-08-08 06:04:49 -0700 (Wed, 08 Aug 2007)
New Revision: 13457
Modified:
trunk/ezstream/src/metadata.c
trunk/ezstream/src/playlist.c
Log:
Use a better \n and \r trimming idiom after fgets().
Modified: trunk/ezstream/src/metadata.c
===================================================================
--- trunk/ezstream/src/metadata.c 2007-08-06 23:42:26 UTC (rev 13456)
+++ trunk/ezstream/src/metadata.c 2007-08-08 13:04:49 UTC (rev 13457)
@@ -533,10 +533,8 @@
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:
Modified: trunk/ezstream/src/playlist.c
===================================================================
--- trunk/ezstream/src/playlist.c 2007-08-06 23:42:26 UTC (rev 13456)
+++ trunk/ezstream/src/playlist.c 2007-08-08 13:04:49 UTC (rev 13457)
@@ -171,10 +171,8 @@
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 @@
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);
More information about the commits
mailing list