Routino SVN Repository Browser

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

ViewVC logotype

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1418 - (hide annotations) (download) (as text)
Sat Jun 22 18:56:18 2013 UTC (11 years, 8 months ago) by amb
Original Path: trunk/src/files.h
File MIME type: text/x-chdr
File size: 4088 byte(s)
Make the changes required to handle the new function names from the last few
checkins.

1 amb 450 /***************************************
2     Header file for file function prototypes
3    
4     Part of the Routino routing software.
5     ******************/ /******************
6 amb 1300 This file Copyright 2008-2013 Andrew M. Bishop
7 amb 450
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 amb 888 /* 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     #define HAVE_PREAD_PWRITE 1
30    
31    
32 amb 450 #include <unistd.h>
33     #include <sys/types.h>
34    
35 amb 1166 #include "logging.h"
36 amb 450
37 amb 1166
38 amb 680 /* Functions in files.c */
39 amb 450
40     char *FileName(const char *dirname,const char *prefix, const char *name);
41    
42     void *MapFile(const char *filename);
43 amb 507 void *MapFileWriteable(const char *filename);
44 amb 1399
45 amb 1122 void *UnmapFile(const void *address);
46 amb 450
47 amb 1418 int SlimMapFile(const char *filename);
48     int SlimMapFileWriteable(const char *filename);
49 amb 1399
50 amb 1418 int SlimUnmapFile(int fd);
51    
52 amb 1401 int OpenFileBufferedNew(const char *filename);
53     int OpenFileBufferedAppend(const char *filename);
54    
55 amb 1404 int ReOpenFileBuffered(const char *filename);
56    
57 amb 1401 int WriteFileBuffered(int fd,const void *address,size_t length);
58     int ReadFileBuffered(int fd,void *address,size_t length);
59    
60 amb 1407 int SeekFileBuffered(int fd,off_t position);
61 amb 1406 int SkipFileBuffered(int fd,off_t skip);
62 amb 1404
63 amb 1401 int CloseFileBuffered(int fd);
64 amb 1399
65 amb 1418 int OpenFile(const char *filename);
66    
67     void CloseFile(int fd);
68    
69 amb 1399 off_t SizeFile(const char *filename);
70     int ExistsFile(const char *filename);
71    
72     int DeleteFile(const char *filename);
73    
74     int RenameFile(const char *oldfilename,const char *newfilename);
75    
76     /* Functions in files.h */
77    
78 amb 1418 static inline int SlimReplace(int fd,const void *address,size_t length,off_t position);
79     static inline int SlimFetch(int fd,void *address,size_t length,off_t position);
80 amb 450
81 amb 887
82 amb 450 /* Inline the frequently called functions */
83    
84     /*++++++++++++++++++++++++++++++++++++++
85 amb 1418 Write data to a file that has been opened for slim mode access.
86 amb 450
87 amb 1418 int SlimReplace Returns 0 if OK or something else in case of an error.
88 amb 450
89     int fd The file descriptor to write to.
90    
91 amb 680 const void *address The address of the data to be written.
92 amb 450
93     size_t length The length of data to write.
94    
95 amb 1418 off_t position The position in the file to seek to.
96 amb 450 ++++++++++++++++++++++++++++++++++++++*/
97    
98 amb 1418 static inline int SlimReplace(int fd,const void *address,size_t length,off_t position)
99 amb 450 {
100 amb 888 /* Seek and write the data */
101 amb 887
102 amb 888 #if HAVE_PREAD_PWRITE
103    
104 amb 1300 if(pwrite(fd,address,length,position)!=(ssize_t)length)
105 amb 887 return(-1);
106    
107 amb 888 #else
108    
109     if(lseek(fd,position,SEEK_SET)!=position)
110     return(-1);
111    
112     if(write(fd,address,length)!=length)
113     return(-1);
114    
115     #endif
116    
117 amb 887 return(0);
118     }
119    
120    
121     /*++++++++++++++++++++++++++++++++++++++
122 amb 1418 Read data from a file that has been opened for slim mode access.
123 amb 887
124 amb 1418 int SlimFetch Returns 0 if OK or something else in case of an error.
125 amb 887
126     int fd The file descriptor to read from.
127    
128     void *address The address the data is to be read into.
129    
130     size_t length The length of data to read.
131    
132 amb 1418 off_t position The position in the file to seek to.
133 amb 887 ++++++++++++++++++++++++++++++++++++++*/
134    
135 amb 1418 static inline int SlimFetch(int fd,void *address,size_t length,off_t position)
136 amb 887 {
137 amb 888 /* Seek and read the data */
138 amb 887
139 amb 888 #if HAVE_PREAD_PWRITE
140    
141 amb 1300 if(pread(fd,address,length,position)!=(ssize_t)length)
142 amb 887 return(-1);
143    
144 amb 888 #else
145    
146     if(lseek(fd,position,SEEK_SET)!=position)
147     return(-1);
148    
149     if(read(fd,address,length)!=length)
150     return(-1);
151    
152     #endif
153    
154 amb 887 return(0);
155     }
156    
157    
158 amb 450 #endif /* FILES_H */

Properties

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