Main MRPT website > C++ reference for MRPT 1.5.6
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-2017, 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 /*! Default constructor, initializes all members to their default values.
58 */
60 {
61  m_readPos = 0;
62  m_writePos = 0;
64  m_reading = true;
65  m_fileSize = 0;
66  m_readOnly = false;
67  m_handle = 0;
68 }
69 
70 /*! Destructor
71 */
73 {
74  try {
75  closeFile(); //lint !e534
76  } catch(...)
77  {}
78 }
79 
80 /*! \brief Write data to the end of the file.
81  \details The function writes the given data to the file at the end. The current write
82  position is also moved to the end of the file.
83  \param bdata The byte data to append to the file
84  \returns XRV_OK if the write was successful
85 */
87 {
88  if (!m_handle)
90  if (m_readOnly)
91  return m_lastResult = XRV_READONLY;
92  if (!bdata.size())
93  return m_lastResult = XRV_OK;
94 
96  {
97  m_reading = false;
98  FSEEK_R(0); //lint !e534
99  }
100  size_t bytesWritten = fwrite(bdata.data(), 1, bdata.size(), m_handle);
101  (void)bytesWritten;
102  m_writePos = FTELL();
104 
105  return (m_lastResult = XRV_OK);
106 }
107 
108 //////////////////////////////////////////////////////////////////////////////////////////
109 /*! \brief Close the file, overrides IoInterface::close().
110  \returns XRV_OK if the file was closed successfully
111 */
113 {
114  return closeFile();
115 }
116 
117 /*! \brief Close the file.
118  \returns XRV_OK if the file was closed successfully
119 */
121 {
122  if (m_handle)
123  {
124  #ifdef _WIN32
125  fflush(m_handle);
126  fclose(m_handle);
127  #else
128  ::fflush(m_handle);
130  #endif
131  }
132  m_readPos = 0;
133  m_writePos = 0;
134  m_reading = true;
135  m_fileSize = 0;
136  m_readOnly = false;
137  m_handle = 0;
138 
139  return m_lastResult = XRV_OK;
140 }
141 
142 /*! \brief Close the file and delete it.
143  \returns XRV_OK if the file was closed and deleted successfully
144 */
146 {
147  if (m_handle)
148  {
149  #ifdef _WIN32
150  fflush(m_handle);
151  fclose(m_handle);
152  #else
153  ::fflush(m_handle);
155  #endif
156  if (m_readOnly)
158  else
159  {
160 #ifdef _WIN32
161  if (_wunlink(m_filename.toStdWString().c_str()) != 0)
162 #else
163  if (unlink(m_filename.c_str()) != 0)
164 #endif
166  else
168  }
169  }
170  else
172 
173  m_readPos = 0;
174  m_writePos = 0;
175  m_reading = true;
176  m_fileSize = 0;
177  m_readOnly = false;
178  m_handle = 0;
179 
180  return m_lastResult;
181 }
182 
183 /*! \brief Create an empty file
184  \param filename The desired (path+)name of the file
185  \returns XRV_OK if the file was created successfully
186 */
188 {
189  if (m_handle)
190  return m_lastResult = XRV_ALREADYOPEN;
191 
192  //! \test does this work for non-existing files? Or do we need a check and create?
193 #ifdef _WIN32
194  m_handle = _wfopen(filename.toStdWString().c_str(), L"w+b"); // open for update (r/w)
195 #else
196  m_handle = fopen(filename.c_str(), "w+b"); // open for update (r/w)
197 #endif
198  if (m_handle == NULL)
200 
201  bool fail = false;
202 #ifdef _WIN32
203  wchar_t fullpath[XS_MAX_FILENAME_LENGTH];
204  if (_wfullpath(fullpath,filename.toStdWString().c_str(),XS_MAX_FILENAME_LENGTH) == NULL)
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) == NULL)
212  fail = true;
213 #endif
214  m_filename = XsString(fullpath);
215 
216  if (fail)
217  {
218  fclose(m_handle);
219 #ifdef _WIN32
220  _wunlink(m_filename.toStdWString().c_str());
221 #else
222  unlink(m_filename.c_str());
223 #endif
224  m_handle = 0;
226  }
227 
228  m_readPos = 0;
229  m_writePos = 0;
230  m_fileSize = 0;
231  m_reading = true;
232  m_readOnly = false;
233  return m_lastResult = XRV_OK;
234 }
235 
236 /*! \brief Delete the given data from the file.
237  \details The function erases the given data from the file at the given write 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 validity upon function exit.
241  \param start The offset of the first byte to delete
242  \param length The total number of bytes to delete
243  \returns XRV_OK if the data was deleted successfully
244 */
246 {
247  if (!m_handle)
248  return m_lastResult = XRV_NOFILEOPEN;
249  if (m_readOnly)
250  return m_lastResult = XRV_READONLY;
251 
252  gotoWrite();
253 
254  XsFilePos wPos = start;
255  XsFilePos rPos = wPos + length;
256 
257  size_t read1;
258  XsFilePos endPos = (start + (XsFilePos) length);
259  if (endPos < m_fileSize)
260  {
261  XsFilePos remaining = m_fileSize - endPos;
262  char buffer[512];
263 
264  // copy data
265  FSEEK(rPos);
266 
267  while (remaining > 0)
268  {
269  if (remaining >= 512)
270  read1 = fread(buffer,1,512,m_handle);
271  else
272  read1 = fread(buffer,1,(size_t) remaining,m_handle);
273 
274  remaining -= read1;
275  rPos += read1;
276 
277  // write block to the correct position
278  FSEEK(wPos);
279  wPos += fwrite(buffer, 1, read1, m_handle);
280  FSEEK(rPos);
281  }
282  m_fileSize -= length;
283  }
284  else
285  {
286  m_fileSize = start;
287  }
288 
289 #ifdef _WIN32
290  int32_t rv = _chsize(_fileno(m_handle),(int32_t) m_fileSize);
291 #else
292  int32_t rv = ftruncate(fileno(m_handle),(int32_t) m_fileSize);
293 #endif
294  int32_t eno = 0;
295  if (rv != 0)
296  eno = errno;
297  m_writePos = start;
298  FSEEK(wPos);
299  if (rv != 0)
300  {
301  switch(eno)
302  {
303  case EACCES:
304  return m_lastResult = XRV_BUSY;
305  case EBADF:
307  case ENOSPC:
308  return m_lastResult = XRV_OUTOFMEMORY;
309  case EINVAL:
311  default:
312  return m_lastResult = XRV_ERROR;
313  }
314  }
315 
316  return m_lastResult = XRV_OK;
317 }
318 
319 /*! \brief Find a string of bytes in the file
320  \details The function searches from the current read position until the given \c needle is
321  found. If the needle is not found, XsResultValue::NOT_FOUND is returned. The 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 the first character
325  of the found \a needleV.
326  \returns XRV_OK if the data was found, XRV_ENDOFFILE if it wasn't found
327 */
329 {
330  if (!m_handle)
331  return m_lastResult = XRV_NOFILEOPEN;
332 
333  XsSize needleLength = needleV.size();
334 
335  pos = 0;
336  if (needleLength == 0)
337  return m_lastResult = XRV_OK;
338 
339  const char* needle = (const char*) needleV.data();
340 
341  gotoRead();
342 
343  char buffer[512];
344  uint32_t bufferPos, needlePos = 0;
345  size_t readBytes;
346  if (m_readPos & 0x1FF) // read a block of data
347  readBytes = 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
368  if (buffer[bufferPos] == needle[0])
369  {
370  // found a byte
371  needlePos = 1;
372  }
373  }
374  ++bufferPos;
375  }
376  if (needlePos < needleLength)
377  readBytes = fread(buffer, 1, 512, m_handle); // read next block
378  else
379  {
380  m_readPos = m_readPos + bufferPos - readBytes - 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 {
394  return m_fileSize;
395 }
396 
397 /*! \brief Return the creation date of the file
398  \returns The creation date of the file
399 */
401 {
402 #ifdef _WIN32
403  struct _stat stats;
404  if (_wstat(m_filename.toStdWString().c_str(), &stats) == 0)
405 #else
406  struct stat stats;
407  if (stat(m_filename.c_str(), &stats) == 0)
408 #endif
409  {
410  XsTimeStamp t = XsTimeStamp( (int64_t)stats.st_mtime * 1000);
411  return t;
412  }
413  return XsTimeStamp();
414 }
415 
416 /*! \copydoc IoInterface::flushData */
418 {
419  fflush(m_handle);
420 
421  return m_lastResult = XRV_OK;
422 }
423 
424 /*! \brief Retrieve the filename that was last successfully opened.
425 
426  \param filename The XsString which will contain the filename.
427  \returns XRV_OK
428 */
430 {
431  filename = m_filename;
432  return m_lastResult = XRV_OK;
433 }
434 
435 //! \brief Change from writing to reading mode
437 {
438  if (m_reading)
439  return;
440 
441  fflush(m_handle);
442  FSEEK(m_readPos);
443  m_reading = true;
444 }
445 
446 //! \brief Change from reading to writing mode
448 {
449  if (!m_reading)
450  return;
451 
452  fflush(m_handle);
453  FSEEK(m_writePos);
454  m_reading = false;
455 }
456 
457 /*! \brief Insert the given data into the file.
458  \details The function writes the given data to the file at the current write position. This
459  operation may take a while to complete.
460 
461  The write position is placed at the end of the inserted data.
462  \param start The offset in the file to write the first byte
463  \param data The data to insert in the file
464  \returns XRV_OK if the data was inserted successfully
465 */
467 {
468  if (!m_handle)
469  return m_lastResult = XRV_NOFILEOPEN;
470  if (m_readOnly)
471  return m_lastResult = XRV_READONLY;
472 
473  gotoWrite();
474 
475  XsSize length = data.size();
476  XsFilePos rPos = start;
477  XsFilePos wPos = rPos + length;
478 
479  size_t read1, read2;
480  XsFilePos remaining = m_fileSize - start;
481  size_t bsize = (length > 512)?length:512;
482  char* bufferRoot = (char*) malloc(bsize*2);
483  if (!bufferRoot)
484  return XRV_OUTOFMEMORY;
485  char* buffer1 = bufferRoot;
486  char* buffer2 = bufferRoot+bsize;
487  char* btemp;
488 
489  // copy data
490  FSEEK(rPos);
491 
492  if (data.size() == 0)
493  return m_lastResult = XRV_OK;
494 
495  if (remaining >= (XsFilePos) bsize)
496  read1 = fread(buffer1, 1, bsize, m_handle);
497  else
498  read1 = fread(buffer1, 1, (size_t) remaining, m_handle);
499 
500  remaining -= read1;
501  rPos += read1;
502 
503  while(remaining > 0)
504  {
505  // move data to correct buffer
506  read2 = read1;
507  btemp = buffer1; buffer1 = buffer2; buffer2 = btemp;
508 
509  // read next block
510  if (remaining >= (XsFilePos) bsize)
511  read1 = fread(buffer1, 1, bsize, m_handle);
512  else
513  read1 = fread(buffer1, 1, (size_t) remaining, m_handle);
514 
515  remaining -= read1;
516  rPos += read1;
517 
518  // write block to the correct position
519  FSEEK(wPos);
520  wPos += fwrite(buffer2, 1, read2, m_handle);
521  FSEEK(rPos);
522  }
523 
524  FSEEK(wPos);
525  wPos += fwrite(buffer1, 1, read1, m_handle);
526 
527  FSEEK(start);
528  m_writePos = start + fwrite(data.data(), 1, length, m_handle);
529  m_fileSize += length;
530 
531  free(bufferRoot);
532  return m_lastResult = XRV_OK;
533 }
534 
535 /*! \brief Open a file.
536  \param filename The name of the file to open
537  \param createNew When true, the file will be created if it doesn't exist yet
538  \param readOnly When true, the file will be marked as read only for %IoInterfaceFile,
539  preventing accidental writes to the file.
540  \returns XRV_OK if the file was opened successfully
541  \sa createFile
542 */
543 XsResultValue IoInterfaceFile::open(const XsString& filename, bool createNew, bool readOnly)
544 {
545  if (m_handle)
546  return m_lastResult = XRV_ALREADYOPEN;
547 
548  //! \test does this work for non-existing files? Or do we need a check and create?
549  m_readOnly = readOnly;
550  if (readOnly)
551 #ifdef _WIN32
552  m_handle = _wfopen(filename.toStdWString().c_str(), L"rb"); // open for read only (r)
553 #else
554  m_handle = fopen(filename.c_str(), "rb"); // open for read only (r)
555 #endif
556  else
557 #ifdef _WIN32
558  m_handle = _wfopen(filename.toStdWString().c_str(), L"r+b"); // open for update (r/w)
559 #else
560  m_handle = fopen(filename.c_str(), "r+b"); // open for update (r/w)
561 #endif
562  if (m_handle == NULL)
563  {
564  if (createNew)
565 #ifdef _win32
566  m_handle = _wfopen(filename.toStdWString().c_str(), L"w+b"); // create for update (r/w)
567 #else
568  m_handle = fopen(filename.c_str(), "w+b"); // create for update (r/w)
569 #endif
570  else
571  {
572 #ifdef _WIN32
573  m_handle = _wfopen(filename.toStdWString().c_str(), L"rb"); // open for read only (r)
574 #else
575  m_handle = fopen(filename.c_str(), "rb"); // open for read only (r)
576 #endif
577  m_readOnly = true;
578  }
579  }
580  if (m_handle == NULL)
582 
583  bool fail = false;
584 #ifdef _WIN32
585  wchar_t fullpath[XS_MAX_FILENAME_LENGTH];
586  if (_wfullpath(fullpath,filename.toStdWString().c_str(),XS_MAX_FILENAME_LENGTH) == NULL)
587  fail = true;
588 #else
589  // use the same trick again.
590  char fullpath[XS_MAX_FILENAME_LENGTH*2];
591  if (realpath(filename.c_str(), fullpath) == NULL)
592  fail = true;
593 #endif
594  m_filename = XsString(fullpath);
595 
596  if (fail)
597  {
598  fclose(m_handle);
599  m_handle = 0;
601  }
602 
603  m_readPos = 0;
604  m_writePos = 0;
605  m_reading = true;
606  FSEEK_R(0);
607  m_fileSize = FTELL();
608  FSEEK(0);
609  return (m_lastResult = XRV_OK);
610 }
611 
612 /*! \copydoc IoInterface::readData
613  \note This function reads exactly the number of bytes as requested from the file unless the end
614  of file boundary is encountered.
615 */
617 {
618  if (!m_handle)
619  return m_lastResult = XRV_NOFILEOPEN;
620 
621  if (maxLength == 0)
622  {
623  data.clear();
624  return m_lastResult = XRV_OK;
625  }
626 
627  XsSize length;
628 
629  gotoRead();
630  data.setSize(maxLength);
631 
632  length = fread(data.data(), 1, maxLength, m_handle);
633  if (feof(m_handle))
634  {
635  data.clear();
636  return (m_lastResult = XRV_ENDOFFILE);
637  }
638 
639  m_readPos += length;
640  if (length < maxLength)
641  data.pop_back(maxLength - length);
642  return m_lastResult = XRV_OK;
643 }
644 
645 /*! \brief Read data from the file and put it into the data buffer.
646 
647  This function reads upp to the number of bytes as requested from the file.
648  The function will also stop if the given terminator character is encountered.
649  The terminator is included in the output buffer.
650  \param maxLength The amount of data that will be read.
651  \param terminator A character that will end the read operation if encountered.
652  \param bdata A buffer that will store the read data.
653  \returns XRV_OK if the data was read successfully
654 */
656 {
657  if (!m_handle)
658  return m_lastResult = XRV_NOFILEOPEN;
659 
660  if (maxLength == 0)
661  {
662  bdata.clear();
663  return m_lastResult = XRV_OK;
664  }
665 
666  bdata.setSize(maxLength);
667  char *data = (char *) bdata.data();
668 
669  XsSize length;
670  int32_t readChar;
671 
672  gotoRead();
673 
674  length = 0;
675  readChar = (uint32_t) fgetc(m_handle);
676 
677  while (!feof(m_handle) && !ferror(m_handle))
678  {
679  data[length] = (char) readChar;
680  ++length;
681  ++m_readPos;
682 
683  if (length >= maxLength)
684  return m_lastResult = XRV_OK;
685  if ((unsigned char) readChar == terminator)
686  {
687  bdata.pop_back(maxLength - length);
688  return m_lastResult = XRV_OK;
689  }
690  }
691  bdata.pop_back(maxLength - length);
692  return m_lastResult = XRV_ENDOFFILE;
693 }
694 
695 /*! \brief Set the new absolute read position
696  \details The read position is checked against the filesize first.
697  \param pos The new read position
698  \returns XRV_OK if the read position was updated successfully
699 */
701 {
702  if (!m_handle)
703  return m_lastResult = XRV_NOFILEOPEN;
704 
705  if (m_readPos != pos)
706  {
707  m_readPos = pos;
708  if (m_reading)
709  FSEEK(m_readPos);
710  }
711 
712  return m_lastResult = XRV_OK;
713 }
714 
715 /*! \brief Set the new absolute write position
716  \details The write position is checked against the filesize first.
717  \param pos The new write position
718  \returns XRV_OK if the write position was updated successfully
719 */
721 {
722  if (!m_handle)
723  return m_lastResult = XRV_NOFILEOPEN;
724  if (m_readOnly)
725  return m_lastResult = XRV_READONLY;
726 
727  if (pos == -1)
728  {
729  if (m_reading)
730  m_reading = false;
731  FSEEK_R(0);
732  m_writePos = FTELL();
733  }
734  else
735  {
736  if (m_writePos != pos)
737  {
738  m_writePos = pos;
739  if (!m_reading)
740  FSEEK(m_writePos);
741  }
742  }
743 
744  return m_lastResult = XRV_OK;
745 }
746 
747 /*! \copydoc IoInterface::writeData
748  \note The function writes the given data to the file at the current write position.
749 */
751 {
752  if (!m_handle)
753  return m_lastResult = XRV_NOFILEOPEN;
754  if (m_readOnly)
755  return m_lastResult = XRV_READONLY;
756 
757  size_t length = data.size();
758  if (length == 0)
759  return m_lastResult = XRV_OK;
760 
761  gotoWrite();
762  size_t writeRes = fwrite(data.data(), 1, length, m_handle);
763  if (writeRes == (size_t)EOF || writeRes < length)
764  {
765  int32_t err = (int32_t)errno;
766  switch (err)
767  {
768  case 0: break;
769  case ENOSPC: return m_lastResult = XRV_INSUFFICIENTSPACE;
770  case ENOMEM: return m_lastResult = XRV_OUTOFMEMORY;
771  default: return m_lastResult = XRV_ERROR;
772  }
773  }
774  m_writePos += writeRes;
775  if (written)
776  *written = (uint32_t)writeRes;
777 
778  if (m_writePos > m_fileSize)
780 
781  return m_lastResult = XRV_OK;
782 }
783 
784 /*! \brief Return the current read position.
785  \returns The current read position.
786 */
788 {
789  return m_readPos;
790 }
791 
792 /*! \brief Return the current write position.
793  \returns The current write position.
794 */
796 {
797  return m_writePos;
798 }
799 
800 /*! \brief Return the result code of the last operation.
801  \returns The result code of the last operation.
802 */
804 {
805  return m_lastResult;
806 }
807 
808 /*! \brief Return whether the file is open or not.
809  \returns true if the file is open
810 */
811 bool IoInterfaceFile::isOpen(void) const
812 {
813  return m_handle != NULL;
814 }
815 
816 /*! \brief Return whether the file is readonly or not.
817  \returns true if the file is readonly
818 */
820 {
821  return !isOpen() || m_readOnly;
822 }
823 
Operation was performed successfully.
Definition: xsens_std.h:32
XsResultValue getName(XsString &filename) const
Retrieve the filename that was last successfully opened.
FILE BASE_IMPEXP * fopen(const char *fileName, const char *mode) MRPT_NO_THROWS
An OS-independent version of fopen.
Definition: os.cpp:255
#define XS_MAX_FILENAME_LENGTH
Definition: iointerface.h:30
GLdouble GLdouble t
Definition: glext.h:3610
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:47
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 BASE_IMPEXP void BASE_IMPEXP fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:272
GLuint buffer
Definition: glext.h:3775
XsString m_filename
Contains the name of the file that was last successfully opened.
struct XsByteArray XsByteArray
Definition: xsbytearray.h:25
The specified i/o device can not be opened.
Definition: xsens_std.h:69
The specified i/o device can not be opened.
Definition: xsens_std.h:70
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:17
XsResultValue readData(XsSize maxLength, XsByteArray &data)
Read at most maxLength bytes from the device into data.
No internal memory available.
Definition: xsens_std.h:63
XsFilePos getWritePosition(void) const
Return the current write position.
XsFilePos m_fileSize
Contains the size of the file.
Insufficient buffer space available.
Definition: xsens_std.h:68
End of file is reached.
Definition: xsens_std.h:72
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.
Tried to change a read-only value.
Definition: xsens_std.h:75
XsResultValue getLastResult(void) const
Return the result code of the last operation.
XsResultValue
Xsens result values.
Definition: xsresultvalue.h:26
void gotoRead(void)
Change from writing to reading mode.
__int64 XsFilePos
The type that is used for positioning inside a file.
Definition: xsfilepos.h:33
__int64 int64_t
Definition: rptypes.h:51
#define FSEEK_R(x)
bool isReadOnly(void) const
Return whether the file is readonly or not.
struct XsTimeStamp XsTimeStamp
Definition: xstimestamp.h:227
Class for managing timestamps in a unified way.
Definition: xstimestamp.h:43
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.
__int32 int32_t
Definition: rptypes.h:48
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 writeData(const XsByteArray &data, XsSize *written=NULL)
Write the data contained in data to the device.
XsFilePos getReadPosition(void) const
Return the current read position.
#define FTELL()
GLuint GLsizei GLsizei * length
Definition: glext.h:3900
Invalid instance called.
Definition: xsens_std.h:79
An invalid parameter is supplied.
Definition: xsens_std.h:53
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.
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
XsResultValue close(void)
Close the file, overrides IoInterface::close().
A generic error occurred.
Definition: xsens_std.h:58
GLsizei maxLength
Definition: glext.h:4504
XsResultValue find(const XsByteArray &data, XsFilePos &pos)
Find a string of bytes in the file.
GLuint start
Definition: glext.h:3512
struct XsString XsString
Definition: xsstring.h:34
unsigned __int32 uint32_t
Definition: rptypes.h:49
XsResultValue setReadPosition(XsFilePos pos)
Set the new absolute read position.
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3520
bool m_readOnly
Indicates if the file was opened in read-only mode.
An I/O device is already opened with this object.
Definition: xsens_std.h:71
Busy processing, try again later.
Definition: xsens_std.h:78
No file opened for reading/writing.
Definition: xsens_std.h:91
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.5.6 Git: 4c65e8431 Tue Apr 24 08:18:17 2018 +0200 at lun oct 28 01:35:26 CET 2019