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
d8bef327
Commit
d8bef327
authored
Jan 21, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
config/File: use FileReader/BufferedReader instead of stdio
parent
a33db8fe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
28 deletions
+21
-28
ConfigFile.cxx
src/config/ConfigFile.cxx
+21
-28
No files found.
src/config/ConfigFile.cxx
View file @
d8bef327
...
@@ -26,15 +26,12 @@
...
@@ -26,15 +26,12 @@
#include "util/StringUtil.hxx"
#include "util/StringUtil.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "fs/Limits.hxx"
#include "fs/Path.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include "fs/io/FileReader.hxx"
#include "fs/io/BufferedReader.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include <assert.h>
#include <assert.h>
#include <stdio.h>
static
constexpr
size_t
MAX_STRING_SIZE
=
MPD_PATH_MAX
+
80
;
static
constexpr
char
CONF_COMMENT
=
'#'
;
static
constexpr
char
CONF_COMMENT
=
'#'
;
...
@@ -81,18 +78,18 @@ config_read_name_value(struct config_param *param, char *input, unsigned line,
...
@@ -81,18 +78,18 @@ config_read_name_value(struct config_param *param, char *input, unsigned line,
}
}
static
struct
config_param
*
static
struct
config_param
*
config_read_block
(
FILE
*
fp
,
int
*
count
,
char
*
string
,
Error
&
error
)
config_read_block
(
BufferedReader
&
reader
,
int
*
count
,
Error
&
error
)
{
{
struct
config_param
*
ret
=
new
config_param
(
*
count
);
struct
config_param
*
ret
=
new
config_param
(
*
count
);
while
(
true
)
{
while
(
true
)
{
char
*
line
;
char
*
line
=
reader
.
ReadLine
();
line
=
fgets
(
string
,
MAX_STRING_SIZE
,
fp
);
if
(
line
==
nullptr
)
{
if
(
line
==
nullptr
)
{
delete
ret
;
delete
ret
;
error
.
Set
(
config_file_domain
,
"Expected '}' before end-of-file"
);
if
(
reader
.
Check
(
error
))
error
.
Set
(
config_file_domain
,
"Expected '}' before end-of-file"
);
return
nullptr
;
return
nullptr
;
}
}
...
@@ -142,21 +139,21 @@ Append(config_param *&head, config_param *p)
...
@@ -142,21 +139,21 @@ Append(config_param *&head, config_param *p)
}
}
static
bool
static
bool
ReadConfigFile
(
ConfigData
&
config_data
,
FILE
*
fp
,
Error
&
error
)
ReadConfigFile
(
ConfigData
&
config_data
,
BufferedReader
&
reader
,
Error
&
error
)
{
{
assert
(
fp
!=
nullptr
);
char
string
[
MAX_STRING_SIZE
+
1
];
int
count
=
0
;
int
count
=
0
;
struct
config_param
*
param
;
struct
config_param
*
param
;
while
(
fgets
(
string
,
MAX_STRING_SIZE
,
fp
))
{
while
(
true
)
{
char
*
line
;
char
*
line
=
reader
.
ReadLine
();
if
(
line
==
nullptr
)
return
true
;
const
char
*
name
,
*
value
;
const
char
*
name
,
*
value
;
count
++
;
count
++
;
line
=
StripLeft
(
string
);
line
=
StripLeft
(
line
);
if
(
*
line
==
0
||
*
line
==
CONF_COMMENT
)
if
(
*
line
==
0
||
*
line
==
CONF_COMMENT
)
continue
;
continue
;
...
@@ -214,7 +211,7 @@ ReadConfigFile(ConfigData &config_data, FILE *fp, Error &error)
...
@@ -214,7 +211,7 @@ ReadConfigFile(ConfigData &config_data, FILE *fp, Error &error)
return
false
;
return
false
;
}
}
param
=
config_read_block
(
fp
,
&
count
,
string
,
error
);
param
=
config_read_block
(
reader
,
&
count
,
error
);
if
(
param
==
nullptr
)
{
if
(
param
==
nullptr
)
{
return
false
;
return
false
;
}
}
...
@@ -246,8 +243,6 @@ ReadConfigFile(ConfigData &config_data, FILE *fp, Error &error)
...
@@ -246,8 +243,6 @@ ReadConfigFile(ConfigData &config_data, FILE *fp, Error &error)
Append
(
head
,
param
);
Append
(
head
,
param
);
}
}
return
true
;
}
}
bool
bool
...
@@ -258,13 +253,11 @@ ReadConfigFile(ConfigData &config_data, Path path, Error &error)
...
@@ -258,13 +253,11 @@ ReadConfigFile(ConfigData &config_data, Path path, Error &error)
FormatDebug
(
config_file_domain
,
"loading file %s"
,
path_utf8
.
c_str
());
FormatDebug
(
config_file_domain
,
"loading file %s"
,
path_utf8
.
c_str
());
FILE
*
fp
=
FOpen
(
path
,
FOpenMode
::
ReadText
);
FileReader
file
(
path
,
error
);
if
(
fp
==
nullptr
)
{
if
(
!
file
.
IsDefined
())
error
.
FormatErrno
(
"Failed to open %s"
,
path_utf8
.
c_str
());
return
false
;
return
false
;
}
bool
result
=
ReadConfigFile
(
config_data
,
fp
,
error
);
BufferedReader
reader
(
file
);
fclose
(
fp
);
return
ReadConfigFile
(
config_data
,
reader
,
error
)
&&
return
result
;
reader
.
Check
(
error
)
;
}
}
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