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 @@
...
@@ -17,35 +17,40 @@
*/
*/
#include "input_file.h"
#include "input_file.h"
#include "log.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
static
bool
input_file_open
(
struct
input_stream
*
is
,
const
char
*
filename
)
input_file_open
(
struct
input_stream
*
is
,
const
char
*
filename
)
{
{
FILE
*
fp
;
int
fd
,
ret
;
struct
stat
st
;
if
(
filename
[
0
]
!=
'/'
)
if
(
filename
[
0
]
!=
'/'
)
return
false
;
return
false
;
f
p
=
fopen
(
filename
,
"r"
);
f
d
=
open
(
filename
,
O_RDONLY
);
if
(
!
fp
)
{
if
(
fd
<
0
)
{
is
->
error
=
errno
;
is
->
error
=
errno
;
return
false
;
return
false
;
}
}
is
->
seekable
=
true
;
is
->
seekable
=
true
;
fseek
(
fp
,
0
,
SEEK_END
);
ret
=
fstat
(
fd
,
&
st
);
is
->
size
=
ftell
(
fp
);
is
->
size
=
st
.
st_size
;
fseek
(
fp
,
0
,
SEEK_SET
);
#ifdef POSIX_FADV_SEQUENTIAL
#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
#endif
is
->
data
=
fp
;
is
->
data
=
GINT_TO_POINTER
(
fd
)
;
is
->
ready
=
true
;
is
->
ready
=
true
;
return
true
;
return
true
;
...
@@ -54,50 +59,48 @@ input_file_open(struct input_stream *is, const char *filename)
...
@@ -54,50 +59,48 @@ input_file_open(struct input_stream *is, const char *filename)
static
bool
static
bool
input_file_seek
(
struct
input_stream
*
is
,
off_t
offset
,
int
whence
)
input_file_seek
(
struct
input_stream
*
is
,
off_t
offset
,
int
whence
)
{
{
if
(
fseek
((
FILE
*
)
is
->
data
,
offset
,
whence
)
==
0
)
{
int
fd
=
GPOINTER_TO_INT
(
is
->
data
);
is
->
offset
=
ftell
((
FILE
*
)
is
->
data
);
}
else
{
offset
=
lseek
(
fd
,
offset
,
whence
);
if
(
offset
<
0
)
{
is
->
error
=
errno
;
is
->
error
=
errno
;
return
false
;
return
false
;
}
}
is
->
offset
=
offset
;
return
true
;
return
true
;
}
}
static
size_t
static
size_t
input_file_read
(
struct
input_stream
*
is
,
void
*
ptr
,
size_t
size
)
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
);
nbytes
=
read
(
fd
,
ptr
,
size
);
if
(
readSize
<=
0
&&
ferror
((
FILE
*
)
is
->
data
)
)
{
if
(
nbytes
<
0
)
{
is
->
error
=
errno
;
is
->
error
=
errno
;
DEBUG
(
"input_file_read: error reading: %s
\n
"
,
DEBUG
(
"input_file_read: error reading: %s
\n
"
,
strerror
(
is
->
error
));
strerror
(
is
->
error
));
return
0
;
}
}
is
->
offset
=
ftell
((
FILE
*
)
is
->
data
);
is
->
offset
+=
nbytes
;
return
(
size_t
)
nbytes
;
return
readSize
;
}
}
static
void
static
void
input_file_close
(
struct
input_stream
*
is
)
input_file_close
(
struct
input_stream
*
is
)
{
{
fclose
((
FILE
*
)
is
->
data
);
int
fd
=
GPOINTER_TO_INT
(
is
->
data
);
close
(
fd
);
}
}
static
bool
static
bool
input_file_eof
(
struct
input_stream
*
is
)
input_file_eof
(
struct
input_stream
*
is
)
{
{
if
(
feof
((
FILE
*
)
is
->
data
))
return
is
->
offset
>=
is
->
size
;
return
1
;
if
(
ferror
((
FILE
*
)
is
->
data
)
&&
is
->
error
!=
EINTR
)
{
return
1
;
}
return
0
;
}
}
static
int
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