14 # include <sys/ioctl.h>
17 # include <sys/param.h>
18 # include <sys/stat.h>
22 # include <sys/stat.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
100 size_t bytesWritten = fwrite(bdata.data(), 1, bdata.size(),
m_handle);
161 if (_wunlink(
m_filename.toStdWString().c_str()) != 0)
194 m_handle = _wfopen(filename.toStdWString().c_str(), L
"w+b");
211 if (realpath(filename.c_str(), fullpath) == NULL)
267 while (remaining > 0)
269 if (remaining >= 512)
333 XsSize needleLength = needleV.size();
336 if (needleLength == 0)
339 const char* needle = (
const char*) needleV.data();
351 while (readBytes > 0)
356 while (bufferPos < readBytes && needlePos < needleLength)
358 if (
buffer[bufferPos] == needle[needlePos])
368 if (
buffer[bufferPos] == needle[0])
376 if (needlePos < needleLength)
404 if (_wstat(
m_filename.toStdWString().c_str(), &stats) == 0)
482 char* bufferRoot = (
char*) malloc(bsize*2);
485 char* buffer1 = bufferRoot;
486 char* buffer2 = bufferRoot+bsize;
492 if (
data.size() == 0)
496 read1 = fread(buffer1, 1, bsize,
m_handle);
498 read1 = fread(buffer1, 1, (
size_t) remaining,
m_handle);
507 btemp = buffer1; buffer1 = buffer2; buffer2 = btemp;
511 read1 = fread(buffer1, 1, bsize,
m_handle);
513 read1 = fread(buffer1, 1, (
size_t) remaining,
m_handle);
520 wPos += fwrite(buffer2, 1, read2,
m_handle);
525 wPos += fwrite(buffer1, 1, read1,
m_handle);
552 m_handle = _wfopen(filename.toStdWString().c_str(), L
"rb");
558 m_handle = _wfopen(filename.toStdWString().c_str(), L
"r+b");
566 m_handle = _wfopen(filename.toStdWString().c_str(), L
"w+b");
573 m_handle = _wfopen(filename.toStdWString().c_str(), L
"rb");
591 if (realpath(filename.c_str(), fullpath) == NULL)
667 char *
data = (
char *) bdata.data();
685 if ((
unsigned char) readChar == terminator)
763 if (writeRes == (
size_t)EOF || writeRes <
length)
XsResultValue appendData(const XsByteArray &bdata)
Write data to the end of the file.
XsResultValue getLastResult(void) const
Return the result code of the last operation.
XsResultValue getName(XsString &filename) const
Retrieve the filename that was last successfully opened.
void gotoRead(void)
Change from writing to reading mode.
XsResultValue deleteData(XsFilePos start, XsSize length)
Delete the given data from the file.
XsFileHandle * m_handle
The file handlem, also indicates if the file is open or not.
XsResultValue open(const XsString &filename, bool createNew, bool readOnly)
Open a file.
XsString m_filename
Contains the name of the file that was last successfully opened.
bool m_reading
Indicates whether the last operation was a read or write operation.
XsResultValue writeData(const XsByteArray &data, XsSize *written=NULL)
Write the data contained in data to the device.
bool isOpen(void) const
Return whether the file is open or not.
XsTimeStamp getFileDate(void) const
Return the creation date of the file.
XsResultValue insertData(XsFilePos start, const XsByteArray &data)
Insert the given data into the file.
XsResultValue closeFile(void)
Close the file.
XsFilePos getReadPosition(void) const
Return the current read position.
XsResultValue closeAndDelete(void)
Close the file and delete it.
XsResultValue close(void)
Close the file, overrides IoInterface::close().
XsResultValue readData(XsSize maxLength, XsByteArray &data)
Read at most maxLength bytes from the device into data.
XsResultValue setReadPosition(XsFilePos pos)
Set the new absolute read position.
XsResultValue create(const XsString &filename)
Create an empty file.
XsResultValue flushData(void)
Flush all data in the buffers to and from the device.
XsResultValue setWritePosition(XsFilePos pos=-1)
Set the new absolute write position.
XsFilePos getFileSize(void) const
Return the size of the file.
bool isReadOnly(void) const
Return whether the file is readonly or not.
XsFilePos m_writePos
The last write position in the file.
XsResultValue m_lastResult
The last result of an operation.
XsFilePos m_fileSize
Contains the size of the file.
XsFilePos m_readPos
The last read position in the file.
XsResultValue find(const XsByteArray &data, XsFilePos &pos)
Find a string of bytes in the file.
void gotoWrite(void)
Change from reading to writing mode.
bool m_readOnly
Indicates if the file was opened in read-only mode.
XsResultValue readTerminatedData(XsSize maxLength, unsigned char terminator, XsByteArray &bdata)
Read data from the file and put it into the data buffer.
XsFilePos getWritePosition(void) const
Return the current write position.
GLsizei GLsizei GLenum GLenum const GLvoid * data
GLuint GLsizei GLsizei * length
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
__int64 XsFilePos
The type that is used for positioning inside a file.
XsResultValue
Xsens result values.
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
int BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
#define XS_MAX_FILENAME_LENGTH
unsigned __int32 uint32_t
Class for managing timestamps in a unified way.
struct XsByteArray XsByteArray
@ XRV_BUSY
Busy processing, try again later.
@ XRV_ALREADYOPEN
An I/O device is already opened with this object.
@ XRV_INPUTCANNOTBEOPENED
The specified i/o device can not be opened.
@ XRV_ENDOFFILE
End of file is reached.
@ XRV_INVALIDINSTANCE
Invalid instance called.
@ XRV_NOFILEOPEN
No file opened for reading/writing.
@ XRV_OUTPUTCANNOTBEOPENED
The specified i/o device can not be opened.
@ XRV_INSUFFICIENTSPACE
Insufficient buffer space available.
@ XRV_ERROR
A generic error occurred.
@ XRV_OUTOFMEMORY
No internal memory available.
@ XRV_OK
Operation was performed successfully.
@ XRV_INVALIDPARAM
An invalid parameter is supplied.
@ XRV_READONLY
Tried to change a read-only value.
struct XsTimeStamp XsTimeStamp
size_t XsSize
XsSize must be unsigned number!