Back to index

lightning-sunbird  0.9+nobinonly
vr_stubs.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* this file contains stubs needed to build the registry routines
00039  * into a stand-alone library for use with our installers
00040  */
00041 
00042 #ifdef STANDALONE_REGISTRY
00043 
00044 #include <stdlib.h>
00045 #include <stdio.h>
00046 #include <string.h>
00047 
00048 #else
00049 
00050 #include "prtypes.h"
00051 #include "plstr.h"
00052 
00053 #endif /*STANDALONE_REGISTRY*/
00054 
00055 #include "vr_stubs.h"
00056 
00057 #if defined(XP_MAC)
00058 #include <Folders.h>
00059 #include <Script.h>
00060 #include <stdlib.h>
00061 #include <Errors.h>
00062 #include "MoreFiles.h"
00063 #include "FullPath.h"  /* For FSpLocationFromFullPath() */
00064 #endif
00065 
00066 #if defined(XP_MACOSX)
00067 #include <Folders.h>
00068 #include <stdlib.h>
00069 #endif
00070 
00071 #ifdef XP_BEOS
00072 #include <FindDirectory.h>
00073 #endif 
00074 
00075 #ifdef XP_MACOSX
00076 /* So that we're not dependent on the size of chars in a wide string literal */
00077 static const UniChar kOSXRegParentName[] =
00078   { 'M', 'o', 'z', 'i', 'l', 'l', 'a' };
00079 static const UniChar kOSXRegName[] =
00080   { 'G', 'l', 'o', 'b', 'a', 'l', '.', 'r', 'e', 'g', 's' };
00081 static const UniChar kOSXVersRegName[] =
00082   { 'V', 'e', 'r', 's', 'i', 'o', 'n', 's', '.', 'r', 'e', 'g', 's' };
00083 
00084 #define UNICHAR_ARRAY_LEN(s) (sizeof(s) / sizeof(UniChar))
00085 #endif
00086 
00087 #define DEF_REG "/.mozilla/registry"
00088 #define WIN_REG "\\mozregistry.dat"
00089 #define MAC_REG "\pMozilla Registry"
00090 #define BEOS_REG "/mozilla/registry"
00091 
00092 #define DEF_VERREG "/.mozilla/mozver.dat"
00093 #define WIN_VERREG "\\mozver.dat"
00094 #define MAC_VERREG "\pMozilla Versions"
00095 #define BEOS_VERREG "/mozilla/mozver.dat"
00096 
00097 
00098 /* ------------------------------------------------------------------
00099  *  OS/2 STUBS
00100  * ------------------------------------------------------------------
00101  */
00102 #ifdef XP_OS2
00103 #define INCL_DOS
00104 #include <os2.h>
00105 
00106 #ifdef STANDALONE_REGISTRY
00107 extern XP_File vr_fileOpen (const char *name, const char * mode)
00108 {
00109     XP_File fh = NULL;
00110     struct stat st;
00111 
00112     if ( name != NULL ) {
00113         if ( stat( name, &st ) == 0 )
00114             fh = fopen( name, XP_FILE_UPDATE_BIN );
00115         else
00116             fh = fopen( name, XP_FILE_TRUNCATE_BIN );
00117     }
00118 
00119     return fh;
00120 }
00121 #endif /*STANDALONE_REGISTRY*/
00122 
00123 extern void vr_findGlobalRegName ()
00124 {
00125     char    path[ CCHMAXPATH ];
00126     int     pathlen;
00127     XP_File fh = NULL;
00128     struct stat st;
00129 
00130     XP_STRCPY(path, ".");
00131     pathlen = strlen(path);
00132 
00133     if ( pathlen > 0 ) {
00134         XP_STRCPY( path+pathlen, WIN_REG );
00135         globalRegName = XP_STRDUP(path);
00136     }
00137 }
00138 
00139 char* vr_findVerRegName()
00140 {
00141     /* need to find a global place for the version registry */
00142     if ( verRegName == NULL )
00143     {
00144         if ( globalRegName == NULL)
00145             vr_findGlobalRegName();
00146         verRegName = XP_STRDUP(globalRegName);
00147     }
00148 
00149     return verRegName;
00150 }
00151 
00152 #endif /* XP_OS2 */
00153 
00154 
00155 /* ------------------------------------------------------------------
00156  *  WINDOWS STUBS
00157  * ------------------------------------------------------------------
00158  */
00159 #if defined(XP_WIN)
00160 #include "windows.h"
00161 #define PATHLEN 260
00162 
00163 #ifdef STANDALONE_REGISTRY
00164 extern XP_File vr_fileOpen (const char *name, const char * mode)
00165 {
00166     XP_File fh = NULL;
00167     struct stat st;
00168 
00169     if ( name != NULL ) {
00170         if ( stat( name, &st ) == 0 )
00171             fh = fopen( name, XP_FILE_UPDATE_BIN );
00172         else
00173             fh = fopen( name, XP_FILE_TRUNCATE_BIN );
00174     }
00175 
00176     return fh;
00177 }
00178 #endif /*STANDALONE_REGISTRY*/
00179 
00180 extern void vr_findGlobalRegName ()
00181 {
00182     char    path[ PATHLEN ];
00183     int     pathlen;
00184    
00185     pathlen = GetWindowsDirectory(path, PATHLEN);
00186     if ( pathlen > 0 ) {
00187         XP_FREEIF(globalRegName);
00188         XP_STRCPY( path+pathlen, WIN_REG );
00189         globalRegName = XP_STRDUP(path);
00190     }
00191 }
00192 
00193 char* vr_findVerRegName()
00194 {
00195     char    path[ PATHLEN ];
00196     int     pathlen;
00197    
00198     if ( verRegName == NULL )
00199     {
00200         pathlen = GetWindowsDirectory(path, PATHLEN);
00201         if ( pathlen > 0 ) {
00202             XP_STRCPY( path+pathlen, WIN_VERREG );
00203             verRegName = XP_STRDUP(path);
00204         }
00205     }
00206 
00207     return verRegName;
00208 }
00209 
00210 #if !defined(WIN32) && !defined(__BORLANDC__)
00211 int FAR PASCAL _export WEP(int);
00212 
00213 int FAR PASCAL LibMain(HANDLE hInst, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
00214 {
00215     if ( wHeapSize > 0 )
00216         UnlockData(0);
00217     return 1;
00218 }
00219 
00220 int FAR PASCAL _export WEP(int nParam)
00221 { 
00222     return 1; 
00223 }
00224 #endif /* not WIN32 */
00225 
00226 #endif /* XP_WIN */
00227 
00228 
00229 /* ------------------------------------------------------------------
00230  *  MACINTOSH STUBS
00231  * ------------------------------------------------------------------
00232  */
00233 
00234 #if defined(XP_MAC) || defined(XP_MACOSX)
00235 #include <Files.h>
00236 
00237 #ifdef STANDALONE_REGISTRY
00238 extern XP_File vr_fileOpen(const char *name, const char * mode)
00239 {
00240     XP_File fh = NULL;
00241     struct stat st;
00242     
00243 #ifdef STANDALONE_REGISTRY
00244     errno = 0; /* reset errno (only if we're using stdio) */
00245 #endif
00246 
00247     if ( name != NULL ) {
00248         if ( stat( name, &st ) == 0 )
00249             fh = fopen( name, XP_FILE_UPDATE_BIN );
00250         else 
00251         {
00252             /* should never get here! */
00253             fh = fopen( name, XP_FILE_TRUNCATE_BIN );
00254         }
00255     }
00256     return fh;
00257 }
00258 #endif /*STANDALONE_REGISTRY*/
00259 
00260 #if defined (XP_MACOSX)
00261 extern void vr_findGlobalRegName()
00262 {
00263     OSErr   err;
00264     FSRef   foundRef;
00265     
00266     err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef);
00267     if (err == noErr)
00268     {
00269         FSRef parentRef;
00270         err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
00271                                  kTextEncodingUnknown, &parentRef);
00272         if (err == fnfErr)
00273         {
00274             err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
00275                                            kFSCatInfoNone, NULL, &parentRef, NULL, NULL);
00276         }
00277         if (err == noErr)
00278         {
00279             FSRef regRef;
00280             err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName,
00281                                      kTextEncodingUnknown, &regRef);
00282             if (err == fnfErr)
00283             {
00284                 FSCatalogInfo catalogInfo;
00285                 FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
00286                 BlockMoveData(&fileInfo, &(catalogInfo.finderInfo), sizeof(FileInfo));
00287                 err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXRegName), kOSXRegName,
00288                                                kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
00289             }
00290             if (err == noErr)
00291             {
00292                 UInt8 pathBuf[PATH_MAX];
00293                 err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
00294                 if (err == noErr)
00295                     globalRegName = XP_STRDUP(pathBuf);
00296             }
00297         }
00298     }
00299 }
00300 #else
00301 extern void vr_findGlobalRegName()
00302 {
00303     FSSpec  regSpec;
00304     OSErr   err;
00305     short   foundVRefNum;
00306     long    foundDirID;
00307     int     bCreate = 0;
00308     
00309     err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID);
00310 
00311     if (err == noErr)
00312     {
00313         err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_REG, &regSpec);
00314 
00315         if (err == -43) /* if file doesn't exist */
00316         {
00317             err = FSpCreate(&regSpec, 'MOSS', 'REGS', smSystemScript);
00318             bCreate = 1;
00319         }
00320 
00321         if (err == noErr)
00322         {
00323             Handle thePath;
00324             short pathLen;
00325             err = FSpGetFullPath(&regSpec, &pathLen, &thePath);
00326             if (err == noErr && thePath)
00327             {
00328                 /* we have no idea if this moves memory, so better lock the handle */
00329             #if defined(STANDALONE_REGISTRY) || defined(USE_STDIO_MODES)
00330                 HLock(thePath);
00331                 globalRegName = (char *)XP_ALLOC(pathLen + 1);
00332                 XP_STRNCPY(globalRegName, *thePath, pathLen);
00333                 globalRegName[pathLen] = '\0';
00334             #else
00335                 /* Since we're now using NSPR, this HAS to be a unix path! */
00336                 const char* src;
00337                 char* dst;
00338                 HLock(thePath);
00339                 globalRegName = (char*)XP_ALLOC(pathLen + 2);
00340                 src = *(char**)thePath;
00341                 dst = globalRegName;
00342                 *dst++ = '/';
00343                 while (pathLen--)
00344                 {
00345                     char c = *src++;
00346                     *dst++ = (c == ':') ? '/' : c;
00347                 }
00348                 *dst = '\0';
00349             #endif
00350             }
00351             DisposeHandle(thePath);
00352         }
00353     }
00354 }
00355 #endif /* XP_MACOSX */
00356 
00357 #ifdef XP_MACOSX
00358 extern char* vr_findVerRegName()
00359 {
00360     OSErr   err;
00361     FSRef   foundRef;
00362     
00363     err = FSFindFolder(kLocalDomain, kDomainLibraryFolderType, kDontCreateFolder, &foundRef);
00364     if (err == noErr)
00365     {
00366         FSRef parentRef;
00367         err = FSMakeFSRefUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
00368                                  kTextEncodingUnknown, &parentRef);
00369         if (err == fnfErr)
00370         {
00371             err = FSCreateDirectoryUnicode(&foundRef, UNICHAR_ARRAY_LEN(kOSXRegParentName), kOSXRegParentName,
00372                                            kFSCatInfoNone, NULL, &parentRef, NULL, NULL);
00373         }
00374         if (err == noErr)
00375         {
00376             FSRef regRef;
00377             err = FSMakeFSRefUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
00378                                      kTextEncodingUnknown, &regRef);
00379             if (err == fnfErr)
00380             {
00381                 FSCatalogInfo catalogInfo;
00382                 FileInfo fileInfo = { 'REGS', 'MOSS', 0, { 0, 0 }, 0 };
00383                 BlockMoveData(&fileInfo, &(catalogInfo.finderInfo), sizeof(FileInfo));
00384                 err = FSCreateFileUnicode(&parentRef, UNICHAR_ARRAY_LEN(kOSXVersRegName), kOSXVersRegName,
00385                                                kFSCatInfoFinderInfo, &catalogInfo, &regRef, NULL);
00386             }
00387             if (err == noErr)
00388             {
00389                 UInt8 pathBuf[PATH_MAX];
00390                 err = FSRefMakePath(&regRef, pathBuf, sizeof(pathBuf));
00391                 if (err == noErr)
00392                     verRegName = XP_STRDUP(pathBuf);
00393             }
00394         }
00395     }
00396     return verRegName;
00397 }
00398 #else
00399 extern char* vr_findVerRegName()
00400 {
00401     FSSpec  regSpec;
00402     OSErr   err;
00403     short   foundVRefNum;
00404     long    foundDirID;
00405     int     bCreate = 0;
00406     
00407     /* quick exit if we have the info */
00408     if ( verRegName != NULL )
00409         return verRegName;
00410 
00411     err = FindFolder(kOnSystemDisk,'pref', false, &foundVRefNum, &foundDirID);
00412 
00413     if (err == noErr)
00414     {
00415         err = FSMakeFSSpec(foundVRefNum, foundDirID, MAC_VERREG, &regSpec);
00416 
00417         if (err == -43) /* if file doesn't exist */
00418         {
00419             err = FSpCreate(&regSpec, 'MOSS', 'REGS', smSystemScript);
00420             bCreate = 1;
00421         }
00422 
00423         if (err == noErr)
00424         {
00425             Handle thePath;
00426             short pathLen;
00427             err = FSpGetFullPath(&regSpec, &pathLen, &thePath);
00428             if (err == noErr && thePath)
00429             {
00430                 /* we have no idea if this moves memory, so better lock the handle */
00431              #if defined(STANDALONE_REGISTRY) || defined(USE_STDIO_MODES)
00432                 HLock(thePath);
00433                 verRegName = (char *)XP_ALLOC(pathLen + 1);
00434                 XP_STRNCPY(verRegName, *thePath, pathLen);
00435                 verRegName[pathLen] = '\0';
00436             #else
00437                 /* Since we're now using NSPR, this HAS to be a unix path! */
00438                 const char* src;
00439                 char* dst;
00440                 HLock(thePath);
00441                 verRegName = (char*)XP_ALLOC(pathLen + 2);
00442                 src = *(char**)thePath;
00443                 dst = verRegName;
00444                 *dst++ = '/';
00445                 while (pathLen--)
00446                 {
00447                     char c = *src++;
00448                     *dst++ = (c == ':') ? '/' : c;
00449                 }
00450                 *dst = '\0';
00451             #endif
00452             }
00453             DisposeHandle(thePath);
00454         }
00455     }
00456 
00457     return verRegName;
00458 }
00459 #endif /* OS_MACOSX */
00460 
00461 /* Moves and renames a file or directory.
00462    Returns 0 on success, -1 on failure (errno contains mac error code).
00463  */
00464 #ifndef XP_MACOSX 
00465 extern int nr_RenameFile(char *from, char *to)
00466 {
00467     OSErr           err = -1;
00468     FSSpec          fromSpec;
00469     FSSpec          toSpec;
00470     FSSpec          destDirSpec;
00471     FSSpec          beforeRenameSpec;
00472     
00473 #ifdef STANDALONE_REGISTRY
00474     errno = 0; /* reset errno (only if we're using stdio) */
00475 #endif
00476 
00477     if (from && to) {
00478         err = FSpLocationFromFullPath(XP_STRLEN(from), from, &fromSpec);
00479         if (err != noErr) goto exit;
00480         
00481         err = FSpLocationFromFullPath(XP_STRLEN(to), to, &toSpec);
00482         if (err != noErr && err != fnfErr) goto exit;
00483         
00484         /* make an FSSpec for the destination directory */
00485         err = FSMakeFSSpec(toSpec.vRefNum, toSpec.parID, nil, &destDirSpec);
00486         if (err != noErr) goto exit; /* parent directory must exist */
00487 
00488         /* move it to the directory specified */
00489         err = FSpCatMove(&fromSpec, &destDirSpec);
00490         if (err != noErr) goto exit;
00491         
00492         /* make a new FSSpec for the file or directory in its new location  */
00493         err = FSMakeFSSpec(toSpec.vRefNum, toSpec.parID, fromSpec.name, &beforeRenameSpec);
00494         if (err != noErr) goto exit;
00495         
00496         /* rename the file or directory */
00497         err = FSpRename(&beforeRenameSpec, toSpec.name);
00498     }
00499         
00500     exit:
00501 #ifdef STANDALONE_REGISTRY
00502     if (err != noErr)
00503         errno = err;
00504 #endif
00505     return (err == noErr ? 0 : -1);
00506 }
00507 #endif
00508 
00509 
00510 #ifdef STANDALONE_REGISTRY
00511 #ifndef XP_MACOSX
00512 char *strdup(const char *source)
00513 {
00514         char    *newAllocation;
00515         size_t  stringLength;
00516 
00517         stringLength = strlen(source) + 1;
00518 
00519         newAllocation = (char *)XP_ALLOC(stringLength);
00520         if (newAllocation == NULL)
00521                 return NULL;
00522         BlockMoveData(source, newAllocation, stringLength);
00523         return newAllocation;
00524 }
00525 
00526 int strcasecmp(const char *str1, const char *str2)
00527 {
00528     char    currentChar1, currentChar2;
00529 
00530     while (1) {
00531     
00532         currentChar1 = *str1;
00533         currentChar2 = *str2;
00534         
00535         if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
00536             currentChar1 += ('A' - 'a');
00537         
00538         if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
00539             currentChar2 += ('A' - 'a');
00540                 
00541         if (currentChar1 == '\0')
00542             break;
00543     
00544         if (currentChar1 != currentChar2)
00545             return currentChar1 - currentChar2;
00546             
00547         str1++;
00548         str2++;
00549     
00550     }
00551     
00552     return currentChar1 - currentChar2;
00553 }
00554 
00555 int strncasecmp(const char *str1, const char *str2, int length)
00556 {
00557     char    currentChar1, currentChar2;
00558 
00559     while (length > 0) {
00560 
00561         currentChar1 = *str1;
00562         currentChar2 = *str2;
00563 
00564         if ((currentChar1 >= 'a') && (currentChar1 <= 'z'))
00565             currentChar1 += ('A' - 'a');
00566 
00567         if ((currentChar2 >= 'a') && (currentChar2 <= 'z'))
00568             currentChar2 += ('A' - 'a');
00569 
00570         if (currentChar1 == '\0')
00571             break;
00572 
00573         if (currentChar1 != currentChar2)
00574             return currentChar1 - currentChar2;
00575 
00576         str1++;
00577         str2++;
00578 
00579         length--;
00580     }
00581 
00582     return currentChar1 - currentChar2;
00583 }
00584 #endif /* XP_MACOSX */
00585 #endif /* STANDALONE_REGISTRY */
00586 
00587 #endif /* XP_MAC */
00588 
00589 
00590 /* ------------------------------------------------------------------
00591  *  UNIX STUBS
00592  * ------------------------------------------------------------------
00593  */
00594 
00595 /*allow OS/2 and Macintosh to use this main to test...*/
00596 #if (defined(STANDALONE_REGISTRY) && defined(XP_MAC)) || defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
00597 
00598 #include <stdlib.h>
00599 
00600 #ifdef XP_OS2
00601 #include <io.h>
00602 #define W_OK 0x02 /*evil hack from the docs...*/
00603 #else
00604 #include <unistd.h>
00605 #endif
00606 
00607 #include "NSReg.h"
00608 #include "VerReg.h"
00609 #include "nsBuildID.h"
00610 
00611 char *TheRegistry = "registry"; 
00612 char *Flist;
00613 
00614 /* WARNING: build hackery */
00615 #if defined(STANDALONE_REGISTRY) && !defined(XP_MAC) && !defined(XP_MACOSX)
00616 long BUILDNUM = NS_BUILD_ID;
00617 #endif
00618 
00619 
00620 REGERR vr_ParseVersion(char *verstr, VERSION *result);
00621 
00622 #if defined(XP_UNIX) && !defined(XP_MACOSX)
00623 
00624 #ifdef STANDALONE_REGISTRY
00625 extern XP_File vr_fileOpen (const char *name, const char * mode)
00626 {
00627     XP_File fh = NULL;
00628     struct stat st;
00629 
00630     if ( name != NULL ) {
00631         if ( stat( name, &st ) == 0 )
00632             fh = fopen( name, XP_FILE_UPDATE_BIN );
00633         else
00634             fh = fopen( name, XP_FILE_TRUNCATE_BIN );
00635     }
00636 
00637     return fh;
00638 }
00639 #endif /*STANDALONE_REGISTRY*/
00640 
00641 extern void vr_findGlobalRegName ()
00642 {
00643 #ifndef STANDALONE_REGISTRY
00644     char *def = NULL;
00645     char *home = getenv("HOME");
00646     if (home != NULL) {
00647         def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_REG)+1);
00648         if (def != NULL) {
00649           XP_STRCPY(def, home);
00650           XP_STRCAT(def, DEF_REG);
00651         }
00652     }
00653     if (def != NULL) {
00654         globalRegName = XP_STRDUP(def);
00655     } else {
00656         globalRegName = XP_STRDUP(TheRegistry);
00657     }
00658     XP_FREEIF(def);
00659 #else
00660     globalRegName = XP_STRDUP(TheRegistry);
00661 #endif /*STANDALONE_REGISTRY*/
00662 }
00663 
00664 char* vr_findVerRegName ()
00665 {
00666     if ( verRegName != NULL )
00667         return verRegName;
00668 
00669 #ifndef STANDALONE_REGISTRY
00670     {
00671         char *def = NULL;
00672         char *home = getenv("HOME");
00673         if (home != NULL) {
00674             def = (char *) XP_ALLOC(XP_STRLEN(home) + XP_STRLEN(DEF_VERREG)+1);
00675             if (def != NULL) {
00676                 XP_STRCPY(def, home);
00677                 XP_STRCAT(def, DEF_VERREG);
00678             }
00679         }
00680         if (def != NULL) {
00681             verRegName = XP_STRDUP(def);
00682         }
00683         XP_FREEIF(def);
00684     }
00685 #else
00686     verRegName = XP_STRDUP(TheRegistry);
00687 #endif /*STANDALONE_REGISTRY*/
00688 
00689     return verRegName;
00690 }
00691 
00692 #endif /*XP_UNIX*/
00693 
00694  /* ------------------------------------------------------------------
00695  *  BeOS STUBS
00696  * ------------------------------------------------------------------
00697  */
00698 
00699 #ifdef XP_BEOS
00700 
00701 #ifdef STANDALONE_REGISTRY
00702 extern XP_File vr_fileOpen (const char *name, const char * mode)
00703 {
00704     XP_File fh = NULL;
00705     struct stat st;
00706 
00707     if ( name != NULL ) {
00708         if ( stat( name, &st ) == 0 )
00709             fh = fopen( name, XP_FILE_UPDATE_BIN );
00710         else
00711             fh = fopen( name, XP_FILE_TRUNCATE_BIN );
00712     }
00713 
00714     return fh;
00715 }
00716 #endif /*STANDALONE_REGISTRY*/
00717 
00718 extern void vr_findGlobalRegName ()
00719 {
00720 #ifndef STANDALONE_REGISTRY
00721     char *def = NULL;
00722       char settings[1024];
00723       find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settings, sizeof(settings));
00724     if (settings != NULL) {
00725         def = (char *) XP_ALLOC(XP_STRLEN(settings) + XP_STRLEN(BEOS_REG)+1);
00726         if (def != NULL) {
00727           XP_STRCPY(def, settings);
00728           XP_STRCAT(def, BEOS_REG);
00729         }
00730     }
00731     if (def != NULL) {
00732         globalRegName = XP_STRDUP(def);
00733     } else {
00734         globalRegName = XP_STRDUP(TheRegistry);
00735     }
00736     XP_FREEIF(def);
00737 #else
00738     globalRegName = XP_STRDUP(TheRegistry);
00739 #endif /*STANDALONE_REGISTRY*/
00740 }
00741 
00742 char* vr_findVerRegName ()
00743 {
00744     if ( verRegName != NULL )
00745         return verRegName;
00746 
00747 #ifndef STANDALONE_REGISTRY
00748     {
00749         char *def = NULL;
00750         char settings[1024];
00751         find_directory(B_USER_SETTINGS_DIRECTORY, -1, false, settings, sizeof(settings));
00752         if (settings != NULL) {
00753             def = (char *) XP_ALLOC(XP_STRLEN(settings) + XP_STRLEN(BEOS_VERREG)+1);
00754             if (def != NULL) {
00755                 XP_STRCPY(def, settings);
00756                 XP_STRCAT(def, BEOS_VERREG);
00757             }
00758         }
00759         if (def != NULL) {
00760             verRegName = XP_STRDUP(def);
00761         }
00762         XP_FREEIF(def);
00763     }
00764 #else
00765     verRegName = XP_STRDUP(TheRegistry);
00766 #endif /*STANDALONE_REGISTRY*/
00767 
00768     return verRegName;
00769 }
00770 
00771 #endif /*XP_BEOS*/
00772 
00773 #endif /* XP_UNIX || XP_OS2 */