Skip to content

Commit 05f60a7

Browse files
committed
Avoid deprecated WIN32 functions
Signed-off-by: Rosen Penev <[email protected]>
1 parent 376e3f9 commit 05f60a7

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

app/actions.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define _setmode(a, b) \
4343
do { \
4444
} while (false)
45+
#define _fileno fileno
4546
#endif
4647

4748
namespace fs = std::filesystem;
@@ -184,7 +185,7 @@ static int setModeAndPrintStructure(Exiv2::PrintStructureOption option, const st
184185
}
185186
}
186187
} else {
187-
_setmode(fileno(stdout), O_BINARY);
188+
_setmode(_fileno(stdout), O_BINARY);
188189
result = printStructure(std::cout, option, path);
189190
}
190191

@@ -776,7 +777,7 @@ int Extract::run(const std::string& path) {
776777

777778
bool bStdout = (Params::instance().target_ & Params::ctStdInOut) != 0;
778779
if (bStdout) {
779-
_setmode(fileno(stdout), _O_BINARY);
780+
_setmode(_fileno(stdout), _O_BINARY);
780781
}
781782

782783
if (Params::instance().target_ & Params::ctThumb) {
@@ -1780,7 +1781,7 @@ int metacopy(const std::string& source, const std::string& tgt, Exiv2::ImageType
17801781

17811782
// if we used a temporary target, copy it to stdout
17821783
if (rc == 0 && bStdout) {
1783-
_setmode(fileno(stdout), O_BINARY);
1784+
_setmode(_fileno(stdout), O_BINARY);
17841785
if (auto f = std::ifstream(target, std::ios::binary)) {
17851786
std::vector<char> buffer(8 * 1024);
17861787

app/exiv2.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace fs = std::filesystem;
3232
#else
3333
#include <sys/select.h>
3434
#include <unistd.h>
35+
#define _strdup strdup
3536
#endif
3637

3738
// *****************************************************************************
@@ -957,7 +958,7 @@ void Params::getStdin(Exiv2::DataBuf& buf) {
957958
if (stdinBuf.empty()) {
958959
#if defined(_WIN32)
959960
DWORD fdwMode;
960-
_setmode(fileno(stdin), O_BINARY);
961+
_setmode(_fileno(stdin), O_BINARY);
961962
Sleep(300);
962963
if (!GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &fdwMode)) { // failed: stdin has bytes!
963964
#else
@@ -1022,9 +1023,9 @@ int Params::getopt(int argc, char* const Argv[]) {
10221023
for (int i = 0; i < argc; i++) {
10231024
std::string arg(Argv[i]);
10241025
if (longs.contains(arg)) {
1025-
argv[i] = ::strdup(longs.at(arg).c_str());
1026+
argv[i] = _strdup(longs.at(arg).c_str());
10261027
} else {
1027-
argv[i] = ::strdup(Argv[i]);
1028+
argv[i] = _strdup(Argv[i]);
10281029
}
10291030
}
10301031

src/basicio.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
namespace fs = std::filesystem;
4444
#endif
4545

46+
#ifndef _WIN32
47+
#define _fileno fileno
48+
#endif
49+
4650
namespace Exiv2 {
4751

4852
BasicIo::~BasicIo() = default;
@@ -256,7 +260,7 @@ byte* FileIo::mmap(bool isWriteable) {
256260
if (p_->isWriteable_) {
257261
prot |= PROT_WRITE;
258262
}
259-
void* rc = ::mmap(nullptr, p_->mappedLength_, prot, MAP_SHARED, fileno(p_->fp_), 0);
263+
void* rc = ::mmap(nullptr, p_->mappedLength_, prot, MAP_SHARED, _fileno(p_->fp_), 0);
260264
if (MAP_FAILED == rc) {
261265
throw Error(ErrorCode::kerCallFailed, path(), strError(), "mmap");
262266
}
@@ -277,7 +281,7 @@ byte* FileIo::mmap(bool isWriteable) {
277281
flProtect = PAGE_READWRITE;
278282
}
279283
HANDLE hPh = GetCurrentProcess();
280-
auto hFd = reinterpret_cast<HANDLE>(_get_osfhandle(fileno(p_->fp_)));
284+
auto hFd = reinterpret_cast<HANDLE>(_get_osfhandle(_fileno(p_->fp_)));
281285
if (hFd == INVALID_HANDLE_VALUE) {
282286
throw Error(ErrorCode::kerCallFailed, path(), "MSG1", "_get_osfhandle");
283287
}
@@ -917,7 +921,7 @@ std::string XPathIo::writeDataToFile(const std::string& orgPath) {
917921
auto path = stringFormat("{}{}", timestamp, XPathIo::TEMP_FILE_EXT);
918922

919923
if (prot == pStdin) {
920-
if (isatty(fileno(stdin)))
924+
if (isatty(_fileno(stdin)))
921925
throw Error(ErrorCode::kerInputDataReadFailed);
922926
#ifdef _WIN32
923927
// convert stdin to binary

0 commit comments

Comments
 (0)