Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / ACE / apps / JAWS / clients / WebSTONE / src / nsapi-includes / base / file.h
blob742bed60d2ee7e376429b58a76622274f09523b1
1 /*
2 * Copyright (c) 1994, 1995. Netscape Communications Corporation. All
3 * rights reserved.
5 * Use of this software is governed by the terms of the license agreement for
6 * the Netscape Communications or Netscape Comemrce Server between the
7 * parties.
8 */
11 /* ------------------------------------------------------------------------ */
15 * file.h: system specific functions for reading/writing files
17 * Rob McCool
21 #ifndef FILE_H
22 #define FILE_H
24 #ifdef XP_WIN32
25 #include <nt/ntfile.h>
26 #else
29 #include "netsite.h"
30 #include "systems.h"
34 * I cheat: These are set up such that system_read can be a macro for read
35 * under UNIX. IO_OKAY is anything positive.
38 #define IO_OKAY 1
39 #define IO_ERROR -1
40 #define IO_EOF 0
43 #ifdef FILE_STDIO
44 #include <stdio.h>
46 #elif defined(FILE_UNIX)
47 #include <sys/types.h>
48 #include <sys/file.h>
49 #include <fcntl.h>
50 #include <unistd.h>
51 #endif
54 /* -------------------------- File related defs --------------------------- */
57 /* The disk page size on this machine. */
58 #define FILE_BUFFERSIZE 4096
62 * The fd data type for this system.
65 #if defined(FILE_STDIO)
66 typedef FILE* SYS_FILE;
67 #define SYS_ERROR_FD 0
68 #define SYS_STDERR stderr
70 #elif defined(FILE_UNIX)
71 typedef int SYS_FILE;
72 #define SYS_ERROR_FD -1
73 #define SYS_STDERR STDERR_FILENO
75 #else
76 #error "undefined file typing for current system"
77 #endif
79 #ifdef XP_UNIX
80 #define FILE_PATHSEP '/'
81 #define FILE_PARENT "../"
83 #define system_chdir chdir
84 #endif
88 * system_fread reads sz bytes from fd into to buf, return number of bytes
89 * read, or IO_EOF if EOF, or IO_ERROR if error.
92 #if defined(FILE_STDIO)
93 int system_fread(SYS_FILE fd, char *buf, int sz);
95 #elif defined(FILE_UNIX)
96 #define system_fread(fd,buf,sz) read(fd,buf,sz)
98 #endif
101 * system_fopenRO opens a given file for reading only
102 * system_fopenWA opens a given file for writing, appending new output
105 #if defined(FILE_STDIO)
106 #define system_fopenRO(path) fopen(path,"r")
107 #define system_fopenWA(path) fopen(path,"a")
108 #define system_fopenRW(path) fopen(path,"w")
110 #elif defined(FILE_UNIX)
111 #define system_fopenRO(path) open(path, O_RDONLY)
112 #define system_fopenWA(path) \
113 open(path, O_RDWR | O_CREAT | O_APPEND, 0644)
114 #define system_fopenRW(path) \
115 open(path, O_RDWR | O_CREAT, 0644)
117 #endif
121 * system_fclose closes the file fd
124 #if defined(FILE_STDIO)
125 #define system_fclose(fd) fclose(fd)
127 #elif defined(FILE_UNIX)
128 #define system_fclose(fd) close(fd)
129 #endif
132 * This call stops core dumps in a portable way. Returns -1 on error.
135 int system_nocoredumps();
138 #if defined(FILE_STDIO)
139 #define system_lseek fseek
141 #elif defined(FILE_UNIX)
142 #define system_lseek lseek
144 #endif
147 * system_write writes sz bytes from buf to fd. The handler function should
148 * handle partial writes and anything else like that. Returns IO_*
151 int system_fwrite(SYS_FILE fd,char *buf,int sz);
154 * system_fwrite_atomic locks the given fd before writing to it. This avoids
155 * interference between simultaneous writes. Returns IO_*
158 int system_fwrite_atomic(SYS_FILE fd, char *buf, int sz);
161 * system_errmsg returns the last error that occurred while processing file
162 * descriptor fd. fd does not have to be specified (if the error is a global
163 * such as in UNIX systems). PPS: Rob is a halfwit. This parameter is useless.
166 #ifndef FILE_WIN32
167 #include <errno.h>
169 extern char *sys_errlist[];
170 #define file_notfound() (errno == ENOENT)
171 #define system_errmsg(fd) (sys_errlist[errno])
172 #endif
176 * flock locks a file against interference from other processes
177 * ulock unlocks it.
179 #ifdef BSD_FLOCK
180 #include <sys/file.h>
181 #define system_initlock(fd) (0)
182 #define system_flock(fd) flock(fd, LOCK_EX)
183 #define system_ulock(fd) flock(fd, LOCK_UN)
185 #elif defined(FILE_UNIX)
186 #include <unistd.h>
187 #define system_initlock(fd) (0)
188 #define system_flock(fd) lockf(fd, F_LOCK, 0)
189 #define system_ulock(fd) lockf(fd, F_ULOCK, 0)
191 #endif
195 * unix2local converts a unix-style pathname to a local one
198 #ifdef XP_UNIX
199 #define file_unix2local(path,p2) strcpy(p2,path)
200 #endif
202 /* -------------------------- Dir related defs ---------------------------- */
205 #ifdef XP_UNIX
206 #include <dirent.h>
207 typedef DIR* SYS_DIR;
208 typedef struct dirent SYS_DIRENT;
209 #define dir_open opendir
210 #define dir_read readdir
211 #define dir_close closedir
213 #endif
214 #endif
215 #endif