|
|
1.1 root 1: /* filewrap.h */
2:
3: /* File system-call wrappers */
4:
5: /* $Id: filewrap.h,v 1.26 2006/05/18 04:09:35 deuce Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This library is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU Lesser General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU Lesser General Public License for more details: lgpl.txt or *
18: * http://www.fsf.org/copyleft/lesser.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #ifndef _FILEWRAP_H
39: #define _FILEWRAP_H
40:
41: #include "wrapdll.h" /* DLLEXPORT and DLLCALL */
42:
43: #include <sys/stat.h> /* S_IREAD and S_IWRITE (for use with sopen) */
44: #include <stdio.h>
45:
46: #if defined(__unix__)
47: #include <unistd.h> /* read, write, close, ftruncate, lseek, etc. */
48: #endif
49:
50: #if defined(_WIN32) || defined(__BORLANDC__)
51: #include <io.h>
52: #endif
53:
54: #include <fcntl.h> /* O_RDONLY, O_CREAT, etc. */
55:
56: /**********/
57: /* Macros */
58: /**********/
59:
60: #if defined(_WIN32)
61:
62:
63: #include <windows.h> /* OF_SHARE_ */
64: #include <share.h> /* SH_DENY */
65:
66: #ifndef SH_DENYNO
67: #define SH_DENYNO OF_SHARE_DENY_NONE
68: #define SH_DENYWR OF_SHARE_DENY_WRITE
69: #define SH_DENYRW OF_SHARE_EXCLUSIVE
70: #endif
71:
72: #ifndef SH_COMPAT
73: #define SH_COMPAT 0
74: #endif
75:
76: #elif defined(__unix__)
77:
78: #ifdef __solaris__
79: #define LOCK_NB 1
80: #define LOCK_SH 2
81: #define LOCK_EX 4
82: #endif
83:
84: #ifdef __QNX__
85: #include <share.h>
86: #define L_SET SEEK_SET
87: #else
88: #ifndef O_TEXT
89: #define O_TEXT 0 /* all files in binary mode on Unix */
90: #define O_BINARY 0 /* all files in binary mode on Unix */
91: #endif
92: #undef O_DENYNONE
93: #define O_DENYNONE (1<<31) /* req'd for Baja/nopen compatibility */
94:
95: #define SH_DENYNO 2 /* no locks */
96: #ifdef F_SANEWRLCKNO
97: #define SH_DENYRW F_SANEWRLCKNO /* exclusive lock */
98: #else
99: #define SH_DENYRW F_WRLCK /* exclusive lock */
100: #endif
101:
102: #ifdef F_SANERDLCKNO
103: #define SH_DENYWR F_SANERDLCKNO /* shareable lock */
104: #else
105: #define SH_DENYWR F_RDLCK /* shareable lock */
106: #endif
107:
108: #ifndef SH_COMPAT
109: #define SH_COMPAT 0
110: #endif
111: #endif
112: #define chsize(fd,size) ftruncate(fd,size)
113: #define tell(fd) lseek(fd,0,SEEK_CUR)
114: #define eof(fd) (tell(fd)==filelength(fd))
115:
116: #elif defined(__OS2__)
117:
118: #include <share.h> /* SH_DENY */
119:
120: #endif
121:
122: /* Standard file descriptors. */
123: #ifndef STDIN_FILENO
124: #define STDIN_FILENO 0 /* Standard input */
125: #define STDOUT_FILENO 1 /* Standard output */
126: #define STDERR_FILENO 2 /* Standard error output */
127: #endif
128:
129: #ifndef O_DENYNONE
130: #define O_DENYNONE SH_DENYNO
131: #endif
132:
133: /**************/
134: /* Prototypes */
135: /**************/
136:
137: #if defined(__cplusplus)
138: extern "C" {
139: #endif
140:
141: #if !defined(__BORLANDC__) && !defined(__WATCOMC__)
142: DLLEXPORT int DLLCALL lock(int fd, long pos, long len);
143: DLLEXPORT int DLLCALL unlock(int fd, long pos, long len);
144: #endif
145:
146: #if !defined(__BORLANDC__) && defined(__unix__)
147: DLLEXPORT int DLLCALL sopen(const char* fn, int sh_access, int share, ...);
148: DLLEXPORT long DLLCALL filelength(int fd);
149: #endif
150:
151: #if defined(__unix__)
152: DLLEXPORT FILE * DLLCALL _fsopen(char *pszFilename, char *pszMode, int shmode);
153: #endif
154:
155: DLLEXPORT time_t DLLCALL filetime(int fd);
156:
157: #if defined(__cplusplus)
158: }
159: #endif
160:
161: #endif /* Don't add anything after this line */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.