modified: myjupyterlab.sh
[GalaxyCodeBases.git] / tools / vbindiff / curses / FileIO.hpp
blob2a371480978d27bdcea0d3c91c905c7764b6d101
1 //--------------------------------------------------------------------
2 //
3 // Visual Binary Diff
4 // Copyright 1997-2005 by Christopher J. Madsen
5 //
6 // Support functions for Posix file I/O
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of
11 // the License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 //--------------------------------------------------------------------
22 #ifndef INCLUDED_FILEIO_HPP
24 #define INCLUDED_FILEIO_HPP
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <unistd.h>
30 typedef int File;
31 typedef off_t FPos;
32 typedef ssize_t Size;
34 const int
35 SeekEnd = SEEK_END,
36 SeekPos = SEEK_SET;
38 const File InvalidFile = -1;
40 //--------------------------------------------------------------------
41 inline const char* ErrorMsg()
43 return strerror(errno);
44 } // end ErrorMsg
46 //--------------------------------------------------------------------
47 inline File OpenFile(const char* path, bool writable=false)
49 return open(path, (writable ? O_RDWR : O_RDONLY));
50 } // end OpenFile
52 //--------------------------------------------------------------------
53 inline void CloseFile(File file)
55 close(file);
56 } // end CloseFile
58 //--------------------------------------------------------------------
59 bool WriteFile(File file, const void* buffer, Size count)
61 const char* ptr = reinterpret_cast<const char*>(buffer);
63 while (count > 0) {
64 Size bytesWritten = write(file, ptr, count);
65 if (bytesWritten < 1) {
66 if (errno == EINTR)
67 bytesWritten = 0;
68 else
69 return false;
72 ptr += bytesWritten;
73 count -= bytesWritten;
74 } // end while more to write
76 return true;
77 } // end WriteFile
79 //--------------------------------------------------------------------
80 inline Size ReadFile(File file, void* buffer, Size count)
82 return read(file, buffer, count);
83 } // end ReadFile
85 //--------------------------------------------------------------------
86 inline FPos SeekFile(File file, FPos position, int whence=SeekPos)
88 return lseek(file, position, whence);
89 } // end SeekFile
91 #endif // INCLUDED_FILEIO_HPP
93 // Local Variables:
94 // c-file-style: "cjm"
95 // End: