Back to index

lightning-sunbird  0.9+nobinonly
vr_stubs.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is Mozilla Communicator client code, released
00017  * March 31, 1998.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 1998
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   Daniel Veditz <dveditz@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 /* vr_stubs.h
00041  *
00042  * XP code stubs for stand-alone registry library
00043  *
00044  */
00045 
00046 #ifndef _VR_STUBS_H_
00047 #define _VR_STUBS_H_
00048 
00049 #ifdef STANDALONE_REGISTRY
00050 
00051 #include <errno.h>
00052 #include <string.h>
00053 #ifdef XP_MAC
00054 #include "macstdlibextras.h"  /* For strcasecmp and strncasecmp */
00055 #include <extras.h>
00056 #endif
00057 
00058 #else
00059 
00060 #include "prio.h"
00061 #include "prlog.h"
00062 #include "prmem.h"
00063 #include "plstr.h"
00064 
00065 #endif /* STANDALONE_REGISTRY*/
00066 
00067 #ifdef XP_MAC
00068 #include <stat.h>
00069 #else
00070 #if ( defined(BSDI) && !defined(BSDI_2) ) || defined(XP_OS2_EMX)
00071 #include <sys/types.h>
00072 #endif
00073 #include <sys/stat.h>
00074 #endif
00075 
00076 #ifndef FALSE
00077 #define FALSE 0
00078 #endif
00079 #ifndef TRUE
00080 #define TRUE 1
00081 #endif
00082 
00083 #if defined(__cplusplus)
00084 # define XP_CPLUSPLUS
00085 # define XP_IS_CPLUSPLUS 1
00086 #else
00087 # define XP_IS_CPLUSPLUS 0
00088 #endif
00089 
00090 #if defined(XP_CPLUSPLUS)
00091 # define XP_BEGIN_PROTOS extern "C" {
00092 # define XP_END_PROTOS }
00093 #else
00094 # define XP_BEGIN_PROTOS
00095 # define XP_END_PROTOS
00096 #endif
00097 
00098 
00099 #ifdef STANDALONE_REGISTRY
00100 
00101 #define USE_STDIO_MODES
00102 
00103 #define XP_FileSeek(file,offset,whence) fseek((file), (offset), (whence))
00104 #define XP_FileRead(dest,count,file)    fread((dest), 1, (count), (file))
00105 #define XP_FileWrite(src,count,file)    fwrite((src), 1, (count), (file))
00106 #define XP_FileTell(file)               ftell(file)
00107 #define XP_FileFlush(file)              fflush(file)
00108 #define XP_FileClose(file)              fclose(file)
00109 #define XP_FileSetBufferSize(file,bufsize) (-1)
00110 
00111 #define XP_ASSERT(x)        ((void)0)
00112 
00113 #define XP_STRCAT(a,b)      strcat((a),(b))
00114 #define XP_ATOI             atoi
00115 #define XP_STRNCPY(a,b,n)   strncpy((a),(b),(n))
00116 #define XP_STRCPY(a,b)      strcpy((a),(b))
00117 #define XP_STRLEN(x)        strlen(x)
00118 #define XP_SPRINTF          sprintf
00119 #define XP_FREE(x)          free((x))
00120 #define XP_ALLOC(x)         malloc((x))
00121 #define XP_FREEIF(x)        if ((x)) free((x))
00122 #define XP_STRCMP(x,y)      strcmp((x),(y))
00123 #define XP_STRNCMP(x,y,n)   strncmp((x),(y),(n))
00124 #define XP_STRDUP(s)        strdup((s))
00125 #define XP_MEMCPY(d, s, l)  memcpy((d), (s), (l))
00126 #define XP_MEMSET(d, c, l)  memset((d), (c), (l))
00127 
00128 #define PR_Lock(a)          ((void)0)
00129 #define PR_Unlock(a)        ((void)0)
00130 
00131 #if defined(XP_WIN) || defined(XP_OS2)
00132   #define XP_STRCASECMP(x,y)  stricmp((x),(y))
00133   #define XP_STRNCASECMP(x,y,n) strnicmp((x),(y),(n))
00134 #else
00135   #define XP_STRCASECMP(x,y)  strcasecmp((x),(y))
00136   #define XP_STRNCASECMP(x,y,n) strncasecmp((x),(y),(n))
00137 #endif /* XP_WIN || XP_OS2 */
00138 
00139 typedef FILE          * XP_File;
00140 
00141 #else /* not standalone, use NSPR */
00142 
00143 
00144 /*-------------------------------------*/
00145 /* Alternate fileI/O function mappings */
00146 /*-------------------------------------*/
00147 
00148 #if USE_MMAP_REGISTRY_IO
00149   /*-----------------------------------------------*/
00150   /* NSPR mememory-mapped I/O (write through)      */
00151   /* unfortunately this isn't supported on the Mac */
00152   /*-----------------------------------------------*/
00153 #define USE_NSPR_MODES
00154 
00155 #include "mmapio.h"
00156 #define XP_FileSeek(file,offset,whence) mmio_FileSeek((file),(offset),(whence))
00157 #define XP_FileRead(dest,count,file)    mmio_FileRead((file), (dest), (count))
00158 #define XP_FileWrite(src,count,file)    mmio_FileWrite((file), (src), (count))
00159 #define XP_FileTell(file)               mmio_FileTell(file)
00160 #define XP_FileClose(file)              mmio_FileClose(file)
00161 #define XP_FileOpen(path, mode)         mmio_FileOpen((path), mode )
00162 #define XP_FileFlush(file)              ((void)1)
00163 #define XP_FileSetBufferSize(file, bufsize) (-1)
00164 
00165 typedef MmioFile* XP_File;
00166 
00167 #elif USE_BUFFERED_REGISTRY_IO
00168   /*-----------------------------------------------*/
00169   /* home-grown XP buffering                       */
00170   /* writes are buffered too so use flush!         */
00171   /*-----------------------------------------------*/
00172 #define USE_STDIO_MODES
00173 
00174 #include "nr_bufio.h"
00175 #define XP_FileSeek(file,offset,whence) bufio_Seek((file),(offset),(whence))
00176 #define XP_FileRead(dest,count,file)    bufio_Read((file), (dest), (count))
00177 #define XP_FileWrite(src,count,file)    bufio_Write((file), (src), (count))
00178 #define XP_FileTell(file)               bufio_Tell(file)
00179 #define XP_FileClose(file)              bufio_Close(file)
00180 #define XP_FileOpen(path, mode)         bufio_Open((path), (mode))
00181 #define XP_FileFlush(file)              bufio_Flush(file)
00182 #define XP_FileSetBufferSize(file,bufsize) bufio_SetBufferSize(file,bufsize)
00183 
00184 
00185 typedef BufioFile* XP_File;
00186 
00187 #else
00188   /*-----------------------------------------------*/
00189   /* standard NSPR file I/O                        */
00190   /*-----------------------------------------------*/
00191 #define USE_NSPR_MODES
00192 /*
00193 ** Note that PR_Seek returns the offset (if successful) and -1 otherwise.  So
00194 ** to make this code work
00195 **           if (XP_FileSeek(fh, offset, SEEK_SET) != 0)  { error handling }
00196 ** we return 1 if PR_Seek() returns a negative value, and 0 otherwise
00197 */
00198 #define XP_FileSeek(file,offset,whence) (PR_Seek((file), (offset), (whence)) < 0)
00199 #define XP_FileRead(dest,count,file)    PR_Read((file), (dest), (count))
00200 #define XP_FileWrite(src,count,file)    PR_Write((file), (src), (count))
00201 #define XP_FileTell(file)               PR_Seek(file, 0, PR_SEEK_CUR)
00202 #define XP_FileOpen(path, mode)         PR_Open((path), mode )
00203 #define XP_FileClose(file)              PR_Close(file)
00204 #define XP_FileFlush(file)              PR_Sync(file)
00205 #define XP_FileSetBufferSize(file,bufsize) (-1)
00206 
00207 typedef PRFileDesc* XP_File;
00208 
00209 #endif /*USE_MMAP_REGISTRY_IO*/
00210 
00211 
00212 
00213 #define XP_ASSERT(x)        PR_ASSERT((x))
00214 
00215 #define XP_STRCAT(a,b)      PL_strcat((a),(b))
00216 #define XP_ATOI             PL_atoi
00217 #define XP_STRCPY(a,b)      PL_strcpy((a),(b))
00218 #define XP_STRNCPY(a,b,n)   PL_strncpy((a),(b),(n))
00219 #define XP_STRLEN(x)        PL_strlen(x)
00220 #define XP_SPRINTF          sprintf
00221 #define XP_FREE(x)          PR_Free((x))
00222 #define XP_ALLOC(x)         PR_Malloc((x))
00223 #define XP_FREEIF(x)        PR_FREEIF(x)
00224 #define XP_STRCMP(x,y)      PL_strcmp((x),(y))
00225 #define XP_STRNCMP(x,y,n)   PL_strncmp((x),(y),(n))
00226 #define XP_STRDUP(s)        PL_strdup((s))
00227 #define XP_MEMCPY(d, s, l)  memcpy((d), (s), (l))
00228 #define XP_MEMSET(d, c, l)  memset((d), (c), (l))
00229 
00230 #define XP_STRCASECMP(x,y)  PL_strcasecmp((x),(y))
00231 #define XP_STRNCASECMP(x,y,n) PL_strncasecmp((x),(y),(n))
00232 
00233 
00234 #endif /*STANDALONE_REGISTRY*/
00235 
00236 /*--- file open modes for stdio ---*/
00237 #ifdef USE_STDIO_MODES
00238 #define XP_FILE_READ             "r"
00239 #define XP_FILE_READ_BIN         "rb"
00240 #define XP_FILE_WRITE            "w"
00241 #define XP_FILE_WRITE_BIN        "wb"
00242 #define XP_FILE_UPDATE           "r+"
00243 #define XP_FILE_TRUNCATE         "w+"
00244 #ifdef SUNOS4
00245 /* XXX SunOS4 hack -- make this universal by using r+b and w+b */
00246 #define XP_FILE_UPDATE_BIN       "r+"
00247 #define XP_FILE_TRUNCATE_BIN     "w+"
00248 #else
00249 #define XP_FILE_UPDATE_BIN       "rb+"
00250 #define XP_FILE_TRUNCATE_BIN     "wb+"
00251 #endif
00252 #endif /* USE_STDIO_MODES */
00253 
00254 /*--- file open modes for NSPR file I/O ---*/
00255 #ifdef USE_NSPR_MODES
00256 #define XP_FILE_READ             PR_RDONLY, 0644
00257 #define XP_FILE_READ_BIN         PR_RDONLY, 0644
00258 #define XP_FILE_WRITE            PR_WRONLY, 0644
00259 #define XP_FILE_WRITE_BIN        PR_WRONLY, 0644
00260 #define XP_FILE_UPDATE           (PR_RDWR|PR_CREATE_FILE), 0644
00261 #define XP_FILE_TRUNCATE         (PR_RDWR | PR_TRUNCATE), 0644
00262 #define XP_FILE_UPDATE_BIN       PR_RDWR|PR_CREATE_FILE, 0644
00263 #define XP_FILE_TRUNCATE_BIN     (PR_RDWR | PR_TRUNCATE), 0644
00264 
00265 #ifdef SEEK_SET
00266     #undef SEEK_SET
00267     #undef SEEK_CUR
00268     #undef SEEK_END
00269     #define SEEK_SET PR_SEEK_SET
00270     #define SEEK_CUR PR_SEEK_CUR
00271     #define SEEK_END PR_SEEK_END
00272 #endif
00273 #endif /* USE_NSPR_MODES */
00274 
00275 
00276 
00277 
00278 
00279 #ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
00280 #include "prtypes.h"
00281 #endif /*STANDALONE_REGISTRY*/
00282 
00283 typedef int XP_Bool;
00284 
00285 typedef struct stat    XP_StatStruct;
00286 #define  XP_Stat(file,data)     stat((file),(data))
00287 
00288 #if defined(XP_MAC)
00289  extern int nr_RenameFile(char *from, char *to);
00290 #else
00291     XP_BEGIN_PROTOS
00292     #define nr_RenameFile(from, to)    rename((from), (to))
00293     XP_END_PROTOS
00294 #endif
00295 
00296 
00297 
00298 XP_BEGIN_PROTOS
00299 
00300 extern char* globalRegName;
00301 extern char* verRegName;
00302 
00303 extern void vr_findGlobalRegName();
00304 extern char* vr_findVerRegName();
00305 
00306 
00307 #ifdef STANDALONE_REGISTRY /* included from prmon.h otherwise */
00308 
00309 extern XP_File vr_fileOpen(const char *name, const char * mode);
00310 
00311 
00312 #else
00313 #define vr_fileOpen PR_Open
00314 #endif /* STANDALONE_REGISTRY */
00315 
00316 XP_END_PROTOS
00317 
00318 #endif /* _VR_STUBS_H_ */