1 /***************************************
2 $Header: /home/amb/routino/src/RCS/files.h,v 1.4 2010/10/09 18:20:18 amb Exp $
4 Header file for file function prototypes
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 Andrew M. Bishop
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.
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.
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 ***************************************/
26 #define FILES_H /*+ To stop multiple inclusions. +*/
29 #include <sys/types.h>
34 char *FileName(const char *dirname,const char *prefix, const char *name);
36 void *MapFile(const char *filename);
37 void *MapFileWriteable(const char *filename);
38 void *UnmapFile(const char *filename);
40 int OpenFileNew(const char *filename);
41 int OpenFileAppend(const char *filename);
42 int ReOpenFile(const char *filename);
43 int ReOpenFileWriteable(const char *filename);
45 static int WriteFile(int fd,const void *address,size_t length);
46 static int ReadFile(int fd,void *address,size_t length);
48 off_t SizeFile(const char *filename);
49 int ExistsFile(const char *filename);
51 static int SeekFile(int fd,off_t position);
53 void CloseFile(int fd);
55 int DeleteFile(char *filename);
58 /* Inline the frequently called functions */
60 /*++++++++++++++++++++++++++++++++++++++
61 Write data to a file on disk.
63 int WriteFile Returns 0 if OK or something else in case of an error.
65 int fd The file descriptor to write to.
67 const void *address The address of the data to be written from.
69 size_t length The length of data to write.
70 ++++++++++++++++++++++++++++++++++++++*/
72 static inline int WriteFile(int fd,const void *address,size_t length)
76 if(write(fd,address,length)!=length)
83 /*++++++++++++++++++++++++++++++++++++++
84 Read data from a file on disk.
86 int ReadFile Returns 0 if OK or something else in case of an error.
88 int fd The file descriptor to read from.
90 void *address The address of the data to be read into.
92 size_t length The length of data to read.
93 ++++++++++++++++++++++++++++++++++++++*/
95 static inline int ReadFile(int fd,void *address,size_t length)
99 if(read(fd,address,length)!=length)
106 /*++++++++++++++++++++++++++++++++++++++
107 Seek to a position in a file on disk.
109 int SeekFile Returns 0 if OK or something else in case of an error.
111 int fd The file descriptor to seek within.
113 off_t position The position to seek to.
114 ++++++++++++++++++++++++++++++++++++++*/
116 static inline int SeekFile(int fd,off_t position)
120 if(lseek(fd,position,SEEK_SET)!=position)