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
25f98a41
Commit
25f98a41
authored
Oct 28, 2008
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input_file: don't use buffered I/O
Yet another superfluous buffering layer. input_file was using FILE*, but we're better off with unbuffered I/O using open(), read(), ...
parent
0a618777
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
28 deletions
+31
-28
input_file.c
src/input_file.c
+31
-28
No files found.
src/input_file.c
View file @
25f98a41
...
...
@@ -17,35 +17,40 @@
*/
#include "input_file.h"
#include "log.h"
#include "os_compat.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <glib.h>
static
bool
input_file_open
(
struct
input_stream
*
is
,
const
char
*
filename
)
{
FILE
*
fp
;
int
fd
,
ret
;
struct
stat
st
;
if
(
filename
[
0
]
!=
'/'
)
return
false
;
f
p
=
fopen
(
filename
,
"r"
);
if
(
!
fp
)
{
f
d
=
open
(
filename
,
O_RDONLY
);
if
(
fd
<
0
)
{
is
->
error
=
errno
;
return
false
;
}
is
->
seekable
=
true
;
fseek
(
fp
,
0
,
SEEK_END
);
is
->
size
=
ftell
(
fp
);
fseek
(
fp
,
0
,
SEEK_SET
);
ret
=
fstat
(
fd
,
&
st
);
is
->
size
=
st
.
st_size
;
#ifdef POSIX_FADV_SEQUENTIAL
posix_fadvise
(
f
ileno
(
fp
)
,
(
off_t
)
0
,
is
->
size
,
POSIX_FADV_SEQUENTIAL
);
posix_fadvise
(
f
d
,
(
off_t
)
0
,
is
->
size
,
POSIX_FADV_SEQUENTIAL
);
#endif
is
->
data
=
fp
;
is
->
data
=
GINT_TO_POINTER
(
fd
)
;
is
->
ready
=
true
;
return
true
;
...
...
@@ -54,50 +59,48 @@ input_file_open(struct input_stream *is, const char *filename)
static
bool
input_file_seek
(
struct
input_stream
*
is
,
off_t
offset
,
int
whence
)
{
if
(
fseek
((
FILE
*
)
is
->
data
,
offset
,
whence
)
==
0
)
{
is
->
offset
=
ftell
((
FILE
*
)
is
->
data
);
}
else
{
int
fd
=
GPOINTER_TO_INT
(
is
->
data
);
offset
=
lseek
(
fd
,
offset
,
whence
);
if
(
offset
<
0
)
{
is
->
error
=
errno
;
return
false
;
}
is
->
offset
=
offset
;
return
true
;
}
static
size_t
input_file_read
(
struct
input_stream
*
is
,
void
*
ptr
,
size_t
size
)
{
size_t
readSize
;
int
fd
=
GPOINTER_TO_INT
(
is
->
data
);
ssize_t
nbytes
;
readSize
=
fread
(
ptr
,
1
,
size
,
(
FILE
*
)
is
->
data
);
if
(
readSize
<=
0
&&
ferror
((
FILE
*
)
is
->
data
)
)
{
nbytes
=
read
(
fd
,
ptr
,
size
);
if
(
nbytes
<
0
)
{
is
->
error
=
errno
;
DEBUG
(
"input_file_read: error reading: %s
\n
"
,
strerror
(
is
->
error
));
return
0
;
}
is
->
offset
=
ftell
((
FILE
*
)
is
->
data
);
return
readSize
;
is
->
offset
+=
nbytes
;
return
(
size_t
)
nbytes
;
}
static
void
input_file_close
(
struct
input_stream
*
is
)
{
fclose
((
FILE
*
)
is
->
data
);
int
fd
=
GPOINTER_TO_INT
(
is
->
data
);
close
(
fd
);
}
static
bool
input_file_eof
(
struct
input_stream
*
is
)
{
if
(
feof
((
FILE
*
)
is
->
data
))
return
1
;
if
(
ferror
((
FILE
*
)
is
->
data
)
&&
is
->
error
!=
EINTR
)
{
return
1
;
}
return
0
;
return
is
->
offset
>=
is
->
size
;
}
static
int
...
...
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