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
f600e226
Commit
f600e226
authored
Sep 04, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/io/FileOutputStream: add mode APPEND_OR_CREATE
parent
d775f13a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
FileOutputStream.cxx
src/fs/io/FileOutputStream.cxx
+14
-5
FileOutputStream.hxx
src/fs/io/FileOutputStream.hxx
+7
-1
No files found.
src/fs/io/FileOutputStream.cxx
View file @
f600e226
...
...
@@ -30,7 +30,11 @@ FileOutputStream::FileOutputStream(Path _path, Mode _mode)
break
;
case
Mode
:
:
APPEND_EXISTING
:
OpenAppendExisting
();
OpenAppend
(
false
);
break
;
case
Mode
:
:
APPEND_OR_CREATE
:
OpenAppend
(
true
);
break
;
}
}
...
...
@@ -50,10 +54,10 @@ FileOutputStream::OpenCreate()
}
inline
void
FileOutputStream
::
OpenAppend
Existing
(
)
FileOutputStream
::
OpenAppend
(
bool
create
)
{
handle
=
CreateFile
(
path
.
c_str
(),
GENERIC_WRITE
,
0
,
nullptr
,
OPEN_EXISTING
,
create
?
OPEN_ALWAYS
:
OPEN_EXISTING
,
FILE_ATTRIBUTE_NORMAL
|
FILE_FLAG_WRITE_THROUGH
,
nullptr
);
if
(
!
IsDefined
())
...
...
@@ -162,9 +166,13 @@ FileOutputStream::OpenCreate()
}
inline
void
FileOutputStream
::
OpenAppend
Existing
(
)
FileOutputStream
::
OpenAppend
(
bool
create
)
{
if
(
!
fd
.
Open
(
path
.
c_str
(),
O_WRONLY
|
O_APPEND
))
int
flags
=
O_WRONLY
|
O_APPEND
;
if
(
create
)
flags
|=
O_CREAT
;
if
(
!
fd
.
Open
(
path
.
c_str
(),
flags
))
throw
FormatErrno
(
"Failed to append to %s"
,
path
.
c_str
());
}
...
...
@@ -234,6 +242,7 @@ FileOutputStream::Cancel()
break
;
case
Mode
:
:
APPEND_EXISTING
:
case
Mode
:
:
APPEND_OR_CREATE
:
/* can't roll this back */
break
;
}
...
...
src/fs/io/FileOutputStream.hxx
View file @
f600e226
...
...
@@ -69,6 +69,12 @@ public:
* not, an exception is thrown.
*/
APPEND_EXISTING
,
/**
* Like #APPEND_EXISTING, but create the file if it
* does not exist.
*/
APPEND_OR_CREATE
,
};
private
:
...
...
@@ -98,7 +104,7 @@ public:
private
:
void
OpenCreate
();
void
OpenAppend
Existing
(
);
void
OpenAppend
(
bool
create
);
bool
Close
()
{
assert
(
IsDefined
());
...
...
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