Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /branches/MS-Windows/src/files.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1684 - (show annotations) (download) (as text)
Tue May 26 19:01:08 2015 UTC (9 years, 9 months ago) by amb
File MIME type: text/x-chdr
File size: 4450 byte(s)
When compiling with MINGW the pread() and pwrite() functions are not
available.  Fix a signed/unsigned assignment warning in the inline
functions.

1 /***************************************
2 Header file for file function prototypes
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2015 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
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 Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #ifndef FILES_H
24 #define FILES_H /*+ To stop multiple inclusions. +*/
25
26 /* If your system does not have the pread() and pwrite() system calls then you
27 * will need to change this line to the value 0 so that seek() and
28 * read()/write() are used instead of pread()/pwrite(). */
29
30 #if defined(_MSC_VER) || defined(__MINGW32__)
31 #define HAVE_PREAD_PWRITE 0
32 #else
33 #define HAVE_PREAD_PWRITE 1
34 #endif
35
36 #if defined(_MSC_VER)
37 #include <io.h>
38 #define read(fd,address,length) _read(fd,address,(unsigned int)(length))
39 #define write(fd,address,length) _write(fd,address,(unsigned int)(length))
40 #define lseek _lseeki64
41 #else
42 #include <unistd.h>
43 #endif
44
45 #include <sys/types.h>
46
47 #include "logging.h"
48
49
50 /* Functions in files.c */
51
52 char *FileName(const char *dirname,const char *prefix, const char *name);
53
54 void *MapFile(const char *filename);
55 void *MapFileWriteable(const char *filename);
56
57 void *UnmapFile(const void *address);
58
59 int SlimMapFile(const char *filename);
60 int SlimMapFileWriteable(const char *filename);
61
62 int SlimUnmapFile(int fd);
63
64 int OpenFileBufferedNew(const char *filename);
65 int OpenFileBufferedAppend(const char *filename);
66
67 int ReOpenFileBuffered(const char *filename);
68
69 int WriteFileBuffered(int fd,const void *address,size_t length);
70 int ReadFileBuffered(int fd,void *address,size_t length);
71
72 int SeekFileBuffered(int fd,off_t position);
73 int SkipFileBuffered(int fd,off_t skip);
74
75 int CloseFileBuffered(int fd);
76
77 int OpenFile(const char *filename);
78
79 void CloseFile(int fd);
80
81 off_t SizeFile(const char *filename);
82 off_t SizeFileFD(int fd);
83 int ExistsFile(const char *filename);
84
85 int DeleteFile(const char *filename);
86
87 int RenameFile(const char *oldfilename,const char *newfilename);
88
89 /* Functions in files.h */
90
91 static inline int SlimReplace(int fd,const void *address,size_t length,off_t position);
92 static inline int SlimFetch(int fd,void *address,size_t length,off_t position);
93
94
95 /* Inline the frequently called functions */
96
97 /*++++++++++++++++++++++++++++++++++++++
98 Write data to a file that has been opened for slim mode access.
99
100 int SlimReplace Returns 0 if OK or something else in case of an error.
101
102 int fd The file descriptor to write to.
103
104 const void *address The address of the data to be written.
105
106 size_t length The length of data to write.
107
108 off_t position The position in the file to seek to.
109 ++++++++++++++++++++++++++++++++++++++*/
110
111 static inline int SlimReplace(int fd,const void *address,size_t length,off_t position)
112 {
113 /* Seek and write the data */
114
115 #if HAVE_PREAD_PWRITE
116
117 if(pwrite(fd,address,length,position)!=(ssize_t)length)
118 return(-1);
119
120 #else
121
122 if(lseek(fd,position,SEEK_SET)!=position)
123 return(-1);
124
125 if(write(fd,address,length)!=(ssize_t)length)
126 return(-1);
127
128 #endif
129
130 return(0);
131 }
132
133
134 /*++++++++++++++++++++++++++++++++++++++
135 Read data from a file that has been opened for slim mode access.
136
137 int SlimFetch Returns 0 if OK or something else in case of an error.
138
139 int fd The file descriptor to read from.
140
141 void *address The address the data is to be read into.
142
143 size_t length The length of data to read.
144
145 off_t position The position in the file to seek to.
146 ++++++++++++++++++++++++++++++++++++++*/
147
148 static inline int SlimFetch(int fd,void *address,size_t length,off_t position)
149 {
150 /* Seek and read the data */
151
152 #if HAVE_PREAD_PWRITE
153
154 if(pread(fd,address,length,position)!=(ssize_t)length)
155 return(-1);
156
157 #else
158
159 if(lseek(fd,position,SEEK_SET)!=position)
160 return(-1);
161
162 if(read(fd,address,length)!=(ssize_t)length)
163 return(-1);
164
165 #endif
166
167 return(0);
168 }
169
170
171 #endif /* FILES_H */

Properties

Name Value
cvs:description A new header file for files.c functions and includes some inline functions.