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
c4223441
Commit
c4223441
authored
Nov 07, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
database: I/O error handling in db_save()
Check ferror() instead of the fprintf() return value.
parent
1a4cfc3d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
19 deletions
+16
-19
database.c
src/database.c
+3
-1
directory_save.c
src/directory_save.c
+12
-17
directory_save.h
src/directory_save.h
+1
-1
No files found.
src/database.c
View file @
c4223441
...
@@ -251,7 +251,9 @@ db_save(void)
...
@@ -251,7 +251,9 @@ db_save(void)
fprintf
(
fp
,
"%s
\n
"
,
DIRECTORY_INFO_END
);
fprintf
(
fp
,
"%s
\n
"
,
DIRECTORY_INFO_END
);
if
(
directory_save
(
fp
,
music_root
)
<
0
)
{
directory_save
(
fp
,
music_root
);
if
(
ferror
(
fp
))
{
g_warning
(
"Failed to write to database file: %s"
,
g_warning
(
"Failed to write to database file: %s"
,
strerror
(
errno
));
strerror
(
errno
));
while
(
fclose
(
fp
)
&&
errno
==
EINTR
);
while
(
fclose
(
fp
)
&&
errno
==
EINTR
);
...
...
src/directory_save.c
View file @
c4223441
...
@@ -39,43 +39,38 @@ directory_quark(void)
...
@@ -39,43 +39,38 @@ directory_quark(void)
return
g_quark_from_static_string
(
"directory"
);
return
g_quark_from_static_string
(
"directory"
);
}
}
/* TODO error checking */
void
int
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
)
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
)
{
{
struct
dirvec
*
children
=
&
directory
->
children
;
struct
dirvec
*
children
=
&
directory
->
children
;
size_t
i
;
size_t
i
;
int
retv
;
if
(
!
directory_is_root
(
directory
))
{
if
(
!
directory_is_root
(
directory
))
{
fprintf
(
fp
,
DIRECTORY_MTIME
"%lu
\n
"
,
fprintf
(
fp
,
DIRECTORY_MTIME
"%lu
\n
"
,
(
unsigned
long
)
directory
->
mtime
);
(
unsigned
long
)
directory
->
mtime
);
retv
=
fprintf
(
fp
,
"%s%s
\n
"
,
DIRECTORY_BEGIN
,
fprintf
(
fp
,
"%s%s
\n
"
,
DIRECTORY_BEGIN
,
directory_get_path
(
directory
));
directory_get_path
(
directory
));
if
(
retv
<
0
)
return
-
1
;
}
}
for
(
i
=
0
;
i
<
children
->
nr
;
++
i
)
{
for
(
i
=
0
;
i
<
children
->
nr
;
++
i
)
{
struct
directory
*
cur
=
children
->
base
[
i
];
struct
directory
*
cur
=
children
->
base
[
i
];
char
*
base
=
g_path_get_basename
(
cur
->
path
);
char
*
base
=
g_path_get_basename
(
cur
->
path
);
retv
=
fprintf
(
fp
,
DIRECTORY_DIR
"%s
\n
"
,
base
);
fprintf
(
fp
,
DIRECTORY_DIR
"%s
\n
"
,
base
);
g_free
(
base
);
g_free
(
base
);
if
(
retv
<
0
)
return
-
1
;
directory_save
(
fp
,
cur
);
if
(
directory_save
(
fp
,
cur
)
<
0
)
return
-
1
;
if
(
ferror
(
fp
))
return
;
}
}
songvec_save
(
fp
,
&
directory
->
songs
);
songvec_save
(
fp
,
&
directory
->
songs
);
if
(
!
directory_is_root
(
directory
)
&&
if
(
!
directory_is_root
(
directory
))
fprintf
(
fp
,
DIRECTORY_END
"%s
\n
"
,
fprintf
(
fp
,
DIRECTORY_END
"%s
\n
"
,
directory_get_path
(
directory
))
<
0
)
directory_get_path
(
directory
));
return
-
1
;
return
0
;
}
}
static
struct
directory
*
static
struct
directory
*
...
...
src/directory_save.h
View file @
c4223441
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
struct
directory
;
struct
directory
;
int
void
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
);
directory_save
(
FILE
*
fp
,
struct
directory
*
directory
);
bool
bool
...
...
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