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
1709ab68
Commit
1709ab68
authored
Feb 17, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/TextFile: use custom allocation instead of GString
parent
ce925ba5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
27 deletions
+32
-27
Makefile.am
Makefile.am
+3
-3
TextFile.cxx
src/fs/TextFile.cxx
+26
-22
TextFile.hxx
src/fs/TextFile.hxx
+3
-2
No files found.
Makefile.am
View file @
1709ab68
...
...
@@ -1322,9 +1322,9 @@ endif
test_read_conf_LDADD
=
\
libconf.a
\
libutil.a
\
libsystem.a
\
libfs.a
\
libutil.a
\
$(GLIB_LIBS)
test_read_conf_SOURCES
=
\
src/Log.cxx src/LogBackend.cxx
\
...
...
@@ -1543,9 +1543,9 @@ endif
test_run_filter_LDADD
=
\
$(FILTER_LIBS)
\
libconf.a
\
libutil.a
\
libsystem.a
\
libfs.a
\
libutil.a
\
$(GLIB_LIBS)
test_run_filter_SOURCES
=
test
/run_filter.cxx
\
test
/FakeReplayGainConfig.cxx
\
...
...
@@ -1681,10 +1681,10 @@ test_read_mixer_LDADD = \
libmixer_plugins.a
\
$(OUTPUT_LIBS)
\
libconf.a
\
libutil.a
\
libevent.a
\
libsystem.a
\
libfs.a
\
libutil.a
\
$(GLIB_LIBS)
test_read_mixer_SOURCES
=
test
/read_mixer.cxx
\
src/Log.cxx src/LogBackend.cxx
\
...
...
src/fs/TextFile.cxx
View file @
1709ab68
...
...
@@ -19,59 +19,63 @@
#include "config.h"
#include "TextFile.hxx"
#include "util/Alloc.hxx"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
#include <glib.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
TextFile
::
TextFile
(
Path
path_fs
)
:
file
(
FOpen
(
path_fs
,
FOpenMode
::
ReadText
)),
buffer
(
g_string_sized_new
(
step
)
)
{}
buffer
(
(
char
*
)
xalloc
(
step
)),
capacity
(
step
),
length
(
0
)
{}
TextFile
::~
TextFile
()
{
free
(
buffer
);
if
(
file
!=
nullptr
)
fclose
(
file
);
g_string_free
(
buffer
,
true
);
}
char
*
TextFile
::
ReadLine
()
{
gsize
length
=
0
,
i
;
char
*
p
;
assert
(
file
!=
nullptr
);
assert
(
buffer
!=
nullptr
);
assert
(
buffer
->
allocated_len
>=
step
);
while
(
buffer
->
len
<
max_length
)
{
p
=
fgets
(
buffer
->
str
+
length
,
buffer
->
allocated_len
-
length
,
file
);
while
(
true
)
{
if
(
length
>=
capacity
)
{
if
(
capacity
>=
max_length
)
/* too large already - bail out */
return
nullptr
;
capacity
<<=
1
;
char
*
new_buffer
=
(
char
*
)
realloc
(
buffer
,
capacity
);
if
(
new_buffer
==
nullptr
)
/* out of memory - bail out */
return
nullptr
;
}
char
*
p
=
fgets
(
buffer
+
length
,
capacity
-
length
,
file
);
if
(
p
==
nullptr
)
{
if
(
length
==
0
||
ferror
(
file
))
return
nullptr
;
break
;
}
i
=
strlen
(
buffer
->
str
+
length
);
length
+=
i
;
if
(
i
<
step
-
1
||
buffer
->
str
[
length
-
1
]
==
'\n'
)
length
+=
strlen
(
buffer
+
length
);
if
(
buffer
[
length
-
1
]
==
'\n'
)
break
;
g_string_set_size
(
buffer
,
length
+
step
);
}
/* remove the newline characters */
if
(
buffer
->
str
[
length
-
1
]
==
'\n'
)
if
(
buffer
[
length
-
1
]
==
'\n'
)
--
length
;
if
(
buffer
->
str
[
length
-
1
]
==
'\r'
)
if
(
buffer
[
length
-
1
]
==
'\r'
)
--
length
;
g_string_set_size
(
buffer
,
length
);
return
buffer
->
str
;
buffer
[
length
]
=
0
;
length
=
0
;
return
buffer
;
}
src/fs/TextFile.hxx
View file @
1709ab68
...
...
@@ -23,9 +23,9 @@
#include "Compiler.h"
#include <stdio.h>
#include <stddef.h>
class
Path
;
typedef
struct
_GString
GString
;
class
TextFile
{
static
constexpr
size_t
max_length
=
512
*
1024
;
...
...
@@ -33,7 +33,8 @@ class TextFile {
FILE
*
const
file
;
GString
*
const
buffer
;
char
*
buffer
;
size_t
capacity
,
length
;
public
:
TextFile
(
Path
path_fs
);
...
...
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