utils: removed myFgets()
Replaced myFgets() with fgets() + g_strchomp().
This commit is contained in:
parent
2598cdd868
commit
859aac7242
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
12
src/utils.c
12
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'))) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue