Skip to content

Commit

Permalink
fix tmpnam
Browse files Browse the repository at this point in the history
  • Loading branch information
bcherry committed Sep 12, 2017
1 parent 004d840 commit 5c5538f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# GCC 4.9.1 gives unnecessary warnings about missing field initializers when compiling
# with -std=c++11 and -Wextra, so use -Wno-missing-field-initializers for now.
set(warnings "-Wall -Wextra -Werror -Wno-missing-field-initializers -Wno-deprecated-declarations")
set(warnings "-Wall -Wextra -Werror -Wno-missing-field-initializers")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(warnings "/W4 /EHsc")
endif()
Expand Down
26 changes: 22 additions & 4 deletions Srcs/heiftojpeg/heiftojpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ struct measure

static void decodeData(ImageFileReaderInterface::DataVector data, Magick::Image *image)
{
string hevcFileName = tmpnam(nullptr);
string bmpFileName = tmpnam(nullptr);
bmpFileName += ".bmp"; // ffmpeg expects the output file to the have the extension ".bmp"
char tmpTemplate[] = "/tmp/tmp-decodeData.XXXXXX";
char *tmpDirName = mkdtemp(tmpTemplate);

string hevcFileName = tmpDirName;
hevcFileName += "/tmp.hevc";
string bmpFileName = tmpDirName;
bmpFileName += "/tmp.bmp";

ofstream hevcFile(hevcFileName);
if (!hevcFile.is_open()) {
cerr << "could not open " << hevcFileName << " for writing HEVC\n";
Expand All @@ -54,18 +59,28 @@ static void decodeData(ImageFileReaderInterface::DataVector data, Magick::Image
remove(hevcFileName.c_str());
if (retval != 0) {
cerr << "ffmpeg failed with exit code " << retval << endl;
string rm = "rmdir ";
rm += tmpDirName;
system(rm.c_str());
exit(1);
}
if (VERBOSE) {
cout << "[timing] ffmpeg " << chrono::duration_cast<chrono::milliseconds>(end - begin).count() << "ms" << endl;
}
*image = Magick::Image(bmpFileName);
remove(bmpFileName.c_str());
string rm = "rmdir ";
rm += tmpDirName;
system(rm.c_str());
}

static void addExif(ImageFileReaderInterface::DataVector exifData, string fileName)
{
string exifFileName = tmpnam(nullptr);
char tmpTemplate[] = "/tmp/tmp-addExif.XXXXXX";
char *tmpDirName = mkdtemp(tmpTemplate);

string exifFileName = tmpDirName;
exifFileName += "/tmp.exif";
ofstream exifFile(exifFileName);
if (!exifFile.is_open()) {
cerr << "could not open " << exifFileName << " for writing EXIF\n";
Expand All @@ -84,6 +99,9 @@ static void addExif(ImageFileReaderInterface::DataVector exifData, string fileNa
int retval = system(("exiftool -m -overwrite_original " + fileName + " -tagsFromFile " + exifFileName).c_str());
chrono::steady_clock::time_point end = chrono::steady_clock::now();
remove(exifFileName.c_str());
string rm = "rmdir ";
rm += tmpDirName;
system(rm.c_str());
if (retval != 0) {
cerr << "exiftool failed with exit code " << retval << endl;
exit(1);
Expand Down

0 comments on commit 5c5538f

Please sign in to comment.