Routino SVN Repository Browser

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

ViewVC logotype

Contents of /trunk/src/files.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 507 - (show annotations) (download) (as text)
Sun Oct 3 15:01:04 2010 UTC (14 years, 6 months ago) by amb
File MIME type: text/x-chdr
File size: 3244 byte(s)
Add a function to map a file writeable and use it for updating the ways when
processing route relations.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/files.h,v 1.3 2010-10-03 15:01:04 amb Exp $
3
4 Header file for file function prototypes
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 Andrew M. Bishop
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
19
20 You should have received a copy of the GNU Affero General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ***************************************/
23
24
25 #ifndef FILES_H
26 #define FILES_H /*+ To stop multiple inclusions. +*/
27
28 #include <unistd.h>
29 #include <sys/types.h>
30
31
32 /* In files.c */
33
34 char *FileName(const char *dirname,const char *prefix, const char *name);
35
36 void *MapFile(const char *filename);
37 void *MapFileWriteable(const char *filename);
38 void *UnmapFile(const char *filename);
39
40 int OpenFileNew(const char *filename);
41 int OpenFileAppend(const char *filename);
42 int ReOpenFile(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 void 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 /* Write the data */
74
75 if(write(fd,address,length)!=length)
76 return(-1);
77
78 return(0);
79 }
80
81
82 /*++++++++++++++++++++++++++++++++++++++
83 Read data from a file on disk.
84
85 int ReadFile Returns 0 if OK or something else in case of an error.
86
87 int fd The file descriptor to read from.
88
89 void *address The address of the data to be read into.
90
91 size_t length The length of data to read.
92 ++++++++++++++++++++++++++++++++++++++*/
93
94 static inline int ReadFile(int fd,void *address,size_t length)
95 {
96 /* Read the data */
97
98 if(read(fd,address,length)!=length)
99 return(-1);
100
101 return(0);
102 }
103
104
105 /*++++++++++++++++++++++++++++++++++++++
106 Seek to a position in a file on disk.
107
108 int SeekFile Returns 0 if OK or something else in case of an error.
109
110 int fd The file descriptor to seek within.
111
112 off_t position The position to seek to.
113 ++++++++++++++++++++++++++++++++++++++*/
114
115 static inline int SeekFile(int fd,off_t position)
116 {
117 /* Seek the data */
118
119 if(lseek(fd,position,SEEK_SET)!=position)
120 return(-1);
121
122 return(0);
123 }
124
125
126 #endif /* FILES_H */

Properties

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