1 #include <sys/file.h>  	// LOCK_EX, LOCK_NB, flock(), LOCK_SH, LOCK_UN
2 #include <sys/stat.h>   // struct stat
3 #include <stdlib.h>	// free(), calloc()
4 #include <stdio.h>	// FILE *, fopen(), fileno(), ftell(), fseek(), fflush(), fclose()
5 #include <string.h>	// strlen(), strncpy()
6 #include <unistd.h>	// read(), write()
7 
8 /**************************************************************************
9  **SA Network Connection Profiler [sancp] - A TCP/IP statistical/collection tool
10  * ************************************************************************
11  * * Copyright (C) 2003 John Curry <john.curry@metre.net>
12  * *
13  * * This program is distributed under the terms of version 1.0 of the
14  * * Q Public License.  See LICENSE.QPL for further details.
15  * *
16  * * This program is distributed in the hope that it will be useful,
17  * * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  * *
20  * ***********************************************************************/
21 
22 
23 #define FILEHANDLE_H
24 #define READ_MODE 0
25 #define WRITE_MODE 1
26 #define APPEND_MODE 2
27 
28 class fileHandle {
29 
30 	public:
31 		fileHandle();
32 
33 		fileHandle(const char *newfilename);
34 
35 		fileHandle(FILE *OFH, int);
36 
37 		fileHandle(const char *newfilename, int);
38 
39 		void setFileName(const char *newfilename);
40 
41 		char * getFileName();
42 
43 		int isOpen();
44 
45 		int open();
46 
47 		void reopen();
48 
49 		FILE *getFileHandle();
50 
51 		ssize_t write(const char *data, int len);
52 
53 		int read(char *data, int len);
54 
55 		long tell();
56 
57 		int seek(long offset, int whence);
58 
59 		void setMode(int mode);
60 
61 		int getMode();
62 
63 		fileHandle * attach();
64 
65 		void detach();
66 
67 		void close();
68 
69 		void destroy();  // Do not call if object is declared on the stack - we need to change this...
70 
71 		~fileHandle();
72 
73 	private:
74 		u_int64_t in_use;// Count of
75 		FILE *handle;	// Where we write data to the file
76 		char *filename; // self-explanatory
77 		int  mode;	// are we opened for reading, writing, append...
78 };
79 
80 
81