diff options
author | Max Kellermann <max@duempel.org> | 2008-12-28 19:54:49 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-12-28 19:54:49 +0100 |
commit | 859aac7242fe3767c19c1bfff73d5e6159cbad31 (patch) | |
tree | 2e433f6ec1a820d99ad171ffd6a49a6828ddd0e4 | |
parent | 2598cdd86814c7792a431470a9143d609399697b (diff) | |
download | mpd-859aac7242fe3767c19c1bfff73d5e6159cbad31.tar.gz mpd-859aac7242fe3767c19c1bfff73d5e6159cbad31.tar.xz mpd-859aac7242fe3767c19c1bfff73d5e6159cbad31.zip |
utils: removed myFgets()
Replaced myFgets() with fgets() + g_strchomp().
Diffstat (limited to '')
-rw-r--r-- | src/audio.c | 4 | ||||
-rw-r--r-- | src/conf.c | 5 | ||||
-rw-r--r-- | src/database.c | 10 | ||||
-rw-r--r-- | src/directory_save.c | 10 | ||||
-rw-r--r-- | src/playlist.c | 13 | ||||
-rw-r--r-- | src/song_save.c | 6 | ||||
-rw-r--r-- | src/stored_playlist.c | 4 | ||||
-rw-r--r-- | src/utils.c | 12 | ||||
-rw-r--r-- | src/utils.h | 2 | ||||
-rw-r--r-- | src/volume.c | 4 |
10 files changed, 38 insertions, 32 deletions
diff --git a/src/audio.c b/src/audio.c index 402d6bc28..1fba0ace0 100644 --- a/src/audio.c +++ b/src/audio.c @@ -396,9 +396,11 @@ void readAudioDevicesState(FILE *fp) assert(audioOutputArraySize != 0); - while (myFgets(buffer, AUDIO_BUFFER_SIZE, fp)) { + while (fgets(buffer, sizeof(buffer), fp)) { char *c, *name; + g_strchomp(buffer); + if (!g_str_has_prefix(buffer, AUDIO_DEVICE_STATE)) continue; diff --git a/src/conf.c b/src/conf.c index 680a5fb1c..919502529 100644 --- a/src/conf.c +++ b/src/conf.c @@ -210,7 +210,7 @@ static ConfigParam *readConfigBlock(FILE * fp, int *count, char *string) int numberOfArgs; int argsMinusComment; - while (myFgets(string, MAX_STRING_SIZE, fp)) { + while (fgets(string, MAX_STRING_SIZE, fp)) { char *array[CONF_LINE_TOKEN_MAX] = { NULL }; (*count)++; @@ -270,8 +270,9 @@ void readConf(const char *file) strerror(errno)); } - while (myFgets(string, MAX_STRING_SIZE, fp)) { + while (fgets(string, MAX_STRING_SIZE, fp)) { char *array[CONF_LINE_TOKEN_MAX] = { NULL }; + count++; numberOfArgs = buffer2array(string, array, CONF_LINE_TOKEN_MAX); diff --git a/src/database.c b/src/database.c index 4010955b7..a90c22a98 100644 --- a/src/database.c +++ b/src/database.c @@ -268,9 +268,11 @@ db_load(void) } /* get initial info */ - if (!myFgets(buffer, sizeof(buffer), fp)) + if (!fgets(buffer, sizeof(buffer), fp)) FATAL("Error reading db, fgets\n"); + g_strchomp(buffer); + if (0 != strcmp(DIRECTORY_INFO_BEGIN, buffer)) { ERROR("db info not found in db file\n"); ERROR("you should recreate the db using --create-db\n"); @@ -278,8 +280,10 @@ db_load(void) return -1; } - while (myFgets(buffer, sizeof(buffer), fp) && - 0 != strcmp(DIRECTORY_INFO_END, buffer)) { + while (fgets(buffer, sizeof(buffer), fp) && + !g_str_has_prefix(buffer, DIRECTORY_INFO_END)) { + g_strchomp(buffer); + if (g_str_has_prefix(buffer, DIRECTORY_MPD_VERSION)) { if (foundVersion) FATAL("already found version in db\n"); diff --git a/src/directory_save.c b/src/directory_save.c index 352b808cf..289f6df3b 100644 --- a/src/directory_save.c +++ b/src/directory_save.c @@ -66,25 +66,27 @@ void directory_load(FILE *fp, struct directory *directory) { char buffer[MPD_PATH_MAX * 2]; - int bufferSize = MPD_PATH_MAX * 2; char key[MPD_PATH_MAX * 2]; char *name; - while (myFgets(buffer, bufferSize, fp) + while (fgets(buffer, sizeof(buffer), fp) && !g_str_has_prefix(buffer, DIRECTORY_END)) { if (g_str_has_prefix(buffer, DIRECTORY_DIR)) { struct directory *subdir; + g_strchomp(buffer); strcpy(key, &(buffer[strlen(DIRECTORY_DIR)])); - if (!myFgets(buffer, bufferSize, fp)) + if (!fgets(buffer, sizeof(buffer), fp)) FATAL("Error reading db, fgets\n"); /* for compatibility with db's prior to 0.11 */ if (g_str_has_prefix(buffer, DIRECTORY_MTIME)) { - if (!myFgets(buffer, bufferSize, fp)) + if (!fgets(buffer, sizeof(buffer), fp)) FATAL("Error reading db, fgets\n"); } + if (!g_str_has_prefix(buffer, DIRECTORY_BEGIN)) FATAL("Error reading db at line: %s\n", buffer); + g_strchomp(buffer); name = &(buffer[strlen(DIRECTORY_BEGIN)]); if (!g_str_has_prefix(name, directory->path) != 0) FATAL("Wrong path in database: '%s' in '%s'\n", diff --git a/src/playlist.c b/src/playlist.c index ba69844de..18068b77c 100644 --- a/src/playlist.c +++ b/src/playlist.c @@ -268,9 +268,11 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer, char *temp; int song; - if (!myFgets(buffer, PLAYLIST_BUFFER_SIZE, fp)) + if (!fgets(buffer, PLAYLIST_BUFFER_SIZE, fp)) state_file_fatal(); - while (strcmp(buffer, PLAYLIST_STATE_FILE_PLAYLIST_END)) { + while (!g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_PLAYLIST_END)) { + g_strchomp(buffer); + temp = strtok(buffer, ":"); if (temp == NULL) state_file_fatal(); @@ -290,7 +292,8 @@ static void loadPlaylistFromStateFile(FILE *fp, char *buffer, seek_time); } } - if (!myFgets(buffer, PLAYLIST_BUFFER_SIZE, fp)) + + if (!fgets(buffer, PLAYLIST_BUFFER_SIZE, fp)) state_file_fatal(); } } @@ -302,7 +305,9 @@ void readPlaylistState(FILE *fp) int state = PLAYER_STATE_STOP; char buffer[PLAYLIST_BUFFER_SIZE]; - while (myFgets(buffer, PLAYLIST_BUFFER_SIZE, fp)) { + while (fgets(buffer, sizeof(buffer), fp)) { + g_strchomp(buffer); + if (g_str_has_prefix(buffer, PLAYLIST_STATE_FILE_STATE)) { if (strcmp(&(buffer[strlen(PLAYLIST_STATE_FILE_STATE)]), PLAYLIST_STATE_FILE_STATE_PLAY) == 0) { diff --git a/src/song_save.c b/src/song_save.c index 41e694611..ff5aeb1a7 100644 --- a/src/song_save.c +++ b/src/song_save.c @@ -104,11 +104,13 @@ void readSongInfoIntoList(FILE *fp, struct songvec *sv, struct directory *parent) { char buffer[MPD_PATH_MAX + 1024]; - int bufferSize = MPD_PATH_MAX + 1024; struct song *song = NULL; int itemType; - while (myFgets(buffer, bufferSize, fp) && 0 != strcmp(SONG_END, buffer)) { + while (fgets(buffer, sizeof(buffer), fp) && + !g_str_has_prefix(buffer, SONG_END)) { + g_strchomp(buffer); + if (0 == strncmp(SONG_KEY, buffer, strlen(SONG_KEY))) { if (song) insertSongIntoList(sv, song); diff --git a/src/stored_playlist.c b/src/stored_playlist.c index 78977bf69..034dfccb6 100644 --- a/src/stored_playlist.c +++ b/src/stored_playlist.c @@ -149,13 +149,15 @@ spl_load(const char *utf8path) list = g_ptr_array_new(); - while (myFgets(buffer, sizeof(buffer), file)) { + while (fgets(buffer, sizeof(buffer), file)) { char *s = buffer; const char *path_utf8; if (*s == PLAYLIST_COMMENT) continue; + g_strchomp(buffer); + if (!isRemoteUrl(s)) { struct song *song; diff --git a/src/utils.c b/src/utils.c index 1b12cd810..9d763c484 100644 --- a/src/utils.c +++ b/src/utils.c @@ -33,18 +33,6 @@ #include <sys/socket.h> #endif -char *myFgets(char *buffer, int bufferSize, FILE * fp) -{ - char *ret = fgets(buffer, bufferSize, fp); - if (ret && strlen(buffer) > 0 && buffer[strlen(buffer) - 1] == '\n') { - buffer[strlen(buffer) - 1] = '\0'; - } - if (ret && strlen(buffer) > 0 && buffer[strlen(buffer) - 1] == '\r') { - buffer[strlen(buffer) - 1] = '\0'; - } - return ret; -} - void stripReturnChar(char *string) { while (string && (string = strchr(string, '\n'))) { diff --git a/src/utils.h b/src/utils.h index e7594c261..9701b9d4c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -37,8 +37,6 @@ } while (0) #endif /* !assert_static */ -char *myFgets(char *buffer, int bufferSize, FILE * fp); - void stripReturnChar(char *string); void my_usleep(long usec); diff --git a/src/volume.c b/src/volume.c index fedccfd7e..2603aeede 100644 --- a/src/volume.c +++ b/src/volume.c @@ -522,9 +522,11 @@ void read_sw_volume_state(FILE *fp) if (volume_mixerType != VOLUME_MIXER_TYPE_SOFTWARE) return; - while (myFgets(buf, sizeof(buf), fp)) { + while (fgets(buf, sizeof(buf), fp)) { if (!g_str_has_prefix(buf, SW_VOLUME_STATE)) continue; + + g_strchomp(buf); sv = strtol(buf + strlen(SW_VOLUME_STATE), &end, 10); if (G_LIKELY(!*end)) changeSoftwareVolume(sv, 0); |