Routino SVN Repository Browser

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

ViewVC logotype

Annotation of /trunk/src/files.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 502 - (hide annotations) (download) (as text)
Sun Sep 19 16:17:45 2010 UTC (14 years, 6 months ago) by amb
File MIME type: text/x-chdr
File size: 3198 byte(s)
Change the names of the functions used to open files, change the ReOpen function
to open R/W.

1 amb 450 /***************************************
2 amb 502 $Header: /home/amb/CVS/routino/src/files.h,v 1.2 2010-09-19 16:17:45 amb Exp $
3 amb 450
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 *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    
43     static int WriteFile(int fd,const void *address,size_t length);
44     static int ReadFile(int fd,void *address,size_t length);
45    
46     off_t SizeFile(const char *filename);
47     int ExistsFile(const char *filename);
48    
49     static int SeekFile(int fd,off_t position);
50    
51     void CloseFile(int fd);
52    
53     int DeleteFile(char *filename);
54    
55    
56     /* Inline the frequently called functions */
57    
58     /*++++++++++++++++++++++++++++++++++++++
59     Write data to a file on disk.
60    
61     int WriteFile Returns 0 if OK or something else in case of an error.
62    
63     int fd The file descriptor to write to.
64    
65     const void *address The address of the data to be written from.
66    
67     size_t length The length of data to write.
68     ++++++++++++++++++++++++++++++++++++++*/
69    
70     static inline int WriteFile(int fd,const void *address,size_t length)
71     {
72     /* Write the data */
73    
74     if(write(fd,address,length)!=length)
75     return(-1);
76    
77     return(0);
78     }
79    
80    
81     /*++++++++++++++++++++++++++++++++++++++
82     Read data from a file on disk.
83    
84     int ReadFile Returns 0 if OK or something else in case of an error.
85    
86     int fd The file descriptor to read from.
87    
88     void *address The address of the data to be read into.
89    
90     size_t length The length of data to read.
91     ++++++++++++++++++++++++++++++++++++++*/
92    
93     static inline int ReadFile(int fd,void *address,size_t length)
94     {
95     /* Read the data */
96    
97     if(read(fd,address,length)!=length)
98     return(-1);
99    
100     return(0);
101     }
102    
103    
104     /*++++++++++++++++++++++++++++++++++++++
105     Seek to a position in a file on disk.
106    
107     int SeekFile Returns 0 if OK or something else in case of an error.
108    
109     int fd The file descriptor to seek within.
110    
111     off_t position The position to seek to.
112     ++++++++++++++++++++++++++++++++++++++*/
113    
114     static inline int SeekFile(int fd,off_t position)
115     {
116     /* Seek the data */
117    
118     if(lseek(fd,position,SEEK_SET)!=position)
119     return(-1);
120    
121     return(0);
122     }
123    
124    
125     #endif /* FILES_H */

Properties

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