aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-10-09 15:21:18 +0200
committerEric Wong <normalperson@yhbt.net>2008-10-11 19:21:49 -0700
commit064e2b83d8fb694813d451d667709dc1b33c2431 (patch)
treed9e47aee5df54a4a2cf57aaff6ae64fccd96fc17 /src
parent0c46207db41840ac70af7a5261969e865b748f1d (diff)
downloadmpd-064e2b83d8fb694813d451d667709dc1b33c2431.tar.gz
mpd-064e2b83d8fb694813d451d667709dc1b33c2431.tar.xz
mpd-064e2b83d8fb694813d451d667709dc1b33c2431.zip
database: simplify db_load()
Removed a superfluous closure.
Diffstat (limited to 'src')
-rw-r--r--src/database.c89
1 files changed, 42 insertions, 47 deletions
diff --git a/src/database.c b/src/database.c
index bd278a635..0fc340c3b 100644
--- a/src/database.c
+++ b/src/database.c
@@ -231,6 +231,10 @@ int db_load(void)
FILE *fp = NULL;
char *dbFile = db_get_file();
struct stat st;
+ char buffer[100];
+ int bufferSize = 100;
+ int foundFsCharset = 0;
+ int foundVersion = 0;
if (!music_root)
music_root = directory_new("", NULL);
@@ -242,54 +246,45 @@ int db_load(void)
}
/* get initial info */
- {
- char buffer[100];
- int bufferSize = 100;
- int foundFsCharset = 0;
- int foundVersion = 0;
-
- if (!myFgets(buffer, bufferSize, fp))
- FATAL("Error reading db, fgets\n");
- if (0 == strcmp(DIRECTORY_INFO_BEGIN, buffer)) {
- while (myFgets(buffer, bufferSize, fp) &&
- 0 != strcmp(DIRECTORY_INFO_END, buffer)) {
- if (!prefixcmp(buffer, DIRECTORY_MPD_VERSION))
- {
- if (foundVersion)
- FATAL("already found version in db\n");
- foundVersion = 1;
- } else if (!prefixcmp(buffer,
- DIRECTORY_FS_CHARSET)) {
- char *fsCharset;
- char *tempCharset;
-
- if (foundFsCharset)
- FATAL("already found fs charset in db\n");
-
- foundFsCharset = 1;
-
- fsCharset = &(buffer[strlen(DIRECTORY_FS_CHARSET)]);
- if ((tempCharset = getConfigParamValue(CONF_FS_CHARSET))
- && strcmp(fsCharset, tempCharset)) {
- WARNING("Using \"%s\" for the "
- "filesystem charset "
- "instead of \"%s\"\n",
- fsCharset, tempCharset);
- WARNING("maybe you need to "
- "recreate the db?\n");
- setFsCharset(fsCharset);
- }
- } else {
- FATAL("directory: unknown line in db info: %s\n",
- buffer);
- }
+ if (!myFgets(buffer, bufferSize, fp))
+ FATAL("Error reading db, fgets\n");
+
+ 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");
+ while (fclose(fp) && errno == EINTR) ;
+ return -1;
+ }
+
+ while (myFgets(buffer, bufferSize, fp) &&
+ 0 != strcmp(DIRECTORY_INFO_END, buffer)) {
+ if (!prefixcmp(buffer, DIRECTORY_MPD_VERSION)) {
+ if (foundVersion)
+ FATAL("already found version in db\n");
+ foundVersion = 1;
+ } else if (!prefixcmp(buffer, DIRECTORY_FS_CHARSET)) {
+ char *fsCharset;
+ char *tempCharset;
+
+ if (foundFsCharset)
+ FATAL("already found fs charset in db\n");
+
+ foundFsCharset = 1;
+
+ fsCharset = &(buffer[strlen(DIRECTORY_FS_CHARSET)]);
+ if ((tempCharset = getConfigParamValue(CONF_FS_CHARSET))
+ && strcmp(fsCharset, tempCharset)) {
+ WARNING("Using \"%s\" for the "
+ "filesystem charset "
+ "instead of \"%s\"\n",
+ fsCharset, tempCharset);
+ WARNING("maybe you need to "
+ "recreate the db?\n");
+ setFsCharset(fsCharset);
}
- } else {
- ERROR("db info not found in db file\n");
- ERROR("you should recreate the db using --create-db\n");
- while (fclose(fp) && errno == EINTR) ;
- return -1;
- }
+ } else
+ FATAL("directory: unknown line in db info: %s\n",
+ buffer);
}
DEBUG("reading DB\n");