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
0d38bd9b
Commit
0d38bd9b
authored
Oct 02, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/file: export function OpenFileInputStream()
parent
2f02e49b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
13 deletions
+37
-13
FileInputPlugin.cxx
src/input/plugins/FileInputPlugin.cxx
+26
-13
FileInputPlugin.hxx
src/input/plugins/FileInputPlugin.hxx
+11
-0
No files found.
src/input/plugins/FileInputPlugin.cxx
View file @
0d38bd9b
...
...
@@ -23,7 +23,8 @@
#include "../InputPlugin.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "fs/Traits.hxx"
#include "fs/FileSystem.hxx"
#include "fs/Path.hxx"
#include "system/fd_util.h"
#include "open.h"
...
...
@@ -60,31 +61,29 @@ public:
bool
Seek
(
offset_type
offset
,
Error
&
error
)
override
;
};
static
InputStream
*
input_file_open
(
const
char
*
filename
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
)
InputStream
*
OpenFileInputStream
(
Path
path
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
)
{
if
(
!
PathTraitsFS
::
IsAbsolute
(
filename
))
return
nullptr
;
const
int
fd
=
open_cloexec
(
filename
,
O_RDONLY
|
O_BINARY
,
0
);
const
int
fd
=
OpenFile
(
path
,
O_RDONLY
|
O_BINARY
,
0
);
if
(
fd
<
0
)
{
if
(
errno
!=
ENOTDIR
)
error
.
FormatErrno
(
"Failed to open
\"
%s
\"
"
,
filename
);
path
.
c_str
()
);
return
nullptr
;
}
struct
stat
st
;
if
(
fstat
(
fd
,
&
st
)
<
0
)
{
error
.
FormatErrno
(
"Failed to stat
\"
%s
\"
"
,
filename
);
error
.
FormatErrno
(
"Failed to stat
\"
%s
\"
"
,
path
.
c_str
()
);
close
(
fd
);
return
nullptr
;
}
if
(
!
S_ISREG
(
st
.
st_mode
))
{
error
.
Format
(
file_domain
,
"Not a regular file: %s"
,
filename
);
error
.
Format
(
file_domain
,
"Not a regular file: %s"
,
path
.
c_str
());
close
(
fd
);
return
nullptr
;
}
...
...
@@ -93,7 +92,21 @@ input_file_open(const char *filename,
posix_fadvise
(
fd
,
(
off_t
)
0
,
st
.
st_size
,
POSIX_FADV_SEQUENTIAL
);
#endif
return
new
FileInputStream
(
filename
,
fd
,
st
.
st_size
,
mutex
,
cond
);
return
new
FileInputStream
(
path
.
c_str
(),
fd
,
st
.
st_size
,
mutex
,
cond
);
}
static
InputStream
*
input_file_open
(
const
char
*
filename
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
)
{
if
(
!
PathTraitsFS
::
IsAbsolute
(
filename
))
return
nullptr
;
/* TODO: the parameter is UTF-8, not filesystem charset */
const
Path
path
=
Path
::
FromFS
(
filename
);
return
OpenFileInputStream
(
path
,
mutex
,
cond
,
error
);
}
bool
...
...
src/input/plugins/FileInputPlugin.hxx
View file @
0d38bd9b
...
...
@@ -20,6 +20,17 @@
#ifndef MPD_INPUT_FILE_HXX
#define MPD_INPUT_FILE_HXX
class
InputStream
;
class
Path
;
class
Mutex
;
class
Cond
;
class
Error
;
extern
const
struct
InputPlugin
input_plugin_file
;
InputStream
*
OpenFileInputStream
(
Path
path
,
Mutex
&
mutex
,
Cond
&
cond
,
Error
&
error
);
#endif
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