aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-23 20:48:12 +0200
committerMax Kellermann <max@duempel.org>2008-09-23 20:48:12 +0200
commit27fad52c6bb1d8803f400a6e95fa5c24396a1c12 (patch)
tree9b1fadeef43c3193b29344cda223c7b2c754433b /src
parentf5df13f853cf4c0e529244dd40ab57c78a7d1bc6 (diff)
downloadmpd-27fad52c6bb1d8803f400a6e95fa5c24396a1c12.tar.gz
mpd-27fad52c6bb1d8803f400a6e95fa5c24396a1c12.tar.xz
mpd-27fad52c6bb1d8803f400a6e95fa5c24396a1c12.zip
start using prefixcmp()
LOC reduction and less noise makes things easier for tired old folks to follow.
Diffstat (limited to '')
-rw-r--r--src/audio.c3
-rw-r--r--src/directory.c23
-rw-r--r--src/inputPlugins/mp3_plugin.c2
-rw-r--r--src/ls.c3
-rw-r--r--src/main.c2
-rw-r--r--src/playlist.c31
-rw-r--r--src/volume.c12
7 files changed, 24 insertions, 52 deletions
diff --git a/src/audio.c b/src/audio.c
index f58a3376e..8c74c3cc8 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -27,7 +27,6 @@
#include "os_compat.h"
#define AUDIO_DEVICE_STATE "audio_device_state:"
-#define AUDIO_DEVICE_STATE_LEN (sizeof(AUDIO_DEVICE_STATE)-1)
#define AUDIO_BUFFER_SIZE 2*MPD_PATH_MAX
static struct audio_format audio_configFormat;
@@ -460,7 +459,7 @@ void readAudioDevicesState(FILE *fp)
while (myFgets(buffer, AUDIO_BUFFER_SIZE, fp)) {
char *c, *name;
- if (strncmp(buffer, AUDIO_DEVICE_STATE, AUDIO_DEVICE_STATE_LEN))
+ if (prefixcmp(buffer, AUDIO_DEVICE_STATE))
continue;
c = strchr(buffer, ':');
diff --git a/src/directory.c b/src/directory.c
index 6762e92bf..0fec43387 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -889,22 +889,18 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
ListNode *nodeTemp;
while (myFgets(buffer, bufferSize, fp)
- && 0 != strncmp(DIRECTORY_END, buffer, strlen(DIRECTORY_END))) {
- if (0 == strncmp(DIRECTORY_DIR, buffer, strlen(DIRECTORY_DIR))) {
+ && prefixcmp(buffer, DIRECTORY_END)) {
+ if (!prefixcmp(buffer, DIRECTORY_DIR)) {
strcpy(key, &(buffer[strlen(DIRECTORY_DIR)]));
if (!myFgets(buffer, bufferSize, fp))
FATAL("Error reading db, fgets\n");
/* for compatibility with db's prior to 0.11 */
- if (0 == strncmp(DIRECTORY_MTIME, buffer,
- strlen(DIRECTORY_MTIME))) {
+ if (!prefixcmp(buffer, DIRECTORY_MTIME)) {
if (!myFgets(buffer, bufferSize, fp))
FATAL("Error reading db, fgets\n");
}
- if (strncmp
- (DIRECTORY_BEGIN, buffer,
- strlen(DIRECTORY_BEGIN))) {
+ if (prefixcmp(buffer, DIRECTORY_BEGIN))
FATAL("Error reading db at line: %s\n", buffer);
- }
name = &(buffer[strlen(DIRECTORY_BEGIN)]);
while (nextDirNode && (strcmpRet =
@@ -932,7 +928,7 @@ static void readDirectoryInfo(FILE * fp, Directory * directory)
}
readDirectoryInfo(fp, subDirectory);
- } else if (0 == strncmp(SONG_BEGIN, buffer, strlen(SONG_BEGIN))) {
+ } else if (!prefixcmp(buffer, SONG_BEGIN)) {
readSongInfoIntoList(fp, directory->songs, directory);
} else {
FATAL("Unknown line in db: %s\n", buffer);
@@ -1086,16 +1082,13 @@ int readDirectoryDB(void)
if (0 == strcmp(DIRECTORY_INFO_BEGIN, buffer)) {
while (myFgets(buffer, bufferSize, fp) &&
0 != strcmp(DIRECTORY_INFO_END, buffer)) {
- if (0 == strncmp(DIRECTORY_MPD_VERSION, buffer,
- strlen(DIRECTORY_MPD_VERSION)))
+ if (!prefixcmp(buffer, DIRECTORY_MPD_VERSION))
{
if (foundVersion)
FATAL("already found version in db\n");
foundVersion = 1;
- } else if (0 ==
- strncmp(DIRECTORY_FS_CHARSET, buffer,
- strlen
- (DIRECTORY_FS_CHARSET))) {
+ } else if (!prefixcmp(buffer,
+ DIRECTORY_FS_CHARSET)) {
char *fsCharset;
char *tempCharset;
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index cf05d98c9..3e57a3704 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -613,7 +613,7 @@ static int parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
/* This is technically incorrect, since the encoder might not be lame.
* But there's no other way to determine if this is a lame tag, and we
* wouldn't want to go reading a tag that's not there. */
- if (strncmp(lame->encoder, "LAME", 4) != 0)
+ if (prefixcmp(lame->encoder, "LAME"))
return 0;
if (sscanf(lame->encoder+4, "%u.%u",
diff --git a/src/ls.c b/src/ls.c
index f5c48a6fa..c123ddc02 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -89,9 +89,8 @@ int isRemoteUrl(const char *url)
while (*urlPrefixes) {
count++;
- if (strncmp(*urlPrefixes, url, strlen(*urlPrefixes)) == 0) {
+ if (!prefixcmp(url, *urlPrefixes))
return count;
- }
urlPrefixes++;
}
diff --git a/src/main.c b/src/main.c
index 2ca5a56d9..f37fa3328 100644
--- a/src/main.c
+++ b/src/main.c
@@ -152,7 +152,7 @@ static void parseOptions(int argc, char **argv, Options * options)
if (argc > 1) {
int i = 1;
while (i < argc) {
- if (strncmp(argv[i], "--", 2) == 0) {
+ if (!prefixcmp(argv[i], "--")) {
if (strcmp(argv[i], "--help") == 0) {
usage(argv);
exit(EXIT_SUCCESS);
diff --git a/src/playlist.c b/src/playlist.c
index e053eb1e1..296b2689b 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -309,8 +309,7 @@ void readPlaylistState(FILE *fp)
char buffer[PLAYLIST_BUFFER_SIZE];
while (myFgets(buffer, PLAYLIST_BUFFER_SIZE, fp)) {
- if (strncmp(buffer, PLAYLIST_STATE_FILE_STATE,
- strlen(PLAYLIST_STATE_FILE_STATE)) == 0) {
+ if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_STATE)) {
if (strcmp(&(buffer[strlen(PLAYLIST_STATE_FILE_STATE)]),
PLAYLIST_STATE_FILE_STATE_PLAY) == 0) {
state = PLAYER_STATE_PLAY;
@@ -321,33 +320,24 @@ void readPlaylistState(FILE *fp)
== 0) {
state = PLAYER_STATE_PAUSE;
}
- } else if (strncmp(buffer, PLAYLIST_STATE_FILE_TIME,
- strlen(PLAYLIST_STATE_FILE_TIME)) == 0) {
+ } else if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_TIME)) {
seek_time =
atoi(&(buffer[strlen(PLAYLIST_STATE_FILE_TIME)]));
} else
- if (strncmp
- (buffer, PLAYLIST_STATE_FILE_REPEAT,
- strlen(PLAYLIST_STATE_FILE_REPEAT)) == 0) {
+ if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_REPEAT)) {
if (strcmp
(&(buffer[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
"1") == 0) {
setPlaylistRepeatStatus(1);
} else
setPlaylistRepeatStatus(0);
- } else
- if (strncmp
- (buffer, PLAYLIST_STATE_FILE_CROSSFADE,
- strlen(PLAYLIST_STATE_FILE_CROSSFADE)) == 0) {
+ } else if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_CROSSFADE)) {
setPlayerCrossFade(atoi
(&
(buffer
[strlen
(PLAYLIST_STATE_FILE_CROSSFADE)])));
- } else
- if (strncmp
- (buffer, PLAYLIST_STATE_FILE_RANDOM,
- strlen(PLAYLIST_STATE_FILE_RANDOM)) == 0) {
+ } else if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_RANDOM)) {
if (strcmp
(&
(buffer
@@ -356,20 +346,15 @@ void readPlaylistState(FILE *fp)
setPlaylistRandomStatus(1);
} else
setPlaylistRandomStatus(0);
- } else if (strncmp(buffer, PLAYLIST_STATE_FILE_CURRENT,
- strlen(PLAYLIST_STATE_FILE_CURRENT))
- == 0) {
+ } else if (!prefixcmp(buffer, PLAYLIST_STATE_FILE_CURRENT)) {
if (strlen(buffer) ==
strlen(PLAYLIST_STATE_FILE_CURRENT))
state_file_fatal();
current = atoi(&(buffer
[strlen
(PLAYLIST_STATE_FILE_CURRENT)]));
- } else
- if (strncmp
- (buffer, PLAYLIST_STATE_FILE_PLAYLIST_BEGIN,
- strlen(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)
- ) == 0) {
+ } else if (!prefixcmp(buffer,
+ PLAYLIST_STATE_FILE_PLAYLIST_BEGIN)) {
if (state == PLAYER_STATE_STOP)
current = -1;
loadPlaylistFromStateFile(fp, buffer, state,
diff --git a/src/volume.c b/src/volume.c
index 519bb814e..bf3e58f02 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -508,26 +508,22 @@ int changeVolumeLevel(int change, int rel)
void read_sw_volume_state(FILE *fp)
{
- /* strlen(SW_VOLUME_STATE) + strlen('100') + '\0' */
- #define bufsize 16
- char buf[bufsize];
- const size_t len = strlen(SW_VOLUME_STATE);
+ char buf[sizeof(SW_VOLUME_STATE) + sizeof("100") - 1];
char *end = NULL;
long int sv;
if (volume_mixerType != VOLUME_MIXER_TYPE_SOFTWARE)
return;
- while (myFgets(buf, bufsize, fp)) {
- if (strncmp(buf, SW_VOLUME_STATE, len))
+ while (myFgets(buf, sizeof(buf), fp)) {
+ if (prefixcmp(buf, SW_VOLUME_STATE))
continue;
- sv = strtol(buf + len, &end, 10);
+ sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10);
if (mpd_likely(!*end))
changeSoftwareVolume(sv, 0);
else
ERROR("Can't parse software volume: %s\n", buf);
return;
}
- #undef bufsize
}
void save_sw_volume_state(FILE *fp)