Skip to content

Commit

Permalink
build(windows): fix some crashes and adapt file operation in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kongjianneu authored and pingkai committed Jun 10, 2020
1 parent 1048145 commit d745c3c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions framework/muxer/ffmpegMuxer/FfmpegMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,13 @@ int FfmpegMuxer::close()

if (mDestFormatContext->metadata) {
av_dict_free(&mDestFormatContext->metadata);
mDestFormatContext->metadata = nullptr;
}

avio_flush(mDestFormatContext->pb);
av_opt_free(mDestFormatContext->pb);
av_free(mDestFormatContext->pb);
mDestFormatContext->pb = nullptr;
avformat_free_context(mDestFormatContext);
mDestFormatContext = nullptr;

Expand Down
6 changes: 6 additions & 0 deletions framework/utils/af_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ void c_make_absolute_url(char *buf, int size, const char *base, const char *rel)
af_strlcpy(buf, rel, size);
return;
}
#ifdef WIN32
if (strnlen_s(rel, 3) >= 3 && isalpha(rel[0]) && rel[1] == ':' && rel[2] == '/') {
af_strlcpy(buf, rel, size);
return;
}
#endif

if (base != buf) {
af_strlcpy(buf, base, size);
Expand Down
9 changes: 7 additions & 2 deletions framework/utils/file/FileCntl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ FileCntl::~FileCntl()

void FileCntl::openFile()
{
#ifdef WIN32
_set_fmode(_O_BINARY);
#endif // WIN32
mFd = open(mFilePath.c_str(), O_RDWR | O_CREAT, 0666);
}

Expand All @@ -41,8 +44,10 @@ int FileCntl::writeFile(uint8_t *buf, int size)

void FileCntl::closeFile()
{
close(mFd);
mFd = -1;
if (mFd >= 0) {
close(mFd);
mFd = -1;
}
}


7 changes: 2 additions & 5 deletions framework/utils/file/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#ifdef _WIN32
#include <io.h>
#include <process.h>
#include <direct.h>
#else
#include <unistd.h>
#endif
Expand Down Expand Up @@ -160,11 +161,7 @@ namespace Cicada {
// make this one if parent has been made
#ifdef _WIN32
// http://msdn.microsoft.com/en-us/library/2fkk4dzw.aspx
//int rc = mkdir(pathname);
int rc = -1;
// BOOL rc = CreateDirectory("pathname", NULL);
// return rc ? FILE_TRUE : -1;
return -1;
int rc = _mkdir(pathname);
#else
//S_IRWXU|S_IRWXG|S_IRWXO = 511
int rc = mkdir(pathname, 511);
Expand Down

0 comments on commit d745c3c

Please sign in to comment.