/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in * compliance with the NPL. You may obtain a copy of the NPL at * http://www.mozilla.org/NPL/ * * Software distributed under the NPL is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL * for the specific language governing rights and limitations under the * NPL. * * The Initial Developer of this code under the NPL is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All Rights * Reserved. */ // // Various utils needed for the Address book functions // Written by: Rich Pizzarro (rhp@netscape.com) // November 1997 // #include #include #include #include #include "xpapi.h" #include "trace.h" #include "nabipc.h" #include "nabutl.h" #define ONE_SEC 20 #define STARTUP "Start" #define STARTUP_TIME 20 #define EXIT "Exit" #define EXIT_TIME 10 // // Global variables // BOOL gLoggingEnabled = FALSE; void SetLoggingEnabled(BOOL val) { gLoggingEnabled = val; } // Log File void LogString(LPCSTR pStr1) { // Off of the declaration line... LPCSTR pStr2 = NULL; BOOL useStr1 = TRUE; if (gLoggingEnabled) { char tempPath[_MAX_PATH] = ""; if (getenv("TEMP")) { lstrcpy((LPSTR) tempPath, getenv("TEMP")); // environmental variable } int len = lstrlen(tempPath); if ((len > 1) && tempPath[len - 1] != '\\') { lstrcat(tempPath, "\\"); } lstrcat(tempPath, szNABLog); HFILE hFile = _lopen(tempPath, OF_WRITE); if (hFile == HFILE_ERROR) { hFile = _lcreat(tempPath, 0); } if (hFile != HFILE_ERROR) { _llseek(hFile, 0, SEEK_END); // seek to the end of the file LPCSTR pTemp = useStr1 ? pStr1 : pStr2; _lwrite(hFile, pTemp, lstrlen(pTemp)); _lclose(hFile); } } } void BuildMemName(LPSTR name, ULONG winSeed) { static DWORD id = 0; if (id == 0) { // Seed the random-number generator with current time so that // the numbers will be different every time we run. srand( (unsigned)time( NULL ) ); id = rand(); } wsprintf(name, "NAB_IPC_SMEM-%d", (winSeed + id++)); TRACE("Shared Memory Name = [%s]\n", name); } DWORD ValidateFile(LPCSTR szFile) { struct _stat buf; int result; result = _stat( szFile, &buf ); if (result != 0) return(1); if (!(buf.st_mode & S_IREAD)) return(2); return(0); } DWORD GetFileCount(LPSTR pFiles, LPSTR delimChar) { DWORD count = 1; if ((!pFiles) || (!*pFiles)) return(0); for (DWORD i=0; i