29 |
|
|
30 |
#include "helper.h" |
#include "helper.h" |
31 |
|
|
32 |
|
#if POSIX |
33 |
|
# include <errno.h> |
34 |
|
#endif |
35 |
|
|
36 |
namespace RIFF { |
namespace RIFF { |
37 |
|
|
38 |
// *************** Internal functions ************** |
// *************** Internal functions ************** |
1551 |
ResizedChunks.push_back(reinterpret_cast<Chunk*>(new std::set<Chunk*>)); |
ResizedChunks.push_back(reinterpret_cast<Chunk*>(new std::set<Chunk*>)); |
1552 |
#if POSIX |
#if POSIX |
1553 |
hFileRead = hFileWrite = open(path.c_str(), O_RDONLY | O_NONBLOCK); |
hFileRead = hFileWrite = open(path.c_str(), O_RDONLY | O_NONBLOCK); |
1554 |
if (hFileRead <= 0) { |
if (hFileRead == -1) { |
1555 |
hFileRead = hFileWrite = 0; |
hFileRead = hFileWrite = 0; |
1556 |
throw RIFF::Exception("Can't open \"" + path + "\""); |
String sError = strerror(errno); |
1557 |
|
throw RIFF::Exception("Can't open \"" + path + "\": " + sError); |
1558 |
} |
} |
1559 |
#elif defined(WIN32) |
#elif defined(WIN32) |
1560 |
hFileRead = hFileWrite = CreateFile( |
hFileRead = hFileWrite = CreateFile( |
1631 |
#if POSIX |
#if POSIX |
1632 |
if (hFileRead) close(hFileRead); |
if (hFileRead) close(hFileRead); |
1633 |
hFileRead = hFileWrite = open(Filename.c_str(), O_RDONLY | O_NONBLOCK); |
hFileRead = hFileWrite = open(Filename.c_str(), O_RDONLY | O_NONBLOCK); |
1634 |
if (hFileRead < 0) { |
if (hFileRead == -1) { |
1635 |
hFileRead = hFileWrite = 0; |
hFileRead = hFileWrite = 0; |
1636 |
throw Exception("Could not (re)open file \"" + Filename + "\" in read mode"); |
String sError = strerror(errno); |
1637 |
|
throw Exception("Could not (re)open file \"" + Filename + "\" in read mode: " + sError); |
1638 |
} |
} |
1639 |
#elif defined(WIN32) |
#elif defined(WIN32) |
1640 |
if (hFileRead != INVALID_HANDLE_VALUE) CloseHandle(hFileRead); |
if (hFileRead != INVALID_HANDLE_VALUE) CloseHandle(hFileRead); |
1661 |
#if POSIX |
#if POSIX |
1662 |
if (hFileRead) close(hFileRead); |
if (hFileRead) close(hFileRead); |
1663 |
hFileRead = hFileWrite = open(Filename.c_str(), O_RDWR | O_NONBLOCK); |
hFileRead = hFileWrite = open(Filename.c_str(), O_RDWR | O_NONBLOCK); |
1664 |
if (hFileRead < 0) { |
if (hFileRead == -1) { |
1665 |
hFileRead = hFileWrite = open(Filename.c_str(), O_RDONLY | O_NONBLOCK); |
hFileRead = hFileWrite = open(Filename.c_str(), O_RDONLY | O_NONBLOCK); |
1666 |
throw Exception("Could not open file \"" + Filename + "\" in read+write mode"); |
String sError = strerror(errno); |
1667 |
|
throw Exception("Could not open file \"" + Filename + "\" in read+write mode: " + sError); |
1668 |
} |
} |
1669 |
#elif defined(WIN32) |
#elif defined(WIN32) |
1670 |
if (hFileRead != INVALID_HANDLE_VALUE) CloseHandle(hFileRead); |
if (hFileRead != INVALID_HANDLE_VALUE) CloseHandle(hFileRead); |
1854 |
// open the other (new) file for writing and truncate it to zero size |
// open the other (new) file for writing and truncate it to zero size |
1855 |
#if POSIX |
#if POSIX |
1856 |
hFileWrite = open(path.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP); |
hFileWrite = open(path.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP); |
1857 |
if (hFileWrite < 0) { |
if (hFileWrite == -1) { |
1858 |
hFileWrite = hFileRead; |
hFileWrite = hFileRead; |
1859 |
throw Exception("Could not open file \"" + path + "\" for writing"); |
String sError = strerror(errno); |
1860 |
|
throw Exception("Could not open file \"" + path + "\" for writing: " + sError); |
1861 |
} |
} |
1862 |
#elif defined(WIN32) |
#elif defined(WIN32) |
1863 |
hFileWrite = CreateFile( |
hFileWrite = CreateFile( |