14 #include <sys/ioctl.h> 15 #include <sys/param.h> 26 #ifndef _CRT_SECURE_NO_DEPRECATE 27 #define _CRT_SECURE_NO_DEPRECATE 29 #pragma warning(disable : 4996) 36 #define FSEEK(x) _fseeki64(m_handle, x, SEEK_SET) 37 #define FSEEK_R(x) _fseeki64(m_handle, x, SEEK_END) 38 #define FTELL() _ftelli64(m_handle) 40 #define FSEEK(x) fseeko(m_handle, x, SEEK_SET) 41 #define FSEEK_R(x) fseeko(m_handle, x, SEEK_END) 42 #define FTELL() ftello(m_handle) 48 #define XDA1LOG_OBSOLETE XSENSLOG 50 #define XDA1LOG_OBSOLETE(...) (void)0 102 size_t bytesWritten = fwrite(bdata.data(), 1, bdata.size(),
m_handle);
159 if (_wunlink(
m_filename.toStdWString().c_str()) != 0)
193 filename.toStdWString().c_str(), L
"w+b");
203 fullpath, filename.toStdWString().c_str(),
211 if (realpath(filename.c_str(), fullpath) ==
nullptr) fail =
true;
266 while (remaining > 0)
268 if (remaining >= 512)
294 if (rv != 0) eno = errno;
333 XsSize needleLength = needleV.size();
338 const char* needle = (
const char*)needleV.data();
351 while (readBytes > 0)
356 while (bufferPos < readBytes && needlePos < needleLength)
358 if (
buffer[bufferPos] == needle[needlePos])
367 else if (
buffer[bufferPos] == needle[0])
375 if (needlePos < needleLength)
400 if (_wstat(
m_filename.toStdWString().c_str(), &stats) == 0)
476 char* bufferRoot = (
char*)malloc(bsize * 2);
478 char* buffer1 = bufferRoot;
479 char* buffer2 = bufferRoot + bsize;
488 read1 = fread(buffer1, 1, bsize,
m_handle);
490 read1 = fread(buffer1, 1, (
size_t)remaining,
m_handle);
495 while (remaining > 0)
505 read1 = fread(buffer1, 1, bsize,
m_handle);
507 read1 = fread(buffer1, 1, (
size_t)remaining,
m_handle);
514 wPos += fwrite(buffer2, 1, read2,
m_handle);
519 wPos += fwrite(buffer1, 1, read1,
m_handle);
539 const XsString& filename,
bool createNew,
bool readOnly)
549 filename.toStdWString().c_str(), L
"rb");
556 filename.toStdWString().c_str(), L
"r+b");
565 filename.toStdWString().c_str(),
569 fopen(filename.c_str(),
"w+b");
575 filename.toStdWString().c_str(),
589 fullpath, filename.toStdWString().c_str(),
595 if (realpath(filename.c_str(), fullpath) ==
nullptr) fail =
true;
671 char*
data = (
char*)bdata.data();
688 if ((
unsigned char)readChar == terminator)
759 if (writeRes == (
size_t)EOF || writeRes <
length)
775 if (written) *written = (
uint32_t)writeRes;
Operation was performed successfully.
#define XS_MAX_FILENAME_LENGTH
XsResultValue setWritePosition(XsFilePos pos=-1) override
Set the new absolute write position.
XsResultValue m_lastResult
The last result of an operation.
XsFilePos getFileSize(void) const override
Return the size of the file.
~IoInterfaceFile() override
XsResultValue readData(XsSize maxLength, XsByteArray &data) override
Read at most maxLength bytes from the device into data.
XsTimeStamp getFileDate(void) const
Return the creation date of the file.
int void fclose(FILE *f)
An OS-independent version of fclose.
XsString m_filename
Contains the name of the file that was last successfully opened.
struct XsByteArray XsByteArray
XsResultValue closeFile(void)
Close the file.
XsFilePos m_writePos
The last write position in the file.
size_t XsSize
XsSize must be unsigned number!
XsResultValue getLastResult(void) const override
Return the result code of the last operation.
XsResultValue appendData(const XsByteArray &bdata) override
Write data to the end of the file.
XsFilePos m_fileSize
Contains the size of the file.
bool m_reading
Indicates whether the last operation was a read or write operation.
XsResultValue
Xsens result values.
void gotoRead(void)
Change from writing to reading mode.
XsFilePos getReadPosition(void) const override
Return the current read position.
__int64 XsFilePos
The type that is used for positioning inside a file.
XsResultValue insertData(XsFilePos start, const XsByteArray &data) override
Insert the given data into the file.
XsResultValue writeData(const XsByteArray &data, XsSize *written=nullptr) override
Write the data contained in data to the device.
XsResultValue close(void) override
Close the file, overrides IoInterface::close().
struct XsTimeStamp XsTimeStamp
XsResultValue flushData(void) override
Flush all data in the buffers to and from the device.
Class for managing timestamps in a unified way.
XsResultValue find(const XsByteArray &data, XsFilePos &pos) override
Find a string of bytes in the file.
XsResultValue closeAndDelete(void) override
Close the file and delete it.
XsResultValue open(const XsString &filename, bool createNew, bool readOnly) override
Open a file.
XsResultValue getName(XsString &filename) const override
Retrieve the filename that was last successfully opened.
void gotoWrite(void)
Change from reading to writing mode.
XsFileHandle * m_handle
The file handlem, also indicates if the file is open or not.
XsResultValue create(const XsString &filename) override
Create an empty file.
GLuint GLsizei GLsizei * length
bool isReadOnly(void) const override
Return whether the file is readonly or not.
XsResultValue readTerminatedData(XsSize maxLength, unsigned char terminator, XsByteArray &bdata)
Read data from the file and put it into the data buffer.
XsResultValue setReadPosition(XsFilePos pos) override
Set the new absolute read position.
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
unsigned __int32 uint32_t
GLsizei GLsizei GLenum GLenum const GLvoid * data
bool m_readOnly
Indicates if the file was opened in read-only mode.
XsResultValue deleteData(XsFilePos start, XsSize length) override
Delete the given data from the file.
bool isOpen(void) const override
Return whether the file is open or not.
XsFilePos getWritePosition(void) const override
Return the current write position.
XsFilePos m_readPos
The last read position in the file.