Skip to content

Commit

Permalink
fix windows compilation (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
farindk committed Sep 10, 2024
1 parent 7b7ac8e commit 252ed4a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions libheif/box.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1413,14 +1413,18 @@ void Box_iloc::set_use_tmp_file(bool flag)
{
m_use_tmpfile = flag;
if (flag) {
#if !defined(_WIN32) && !defined(_WIN64)
#if !defined(_WIN32)
strcpy(m_tmp_filename, "/tmp/libheif-XXXXXX");
m_tmpfile_fd = mkstemp(m_tmp_filename);
#else
// TODO Currently unused code. Implement when needed.
assert(false);
# if 0
char tmpname[L_tmpnam_s];
// TODO: check return value (errno_t)
tmpnam_s(tmpname, L_tmpnam_s);
_sopen_s(&m_tmpfile_fd, tmpname, _O_CREAT | _O_TEMPORARY | _O_TRUNC | _O_RDWR, _SH_DENYRW, _S_IREAD | _S_IWRITE);
# endif
#endif
}
}
Expand Down Expand Up @@ -1643,10 +1647,14 @@ Error Box_iloc::append_data(heif_item_id item_ID,
extent.length = data.size();

if (m_use_tmpfile && construction_method==0) {
#if !defined(_WIN32) && !defined(_WIN64)
#if !defined(_WIN32)
ssize_t cnt = ::write(m_tmpfile_fd, data.data(), data.size());
#else
// TODO Currently unused code. Implement when needed.
assert(false);
# if 0
int cnt = _write(m_tmpfile_fd, data.data(), data.size());
# endif
#endif
if (cnt < 0) {
std::stringstream sstr;
Expand Down Expand Up @@ -1904,7 +1912,11 @@ Error Box_iloc::write_mdat_after_iloc(StreamWriter& writer)
#if !defined(_WIN32) && !defined(_WIN64)
ssize_t cnt = ::read(m_tmpfile_fd, data.data(), extent.length);
#else
// TODO Currently unused code. Implement when needed.
assert(false);
# if 0
int cnt = _read(m_tmpfile_fd, data.data(), extent.length);
# endif
#endif
if (cnt<0) {
std::stringstream sstr;
Expand Down

2 comments on commit 252ed4a

@gitoss
Copy link

@gitoss gitoss commented on 252ed4a Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Um, could you have a look at these dummy if-endif again? This commits produces on my end (msys2, clang64):

C:/media-autobuild/build/libheif-GIT/libheif/box.cc:1659:9: error: use of undeclared identifier 'cnt'
 1659 |     if (cnt < 0) {
      |         ^
C:/media-autobuild/build/libheif-GIT/libheif/box.cc:1666:22: error: use of undeclared identifier 'cnt'; did you mean 'int'?
 1666 |     else if ((size_t)cnt != data.size()) {
      |                      ^~~
      |                      int
C:/media-autobuild/build/libheif-GIT/libheif/box.cc:1666:26: error: expected '(' for function-style cast or type construction
 1666 |     else if ((size_t)cnt != data.size()) {
      |                      ~~~ ^
C:/media-autobuild/build/libheif-GIT/libheif/box.cc:1921:15: error: use of undeclared identifier 'cnt'
 1921 |           if (cnt<0) {
      |               ^
C:/media-autobuild/build/libheif-GIT/libheif/box.cc:1928:30: error: use of undeclared identifier 'cnt'; did you mean 'int'?
 1928 |           else if ((uint64_t)cnt != extent.length) {
      |                              ^~~
      |                              int
C:/media-autobuild/build/libheif-GIT/libheif/box.cc:1928:34: error: expected '(' for function-style cast or type construction
 1928 |           else if ((uint64_t)cnt != extent.length) {
      |                              ~~~ ^

@farindk
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes... Fixed now.

Please sign in to comment.