Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
200ef56d
Commit
200ef56d
authored
Jan 04, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
database: use stdbool
Make db_load(), db_save() and db_check() return bool instead of int.
parent
82166b71
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
26 deletions
+27
-26
database.c
src/database.c
+20
-21
database.h
src/database.h
+4
-3
main.c
src/main.c
+3
-2
No files found.
src/database.c
View file @
200ef56d
...
...
@@ -131,7 +131,7 @@ db_get_file(void)
return
param
->
value
;
}
int
bool
db_check
(
void
)
{
struct
stat
st
;
...
...
@@ -149,14 +149,14 @@ db_check(void)
g_free
(
dirPath
);
g_warning
(
"Couldn't stat parent directory of db file "
"
\"
%s
\"
: %s"
,
dbFile
,
strerror
(
errno
));
return
-
1
;
return
false
;
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
g_free
(
dirPath
);
g_warning
(
"Couldn't create db file
\"
%s
\"
because the "
"parent path is not a directory"
,
dbFile
);
return
-
1
;
return
false
;
}
/* Check if we can write to the directory */
...
...
@@ -164,37 +164,37 @@ db_check(void)
g_warning
(
"Can't create db file in
\"
%s
\"
: %s"
,
dirPath
,
strerror
(
errno
));
g_free
(
dirPath
);
return
-
1
;
return
false
;
}
g_free
(
dirPath
);
return
0
;
return
true
;
}
/* Path exists, now check if it's a regular file */
if
(
stat
(
dbFile
,
&
st
)
<
0
)
{
g_warning
(
"Couldn't stat db file
\"
%s
\"
: %s"
,
dbFile
,
strerror
(
errno
));
return
-
1
;
return
false
;
}
if
(
!
S_ISREG
(
st
.
st_mode
))
{
g_warning
(
"db file
\"
%s
\"
is not a regular file"
,
dbFile
);
return
-
1
;
return
false
;
}
/* And check that we can write to it */
if
(
access
(
dbFile
,
R_OK
|
W_OK
))
{
g_warning
(
"Can't open db file
\"
%s
\"
for reading/writing: %s"
,
dbFile
,
strerror
(
errno
));
return
-
1
;
return
false
;
}
return
0
;
return
true
;
}
int
bool
db_save
(
void
)
{
FILE
*
fp
;
...
...
@@ -214,7 +214,7 @@ db_save(void)
if
(
!
fp
)
{
g_warning
(
"unable to write to db file
\"
%s
\"
: %s"
,
dbFile
,
strerror
(
errno
));
return
-
1
;
return
false
;
}
/* block signals when writing the db so we don't get a corrupted db */
...
...
@@ -227,7 +227,7 @@ db_save(void)
g_warning
(
"Failed to write to database file: %s"
,
strerror
(
errno
));
while
(
fclose
(
fp
)
&&
errno
==
EINTR
);
return
-
1
;
return
false
;
}
while
(
fclose
(
fp
)
&&
errno
==
EINTR
);
...
...
@@ -235,18 +235,17 @@ db_save(void)
if
(
stat
(
dbFile
,
&
st
)
==
0
)
directory_dbModTime
=
st
.
st_mtime
;
return
0
;
return
true
;
}
int
bool
db_load
(
void
)
{
FILE
*
fp
=
NULL
;
char
*
dbFile
=
db_get_file
();
struct
stat
st
;
char
buffer
[
100
];
int
foundFsCharset
=
0
;
int
foundVersion
=
0
;
bool
foundFsCharset
=
false
,
foundVersion
=
false
;
assert
(
music_root
!=
NULL
);
...
...
@@ -256,7 +255,7 @@ db_load(void)
if
(
fp
==
NULL
)
{
g_warning
(
"unable to open db file
\"
%s
\"
: %s"
,
dbFile
,
strerror
(
errno
));
return
-
1
;
return
false
;
}
/* get initial info */
...
...
@@ -269,7 +268,7 @@ db_load(void)
g_warning
(
"db info not found in db file; "
"you should recreate the db using --create-db"
);
while
(
fclose
(
fp
)
&&
errno
==
EINTR
)
;
return
-
1
;
return
false
;
}
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
fp
)
&&
...
...
@@ -279,7 +278,7 @@ db_load(void)
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_MPD_VERSION
))
{
if
(
foundVersion
)
g_error
(
"already found version in db"
);
foundVersion
=
1
;
foundVersion
=
true
;
}
else
if
(
g_str_has_prefix
(
buffer
,
DIRECTORY_FS_CHARSET
))
{
char
*
fsCharset
;
char
*
tempCharset
;
...
...
@@ -287,7 +286,7 @@ db_load(void)
if
(
foundFsCharset
)
g_error
(
"already found fs charset in db"
);
foundFsCharset
=
1
;
foundFsCharset
=
true
;
fsCharset
=
&
(
buffer
[
strlen
(
DIRECTORY_FS_CHARSET
)]);
if
((
tempCharset
=
getConfigParamValue
(
CONF_FS_CHARSET
))
...
...
@@ -315,7 +314,7 @@ db_load(void)
if
(
stat
(
dbFile
,
&
st
)
==
0
)
directory_dbModTime
=
st
.
st_mtime
;
return
0
;
return
true
;
}
time_t
...
...
src/database.h
View file @
200ef56d
...
...
@@ -21,6 +21,7 @@
#define MPD_DATABASE_H
#include <sys/time.h>
#include <stdbool.h>
struct
directory
;
...
...
@@ -56,13 +57,13 @@ int db_walk(const char *name,
int
(
*
forEachSong
)(
struct
song
*
,
void
*
),
int
(
*
forEachDir
)(
struct
directory
*
,
void
*
),
void
*
data
);
int
bool
db_check
(
void
);
int
bool
db_save
(
void
);
int
bool
db_load
(
void
);
time_t
...
...
src/main.c
View file @
200ef56d
...
...
@@ -128,7 +128,7 @@ static void openDB(Options * options, char *argv0)
{
db_init
();
if
(
options
->
createDB
>
0
||
db_load
()
<
0
)
{
if
(
options
->
createDB
>
0
||
!
db_load
()
)
{
unsigned
job
;
if
(
options
->
createDB
<
0
)
{
...
...
@@ -136,7 +136,8 @@ static void openDB(Options * options, char *argv0)
"
\"
--no-create-db
\"
command line option; "
"try running
\"
%s --create-db
\"
"
,
argv0
);
}
if
(
db_check
()
<
0
)
if
(
!
db_check
())
exit
(
EXIT_FAILURE
);
db_clear
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment