1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is Mozilla Communicator client code, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
25 * Daniel Veditz <dveditz@netscape.com>
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
42 * XP code stubs for stand-alone registry library
49 #ifdef STANDALONE_REGISTRY
54 #include "macstdlibextras.h" /* For strcasecmp and strncasecmp */
65 #endif /* STANDALONE_REGISTRY*/
70 #if ( defined(BSDI) && !defined(BSDI_2) ) || defined(XP_OS2_EMX)
71 #include <sys/types.h>
83 #if defined(__cplusplus)
85 # define XP_IS_CPLUSPLUS 1
87 # define XP_IS_CPLUSPLUS 0
90 #if defined(XP_CPLUSPLUS)
91 # define XP_BEGIN_PROTOS extern "C" {
92 # define XP_END_PROTOS }
94 # define XP_BEGIN_PROTOS
95 # define XP_END_PROTOS
99 #ifdef STANDALONE_REGISTRY
101 #define USE_STDIO_MODES
103 #define XP_FileSeek(file,offset,whence) fseek((file), (offset), (whence))
104 #define XP_FileRead(dest,count,file) fread((dest), 1, (count), (file))
105 #define XP_FileWrite(src,count,file) fwrite((src), 1, (count), (file))
106 #define XP_FileTell(file) ftell(file)
107 #define XP_FileFlush(file) fflush(file)
108 #define XP_FileClose(file) fclose(file)
109 #define XP_FileSetBufferSize(file,bufsize) (-1)
111 #define XP_ASSERT(x) ((void)0)
113 #define XP_STRCAT(a,b) strcat((a),(b))
115 #define XP_STRNCPY(a,b,n) strncpy((a),(b),(n))
116 #define XP_STRCPY(a,b) strcpy((a),(b))
117 #define XP_STRLEN(x) strlen(x)
118 #define XP_SPRINTF sprintf
119 #define XP_FREE(x) free((x))
120 #define XP_ALLOC(x) malloc((x))
121 #define XP_FREEIF(x) if ((x)) free((x))
122 #define XP_STRCMP(x,y) strcmp((x),(y))
123 #define XP_STRNCMP(x,y,n) strncmp((x),(y),(n))
124 #define XP_STRDUP(s) strdup((s))
125 #define XP_MEMCPY(d, s, l) memcpy((d), (s), (l))
126 #define XP_MEMSET(d, c, l) memset((d), (c), (l))
128 #define PR_Lock(a) ((void)0)
129 #define PR_Unlock(a) ((void)0)
131 #if defined(XP_WIN) || defined(XP_OS2)
132 #define XP_STRCASECMP(x,y) stricmp((x),(y))
133 #define XP_STRNCASECMP(x,y,n) strnicmp((x),(y),(n))
135 #define XP_STRCASECMP(x,y) strcasecmp((x),(y))
136 #define XP_STRNCASECMP(x,y,n) strncasecmp((x),(y),(n))
137 #endif /* XP_WIN || XP_OS2 */
139 typedef FILE * XP_File
;
141 #else /* not standalone, use NSPR */
144 /*-------------------------------------*/
145 /* Alternate fileI/O function mappings */
146 /*-------------------------------------*/
148 #if USE_MMAP_REGISTRY_IO
149 /*-----------------------------------------------*/
150 /* NSPR mememory-mapped I/O (write through) */
151 /* unfortunately this isn't supported on the Mac */
152 /*-----------------------------------------------*/
153 #define USE_NSPR_MODES
156 #define XP_FileSeek(file,offset,whence) mmio_FileSeek((file),(offset),(whence))
157 #define XP_FileRead(dest,count,file) mmio_FileRead((file), (dest), (count))
158 #define XP_FileWrite(src,count,file) mmio_FileWrite((file), (src), (count))
159 #define XP_FileTell(file) mmio_FileTell(file)
160 #define XP_FileClose(file) mmio_FileClose(file)
161 #define XP_FileOpen(path, mode) mmio_FileOpen((path), mode )
162 #define XP_FileFlush(file) ((void)1)
163 #define XP_FileSetBufferSize(file, bufsize) (-1)
165 typedef MmioFile
* XP_File
;
167 #elif USE_BUFFERED_REGISTRY_IO
168 /*-----------------------------------------------*/
169 /* home-grown XP buffering */
170 /* writes are buffered too so use flush! */
171 /*-----------------------------------------------*/
172 #define USE_STDIO_MODES
174 #include "nr_bufio.h"
175 #define XP_FileSeek(file,offset,whence) bufio_Seek((file),(offset),(whence))
176 #define XP_FileRead(dest,count,file) bufio_Read((file), (dest), (count))
177 #define XP_FileWrite(src,count,file) bufio_Write((file), (src), (count))
178 #define XP_FileTell(file) bufio_Tell(file)
179 #define XP_FileClose(file) bufio_Close(file)
180 #define XP_FileOpen(path, mode) bufio_Open((path), (mode))
181 #define XP_FileFlush(file) bufio_Flush(file)
182 #define XP_FileSetBufferSize(file,bufsize) bufio_SetBufferSize(file,bufsize)
185 typedef BufioFile
* XP_File
;
188 /*-----------------------------------------------*/
189 /* standard NSPR file I/O */
190 /*-----------------------------------------------*/
191 #define USE_NSPR_MODES
193 ** Note that PR_Seek returns the offset (if successful) and -1 otherwise. So
194 ** to make this code work
195 ** if (XP_FileSeek(fh, offset, SEEK_SET) != 0) { error handling }
196 ** we return 1 if PR_Seek() returns a negative value, and 0 otherwise
198 #define XP_FileSeek(file,offset,whence) (PR_Seek((file), (offset), (whence)) < 0)
199 #define XP_FileRead(dest,count,file) PR_Read((file), (dest), (count))
200 #define XP_FileWrite(src,count,file) PR_Write((file), (src), (count))
201 #define XP_FileTell(file) PR_Seek(file, 0, PR_SEEK_CUR)
202 #define XP_FileOpen(path, mode) PR_Open((path), mode )
203 #define XP_FileClose(file) PR_Close(file)
204 #define XP_FileFlush(file) PR_Sync(file)
205 #define XP_FileSetBufferSize(file,bufsize) (-1)
207 typedef PRFileDesc
* XP_File
;
209 #endif /*USE_MMAP_REGISTRY_IO*/
213 #define XP_ASSERT(x) PR_ASSERT((x))
215 #define XP_STRCAT(a,b) PL_strcat((a),(b))
216 #define XP_ATOI PL_atoi
217 #define XP_STRCPY(a,b) PL_strcpy((a),(b))
218 #define XP_STRNCPY(a,b,n) PL_strncpy((a),(b),(n))
219 #define XP_STRLEN(x) PL_strlen(x)
220 #define XP_SPRINTF sprintf
221 #define XP_FREE(x) PR_Free((x))
222 #define XP_ALLOC(x) PR_Malloc((x))
223 #define XP_FREEIF(x) PR_FREEIF(x)
224 #define XP_STRCMP(x,y) PL_strcmp((x),(y))
225 #define XP_STRNCMP(x,y,n) PL_strncmp((x),(y),(n))
226 #define XP_STRDUP(s) PL_strdup((s))
227 #define XP_MEMCPY(d, s, l) memcpy((d), (s), (l))
228 #define XP_MEMSET(d, c, l) memset((d), (c), (l))
230 #define XP_STRCASECMP(x,y) PL_strcasecmp((x),(y))
231 #define XP_STRNCASECMP(x,y,n) PL_strncasecmp((x),(y),(n))
234 #endif /*STANDALONE_REGISTRY*/
236 /*--- file open modes for stdio ---*/
237 #ifdef USE_STDIO_MODES
238 #define XP_FILE_READ "r"
239 #define XP_FILE_READ_BIN "rb"
240 #define XP_FILE_WRITE "w"
241 #define XP_FILE_WRITE_BIN "wb"
242 #define XP_FILE_UPDATE "r+"
243 #define XP_FILE_TRUNCATE "w+"
245 /* XXX SunOS4 hack -- make this universal by using r+b and w+b */
246 #define XP_FILE_UPDATE_BIN "r+"
247 #define XP_FILE_TRUNCATE_BIN "w+"
249 #define XP_FILE_UPDATE_BIN "rb+"
250 #define XP_FILE_TRUNCATE_BIN "wb+"
252 #endif /* USE_STDIO_MODES */
254 /*--- file open modes for NSPR file I/O ---*/
255 #ifdef USE_NSPR_MODES
256 #define XP_FILE_READ PR_RDONLY, 0644
257 #define XP_FILE_READ_BIN PR_RDONLY, 0644
258 #define XP_FILE_WRITE PR_WRONLY, 0644
259 #define XP_FILE_WRITE_BIN PR_WRONLY, 0644
260 #define XP_FILE_UPDATE (PR_RDWR|PR_CREATE_FILE), 0644
261 #define XP_FILE_TRUNCATE (PR_RDWR | PR_TRUNCATE), 0644
262 #define XP_FILE_UPDATE_BIN PR_RDWR|PR_CREATE_FILE, 0644
263 #define XP_FILE_TRUNCATE_BIN (PR_RDWR | PR_TRUNCATE), 0644
269 #define SEEK_SET PR_SEEK_SET
270 #define SEEK_CUR PR_SEEK_CUR
271 #define SEEK_END PR_SEEK_END
273 #endif /* USE_NSPR_MODES */
279 #ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
281 #endif /*STANDALONE_REGISTRY*/
285 typedef struct stat XP_StatStruct
;
286 #define XP_Stat(file,data) stat((file),(data))
289 extern int nr_RenameFile(char *from
, char *to
);
292 #define nr_RenameFile(from, to) rename((from), (to))
300 extern char* globalRegName
;
301 extern char* verRegName
;
303 extern void vr_findGlobalRegName();
304 extern char* vr_findVerRegName();
307 #ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
309 extern XP_File
vr_fileOpen(const char *name
, const char * mode
);
313 #define vr_fileOpen PR_Open
314 #endif /* STANDALONE_REGISTRY */
318 #endif /* _VR_STUBS_H_ */