Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
29a9b12b
Commit
29a9b12b
authored
Sep 09, 2012
by
Martin Storsjö
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
file: Add an avoption for disabling truncating existing files on open
Signed-off-by:
Martin Storsjö
<
martin@martin.st
>
parent
5e357289
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
file.c
libavformat/file.c
+22
-2
No files found.
libavformat/file.c
View file @
29a9b12b
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
*/
*/
#include "libavutil/avstring.h"
#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "avformat.h"
#include "avformat.h"
#include <fcntl.h>
#include <fcntl.h>
#if HAVE_IO_H
#if HAVE_IO_H
...
@@ -37,9 +38,23 @@
...
@@ -37,9 +38,23 @@
/* standard file protocol */
/* standard file protocol */
typedef
struct
FileContext
{
typedef
struct
FileContext
{
const
AVClass
*
class
;
int
fd
;
int
fd
;
int
trunc
;
}
FileContext
;
}
FileContext
;
static
const
AVOption
file_options
[]
=
{
{
"truncate"
,
"Truncate existing files on write"
,
offsetof
(
FileContext
,
trunc
),
AV_OPT_TYPE_INT
,
{
.
i64
=
1
},
0
,
1
,
AV_OPT_FLAG_ENCODING_PARAM
},
{
NULL
}
};
static
const
AVClass
file_class
=
{
.
class_name
=
"file"
,
.
item_name
=
av_default_item_name
,
.
option
=
file_options
,
.
version
=
LIBAVUTIL_VERSION_INT
,
};
static
int
file_read
(
URLContext
*
h
,
unsigned
char
*
buf
,
int
size
)
static
int
file_read
(
URLContext
*
h
,
unsigned
char
*
buf
,
int
size
)
{
{
FileContext
*
c
=
h
->
priv_data
;
FileContext
*
c
=
h
->
priv_data
;
...
@@ -82,9 +97,13 @@ static int file_open(URLContext *h, const char *filename, int flags)
...
@@ -82,9 +97,13 @@ static int file_open(URLContext *h, const char *filename, int flags)
av_strstart
(
filename
,
"file:"
,
&
filename
);
av_strstart
(
filename
,
"file:"
,
&
filename
);
if
(
flags
&
AVIO_FLAG_WRITE
&&
flags
&
AVIO_FLAG_READ
)
{
if
(
flags
&
AVIO_FLAG_WRITE
&&
flags
&
AVIO_FLAG_READ
)
{
access
=
O_CREAT
|
O_TRUNC
|
O_RDWR
;
access
=
O_CREAT
|
O_RDWR
;
if
(
c
->
trunc
)
access
|=
O_TRUNC
;
}
else
if
(
flags
&
AVIO_FLAG_WRITE
)
{
}
else
if
(
flags
&
AVIO_FLAG_WRITE
)
{
access
=
O_CREAT
|
O_TRUNC
|
O_WRONLY
;
access
=
O_CREAT
|
O_WRONLY
;
if
(
c
->
trunc
)
access
|=
O_TRUNC
;
}
else
{
}
else
{
access
=
O_RDONLY
;
access
=
O_RDONLY
;
}
}
...
@@ -126,6 +145,7 @@ URLProtocol ff_file_protocol = {
...
@@ -126,6 +145,7 @@ URLProtocol ff_file_protocol = {
.
url_get_file_handle
=
file_get_handle
,
.
url_get_file_handle
=
file_get_handle
,
.
url_check
=
file_check
,
.
url_check
=
file_check
,
.
priv_data_size
=
sizeof
(
FileContext
),
.
priv_data_size
=
sizeof
(
FileContext
),
.
priv_data_class
=
&
file_class
,
};
};
#endif
/* CONFIG_FILE_PROTOCOL */
#endif
/* CONFIG_FILE_PROTOCOL */
...
...
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