[FFmpeg-cvslog] lavf: replace rename() with ff_rename()
Luca Barbato
git at videolan.org
Sun Jan 18 01:28:52 CET 2015
ffmpeg | branch: release/2.4 | Luca Barbato <lu_zero at gentoo.org> | Mon Oct 20 00:48:49 2014 +0200| [19fc283dbb53a5f7d6658fd4edcfa59b99369b58] | committer: Vittorio Giovara
lavf: replace rename() with ff_rename()
The new function wraps errno so that its value is correctly reported
when other functions overwrite it (eg. in case of logging).
CC: libav-stable at libav.org
Bug-Id: CID 1135748
Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=19fc283dbb53a5f7d6658fd4edcfa59b99369b58
---
libavformat/hdsenc.c | 10 +++++-----
libavformat/internal.h | 14 ++++++++++++++
libavformat/smoothstreamingenc.c | 11 +++++++----
3 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c
index 6217c1f..3a0f36d 100644
--- a/libavformat/hdsenc.c
+++ b/libavformat/hdsenc.c
@@ -204,8 +204,7 @@ static int write_manifest(AVFormatContext *s, int final)
avio_printf(out, "</manifest>\n");
avio_flush(out);
avio_close(out);
- rename(temp_filename, filename);
- return 0;
+ return ff_rename(temp_filename, filename);
}
static void update_size(AVIOContext *out, int64_t pos)
@@ -286,8 +285,7 @@ static int write_abst(AVFormatContext *s, OutputStream *os, int final)
update_size(out, afrt_pos);
update_size(out, 0);
avio_close(out);
- rename(temp_filename, filename);
- return 0;
+ return ff_rename(temp_filename, filename);
}
static int init_file(AVFormatContext *s, OutputStream *os, int64_t start_ts)
@@ -477,7 +475,9 @@ static int hds_flush(AVFormatContext *s, OutputStream *os, int final,
snprintf(target_filename, sizeof(target_filename),
"%s/stream%dSeg1-Frag%d", s->filename, index, os->fragment_index);
- rename(os->temp_filename, target_filename);
+ ret = ff_rename(os->temp_filename, target_filename);
+ if (ret < 0)
+ return ret;
add_fragment(os, target_filename, os->frag_start_ts, end_ts - os->frag_start_ts);
if (!final) {
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 2824436..8a9a88f 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -353,4 +353,18 @@ enum AVCodecID ff_get_pcm_codec_id(int bps, int flt, int be, int sflags);
*/
int ff_generate_avci_extradata(AVStream *st);
+/**
+ * Wrap errno on rename() error.
+ *
+ * @param oldpath source path
+ * @param newpath destination path
+ * @return 0 or AVERROR on failure
+ */
+static inline int ff_rename(const char *oldpath, const char *newpath)
+{
+ if (rename(oldpath, newpath) == -1)
+ return AVERROR(errno);
+ return 0;
+}
+
#endif /* AVFORMAT_INTERNAL_H */
diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index 457472d..137d8fd 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -34,6 +34,7 @@
#include "libavutil/opt.h"
#include "libavutil/avstring.h"
+#include "libavutil/file.h"
#include "libavutil/mathematics.h"
#include "libavutil/intreadwrite.h"
@@ -282,8 +283,7 @@ static int write_manifest(AVFormatContext *s, int final)
avio_printf(out, "</SmoothStreamingMedia>\n");
avio_flush(out);
avio_close(out);
- rename(temp_filename, filename);
- return 0;
+ return ff_rename(temp_filename, filename);
}
static int ism_write_header(AVFormatContext *s)
@@ -533,8 +533,11 @@ static int ism_flush(AVFormatContext *s, int final)
snprintf(header_filename, sizeof(header_filename), "%s/FragmentInfo(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
snprintf(target_filename, sizeof(target_filename), "%s/Fragments(%s=%"PRIu64")", os->dirname, os->stream_type_tag, start_ts);
copy_moof(s, filename, header_filename, moof_size);
- rename(filename, target_filename);
- add_fragment(os, target_filename, header_filename, start_ts, duration, start_pos, size);
+ ret = ff_rename(filename, target_filename);
+ if (ret < 0)
+ break;
+ add_fragment(os, target_filename, header_filename, start_ts, duration,
+ os->cur_start_pos, size);
}
if (c->window_size || (final && c->remove_at_exit)) {
More information about the ffmpeg-cvslog
mailing list