Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/files.h
Parent Directory
|
Revision Log
Revision 614 -
(show annotations)
(download)
(as text)
Sat Jan 29 19:44:36 2011 UTC (14 years, 1 month ago) by amb
File MIME type: text/x-chdr
File size: 3282 byte(s)
Sat Jan 29 19:44:36 2011 UTC (14 years, 1 month ago) by amb
File MIME type: text/x-chdr
File size: 3282 byte(s)
Fix assert problem.
1 | /*************************************** |
2 | Header file for file function prototypes |
3 | |
4 | Part of the Routino routing software. |
5 | ******************/ /****************** |
6 | This file Copyright 2008-2011 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 | #include <assert.h> |
27 | #include <unistd.h> |
28 | #include <sys/types.h> |
29 | |
30 | |
31 | /* In files.c */ |
32 | |
33 | char *FileName(const char *dirname,const char *prefix, const char *name); |
34 | |
35 | void *MapFile(const char *filename); |
36 | void *MapFileWriteable(const char *filename); |
37 | void *UnmapFile(const char *filename); |
38 | |
39 | int OpenFileNew(const char *filename); |
40 | int OpenFileAppend(const char *filename); |
41 | int ReOpenFile(const char *filename); |
42 | int ReOpenFileWriteable(const char *filename); |
43 | |
44 | static int WriteFile(int fd,const void *address,size_t length); |
45 | static int ReadFile(int fd,void *address,size_t length); |
46 | |
47 | off_t SizeFile(const char *filename); |
48 | int ExistsFile(const char *filename); |
49 | |
50 | static int SeekFile(int fd,off_t position); |
51 | |
52 | int CloseFile(int fd); |
53 | |
54 | int DeleteFile(char *filename); |
55 | |
56 | |
57 | /* Inline the frequently called functions */ |
58 | |
59 | /*++++++++++++++++++++++++++++++++++++++ |
60 | Write data to a file on disk. |
61 | |
62 | int WriteFile Returns 0 if OK or something else in case of an error. |
63 | |
64 | int fd The file descriptor to write to. |
65 | |
66 | const void *address The address of the data to be written from. |
67 | |
68 | size_t length The length of data to write. |
69 | ++++++++++++++++++++++++++++++++++++++*/ |
70 | |
71 | static inline int WriteFile(int fd,const void *address,size_t length) |
72 | { |
73 | assert(fd!=-1); |
74 | |
75 | /* Write the data */ |
76 | |
77 | if(write(fd,address,length)!=length) |
78 | return(-1); |
79 | |
80 | return(0); |
81 | } |
82 | |
83 | |
84 | /*++++++++++++++++++++++++++++++++++++++ |
85 | Read data from a file on disk. |
86 | |
87 | int ReadFile Returns 0 if OK or something else in case of an error. |
88 | |
89 | int fd The file descriptor to read from. |
90 | |
91 | void *address The address of the data to be read into. |
92 | |
93 | size_t length The length of data to read. |
94 | ++++++++++++++++++++++++++++++++++++++*/ |
95 | |
96 | static inline int ReadFile(int fd,void *address,size_t length) |
97 | { |
98 | /* Read the data */ |
99 | assert(fd!=-1); |
100 | |
101 | if(read(fd,address,length)!=length) |
102 | return(-1); |
103 | |
104 | return(0); |
105 | } |
106 | |
107 | |
108 | /*++++++++++++++++++++++++++++++++++++++ |
109 | Seek to a position in a file on disk. |
110 | |
111 | int SeekFile Returns 0 if OK or something else in case of an error. |
112 | |
113 | int fd The file descriptor to seek within. |
114 | |
115 | off_t position The position to seek to. |
116 | ++++++++++++++++++++++++++++++++++++++*/ |
117 | |
118 | static inline int SeekFile(int fd,off_t position) |
119 | { |
120 | assert(fd!=-1); |
121 | |
122 | /* Seek the data */ |
123 | |
124 | if(lseek(fd,position,SEEK_SET)!=position) |
125 | return(-1); |
126 | |
127 | return(0); |
128 | } |
129 | |
130 | |
131 | #endif /* FILES_H */ |
Properties
Name | Value |
---|---|
cvs:description | A new header file for files.c functions and includes some inline functions. |