MRPT  1.9.9
iointerfacefile.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #include "iointerfacefile.h"
10 
11 #include <errno.h>
12 #ifndef _WIN32
13 #include <unistd.h> // close
14 #include <sys/ioctl.h> // ioctl
15 #include <fcntl.h> // open, O_RDWR
16 #include <string.h> // strcpy
17 #include <sys/param.h>
18 #include <sys/stat.h>
19 #include <stdarg.h>
20 #else
21 #include <winbase.h>
22 #include <sys/stat.h>
23 #include <io.h>
24 #endif
25 
26 #ifndef _CRT_SECURE_NO_DEPRECATE
27 #define _CRT_SECURE_NO_DEPRECATE
28 #ifdef _WIN32
29 #pragma warning(disable : 4996)
30 #endif
31 #endif
32 
33 // lint -emacro(534, FSEEK, FSEEK_R)
34 // lint -emacro({534}, FSEEK, FSEEK_R)
35 #ifdef _WIN32
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)
39 #else
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)
43 #endif
44 
45 // maybe log to nothing at this level
46 #ifdef LOG_CMT1
47 #include "xslog.h"
48 #define XDA1LOG_OBSOLETE XSENSLOG
49 #else
50 #define XDA1LOG_OBSOLETE(...) (void)0
51 #endif
52 
53 //////////////////////////////////////////////////////////////////////////////////////////
54 ///////////////////////////////////////// IoInterfaceFile
55 ////////////////////////////////////////////
56 //////////////////////////////////////////////////////////////////////////////////////////
57 
58 /*! Default constructor, initializes all members to their default values.
59 */
61 {
62  m_readPos = 0;
63  m_writePos = 0;
65  m_reading = true;
66  m_fileSize = 0;
67  m_readOnly = false;
68  m_handle = 0;
69 }
70 
71 /*! Destructor
72 */
74 {
75  try
76  {
77  closeFile(); // lint !e534
78  }
79  catch (...)
80  {
81  }
82 }
83 
84 /*! \brief Write data to the end of the file.
85  \details The function writes the given data to the file at the end. The
86  current write
87  position is also moved to the end of the file.
88  \param bdata The byte data to append to the file
89  \returns XRV_OK if the write was successful
90 */
92 {
93  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
94  if (m_readOnly) return m_lastResult = XRV_READONLY;
95  if (!bdata.size()) return m_lastResult = XRV_OK;
96 
98  {
99  m_reading = false;
100  FSEEK_R(0); // lint !e534
101  }
102  size_t bytesWritten = fwrite(bdata.data(), 1, bdata.size(), m_handle);
103  (void)bytesWritten;
104  m_writePos = FTELL();
106 
107  return (m_lastResult = XRV_OK);
108 }
109 
110 //////////////////////////////////////////////////////////////////////////////////////////
111 /*! \brief Close the file, overrides IoInterface::close().
112  \returns XRV_OK if the file was closed successfully
113 */
115 /*! \brief Close the file.
116  \returns XRV_OK if the file was closed successfully
117 */
119 {
120  if (m_handle)
121  {
122 #ifdef _WIN32
123  fflush(m_handle);
124  fclose(m_handle);
125 #else
126  ::fflush(m_handle);
128 #endif
129  }
130  m_readPos = 0;
131  m_writePos = 0;
132  m_reading = true;
133  m_fileSize = 0;
134  m_readOnly = false;
135  m_handle = 0;
136 
137  return m_lastResult = XRV_OK;
138 }
139 
140 /*! \brief Close the file and delete it.
141  \returns XRV_OK if the file was closed and deleted successfully
142 */
144 {
145  if (m_handle)
146  {
147 #ifdef _WIN32
148  fflush(m_handle);
149  fclose(m_handle);
150 #else
151  ::fflush(m_handle);
153 #endif
154  if (m_readOnly)
156  else
157  {
158 #ifdef _WIN32
159  if (_wunlink(m_filename.toStdWString().c_str()) != 0)
160 #else
161  if (unlink(m_filename.c_str()) != 0)
162 #endif
164  else
166  }
167  }
168  else
170 
171  m_readPos = 0;
172  m_writePos = 0;
173  m_reading = true;
174  m_fileSize = 0;
175  m_readOnly = false;
176  m_handle = 0;
177 
178  return m_lastResult;
179 }
180 
181 /*! \brief Create an empty file
182  \param filename The desired (path+)name of the file
183  \returns XRV_OK if the file was created successfully
184 */
186 {
187  if (m_handle) return m_lastResult = XRV_ALREADYOPEN;
188 
189 //! \test does this work for non-existing files? Or do we need a check and
190 //! create?
191 #ifdef _WIN32
192  m_handle = _wfopen(
193  filename.toStdWString().c_str(), L"w+b"); // open for update (r/w)
194 #else
195  m_handle = fopen(filename.c_str(), "w+b"); // open for update (r/w)
196 #endif
197  if (m_handle == nullptr) return m_lastResult = XRV_OUTPUTCANNOTBEOPENED;
198 
199  bool fail = false;
200 #ifdef _WIN32
201  wchar_t fullpath[XS_MAX_FILENAME_LENGTH];
202  if (_wfullpath(
203  fullpath, filename.toStdWString().c_str(),
204  XS_MAX_FILENAME_LENGTH) == nullptr)
205  fail = true;
206 #else
207  // based on the assumption that this doesn't concern the serial port, handle
208  // it the same way using realpath(). Apparently realpath() doesn't require a
209  // maximum length. One would possibly want to write a wrapper for it.
210  char fullpath[XS_MAX_FILENAME_LENGTH * 2];
211  if (realpath(filename.c_str(), fullpath) == nullptr) fail = true;
212 #endif
213  m_filename = XsString(fullpath);
214 
215  if (fail)
216  {
217  fclose(m_handle);
218 #ifdef _WIN32
219  _wunlink(m_filename.toStdWString().c_str());
220 #else
221  unlink(m_filename.c_str());
222 #endif
223  m_handle = 0;
225  }
226 
227  m_readPos = 0;
228  m_writePos = 0;
229  m_fileSize = 0;
230  m_reading = true;
231  m_readOnly = false;
232  return m_lastResult = XRV_OK;
233 }
234 
235 /*! \brief Delete the given data from the file.
236  \details The function erases the given data from the file at the given write
237  position. This
238  operation may take a while to complete, but is faster than insertData.
239 
240  The write position is not changed and the read position is checked for
241  validity upon function exit.
242  \param start The offset of the first byte to delete
243  \param length The total number of bytes to delete
244  \returns XRV_OK if the data was deleted successfully
245 */
247 {
248  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
249  if (m_readOnly) return m_lastResult = XRV_READONLY;
250 
251  gotoWrite();
252 
253  XsFilePos wPos = start;
254  XsFilePos rPos = wPos + length;
255 
256  size_t read1;
257  XsFilePos endPos = (start + (XsFilePos)length);
258  if (endPos < m_fileSize)
259  {
260  XsFilePos remaining = m_fileSize - endPos;
261  char buffer[512];
262 
263  // copy data
264  FSEEK(rPos);
265 
266  while (remaining > 0)
267  {
268  if (remaining >= 512)
269  read1 = fread(buffer, 1, 512, m_handle);
270  else
271  read1 = fread(buffer, 1, (size_t)remaining, m_handle);
272 
273  remaining -= read1;
274  rPos += read1;
275 
276  // write block to the correct position
277  FSEEK(wPos);
278  wPos += fwrite(buffer, 1, read1, m_handle);
279  FSEEK(rPos);
280  }
281  m_fileSize -= length;
282  }
283  else
284  {
285  m_fileSize = start;
286  }
287 
288 #ifdef _WIN32
289  int32_t rv = _chsize(_fileno(m_handle), (int32_t)m_fileSize);
290 #else
291  int32_t rv = ftruncate(fileno(m_handle), (int32_t)m_fileSize);
292 #endif
293  int32_t eno = 0;
294  if (rv != 0) eno = errno;
295  m_writePos = start;
296  FSEEK(wPos);
297  if (rv != 0)
298  {
299  switch (eno)
300  {
301  case EACCES:
302  return m_lastResult = XRV_BUSY;
303  case EBADF:
305  case ENOSPC:
306  return m_lastResult = XRV_OUTOFMEMORY;
307  case EINVAL:
309  default:
310  return m_lastResult = XRV_ERROR;
311  }
312  }
313 
314  return m_lastResult = XRV_OK;
315 }
316 
317 /*! \brief Find a string of bytes in the file
318  \details The function searches from the current read position until the
319  given \c needle is
320  found. If the needle is not found, XsResultValue::NOT_FOUND is returned. The
321  function
322  will update the seek position to the first character of the found needle.
323  \param needleV The byte string to find.
324  \param pos The position where \a needleV was found. This will point to
325  the first character
326  of the found \a needleV.
327  \returns XRV_OK if the data was found, XRV_ENDOFFILE if it wasn't found
328 */
330 {
331  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
332 
333  XsSize needleLength = needleV.size();
334 
335  pos = 0;
336  if (needleLength == 0) return m_lastResult = XRV_OK;
337 
338  const char* needle = (const char*)needleV.data();
339 
340  gotoRead();
341 
342  char buffer[512];
343  uint32_t bufferPos, needlePos = 0;
344  size_t readBytes;
345  if (m_readPos & 0x1FF) // read a block of data
346  readBytes =
347  fread(buffer, 1, (512 - ((size_t)m_readPos & 0x1FF)), m_handle);
348  else
349  readBytes = fread(buffer, 1, 512, m_handle); // read a block of data
350 
351  while (readBytes > 0)
352  {
353  m_readPos += readBytes;
354  bufferPos = 0;
355 
356  while (bufferPos < readBytes && needlePos < needleLength)
357  {
358  if (buffer[bufferPos] == needle[needlePos])
359  {
360  // found a byte
361  ++needlePos;
362  }
363  else
364  {
365  if (needlePos > 0)
366  needlePos = 0;
367  else if (buffer[bufferPos] == needle[0])
368  {
369  // found a byte
370  needlePos = 1;
371  }
372  }
373  ++bufferPos;
374  }
375  if (needlePos < needleLength)
376  readBytes = fread(buffer, 1, 512, m_handle); // read next block
377  else
378  {
379  m_readPos = m_readPos + bufferPos - readBytes -
380  needleLength; // or without needleLength
381  pos = m_readPos; // - needleLength;
382  FSEEK(m_readPos);
383  return m_lastResult = XRV_OK;
384  }
385  }
386  return m_lastResult = XRV_ENDOFFILE;
387 }
388 
389 /*! \brief Return the size of the file.
390  \returns The size of the file.
391 */
393 /*! \brief Return the creation date of the file
394  \returns The creation date of the file
395 */
397 {
398 #ifdef _WIN32
399  struct _stat stats;
400  if (_wstat(m_filename.toStdWString().c_str(), &stats) == 0)
401 #else
402  struct stat stats;
403  if (stat(m_filename.c_str(), &stats) == 0)
404 #endif
405  {
406  XsTimeStamp t = XsTimeStamp((int64_t)stats.st_mtime * 1000);
407  return t;
408  }
409  return XsTimeStamp();
410 }
411 
412 /*! \copydoc IoInterface::flushData */
414 {
415  fflush(m_handle);
416 
417  return m_lastResult = XRV_OK;
418 }
419 
420 /*! \brief Retrieve the filename that was last successfully opened.
421 
422  \param filename The XsString which will contain the filename.
423  \returns XRV_OK
424 */
426 {
427  filename = m_filename;
428  return m_lastResult = XRV_OK;
429 }
430 
431 //! \brief Change from writing to reading mode
433 {
434  if (m_reading) return;
435 
436  fflush(m_handle);
437  FSEEK(m_readPos);
438  m_reading = true;
439 }
440 
441 //! \brief Change from reading to writing mode
443 {
444  if (!m_reading) return;
445 
446  fflush(m_handle);
447  FSEEK(m_writePos);
448  m_reading = false;
449 }
450 
451 /*! \brief Insert the given data into the file.
452  \details The function writes the given data to the file at the current write
453  position. This
454  operation may take a while to complete.
455 
456  The write position is placed at the end of the inserted data.
457  \param start The offset in the file to write the first byte
458  \param data The data to insert in the file
459  \returns XRV_OK if the data was inserted successfully
460 */
463 {
464  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
465  if (m_readOnly) return m_lastResult = XRV_READONLY;
466 
467  gotoWrite();
468 
469  XsSize length = data.size();
470  XsFilePos rPos = start;
471  XsFilePos wPos = rPos + length;
472 
473  size_t read1, read2;
474  XsFilePos remaining = m_fileSize - start;
475  size_t bsize = (length > 512) ? length : 512;
476  char* bufferRoot = (char*)malloc(bsize * 2);
477  if (!bufferRoot) return XRV_OUTOFMEMORY;
478  char* buffer1 = bufferRoot;
479  char* buffer2 = bufferRoot + bsize;
480  char* btemp;
481 
482  // copy data
483  FSEEK(rPos);
484 
485  if (data.size() == 0) return m_lastResult = XRV_OK;
486 
487  if (remaining >= (XsFilePos)bsize)
488  read1 = fread(buffer1, 1, bsize, m_handle);
489  else
490  read1 = fread(buffer1, 1, (size_t)remaining, m_handle);
491 
492  remaining -= read1;
493  rPos += read1;
494 
495  while (remaining > 0)
496  {
497  // move data to correct buffer
498  read2 = read1;
499  btemp = buffer1;
500  buffer1 = buffer2;
501  buffer2 = btemp;
502 
503  // read next block
504  if (remaining >= (XsFilePos)bsize)
505  read1 = fread(buffer1, 1, bsize, m_handle);
506  else
507  read1 = fread(buffer1, 1, (size_t)remaining, m_handle);
508 
509  remaining -= read1;
510  rPos += read1;
511 
512  // write block to the correct position
513  FSEEK(wPos);
514  wPos += fwrite(buffer2, 1, read2, m_handle);
515  FSEEK(rPos);
516  }
517 
518  FSEEK(wPos);
519  wPos += fwrite(buffer1, 1, read1, m_handle);
520 
521  FSEEK(start);
522  m_writePos = start + fwrite(data.data(), 1, length, m_handle);
523  m_fileSize += length;
524 
525  free(bufferRoot);
526  return m_lastResult = XRV_OK;
527 }
528 
529 /*! \brief Open a file.
530  \param filename The name of the file to open
531  \param createNew When true, the file will be created if it doesn't exist yet
532  \param readOnly When true, the file will be marked as read only for
533  %IoInterfaceFile,
534  preventing accidental writes to the file.
535  \returns XRV_OK if the file was opened successfully
536  \sa createFile
537 */
539  const XsString& filename, bool createNew, bool readOnly)
540 {
541  if (m_handle) return m_lastResult = XRV_ALREADYOPEN;
542 
543  //! \test does this work for non-existing files? Or do we need a check and
544  //! create?
545  m_readOnly = readOnly;
546  if (readOnly)
547 #ifdef _WIN32
548  m_handle = _wfopen(
549  filename.toStdWString().c_str(), L"rb"); // open for read only (r)
550 #else
551  m_handle = fopen(filename.c_str(), "rb"); // open for read only (r)
552 #endif
553  else
554 #ifdef _WIN32
555  m_handle = _wfopen(
556  filename.toStdWString().c_str(), L"r+b"); // open for update (r/w)
557 #else
558  m_handle = fopen(filename.c_str(), "r+b"); // open for update (r/w)
559 #endif
560  if (m_handle == nullptr)
561  {
562  if (createNew)
563 #ifdef _win32
564  m_handle = _wfopen(
565  filename.toStdWString().c_str(),
566  L"w+b"); // create for update (r/w)
567 #else
568  m_handle =
569  fopen(filename.c_str(), "w+b"); // create for update (r/w)
570 #endif
571  else
572  {
573 #ifdef _WIN32
574  m_handle = _wfopen(
575  filename.toStdWString().c_str(),
576  L"rb"); // open for read only (r)
577 #else
578  m_handle = fopen(filename.c_str(), "rb"); // open for read only (r)
579 #endif
580  m_readOnly = true;
581  }
582  }
583  if (m_handle == nullptr) return m_lastResult = XRV_INPUTCANNOTBEOPENED;
584 
585  bool fail = false;
586 #ifdef _WIN32
587  wchar_t fullpath[XS_MAX_FILENAME_LENGTH];
588  if (_wfullpath(
589  fullpath, filename.toStdWString().c_str(),
590  XS_MAX_FILENAME_LENGTH) == nullptr)
591  fail = true;
592 #else
593  // use the same trick again.
594  char fullpath[XS_MAX_FILENAME_LENGTH * 2];
595  if (realpath(filename.c_str(), fullpath) == nullptr) fail = true;
596 #endif
597  m_filename = XsString(fullpath);
598 
599  if (fail)
600  {
601  fclose(m_handle);
602  m_handle = 0;
604  }
605 
606  m_readPos = 0;
607  m_writePos = 0;
608  m_reading = true;
609  FSEEK_R(0);
610  m_fileSize = FTELL();
611  FSEEK(0);
612  return (m_lastResult = XRV_OK);
613 }
614 
615 /*! \copydoc IoInterface::readData
616  \note This function reads exactly the number of bytes as requested from the
617  file unless the end
618  of file boundary is encountered.
619 */
621 {
622  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
623 
624  if (maxLength == 0)
625  {
626  data.clear();
627  return m_lastResult = XRV_OK;
628  }
629 
630  XsSize length;
631 
632  gotoRead();
633  data.setSize(maxLength);
634 
635  length = fread(data.data(), 1, maxLength, m_handle);
636  if (feof(m_handle))
637  {
638  data.clear();
639  return (m_lastResult = XRV_ENDOFFILE);
640  }
641 
642  m_readPos += length;
643  if (length < maxLength) data.pop_back(maxLength - length);
644  return m_lastResult = XRV_OK;
645 }
646 
647 /*! \brief Read data from the file and put it into the data buffer.
648 
649  This function reads upp to the number of bytes as requested from the file.
650  The function will also stop if the given terminator character is
651  encountered.
652  The terminator is included in the output buffer.
653  \param maxLength The amount of data that will be read.
654  \param terminator A character that will end the read operation if
655  encountered.
656  \param bdata A buffer that will store the read data.
657  \returns XRV_OK if the data was read successfully
658 */
660  XsSize maxLength, unsigned char terminator, XsByteArray& bdata)
661 {
662  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
663 
664  if (maxLength == 0)
665  {
666  bdata.clear();
667  return m_lastResult = XRV_OK;
668  }
669 
670  bdata.setSize(maxLength);
671  char* data = (char*)bdata.data();
672 
673  XsSize length;
674  int32_t readChar;
675 
676  gotoRead();
677 
678  length = 0;
679  readChar = (uint32_t)fgetc(m_handle);
680 
681  while (!feof(m_handle) && !ferror(m_handle))
682  {
683  data[length] = (char)readChar;
684  ++length;
685  ++m_readPos;
686 
687  if (length >= maxLength) return m_lastResult = XRV_OK;
688  if ((unsigned char)readChar == terminator)
689  {
690  bdata.pop_back(maxLength - length);
691  return m_lastResult = XRV_OK;
692  }
693  }
694  bdata.pop_back(maxLength - length);
695  return m_lastResult = XRV_ENDOFFILE;
696 }
697 
698 /*! \brief Set the new absolute read position
699  \details The read position is checked against the filesize first.
700  \param pos The new read position
701  \returns XRV_OK if the read position was updated successfully
702 */
704 {
705  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
706 
707  if (m_readPos != pos)
708  {
709  m_readPos = pos;
710  if (m_reading) FSEEK(m_readPos);
711  }
712 
713  return m_lastResult = XRV_OK;
714 }
715 
716 /*! \brief Set the new absolute write position
717  \details The write position is checked against the filesize first.
718  \param pos The new write position
719  \returns XRV_OK if the write position was updated successfully
720 */
722 {
723  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
724  if (m_readOnly) return m_lastResult = XRV_READONLY;
725 
726  if (pos == -1)
727  {
728  if (m_reading) m_reading = false;
729  FSEEK_R(0);
730  m_writePos = FTELL();
731  }
732  else
733  {
734  if (m_writePos != pos)
735  {
736  m_writePos = pos;
737  if (!m_reading) FSEEK(m_writePos);
738  }
739  }
740 
741  return m_lastResult = XRV_OK;
742 }
743 
744 /*! \copydoc IoInterface::writeData
745  \note The function writes the given data to the file at the current write
746  position.
747 */
749  const XsByteArray& data, XsSize* written)
750 {
751  if (!m_handle) return m_lastResult = XRV_NOFILEOPEN;
752  if (m_readOnly) return m_lastResult = XRV_READONLY;
753 
754  size_t length = data.size();
755  if (length == 0) return m_lastResult = XRV_OK;
756 
757  gotoWrite();
758  size_t writeRes = fwrite(data.data(), 1, length, m_handle);
759  if (writeRes == (size_t)EOF || writeRes < length)
760  {
761  int32_t err = (int32_t)errno;
762  switch (err)
763  {
764  case 0:
765  break;
766  case ENOSPC:
768  case ENOMEM:
769  return m_lastResult = XRV_OUTOFMEMORY;
770  default:
771  return m_lastResult = XRV_ERROR;
772  }
773  }
774  m_writePos += writeRes;
775  if (written) *written = (uint32_t)writeRes;
776 
778 
779  return m_lastResult = XRV_OK;
780 }
781 
782 /*! \brief Return the current read position.
783  \returns The current read position.
784 */
786 /*! \brief Return the current write position.
787  \returns The current write position.
788 */
790 /*! \brief Return the result code of the last operation.
791  \returns The result code of the last operation.
792 */
794 {
795  return m_lastResult;
796 }
797 
798 /*! \brief Return whether the file is open or not.
799  \returns true if the file is open
800 */
801 bool IoInterfaceFile::isOpen(void) const { return m_handle != nullptr; }
802 /*! \brief Return whether the file is readonly or not.
803  \returns true if the file is readonly
804 */
805 bool IoInterfaceFile::isReadOnly(void) const { return !isOpen() || m_readOnly; }
Operation was performed successfully.
Definition: xsens_std.h:34
XsResultValue getName(XsString &filename) const
Retrieve the filename that was last successfully opened.
#define XS_MAX_FILENAME_LENGTH
Definition: iointerface.h:30
GLdouble GLdouble t
Definition: glext.h:3689
XsResultValue flushData(void)
Flush all data in the buffers to and from the device.
XsResultValue m_lastResult
The last result of an operation.
#define _stat
Definition: filesystem.cpp:48
XsResultValue closeAndDelete(void)
Close the file and delete it.
XsTimeStamp getFileDate(void) const
Return the creation date of the file.
bool isOpen(void) const
Return whether the file is open or not.
int void fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:273
GLuint buffer
Definition: glext.h:3917
XsString m_filename
Contains the name of the file that was last successfully opened.
struct XsByteArray XsByteArray
Definition: xsbytearray.h:25
XsResultValue closeFile(void)
Close the file.
XsFilePos m_writePos
The last write position in the file.
XsResultValue open(const XsString &filename, bool createNew, bool readOnly)
Open a file.
XsFilePos getFileSize(void) const
Return the size of the file.
size_t XsSize
XsSize must be unsigned number!
Definition: xstypedefs.h:19
XsResultValue readData(XsSize maxLength, XsByteArray &data)
Read at most maxLength bytes from the device into data.
XsFilePos getWritePosition(void) const
Return the current write position.
XsFilePos m_fileSize
Contains the size of the file.
bool m_reading
Indicates whether the last operation was a read or write operation.
XsResultValue insertData(XsFilePos start, const XsByteArray &data)
Insert the given data into the file.
XsResultValue getLastResult(void) const
Return the result code of the last operation.
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:27
void gotoRead(void)
Change from writing to reading mode.
__int64 XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:34
__int64 int64_t
Definition: rptypes.h:49
#define FSEEK_R(x)
bool isReadOnly(void) const
Return whether the file is readonly or not.
struct XsTimeStamp XsTimeStamp
Definition: xstimestamp.h:253
Class for managing timestamps in a unified way.
Definition: xstimestamp.h:53
XsResultValue setWritePosition(XsFilePos pos=-1)
Set the new absolute write position.
#define FSEEK(x)
XsResultValue deleteData(XsFilePos start, XsSize length)
Delete the given data from the file.
XsResultValue writeData(const XsByteArray &data, XsSize *written=nullptr)
Write the data contained in data to the device.
__int32 int32_t
Definition: rptypes.h:46
void gotoWrite(void)
Change from reading to writing mode.
XsFileHandle * m_handle
The file handlem, also indicates if the file is open or not.
XsFilePos getReadPosition(void) const
Return the current read position.
#define FTELL()
GLuint GLsizei GLsizei * length
Definition: glext.h:4064
XsResultValue create(const XsString &filename)
Create an empty file.
XsResultValue readTerminatedData(XsSize maxLength, unsigned char terminator, XsByteArray &bdata)
Read data from the file and put it into the data buffer.
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
Definition: os.cpp:255
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
XsResultValue close(void)
Close the file, overrides IoInterface::close().
GLsizei maxLength
Definition: glext.h:4932
XsResultValue find(const XsByteArray &data, XsFilePos &pos)
Find a string of bytes in the file.
GLuint start
Definition: glext.h:3528
struct XsString XsString
Definition: xsstring.h:34
unsigned __int32 uint32_t
Definition: rptypes.h:47
XsResultValue setReadPosition(XsFilePos pos)
Set the new absolute read position.
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
bool m_readOnly
Indicates if the file was opened in read-only mode.
XsFilePos m_readPos
The last read position in the file.
XsResultValue appendData(const XsByteArray &bdata)
Write data to the end of the file.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020