Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/files.h
Parent Directory
|
Revision Log
Revision 680 -
(hide annotations)
(download)
(as text)
Sun Apr 24 15:14:53 2011 UTC (13 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 3297 byte(s)
Sun Apr 24 15:14:53 2011 UTC (13 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 3297 byte(s)
Update comments throughout the source code.
1 | amb | 450 | /*************************************** |
2 | Header file for file function prototypes | ||
3 | |||
4 | Part of the Routino routing software. | ||
5 | ******************/ /****************** | ||
6 | amb | 612 | This file Copyright 2008-2011 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 | 612 | #include <assert.h> |
27 | amb | 450 | #include <unistd.h> |
28 | #include <sys/types.h> | ||
29 | |||
30 | |||
31 | amb | 680 | /* Functions in files.c */ |
32 | amb | 450 | |
33 | char *FileName(const char *dirname,const char *prefix, const char *name); | ||
34 | |||
35 | void *MapFile(const char *filename); | ||
36 | amb | 507 | void *MapFileWriteable(const char *filename); |
37 | amb | 450 | void *UnmapFile(const char *filename); |
38 | |||
39 | amb | 502 | int OpenFileNew(const char *filename); |
40 | int OpenFileAppend(const char *filename); | ||
41 | amb | 450 | int ReOpenFile(const char *filename); |
42 | amb | 511 | int ReOpenFileWriteable(const char *filename); |
43 | amb | 450 | |
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 | amb | 612 | int CloseFile(int fd); |
53 | amb | 450 | |
54 | int DeleteFile(char *filename); | ||
55 | |||
56 | |||
57 | /* Inline the frequently called functions */ | ||
58 | |||
59 | /*++++++++++++++++++++++++++++++++++++++ | ||
60 | amb | 680 | Write data to a file descriptor. |
61 | amb | 450 | |
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 | amb | 680 | const void *address The address of the data to be written. |
67 | amb | 450 | |
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 | amb | 614 | assert(fd!=-1); |
74 | amb | 612 | |
75 | amb | 450 | /* Write the data */ |
76 | |||
77 | if(write(fd,address,length)!=length) | ||
78 | return(-1); | ||
79 | |||
80 | return(0); | ||
81 | } | ||
82 | |||
83 | |||
84 | /*++++++++++++++++++++++++++++++++++++++ | ||
85 | amb | 680 | Read data from a file descriptor. |
86 | amb | 450 | |
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 | amb | 680 | void *address The address the data is to be read into. |
92 | amb | 450 | |
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 | amb | 614 | assert(fd!=-1); |
99 | amb | 450 | |
100 | amb | 680 | /* Read the data */ |
101 | |||
102 | amb | 450 | if(read(fd,address,length)!=length) |
103 | return(-1); | ||
104 | |||
105 | return(0); | ||
106 | } | ||
107 | |||
108 | |||
109 | /*++++++++++++++++++++++++++++++++++++++ | ||
110 | amb | 680 | Seek to a position in a file descriptor. |
111 | amb | 450 | |
112 | int SeekFile Returns 0 if OK or something else in case of an error. | ||
113 | |||
114 | int fd The file descriptor to seek within. | ||
115 | |||
116 | off_t position The position to seek to. | ||
117 | ++++++++++++++++++++++++++++++++++++++*/ | ||
118 | |||
119 | static inline int SeekFile(int fd,off_t position) | ||
120 | { | ||
121 | amb | 614 | assert(fd!=-1); |
122 | amb | 612 | |
123 | amb | 450 | /* Seek the data */ |
124 | |||
125 | if(lseek(fd,position,SEEK_SET)!=position) | ||
126 | return(-1); | ||
127 | |||
128 | return(0); | ||
129 | } | ||
130 | |||
131 | |||
132 | #endif /* FILES_H */ |
Properties
Name | Value |
---|---|
cvs:description | A new header file for files.c functions and includes some inline functions. |