1*12720SWyllys.Ingersoll@Sun.COM /* 2*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER START 3*12720SWyllys.Ingersoll@Sun.COM * 4*12720SWyllys.Ingersoll@Sun.COM * The contents of this file are subject to the terms of the 5*12720SWyllys.Ingersoll@Sun.COM * Common Development and Distribution License (the "License"). 6*12720SWyllys.Ingersoll@Sun.COM * You may not use this file except in compliance with the License. 7*12720SWyllys.Ingersoll@Sun.COM * 8*12720SWyllys.Ingersoll@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*12720SWyllys.Ingersoll@Sun.COM * or http://www.opensolaris.org/os/licensing. 10*12720SWyllys.Ingersoll@Sun.COM * See the License for the specific language governing permissions 11*12720SWyllys.Ingersoll@Sun.COM * and limitations under the License. 12*12720SWyllys.Ingersoll@Sun.COM * 13*12720SWyllys.Ingersoll@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each 14*12720SWyllys.Ingersoll@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*12720SWyllys.Ingersoll@Sun.COM * If applicable, add the following below this CDDL HEADER, with the 16*12720SWyllys.Ingersoll@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying 17*12720SWyllys.Ingersoll@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner] 18*12720SWyllys.Ingersoll@Sun.COM * 19*12720SWyllys.Ingersoll@Sun.COM * CDDL HEADER END 20*12720SWyllys.Ingersoll@Sun.COM */ 21*12720SWyllys.Ingersoll@Sun.COM 22*12720SWyllys.Ingersoll@Sun.COM /* 23*12720SWyllys.Ingersoll@Sun.COM * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 24*12720SWyllys.Ingersoll@Sun.COM */ 25*12720SWyllys.Ingersoll@Sun.COM 26*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 27*12720SWyllys.Ingersoll@Sun.COM * Module: System Abstraction Layer 28*12720SWyllys.Ingersoll@Sun.COM * 29*12720SWyllys.Ingersoll@Sun.COM * Description: 30*12720SWyllys.Ingersoll@Sun.COM * The system layer provides an abstract layer for the most commonly 31*12720SWyllys.Ingersoll@Sun.COM * used system calls for multi-platforms including Windows and most 32*12720SWyllys.Ingersoll@Sun.COM * Unix variants. 33*12720SWyllys.Ingersoll@Sun.COM * 34*12720SWyllys.Ingersoll@Sun.COM * All the functions defined in this layer fall into 4 categories: 35*12720SWyllys.Ingersoll@Sun.COM * Threading related functions 36*12720SWyllys.Ingersoll@Sun.COM * Mutexes 37*12720SWyllys.Ingersoll@Sun.COM * Conditional variables 38*12720SWyllys.Ingersoll@Sun.COM * Other Utilities 39*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 40*12720SWyllys.Ingersoll@Sun.COM 41*12720SWyllys.Ingersoll@Sun.COM #ifndef SYS_COMMON_H 42*12720SWyllys.Ingersoll@Sun.COM #define SYS_COMMON_H 43*12720SWyllys.Ingersoll@Sun.COM #ifdef __cplusplus 44*12720SWyllys.Ingersoll@Sun.COM extern "C" { 45*12720SWyllys.Ingersoll@Sun.COM #endif 46*12720SWyllys.Ingersoll@Sun.COM 47*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 48*12720SWyllys.Ingersoll@Sun.COM * ERROR code 49*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 50*12720SWyllys.Ingersoll@Sun.COM 51*12720SWyllys.Ingersoll@Sun.COM #define K_SYS_OK 0 52*12720SWyllys.Ingersoll@Sun.COM #define K_SYS_ERR_NO_MEMORY 1 53*12720SWyllys.Ingersoll@Sun.COM #define K_SYS_ERR_CREATE_THREAD 2 54*12720SWyllys.Ingersoll@Sun.COM #define K_SYS_ERR_JOIN_THREAD 3 55*12720SWyllys.Ingersoll@Sun.COM #define K_SYS_ERR_COND 4 56*12720SWyllys.Ingersoll@Sun.COM 57*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 58*12720SWyllys.Ingersoll@Sun.COM * Header files 59*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 60*12720SWyllys.Ingersoll@Sun.COM 61*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 62*12720SWyllys.Ingersoll@Sun.COM #include <windows.h> 63*12720SWyllys.Ingersoll@Sun.COM #include <process.h> 64*12720SWyllys.Ingersoll@Sun.COM #else 65*12720SWyllys.Ingersoll@Sun.COM #include <pthread.h> 66*12720SWyllys.Ingersoll@Sun.COM 67*12720SWyllys.Ingersoll@Sun.COM /* UNIX : added by STG */ 68*12720SWyllys.Ingersoll@Sun.COM #include <stdlib.h> 69*12720SWyllys.Ingersoll@Sun.COM #include <string.h> 70*12720SWyllys.Ingersoll@Sun.COM #ifndef METAWARE 71*12720SWyllys.Ingersoll@Sun.COM #include <wchar.h> 72*12720SWyllys.Ingersoll@Sun.COM #endif 73*12720SWyllys.Ingersoll@Sun.COM #include <sys/types.h> 74*12720SWyllys.Ingersoll@Sun.COM #include <sys/stat.h> 75*12720SWyllys.Ingersoll@Sun.COM #include <stdarg.h> 76*12720SWyllys.Ingersoll@Sun.COM 77*12720SWyllys.Ingersoll@Sun.COM /* 78*12720SWyllys.Ingersoll@Sun.COM * These functions are not needed, since the Agent API hides them 79*12720SWyllys.Ingersoll@Sun.COM * enum KeystoneAgent_SortOrder {}; 80*12720SWyllys.Ingersoll@Sun.COM * enum KeystoneAgent_FilterOperator {}; 81*12720SWyllys.Ingersoll@Sun.COM */ 82*12720SWyllys.Ingersoll@Sun.COM 83*12720SWyllys.Ingersoll@Sun.COM #endif 84*12720SWyllys.Ingersoll@Sun.COM 85*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 86*12720SWyllys.Ingersoll@Sun.COM * MACRO definitions 87*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 88*12720SWyllys.Ingersoll@Sun.COM 89*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 90*12720SWyllys.Ingersoll@Sun.COM #define PATH_SEPARATOR '\\' 91*12720SWyllys.Ingersoll@Sun.COM #define PATH_SEPARATOR_WSTR L"\\" 92*12720SWyllys.Ingersoll@Sun.COM #ifndef PATH_MAX 93*12720SWyllys.Ingersoll@Sun.COM #define PATH_MAX MAX_PATH 94*12720SWyllys.Ingersoll@Sun.COM #endif 95*12720SWyllys.Ingersoll@Sun.COM #else 96*12720SWyllys.Ingersoll@Sun.COM #define PATH_SEPARATOR '/' 97*12720SWyllys.Ingersoll@Sun.COM #define PATH_SEPARATOR_WSTR L"/" 98*12720SWyllys.Ingersoll@Sun.COM #endif 99*12720SWyllys.Ingersoll@Sun.COM 100*12720SWyllys.Ingersoll@Sun.COM #ifndef BOOL 101*12720SWyllys.Ingersoll@Sun.COM #define BOOL int 102*12720SWyllys.Ingersoll@Sun.COM #endif 103*12720SWyllys.Ingersoll@Sun.COM #ifndef TRUE 104*12720SWyllys.Ingersoll@Sun.COM #define TRUE 1 105*12720SWyllys.Ingersoll@Sun.COM #define FALSE 0 106*12720SWyllys.Ingersoll@Sun.COM #endif 107*12720SWyllys.Ingersoll@Sun.COM 108*12720SWyllys.Ingersoll@Sun.COM #ifdef K_LINUX_PLATFORM 109*12720SWyllys.Ingersoll@Sun.COM #ifndef UNIX 110*12720SWyllys.Ingersoll@Sun.COM #define UNIX 111*12720SWyllys.Ingersoll@Sun.COM #endif 112*12720SWyllys.Ingersoll@Sun.COM #endif 113*12720SWyllys.Ingersoll@Sun.COM 114*12720SWyllys.Ingersoll@Sun.COM #ifdef K_AIX_PLATFORM 115*12720SWyllys.Ingersoll@Sun.COM #ifndef UNIX 116*12720SWyllys.Ingersoll@Sun.COM #define UNIX 117*12720SWyllys.Ingersoll@Sun.COM #endif 118*12720SWyllys.Ingersoll@Sun.COM #endif 119*12720SWyllys.Ingersoll@Sun.COM 120*12720SWyllys.Ingersoll@Sun.COM #ifdef K_SOLARIS_PLATFORM 121*12720SWyllys.Ingersoll@Sun.COM #ifndef UNIX 122*12720SWyllys.Ingersoll@Sun.COM #define UNIX 123*12720SWyllys.Ingersoll@Sun.COM #endif 124*12720SWyllys.Ingersoll@Sun.COM #endif 125*12720SWyllys.Ingersoll@Sun.COM 126*12720SWyllys.Ingersoll@Sun.COM #ifdef K_HPUX_PLATFORM 127*12720SWyllys.Ingersoll@Sun.COM #ifndef UNIX 128*12720SWyllys.Ingersoll@Sun.COM #define UNIX 129*12720SWyllys.Ingersoll@Sun.COM #endif 130*12720SWyllys.Ingersoll@Sun.COM #endif 131*12720SWyllys.Ingersoll@Sun.COM 132*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 133*12720SWyllys.Ingersoll@Sun.COM * Fatal error definitions 134*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 135*12720SWyllys.Ingersoll@Sun.COM 136*12720SWyllys.Ingersoll@Sun.COM #ifndef __FUNCTION__ 137*12720SWyllys.Ingersoll@Sun.COM #define __FUNCTION__ "(Unknown)" 138*12720SWyllys.Ingersoll@Sun.COM #endif 139*12720SWyllys.Ingersoll@Sun.COM 140*12720SWyllys.Ingersoll@Sun.COM #ifndef FATAL_APPLICATION_STATE 141*12720SWyllys.Ingersoll@Sun.COM 142*12720SWyllys.Ingersoll@Sun.COM #ifdef DEBUG 143*12720SWyllys.Ingersoll@Sun.COM 144*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 145*12720SWyllys.Ingersoll@Sun.COM #include "crtdbg.h" 146*12720SWyllys.Ingersoll@Sun.COM #define DEBUG_BREAK() { _CrtDbgBreak(); } 147*12720SWyllys.Ingersoll@Sun.COM #else /* WIN32 */ 148*12720SWyllys.Ingersoll@Sun.COM #ifdef METAWARE 149*12720SWyllys.Ingersoll@Sun.COM #define DEBUG_BREAK() (void *) 0x00000000; /* dummy operation */ 150*12720SWyllys.Ingersoll@Sun.COM #else 151*12720SWyllys.Ingersoll@Sun.COM #if !defined(__i386) 152*12720SWyllys.Ingersoll@Sun.COM #define DEBUG_BREAK() 153*12720SWyllys.Ingersoll@Sun.COM #else 154*12720SWyllys.Ingersoll@Sun.COM #ifdef __GNUC__ 155*12720SWyllys.Ingersoll@Sun.COM #define DEBUG_BREAK() { __asm__ ( "int3" ); } /* NOTE: This only works for x86 platforms */ 156*12720SWyllys.Ingersoll@Sun.COM #else 157*12720SWyllys.Ingersoll@Sun.COM #define DEBUG_BREAK() 158*12720SWyllys.Ingersoll@Sun.COM #endif 159*12720SWyllys.Ingersoll@Sun.COM #endif /* __i386 */ 160*12720SWyllys.Ingersoll@Sun.COM #endif /* METAWARE */ 161*12720SWyllys.Ingersoll@Sun.COM #endif /* WIN32 */ 162*12720SWyllys.Ingersoll@Sun.COM 163*12720SWyllys.Ingersoll@Sun.COM #define FATAL_APPLICATION_STATE() \ 164*12720SWyllys.Ingersoll@Sun.COM do { \ 165*12720SWyllys.Ingersoll@Sun.COM DEBUG_BREAK(); \ 166*12720SWyllys.Ingersoll@Sun.COM process_fatal_application_state(__FILE__,__FUNCTION__,__LINE__,0); \ 167*12720SWyllys.Ingersoll@Sun.COM } while(0) 168*12720SWyllys.Ingersoll@Sun.COM 169*12720SWyllys.Ingersoll@Sun.COM #define FATAL_APPLICATION_STATE1(additional_text) \ 170*12720SWyllys.Ingersoll@Sun.COM do { \ 171*12720SWyllys.Ingersoll@Sun.COM DEBUG_BREAK(); \ 172*12720SWyllys.Ingersoll@Sun.COM process_fatal_application_state(__FILE__,__FUNCTION__,__LINE__,additional_text); \ 173*12720SWyllys.Ingersoll@Sun.COM } while(0) 174*12720SWyllys.Ingersoll@Sun.COM 175*12720SWyllys.Ingersoll@Sun.COM #else //DEBUG 176*12720SWyllys.Ingersoll@Sun.COM 177*12720SWyllys.Ingersoll@Sun.COM #define DEBUG_BREAK() 178*12720SWyllys.Ingersoll@Sun.COM 179*12720SWyllys.Ingersoll@Sun.COM #define FATAL_APPLICATION_STATE() \ 180*12720SWyllys.Ingersoll@Sun.COM do { \ 181*12720SWyllys.Ingersoll@Sun.COM process_fatal_application_state(__FILE__,__FUNCTION__,__LINE__,0); \ 182*12720SWyllys.Ingersoll@Sun.COM } while(0) 183*12720SWyllys.Ingersoll@Sun.COM 184*12720SWyllys.Ingersoll@Sun.COM #define FATAL_APPLICATION_STATE1(additional_text) \ 185*12720SWyllys.Ingersoll@Sun.COM do { \ 186*12720SWyllys.Ingersoll@Sun.COM process_fatal_application_state(__FILE__,__FUNCTION__,__LINE__,additional_text); \ 187*12720SWyllys.Ingersoll@Sun.COM } while(0) 188*12720SWyllys.Ingersoll@Sun.COM 189*12720SWyllys.Ingersoll@Sun.COM #endif //DEBUG 190*12720SWyllys.Ingersoll@Sun.COM 191*12720SWyllys.Ingersoll@Sun.COM #define FATAL_ASSERT(expression) do { if(!(expression)) {FATAL_APPLICATION_STATE();} } while(0) 192*12720SWyllys.Ingersoll@Sun.COM #define FATAL_ASSERT1(expression,additional_text) do { if(!(expression)) {FATAL_APPLICATION_STATE1(additional_text);} } while(0) 193*12720SWyllys.Ingersoll@Sun.COM 194*12720SWyllys.Ingersoll@Sun.COM /* MS Visual Studio compiler does not support __attribute__() */ 195*12720SWyllys.Ingersoll@Sun.COM #ifndef __GNUC__ 196*12720SWyllys.Ingersoll@Sun.COM #define __attribute__(x) 197*12720SWyllys.Ingersoll@Sun.COM #endif 198*12720SWyllys.Ingersoll@Sun.COM 199*12720SWyllys.Ingersoll@Sun.COM void process_fatal_application_state(const char* sFile, const char* sFunction, int iLine, const char* sAdditionalText) __attribute__((noreturn)); 200*12720SWyllys.Ingersoll@Sun.COM 201*12720SWyllys.Ingersoll@Sun.COM void generate_stack_trace(const char* i_sFile, const wchar_t* i_wsErrMsg); 202*12720SWyllys.Ingersoll@Sun.COM 203*12720SWyllys.Ingersoll@Sun.COM #endif /* FATAL_APPLICATION_STATE */ 204*12720SWyllys.Ingersoll@Sun.COM 205*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 206*12720SWyllys.Ingersoll@Sun.COM * Primitive type definitions 207*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 208*12720SWyllys.Ingersoll@Sun.COM 209*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 210*12720SWyllys.Ingersoll@Sun.COM typedef __int64 int64; 211*12720SWyllys.Ingersoll@Sun.COM #else 212*12720SWyllys.Ingersoll@Sun.COM #ifndef K_AIX_PLATFORM 213*12720SWyllys.Ingersoll@Sun.COM typedef signed long long int64; 214*12720SWyllys.Ingersoll@Sun.COM #endif 215*12720SWyllys.Ingersoll@Sun.COM #endif 216*12720SWyllys.Ingersoll@Sun.COM 217*12720SWyllys.Ingersoll@Sun.COM 218*12720SWyllys.Ingersoll@Sun.COM #ifdef K_HPUX_PLATFORM 219*12720SWyllys.Ingersoll@Sun.COM wchar_t* wcsstr (const wchar_t* haystack, const wchar_t* needle); 220*12720SWyllys.Ingersoll@Sun.COM int wprintf (const wchar_t* format, ...); 221*12720SWyllys.Ingersoll@Sun.COM int swprintf (wchar_t* s, size_t maxlen, const wchar_t* format, ...); 222*12720SWyllys.Ingersoll@Sun.COM int vswprintf (wchar_t* s, size_t maxlen, const wchar_t* format, va_list args); 223*12720SWyllys.Ingersoll@Sun.COM int swscanf(const wchar_t *s, const wchar_t *format, ...); 224*12720SWyllys.Ingersoll@Sun.COM int64 atoll(const char *str); 225*12720SWyllys.Ingersoll@Sun.COM #endif 226*12720SWyllys.Ingersoll@Sun.COM 227*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 228*12720SWyllys.Ingersoll@Sun.COM * Thread type definitions 229*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 230*12720SWyllys.Ingersoll@Sun.COM 231*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 232*12720SWyllys.Ingersoll@Sun.COM typedef HANDLE K_THREAD_HANDLE; 233*12720SWyllys.Ingersoll@Sun.COM #else 234*12720SWyllys.Ingersoll@Sun.COM typedef pthread_t K_THREAD_HANDLE; 235*12720SWyllys.Ingersoll@Sun.COM #endif 236*12720SWyllys.Ingersoll@Sun.COM 237*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 238*12720SWyllys.Ingersoll@Sun.COM * Mutex type definitions 239*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 240*12720SWyllys.Ingersoll@Sun.COM 241*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 242*12720SWyllys.Ingersoll@Sun.COM 243*12720SWyllys.Ingersoll@Sun.COM typedef struct { 244*12720SWyllys.Ingersoll@Sun.COM HANDLE m_handle; /* mutex handle */ 245*12720SWyllys.Ingersoll@Sun.COM 246*12720SWyllys.Ingersoll@Sun.COM CRITICAL_SECTION m_stCriticalSection; /* criticalSection */ 247*12720SWyllys.Ingersoll@Sun.COM 248*12720SWyllys.Ingersoll@Sun.COM int m_bIsRecursive; 249*12720SWyllys.Ingersoll@Sun.COM } WIN32Mutex; 250*12720SWyllys.Ingersoll@Sun.COM 251*12720SWyllys.Ingersoll@Sun.COM typedef WIN32Mutex* K_MUTEX_HANDLE; 252*12720SWyllys.Ingersoll@Sun.COM 253*12720SWyllys.Ingersoll@Sun.COM #else 254*12720SWyllys.Ingersoll@Sun.COM typedef pthread_mutex_t* K_MUTEX_HANDLE; 255*12720SWyllys.Ingersoll@Sun.COM #endif 256*12720SWyllys.Ingersoll@Sun.COM 257*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 258*12720SWyllys.Ingersoll@Sun.COM * Conditional variable type definitions 259*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 260*12720SWyllys.Ingersoll@Sun.COM 261*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 262*12720SWyllys.Ingersoll@Sun.COM struct K_CondStruct 263*12720SWyllys.Ingersoll@Sun.COM { 264*12720SWyllys.Ingersoll@Sun.COM HANDLE m_hEvent; 265*12720SWyllys.Ingersoll@Sun.COM HANDLE m_hMutex; 266*12720SWyllys.Ingersoll@Sun.COM int m_iSignalAll; 267*12720SWyllys.Ingersoll@Sun.COM int m_iNumWaiting; 268*12720SWyllys.Ingersoll@Sun.COM int m_iSignalled; 269*12720SWyllys.Ingersoll@Sun.COM }; 270*12720SWyllys.Ingersoll@Sun.COM typedef struct K_CondStruct K_ConditionalVariable; 271*12720SWyllys.Ingersoll@Sun.COM 272*12720SWyllys.Ingersoll@Sun.COM #else 273*12720SWyllys.Ingersoll@Sun.COM typedef pthread_cond_t K_ConditionalVariable; 274*12720SWyllys.Ingersoll@Sun.COM #endif 275*12720SWyllys.Ingersoll@Sun.COM 276*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 277*12720SWyllys.Ingersoll@Sun.COM * Thread function type definitions 278*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 279*12720SWyllys.Ingersoll@Sun.COM 280*12720SWyllys.Ingersoll@Sun.COM /* 281*12720SWyllys.Ingersoll@Sun.COM * Having the function return int breaks compatibility between Windows 282*12720SWyllys.Ingersoll@Sun.COM * and Unix; the function has to return void 283*12720SWyllys.Ingersoll@Sun.COM */ 284*12720SWyllys.Ingersoll@Sun.COM /*#ifdef WIN32 285*12720SWyllys.Ingersoll@Sun.COM * typedef int (_stdcall *K_ThreadFunc) (void *vpData); 286*12720SWyllys.Ingersoll@Sun.COM *#else 287*12720SWyllys.Ingersoll@Sun.COM */ 288*12720SWyllys.Ingersoll@Sun.COM typedef void (*K_ThreadFunc) (void *vpData); 289*12720SWyllys.Ingersoll@Sun.COM /* 290*12720SWyllys.Ingersoll@Sun.COM *#endif 291*12720SWyllys.Ingersoll@Sun.COM */ 292*12720SWyllys.Ingersoll@Sun.COM 293*12720SWyllys.Ingersoll@Sun.COM 294*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 295*12720SWyllys.Ingersoll@Sun.COM * Function: K_CreateThread 296*12720SWyllys.Ingersoll@Sun.COM * 297*12720SWyllys.Ingersoll@Sun.COM * Description: 298*12720SWyllys.Ingersoll@Sun.COM * This thread creation function takes a thread function 299*12720SWyllys.Ingersoll@Sun.COM * and its parameter to create a thread. It also has a Boolean 300*12720SWyllys.Ingersoll@Sun.COM * parameter to indicate if the thread is detached or joinable. 301*12720SWyllys.Ingersoll@Sun.COM * A new thread's handle is returned through the output parameter. 302*12720SWyllys.Ingersoll@Sun.COM * 303*12720SWyllys.Ingersoll@Sun.COM * Input 304*12720SWyllys.Ingersoll@Sun.COM * ----- 305*12720SWyllys.Ingersoll@Sun.COM * i_pFunc Function pointer of the thread function 306*12720SWyllys.Ingersoll@Sun.COM * i_pvData The point of the parameter passed to the thread function 307*12720SWyllys.Ingersoll@Sun.COM * i_bIsDetached The thread is detached or not. If detached, then it is 308*12720SWyllys.Ingersoll@Sun.COM * not joinable. (Note: It is not supported on Win32) 309*12720SWyllys.Ingersoll@Sun.COM * 310*12720SWyllys.Ingersoll@Sun.COM * Output 311*12720SWyllys.Ingersoll@Sun.COM * ------ 312*12720SWyllys.Ingersoll@Sun.COM * o_pNewThread The Thread handle 313*12720SWyllys.Ingersoll@Sun.COM * 314*12720SWyllys.Ingersoll@Sun.COM * Return value Error code 315*12720SWyllys.Ingersoll@Sun.COM * 316*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 317*12720SWyllys.Ingersoll@Sun.COM int K_CreateThread(K_ThreadFunc i_pFunc, 318*12720SWyllys.Ingersoll@Sun.COM void *i_pvData, 319*12720SWyllys.Ingersoll@Sun.COM int i_bIsDetached, 320*12720SWyllys.Ingersoll@Sun.COM K_THREAD_HANDLE *o_pNewThread); 321*12720SWyllys.Ingersoll@Sun.COM 322*12720SWyllys.Ingersoll@Sun.COM 323*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 324*12720SWyllys.Ingersoll@Sun.COM * Function: K_JoinThread 325*12720SWyllys.Ingersoll@Sun.COM * 326*12720SWyllys.Ingersoll@Sun.COM * Description: 327*12720SWyllys.Ingersoll@Sun.COM * This thread joining function is called when the current thread 328*12720SWyllys.Ingersoll@Sun.COM * waits another thread to terminate. 329*12720SWyllys.Ingersoll@Sun.COM * 330*12720SWyllys.Ingersoll@Sun.COM * Input 331*12720SWyllys.Ingersoll@Sun.COM * ----- 332*12720SWyllys.Ingersoll@Sun.COM * i_hThread The thread handle of the to-be-joined thread 333*12720SWyllys.Ingersoll@Sun.COM * 334*12720SWyllys.Ingersoll@Sun.COM * Output 335*12720SWyllys.Ingersoll@Sun.COM * ------ 336*12720SWyllys.Ingersoll@Sun.COM * (none) 337*12720SWyllys.Ingersoll@Sun.COM * 338*12720SWyllys.Ingersoll@Sun.COM * Return value Error code 339*12720SWyllys.Ingersoll@Sun.COM * 340*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 341*12720SWyllys.Ingersoll@Sun.COM int K_JoinThread(K_THREAD_HANDLE i_hThread); 342*12720SWyllys.Ingersoll@Sun.COM 343*12720SWyllys.Ingersoll@Sun.COM 344*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 345*12720SWyllys.Ingersoll@Sun.COM * Function: K_GetCurrentThreadId 346*12720SWyllys.Ingersoll@Sun.COM * 347*12720SWyllys.Ingersoll@Sun.COM * Description: 348*12720SWyllys.Ingersoll@Sun.COM * Returns the thread ID of the current thread. 349*12720SWyllys.Ingersoll@Sun.COM * 350*12720SWyllys.Ingersoll@Sun.COM * Input 351*12720SWyllys.Ingersoll@Sun.COM * ----- 352*12720SWyllys.Ingersoll@Sun.COM * (none) 353*12720SWyllys.Ingersoll@Sun.COM * 354*12720SWyllys.Ingersoll@Sun.COM * Output 355*12720SWyllys.Ingersoll@Sun.COM * ------ 356*12720SWyllys.Ingersoll@Sun.COM * (none) 357*12720SWyllys.Ingersoll@Sun.COM * 358*12720SWyllys.Ingersoll@Sun.COM * Return value The thread ID 359*12720SWyllys.Ingersoll@Sun.COM * 360*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 361*12720SWyllys.Ingersoll@Sun.COM 362*12720SWyllys.Ingersoll@Sun.COM int K_GetCurrentThreadId(); 363*12720SWyllys.Ingersoll@Sun.COM 364*12720SWyllys.Ingersoll@Sun.COM 365*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 366*12720SWyllys.Ingersoll@Sun.COM * Function: K_CreateMutex 367*12720SWyllys.Ingersoll@Sun.COM * 368*12720SWyllys.Ingersoll@Sun.COM * Description: 369*12720SWyllys.Ingersoll@Sun.COM * The mutex creation function creates a mutex according to the given 370*12720SWyllys.Ingersoll@Sun.COM * mutex type, and returns the mutex handle to the output parameter. 371*12720SWyllys.Ingersoll@Sun.COM * 372*12720SWyllys.Ingersoll@Sun.COM * Input 373*12720SWyllys.Ingersoll@Sun.COM * ----- 374*12720SWyllys.Ingersoll@Sun.COM * (none) 375*12720SWyllys.Ingersoll@Sun.COM * 376*12720SWyllys.Ingersoll@Sun.COM * Output 377*12720SWyllys.Ingersoll@Sun.COM * ------ 378*12720SWyllys.Ingersoll@Sun.COM * o_phandle the handle pointer to the mutex 379*12720SWyllys.Ingersoll@Sun.COM * 380*12720SWyllys.Ingersoll@Sun.COM * Return value Error Code 381*12720SWyllys.Ingersoll@Sun.COM * 382*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 383*12720SWyllys.Ingersoll@Sun.COM 384*12720SWyllys.Ingersoll@Sun.COM int K_CreateMutex( K_MUTEX_HANDLE *o_phandle ); 385*12720SWyllys.Ingersoll@Sun.COM 386*12720SWyllys.Ingersoll@Sun.COM 387*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 388*12720SWyllys.Ingersoll@Sun.COM * Function: K_LockMutex 389*12720SWyllys.Ingersoll@Sun.COM * 390*12720SWyllys.Ingersoll@Sun.COM * Description: 391*12720SWyllys.Ingersoll@Sun.COM * K_LockMutex is used to lock the mutex, and K_UnlockMutex is 392*12720SWyllys.Ingersoll@Sun.COM * used to unlock it. 393*12720SWyllys.Ingersoll@Sun.COM * 394*12720SWyllys.Ingersoll@Sun.COM * Input 395*12720SWyllys.Ingersoll@Sun.COM * ----- 396*12720SWyllys.Ingersoll@Sun.COM * i_handle the mutex handle 397*12720SWyllys.Ingersoll@Sun.COM * 398*12720SWyllys.Ingersoll@Sun.COM * Output 399*12720SWyllys.Ingersoll@Sun.COM * ------ 400*12720SWyllys.Ingersoll@Sun.COM * (none) 401*12720SWyllys.Ingersoll@Sun.COM * 402*12720SWyllys.Ingersoll@Sun.COM * return value Error Code 403*12720SWyllys.Ingersoll@Sun.COM * 404*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 405*12720SWyllys.Ingersoll@Sun.COM int K_LockMutex(K_MUTEX_HANDLE i_handle); 406*12720SWyllys.Ingersoll@Sun.COM 407*12720SWyllys.Ingersoll@Sun.COM 408*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 409*12720SWyllys.Ingersoll@Sun.COM * Function: K_UnlockMutex 410*12720SWyllys.Ingersoll@Sun.COM * 411*12720SWyllys.Ingersoll@Sun.COM * Description: 412*12720SWyllys.Ingersoll@Sun.COM * K_UnlockMutex is used to unlock the lock. 413*12720SWyllys.Ingersoll@Sun.COM * 414*12720SWyllys.Ingersoll@Sun.COM * Input 415*12720SWyllys.Ingersoll@Sun.COM * ----- 416*12720SWyllys.Ingersoll@Sun.COM * i_handle the mutex handle 417*12720SWyllys.Ingersoll@Sun.COM * 418*12720SWyllys.Ingersoll@Sun.COM * Output 419*12720SWyllys.Ingersoll@Sun.COM * ------ 420*12720SWyllys.Ingersoll@Sun.COM * (none) 421*12720SWyllys.Ingersoll@Sun.COM * 422*12720SWyllys.Ingersoll@Sun.COM * Return value Error Code 423*12720SWyllys.Ingersoll@Sun.COM * 424*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 425*12720SWyllys.Ingersoll@Sun.COM int K_UnlockMutex(K_MUTEX_HANDLE i_handle); 426*12720SWyllys.Ingersoll@Sun.COM 427*12720SWyllys.Ingersoll@Sun.COM 428*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 429*12720SWyllys.Ingersoll@Sun.COM * Function: K_DestroyMutex 430*12720SWyllys.Ingersoll@Sun.COM * 431*12720SWyllys.Ingersoll@Sun.COM * Description: 432*12720SWyllys.Ingersoll@Sun.COM * When a mutex is no longer needed, K_DestroyMutex must be called 433*12720SWyllys.Ingersoll@Sun.COM * to destroy it. 434*12720SWyllys.Ingersoll@Sun.COM * 435*12720SWyllys.Ingersoll@Sun.COM * Input 436*12720SWyllys.Ingersoll@Sun.COM * ----- 437*12720SWyllys.Ingersoll@Sun.COM * i_handle the mutex handle 438*12720SWyllys.Ingersoll@Sun.COM * 439*12720SWyllys.Ingersoll@Sun.COM * Output 440*12720SWyllys.Ingersoll@Sun.COM * ------ 441*12720SWyllys.Ingersoll@Sun.COM * (none) 442*12720SWyllys.Ingersoll@Sun.COM * 443*12720SWyllys.Ingersoll@Sun.COM * Return value Error Code 444*12720SWyllys.Ingersoll@Sun.COM * 445*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 446*12720SWyllys.Ingersoll@Sun.COM 447*12720SWyllys.Ingersoll@Sun.COM int K_DestroyMutex(K_MUTEX_HANDLE i_handle); 448*12720SWyllys.Ingersoll@Sun.COM 449*12720SWyllys.Ingersoll@Sun.COM 450*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 451*12720SWyllys.Ingersoll@Sun.COM * 452*12720SWyllys.Ingersoll@Sun.COM * The following section defines Conditional Variable 453*12720SWyllys.Ingersoll@Sun.COM * 454*12720SWyllys.Ingersoll@Sun.COM * Conditional Variable implements similar functionalities defined 455*12720SWyllys.Ingersoll@Sun.COM * in POSIX thread library. But it only supports conditional variables 456*12720SWyllys.Ingersoll@Sun.COM * inside one process and doesn't support pthread_cond_timedwait(). 457*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 458*12720SWyllys.Ingersoll@Sun.COM 459*12720SWyllys.Ingersoll@Sun.COM 460*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 461*12720SWyllys.Ingersoll@Sun.COM * Function: K_InitConditionalVariable 462*12720SWyllys.Ingersoll@Sun.COM * 463*12720SWyllys.Ingersoll@Sun.COM * Description: 464*12720SWyllys.Ingersoll@Sun.COM * This function initializes a conditional variable; Upon successful 465*12720SWyllys.Ingersoll@Sun.COM * completion, the new condition variable is returned via the condition 466*12720SWyllys.Ingersoll@Sun.COM * parameter, and 0 is returned. Otherwise, an error code is returned. 467*12720SWyllys.Ingersoll@Sun.COM * 468*12720SWyllys.Ingersoll@Sun.COM * Input 469*12720SWyllys.Ingersoll@Sun.COM * ----- 470*12720SWyllys.Ingersoll@Sun.COM * i_pCond the pointer to the conditional variable which is to be 471*12720SWyllys.Ingersoll@Sun.COM * initialized 472*12720SWyllys.Ingersoll@Sun.COM * 473*12720SWyllys.Ingersoll@Sun.COM * Output 474*12720SWyllys.Ingersoll@Sun.COM * ------ 475*12720SWyllys.Ingersoll@Sun.COM * (none) 476*12720SWyllys.Ingersoll@Sun.COM * 477*12720SWyllys.Ingersoll@Sun.COM * Return value Error Code 478*12720SWyllys.Ingersoll@Sun.COM * 479*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 480*12720SWyllys.Ingersoll@Sun.COM int K_InitConditionalVariable (K_ConditionalVariable * i_pCond); 481*12720SWyllys.Ingersoll@Sun.COM 482*12720SWyllys.Ingersoll@Sun.COM 483*12720SWyllys.Ingersoll@Sun.COM 484*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 485*12720SWyllys.Ingersoll@Sun.COM * Function: K_DestroyConditionalVariable 486*12720SWyllys.Ingersoll@Sun.COM * 487*12720SWyllys.Ingersoll@Sun.COM * Description: 488*12720SWyllys.Ingersoll@Sun.COM * This function destroys a conditional variable. Upon successful 489*12720SWyllys.Ingersoll@Sun.COM * completion, the condition variable is destroyed, and 0 is returned. 490*12720SWyllys.Ingersoll@Sun.COM * Otherwise, an error code is returned. 491*12720SWyllys.Ingersoll@Sun.COM * After deletion of the condition variable, the condition parameter 492*12720SWyllys.Ingersoll@Sun.COM * is not valid until it is initialized again by a call to the 493*12720SWyllys.Ingersoll@Sun.COM * K_InitConditionalVariable subroutine. 494*12720SWyllys.Ingersoll@Sun.COM * 495*12720SWyllys.Ingersoll@Sun.COM * Input 496*12720SWyllys.Ingersoll@Sun.COM * ----- 497*12720SWyllys.Ingersoll@Sun.COM * i_pCond the pointer to the conditional variable which is to be 498*12720SWyllys.Ingersoll@Sun.COM * destroyed 499*12720SWyllys.Ingersoll@Sun.COM * 500*12720SWyllys.Ingersoll@Sun.COM * Output 501*12720SWyllys.Ingersoll@Sun.COM * ------ 502*12720SWyllys.Ingersoll@Sun.COM * (none) 503*12720SWyllys.Ingersoll@Sun.COM * 504*12720SWyllys.Ingersoll@Sun.COM * Return value Error Code 505*12720SWyllys.Ingersoll@Sun.COM * 506*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 507*12720SWyllys.Ingersoll@Sun.COM 508*12720SWyllys.Ingersoll@Sun.COM int K_DestroyConditionalVariable(K_ConditionalVariable * i_pCond); 509*12720SWyllys.Ingersoll@Sun.COM 510*12720SWyllys.Ingersoll@Sun.COM 511*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 512*12720SWyllys.Ingersoll@Sun.COM * Function: K_WaitConditionalVariable 513*12720SWyllys.Ingersoll@Sun.COM * 514*12720SWyllys.Ingersoll@Sun.COM * Description: 515*12720SWyllys.Ingersoll@Sun.COM * This function is used to block on a condition variable. 516*12720SWyllys.Ingersoll@Sun.COM * They are called with mutex locked by the calling thread or undefined 517*12720SWyllys.Ingersoll@Sun.COM * behaviour will result. 518*12720SWyllys.Ingersoll@Sun.COM * 519*12720SWyllys.Ingersoll@Sun.COM * Input 520*12720SWyllys.Ingersoll@Sun.COM * ----- 521*12720SWyllys.Ingersoll@Sun.COM * i_pCond the pointer to the conditional variable 522*12720SWyllys.Ingersoll@Sun.COM * i_handle the companion mutex handle 523*12720SWyllys.Ingersoll@Sun.COM * 524*12720SWyllys.Ingersoll@Sun.COM * Output 525*12720SWyllys.Ingersoll@Sun.COM * ------ 526*12720SWyllys.Ingersoll@Sun.COM * (none) 527*12720SWyllys.Ingersoll@Sun.COM * 528*12720SWyllys.Ingersoll@Sun.COM * Return value Error Code 529*12720SWyllys.Ingersoll@Sun.COM * 530*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 531*12720SWyllys.Ingersoll@Sun.COM int K_WaitConditionalVariable(K_ConditionalVariable * i_pCond, 532*12720SWyllys.Ingersoll@Sun.COM K_MUTEX_HANDLE i_handle); 533*12720SWyllys.Ingersoll@Sun.COM 534*12720SWyllys.Ingersoll@Sun.COM 535*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 536*12720SWyllys.Ingersoll@Sun.COM * Function: K_SignalConditionalVariable 537*12720SWyllys.Ingersoll@Sun.COM * 538*12720SWyllys.Ingersoll@Sun.COM * Description: 539*12720SWyllys.Ingersoll@Sun.COM * This function is used to restart one of the threads that are waiting on 540*12720SWyllys.Ingersoll@Sun.COM * the condition variable. If no threads are waiting on it, nothing happens. 541*12720SWyllys.Ingersoll@Sun.COM * If several threads are waiting on it, exactly one is restarted. 542*12720SWyllys.Ingersoll@Sun.COM * 543*12720SWyllys.Ingersoll@Sun.COM * Input 544*12720SWyllys.Ingersoll@Sun.COM * ----- 545*12720SWyllys.Ingersoll@Sun.COM * i_pCond the pointer to the conditional variable 546*12720SWyllys.Ingersoll@Sun.COM * 547*12720SWyllys.Ingersoll@Sun.COM * Output 548*12720SWyllys.Ingersoll@Sun.COM * ------ 549*12720SWyllys.Ingersoll@Sun.COM * (none) 550*12720SWyllys.Ingersoll@Sun.COM * 551*12720SWyllys.Ingersoll@Sun.COM * Return value Error Code 552*12720SWyllys.Ingersoll@Sun.COM * 553*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 554*12720SWyllys.Ingersoll@Sun.COM int K_SignalConditionalVariable(K_ConditionalVariable * i_pCond); 555*12720SWyllys.Ingersoll@Sun.COM 556*12720SWyllys.Ingersoll@Sun.COM 557*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 558*12720SWyllys.Ingersoll@Sun.COM * Function: K_BroadcastConditionalVariable 559*12720SWyllys.Ingersoll@Sun.COM * 560*12720SWyllys.Ingersoll@Sun.COM * Description: 561*12720SWyllys.Ingersoll@Sun.COM * This function is used to restart all threads that are waiting on 562*12720SWyllys.Ingersoll@Sun.COM * the condition variable. 563*12720SWyllys.Ingersoll@Sun.COM * 564*12720SWyllys.Ingersoll@Sun.COM * Input 565*12720SWyllys.Ingersoll@Sun.COM * ----- 566*12720SWyllys.Ingersoll@Sun.COM * i_pCond the pointer to the conditional variable 567*12720SWyllys.Ingersoll@Sun.COM * 568*12720SWyllys.Ingersoll@Sun.COM * Output 569*12720SWyllys.Ingersoll@Sun.COM * ------ 570*12720SWyllys.Ingersoll@Sun.COM * (none) 571*12720SWyllys.Ingersoll@Sun.COM * 572*12720SWyllys.Ingersoll@Sun.COM * Return value Error Code 573*12720SWyllys.Ingersoll@Sun.COM * 574*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 575*12720SWyllys.Ingersoll@Sun.COM int K_BroadcastConditionalVariable(K_ConditionalVariable * i_pCond); 576*12720SWyllys.Ingersoll@Sun.COM 577*12720SWyllys.Ingersoll@Sun.COM 578*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 579*12720SWyllys.Ingersoll@Sun.COM * Function: K_Sleep 580*12720SWyllys.Ingersoll@Sun.COM * 581*12720SWyllys.Ingersoll@Sun.COM * Description: 582*12720SWyllys.Ingersoll@Sun.COM * Sleep for a given period in the given milliseconds. 583*12720SWyllys.Ingersoll@Sun.COM * 584*12720SWyllys.Ingersoll@Sun.COM * Input 585*12720SWyllys.Ingersoll@Sun.COM * ----- 586*12720SWyllys.Ingersoll@Sun.COM * i_ms milliseconds 587*12720SWyllys.Ingersoll@Sun.COM * 588*12720SWyllys.Ingersoll@Sun.COM * Output 589*12720SWyllys.Ingersoll@Sun.COM * ------ 590*12720SWyllys.Ingersoll@Sun.COM * (none) 591*12720SWyllys.Ingersoll@Sun.COM * 592*12720SWyllys.Ingersoll@Sun.COM * Return value (none) 593*12720SWyllys.Ingersoll@Sun.COM * 594*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 595*12720SWyllys.Ingersoll@Sun.COM void K_Sleep(int i_ms); 596*12720SWyllys.Ingersoll@Sun.COM 597*12720SWyllys.Ingersoll@Sun.COM 598*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 599*12720SWyllys.Ingersoll@Sun.COM * Function: K_GetTickCount 600*12720SWyllys.Ingersoll@Sun.COM * 601*12720SWyllys.Ingersoll@Sun.COM * Description: 602*12720SWyllys.Ingersoll@Sun.COM * The K_GetTickCount function retrieves the number of 603*12720SWyllys.Ingersoll@Sun.COM * milliseconds that have elapsed since the system was started. 604*12720SWyllys.Ingersoll@Sun.COM * 605*12720SWyllys.Ingersoll@Sun.COM * Input 606*12720SWyllys.Ingersoll@Sun.COM * ----- 607*12720SWyllys.Ingersoll@Sun.COM * (none) 608*12720SWyllys.Ingersoll@Sun.COM * 609*12720SWyllys.Ingersoll@Sun.COM * Output 610*12720SWyllys.Ingersoll@Sun.COM * ------ 611*12720SWyllys.Ingersoll@Sun.COM * (none) 612*12720SWyllys.Ingersoll@Sun.COM * 613*12720SWyllys.Ingersoll@Sun.COM * Return value the elasped milliseconds since the system was started 614*12720SWyllys.Ingersoll@Sun.COM * 615*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 616*12720SWyllys.Ingersoll@Sun.COM unsigned int K_GetTickCount(); 617*12720SWyllys.Ingersoll@Sun.COM 618*12720SWyllys.Ingersoll@Sun.COM 619*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 620*12720SWyllys.Ingersoll@Sun.COM * Function: K_AdjustClock 621*12720SWyllys.Ingersoll@Sun.COM * 622*12720SWyllys.Ingersoll@Sun.COM * Description: 623*12720SWyllys.Ingersoll@Sun.COM * The K_AdjustClock function immediately adjusts the system clock by 624*12720SWyllys.Ingersoll@Sun.COM * the given number of seconds. A positive number adjusts the system 625*12720SWyllys.Ingersoll@Sun.COM * clock forward; a negative number adjusts the system clock backward. 626*12720SWyllys.Ingersoll@Sun.COM * 627*12720SWyllys.Ingersoll@Sun.COM * Input 628*12720SWyllys.Ingersoll@Sun.COM * ----- 629*12720SWyllys.Ingersoll@Sun.COM * i_iAdjustmentInSeconds Number of seconds by which to adjust the 630*12720SWyllys.Ingersoll@Sun.COM * system clock 631*12720SWyllys.Ingersoll@Sun.COM * Output 632*12720SWyllys.Ingersoll@Sun.COM * ------ 633*12720SWyllys.Ingersoll@Sun.COM * (none) 634*12720SWyllys.Ingersoll@Sun.COM * 635*12720SWyllys.Ingersoll@Sun.COM * Return value 1 if successful, 0 on error 636*12720SWyllys.Ingersoll@Sun.COM * 637*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 638*12720SWyllys.Ingersoll@Sun.COM int K_AdjustClock( long i_iAdjustmentInSeconds ); 639*12720SWyllys.Ingersoll@Sun.COM 640*12720SWyllys.Ingersoll@Sun.COM 641*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 642*12720SWyllys.Ingersoll@Sun.COM * Function: K_IsLittleEndian 643*12720SWyllys.Ingersoll@Sun.COM * 644*12720SWyllys.Ingersoll@Sun.COM * Description: 645*12720SWyllys.Ingersoll@Sun.COM * Checks to see whether this platform uses little endian integer 646*12720SWyllys.Ingersoll@Sun.COM * representation. 647*12720SWyllys.Ingersoll@Sun.COM * 648*12720SWyllys.Ingersoll@Sun.COM * Input 649*12720SWyllys.Ingersoll@Sun.COM * ----- 650*12720SWyllys.Ingersoll@Sun.COM * (none) 651*12720SWyllys.Ingersoll@Sun.COM * 652*12720SWyllys.Ingersoll@Sun.COM * Output 653*12720SWyllys.Ingersoll@Sun.COM * ------ 654*12720SWyllys.Ingersoll@Sun.COM * (none) 655*12720SWyllys.Ingersoll@Sun.COM * 656*12720SWyllys.Ingersoll@Sun.COM * Return value 1 for little endian 657*12720SWyllys.Ingersoll@Sun.COM * 658*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 659*12720SWyllys.Ingersoll@Sun.COM int K_IsLittleEndian(); 660*12720SWyllys.Ingersoll@Sun.COM 661*12720SWyllys.Ingersoll@Sun.COM 662*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 663*12720SWyllys.Ingersoll@Sun.COM * Function: K_FileLength32 664*12720SWyllys.Ingersoll@Sun.COM * 665*12720SWyllys.Ingersoll@Sun.COM * Description: 666*12720SWyllys.Ingersoll@Sun.COM * Gets the size in bytes of the file associated with the given FILE pointer. 667*12720SWyllys.Ingersoll@Sun.COM * 668*12720SWyllys.Ingersoll@Sun.COM * Input 669*12720SWyllys.Ingersoll@Sun.COM * ----- 670*12720SWyllys.Ingersoll@Sun.COM * i_fpFile File handle 671*12720SWyllys.Ingersoll@Sun.COM * 672*12720SWyllys.Ingersoll@Sun.COM * Output 673*12720SWyllys.Ingersoll@Sun.COM * ------ 674*12720SWyllys.Ingersoll@Sun.COM * (none) 675*12720SWyllys.Ingersoll@Sun.COM * 676*12720SWyllys.Ingersoll@Sun.COM * Return value File size in bytes, or -1L on error 677*12720SWyllys.Ingersoll@Sun.COM * 678*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 679*12720SWyllys.Ingersoll@Sun.COM long K_FileLength32( FILE* i_fpFile ); 680*12720SWyllys.Ingersoll@Sun.COM 681*12720SWyllys.Ingersoll@Sun.COM 682*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 683*12720SWyllys.Ingersoll@Sun.COM * Function: K_StringCompareNoCase 684*12720SWyllys.Ingersoll@Sun.COM * 685*12720SWyllys.Ingersoll@Sun.COM * Description: 686*12720SWyllys.Ingersoll@Sun.COM * Compares the two given strings insensitive to case. 687*12720SWyllys.Ingersoll@Sun.COM * 688*12720SWyllys.Ingersoll@Sun.COM * Input 689*12720SWyllys.Ingersoll@Sun.COM * ----- 690*12720SWyllys.Ingersoll@Sun.COM * i_sString1 First string 691*12720SWyllys.Ingersoll@Sun.COM * i_sString2 Second string 692*12720SWyllys.Ingersoll@Sun.COM * 693*12720SWyllys.Ingersoll@Sun.COM * Output 694*12720SWyllys.Ingersoll@Sun.COM * ------ 695*12720SWyllys.Ingersoll@Sun.COM * (none) 696*12720SWyllys.Ingersoll@Sun.COM * 697*12720SWyllys.Ingersoll@Sun.COM * Return value 0 if identical, -1 if first string is less than second 698*12720SWyllys.Ingersoll@Sun.COM * string, or 1 if first string is greater than second 699*12720SWyllys.Ingersoll@Sun.COM * 700*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 701*12720SWyllys.Ingersoll@Sun.COM int K_StringCompareNoCase( const char* i_sString1, const char* i_sString2 ); 702*12720SWyllys.Ingersoll@Sun.COM 703*12720SWyllys.Ingersoll@Sun.COM 704*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 705*12720SWyllys.Ingersoll@Sun.COM * Function: K_StringCompareNoCaseWide 706*12720SWyllys.Ingersoll@Sun.COM * 707*12720SWyllys.Ingersoll@Sun.COM * Description: 708*12720SWyllys.Ingersoll@Sun.COM * Compares the two given wide strings insensitive to case. 709*12720SWyllys.Ingersoll@Sun.COM * 710*12720SWyllys.Ingersoll@Sun.COM * Input 711*12720SWyllys.Ingersoll@Sun.COM * ----- 712*12720SWyllys.Ingersoll@Sun.COM * i_wsString1 First wide string 713*12720SWyllys.Ingersoll@Sun.COM * i_wsString2 Second wide string 714*12720SWyllys.Ingersoll@Sun.COM * 715*12720SWyllys.Ingersoll@Sun.COM * Output 716*12720SWyllys.Ingersoll@Sun.COM * ------ 717*12720SWyllys.Ingersoll@Sun.COM * (none) 718*12720SWyllys.Ingersoll@Sun.COM * 719*12720SWyllys.Ingersoll@Sun.COM * Return value 0 if identical, -1 if first string is less than second 720*12720SWyllys.Ingersoll@Sun.COM * string, or 1 if first string is greater than second 721*12720SWyllys.Ingersoll@Sun.COM * 722*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 723*12720SWyllys.Ingersoll@Sun.COM int K_StringCompareNoCaseWide( const wchar_t* i_wsString1, const wchar_t* i_wsString2 ); 724*12720SWyllys.Ingersoll@Sun.COM 725*12720SWyllys.Ingersoll@Sun.COM 726*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 727*12720SWyllys.Ingersoll@Sun.COM * Function: K_snprintf 728*12720SWyllys.Ingersoll@Sun.COM * 729*12720SWyllys.Ingersoll@Sun.COM * Description: 730*12720SWyllys.Ingersoll@Sun.COM * See the snprintf(3C) man page. 731*12720SWyllys.Ingersoll@Sun.COM * 732*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 733*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 734*12720SWyllys.Ingersoll@Sun.COM #define K_snprintf _snprintf 735*12720SWyllys.Ingersoll@Sun.COM #else 736*12720SWyllys.Ingersoll@Sun.COM #define K_snprintf snprintf 737*12720SWyllys.Ingersoll@Sun.COM #endif 738*12720SWyllys.Ingersoll@Sun.COM 739*12720SWyllys.Ingersoll@Sun.COM 740*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 741*12720SWyllys.Ingersoll@Sun.COM * Function: K_snwprintf 742*12720SWyllys.Ingersoll@Sun.COM * 743*12720SWyllys.Ingersoll@Sun.COM * Description: 744*12720SWyllys.Ingersoll@Sun.COM * See the swprintf(3C) man page. 745*12720SWyllys.Ingersoll@Sun.COM * 746*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 747*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 748*12720SWyllys.Ingersoll@Sun.COM #define K_snwprintf _snwprintf 749*12720SWyllys.Ingersoll@Sun.COM #else 750*12720SWyllys.Ingersoll@Sun.COM #define K_snwprintf swprintf 751*12720SWyllys.Ingersoll@Sun.COM #endif 752*12720SWyllys.Ingersoll@Sun.COM 753*12720SWyllys.Ingersoll@Sun.COM #ifdef WIN32 754*12720SWyllys.Ingersoll@Sun.COM #define K_fseek fseek 755*12720SWyllys.Ingersoll@Sun.COM #define K_ftell ftell 756*12720SWyllys.Ingersoll@Sun.COM #else 757*12720SWyllys.Ingersoll@Sun.COM #define K_fseek fseeko 758*12720SWyllys.Ingersoll@Sun.COM #define K_ftell ftello 759*12720SWyllys.Ingersoll@Sun.COM #endif 760*12720SWyllys.Ingersoll@Sun.COM 761*12720SWyllys.Ingersoll@Sun.COM 762*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 763*12720SWyllys.Ingersoll@Sun.COM * Function: K_CreateDirectory 764*12720SWyllys.Ingersoll@Sun.COM * 765*12720SWyllys.Ingersoll@Sun.COM * Description: 766*12720SWyllys.Ingersoll@Sun.COM * Creates a directory with the given path name. 767*12720SWyllys.Ingersoll@Sun.COM * 768*12720SWyllys.Ingersoll@Sun.COM * Input 769*12720SWyllys.Ingersoll@Sun.COM * ----- 770*12720SWyllys.Ingersoll@Sun.COM * i_sDirectoryName Directory name 771*12720SWyllys.Ingersoll@Sun.COM * 772*12720SWyllys.Ingersoll@Sun.COM * Output 773*12720SWyllys.Ingersoll@Sun.COM * ------ 774*12720SWyllys.Ingersoll@Sun.COM * (none) 775*12720SWyllys.Ingersoll@Sun.COM * 776*12720SWyllys.Ingersoll@Sun.COM * Return value 0 on success, -1 on failure 777*12720SWyllys.Ingersoll@Sun.COM * 778*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 779*12720SWyllys.Ingersoll@Sun.COM int K_CreateDirectory( const char* i_sDirectoryName ); 780*12720SWyllys.Ingersoll@Sun.COM 781*12720SWyllys.Ingersoll@Sun.COM 782*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 783*12720SWyllys.Ingersoll@Sun.COM * Function: K_DeleteFile 784*12720SWyllys.Ingersoll@Sun.COM * 785*12720SWyllys.Ingersoll@Sun.COM * Description: 786*12720SWyllys.Ingersoll@Sun.COM * Deletes the given file. 787*12720SWyllys.Ingersoll@Sun.COM * 788*12720SWyllys.Ingersoll@Sun.COM * Input 789*12720SWyllys.Ingersoll@Sun.COM * ----- 790*12720SWyllys.Ingersoll@Sun.COM * i_sFilename Name of file to delete 791*12720SWyllys.Ingersoll@Sun.COM * 792*12720SWyllys.Ingersoll@Sun.COM * Output 793*12720SWyllys.Ingersoll@Sun.COM * ------ 794*12720SWyllys.Ingersoll@Sun.COM * (none) 795*12720SWyllys.Ingersoll@Sun.COM * 796*12720SWyllys.Ingersoll@Sun.COM * Return value 0 on success, errno on failure 797*12720SWyllys.Ingersoll@Sun.COM * 798*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 799*12720SWyllys.Ingersoll@Sun.COM int K_DeleteFile( const char* i_sFilename ); 800*12720SWyllys.Ingersoll@Sun.COM 801*12720SWyllys.Ingersoll@Sun.COM 802*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 803*12720SWyllys.Ingersoll@Sun.COM * Function: K_ReadFile 804*12720SWyllys.Ingersoll@Sun.COM * 805*12720SWyllys.Ingersoll@Sun.COM * Description: 806*12720SWyllys.Ingersoll@Sun.COM * Reads from the given file and passes the bytes read back to the output 807*12720SWyllys.Ingersoll@Sun.COM * parameter. The caller must deallocate o_ppFileData using free(). 808*12720SWyllys.Ingersoll@Sun.COM * 809*12720SWyllys.Ingersoll@Sun.COM * Input 810*12720SWyllys.Ingersoll@Sun.COM * ----- 811*12720SWyllys.Ingersoll@Sun.COM * i_sFilename Name of file from which to read 812*12720SWyllys.Ingersoll@Sun.COM * 813*12720SWyllys.Ingersoll@Sun.COM * Output 814*12720SWyllys.Ingersoll@Sun.COM * ------ 815*12720SWyllys.Ingersoll@Sun.COM * o_ppFileData Pointer to bytes read 816*12720SWyllys.Ingersoll@Sun.COM * 817*12720SWyllys.Ingersoll@Sun.COM * Return value Number of bytes read on success, -1 on failure 818*12720SWyllys.Ingersoll@Sun.COM * 819*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 820*12720SWyllys.Ingersoll@Sun.COM int K_ReadFile( const char* i_sFilename, unsigned char** o_ppFileData ); 821*12720SWyllys.Ingersoll@Sun.COM 822*12720SWyllys.Ingersoll@Sun.COM 823*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 824*12720SWyllys.Ingersoll@Sun.COM * Function: K_ReadFileString 825*12720SWyllys.Ingersoll@Sun.COM * 826*12720SWyllys.Ingersoll@Sun.COM * Description: 827*12720SWyllys.Ingersoll@Sun.COM * Reads from the given file and passes the bytes read back to the output 828*12720SWyllys.Ingersoll@Sun.COM * parameter, appending these bytes with a null terminator. There is no 829*12720SWyllys.Ingersoll@Sun.COM * guarantee that there are no non-text characters in the returned "string". 830*12720SWyllys.Ingersoll@Sun.COM * The caller must deallocate o_ppFileData using free(). 831*12720SWyllys.Ingersoll@Sun.COM * 832*12720SWyllys.Ingersoll@Sun.COM * Input 833*12720SWyllys.Ingersoll@Sun.COM * ----- 834*12720SWyllys.Ingersoll@Sun.COM * i_sFilename Name of file from which to read 835*12720SWyllys.Ingersoll@Sun.COM * 836*12720SWyllys.Ingersoll@Sun.COM * Output 837*12720SWyllys.Ingersoll@Sun.COM * ------ 838*12720SWyllys.Ingersoll@Sun.COM * o_psFileDataString Pointer to bytes read 839*12720SWyllys.Ingersoll@Sun.COM * 840*12720SWyllys.Ingersoll@Sun.COM * Return value Number of bytes read (including null terminator) on 841*12720SWyllys.Ingersoll@Sun.COM * success (0 if file is empty), -1 on failure 842*12720SWyllys.Ingersoll@Sun.COM * 843*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 844*12720SWyllys.Ingersoll@Sun.COM int K_ReadFileString( const char* i_sFilename, char** o_psFileDataString ); 845*12720SWyllys.Ingersoll@Sun.COM 846*12720SWyllys.Ingersoll@Sun.COM 847*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 848*12720SWyllys.Ingersoll@Sun.COM * Function: K_WriteFile 849*12720SWyllys.Ingersoll@Sun.COM * 850*12720SWyllys.Ingersoll@Sun.COM * Description: 851*12720SWyllys.Ingersoll@Sun.COM * Writes the given bytes to the given file. 852*12720SWyllys.Ingersoll@Sun.COM * 853*12720SWyllys.Ingersoll@Sun.COM * Input 854*12720SWyllys.Ingersoll@Sun.COM * ----- 855*12720SWyllys.Ingersoll@Sun.COM * i_sFilename Name of file to which to write 856*12720SWyllys.Ingersoll@Sun.COM * i_pFileData Bytes to write 857*12720SWyllys.Ingersoll@Sun.COM * i_iFileDataSize Number of bytes to write 858*12720SWyllys.Ingersoll@Sun.COM * 859*12720SWyllys.Ingersoll@Sun.COM * Output 860*12720SWyllys.Ingersoll@Sun.COM * ------ 861*12720SWyllys.Ingersoll@Sun.COM * (none) 862*12720SWyllys.Ingersoll@Sun.COM * 863*12720SWyllys.Ingersoll@Sun.COM * Return value 0 on success, errno or -1 (generic error) on failure 864*12720SWyllys.Ingersoll@Sun.COM * 865*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 866*12720SWyllys.Ingersoll@Sun.COM int K_WriteFile( const char* i_sFilename, const unsigned char* i_pFileData, int i_iFileDataSize ); 867*12720SWyllys.Ingersoll@Sun.COM 868*12720SWyllys.Ingersoll@Sun.COM 869*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 870*12720SWyllys.Ingersoll@Sun.COM * Function: K_WriteFileString 871*12720SWyllys.Ingersoll@Sun.COM * 872*12720SWyllys.Ingersoll@Sun.COM * Description: 873*12720SWyllys.Ingersoll@Sun.COM * Writes the given null-terminated bytes to the given file. The null 874*12720SWyllys.Ingersoll@Sun.COM * terminator itself is not written to the file. 875*12720SWyllys.Ingersoll@Sun.COM * 876*12720SWyllys.Ingersoll@Sun.COM * Input 877*12720SWyllys.Ingersoll@Sun.COM * ----- 878*12720SWyllys.Ingersoll@Sun.COM * i_sFilename Name of file to which to write 879*12720SWyllys.Ingersoll@Sun.COM * i_sFileData Bytes to write 880*12720SWyllys.Ingersoll@Sun.COM * 881*12720SWyllys.Ingersoll@Sun.COM * Output 882*12720SWyllys.Ingersoll@Sun.COM * ------ 883*12720SWyllys.Ingersoll@Sun.COM * (none) 884*12720SWyllys.Ingersoll@Sun.COM * 885*12720SWyllys.Ingersoll@Sun.COM * Return value 0 on success, errno or -1 (generic error) on failure 886*12720SWyllys.Ingersoll@Sun.COM * 887*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 888*12720SWyllys.Ingersoll@Sun.COM int K_WriteFileString( const char* i_sFilename, const char* i_sFileData ); 889*12720SWyllys.Ingersoll@Sun.COM 890*12720SWyllys.Ingersoll@Sun.COM 891*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 892*12720SWyllys.Ingersoll@Sun.COM * Function: K_FileExists 893*12720SWyllys.Ingersoll@Sun.COM * 894*12720SWyllys.Ingersoll@Sun.COM * Description: 895*12720SWyllys.Ingersoll@Sun.COM * Checks to see whehter the given file exists. 896*12720SWyllys.Ingersoll@Sun.COM * 897*12720SWyllys.Ingersoll@Sun.COM * Input 898*12720SWyllys.Ingersoll@Sun.COM * ----- 899*12720SWyllys.Ingersoll@Sun.COM * i_sFilename Name of file to check 900*12720SWyllys.Ingersoll@Sun.COM * 901*12720SWyllys.Ingersoll@Sun.COM * Output 902*12720SWyllys.Ingersoll@Sun.COM * ------ 903*12720SWyllys.Ingersoll@Sun.COM * (none) 904*12720SWyllys.Ingersoll@Sun.COM * 905*12720SWyllys.Ingersoll@Sun.COM * Return value 1 if file exists, 0 if not, -1 on failure 906*12720SWyllys.Ingersoll@Sun.COM * 907*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 908*12720SWyllys.Ingersoll@Sun.COM int K_FileExists( const char* i_sFilename ); 909*12720SWyllys.Ingersoll@Sun.COM 910*12720SWyllys.Ingersoll@Sun.COM 911*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 912*12720SWyllys.Ingersoll@Sun.COM * Function: K_CopyFile 913*12720SWyllys.Ingersoll@Sun.COM * 914*12720SWyllys.Ingersoll@Sun.COM * Description: 915*12720SWyllys.Ingersoll@Sun.COM * Reads from the given source file and writes these bytes to the given 916*12720SWyllys.Ingersoll@Sun.COM * destination file. 917*12720SWyllys.Ingersoll@Sun.COM * 918*12720SWyllys.Ingersoll@Sun.COM * Input 919*12720SWyllys.Ingersoll@Sun.COM * ----- 920*12720SWyllys.Ingersoll@Sun.COM * i_sSrcFilename Name of file from which to read 921*12720SWyllys.Ingersoll@Sun.COM * i_sDestFilename Name of file to which to write 922*12720SWyllys.Ingersoll@Sun.COM * 923*12720SWyllys.Ingersoll@Sun.COM * Output 924*12720SWyllys.Ingersoll@Sun.COM * ------ 925*12720SWyllys.Ingersoll@Sun.COM * o_pbFileExists Non-zero if the destination file already exists 926*12720SWyllys.Ingersoll@Sun.COM * 927*12720SWyllys.Ingersoll@Sun.COM * Return value 0 on success, errno or -1 (generic error) on failure 928*12720SWyllys.Ingersoll@Sun.COM * 929*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 930*12720SWyllys.Ingersoll@Sun.COM int K_CopyFile( 931*12720SWyllys.Ingersoll@Sun.COM const char* i_sSrcFilename, 932*12720SWyllys.Ingersoll@Sun.COM const char* i_sDestFilename, 933*12720SWyllys.Ingersoll@Sun.COM int* o_pbFileExists ); 934*12720SWyllys.Ingersoll@Sun.COM 935*12720SWyllys.Ingersoll@Sun.COM 936*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 937*12720SWyllys.Ingersoll@Sun.COM * Function: K_GetFilenamesInDirectoryCount 938*12720SWyllys.Ingersoll@Sun.COM * 939*12720SWyllys.Ingersoll@Sun.COM * Description: 940*12720SWyllys.Ingersoll@Sun.COM * Reads the given directory and returns the number of files that it contains. 941*12720SWyllys.Ingersoll@Sun.COM * 942*12720SWyllys.Ingersoll@Sun.COM * Input 943*12720SWyllys.Ingersoll@Sun.COM * ----- 944*12720SWyllys.Ingersoll@Sun.COM * i_sDirectoryName Name of directory 945*12720SWyllys.Ingersoll@Sun.COM * 946*12720SWyllys.Ingersoll@Sun.COM * Output 947*12720SWyllys.Ingersoll@Sun.COM * ------ 948*12720SWyllys.Ingersoll@Sun.COM * (none) 949*12720SWyllys.Ingersoll@Sun.COM * 950*12720SWyllys.Ingersoll@Sun.COM * Return value Number of files on success, -1 on failure 951*12720SWyllys.Ingersoll@Sun.COM * 952*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 953*12720SWyllys.Ingersoll@Sun.COM int K_GetFilenamesInDirectoryCount( const char* i_sDirectoryName ); 954*12720SWyllys.Ingersoll@Sun.COM 955*12720SWyllys.Ingersoll@Sun.COM 956*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 957*12720SWyllys.Ingersoll@Sun.COM * Function: K_GetFilenamesInDirectory 958*12720SWyllys.Ingersoll@Sun.COM * 959*12720SWyllys.Ingersoll@Sun.COM * Description: 960*12720SWyllys.Ingersoll@Sun.COM * Reads the given directory and returns an array of names of files that it 961*12720SWyllys.Ingersoll@Sun.COM * contains. A null pointer appears at the last item in the array. The 962*12720SWyllys.Ingersoll@Sun.COM * caller must deallocate o_pasFilenames by using K_FreeFilenames or by 963*12720SWyllys.Ingersoll@Sun.COM * calling free() for each file name and then calling free() on the array 964*12720SWyllys.Ingersoll@Sun.COM * itself. 965*12720SWyllys.Ingersoll@Sun.COM * 966*12720SWyllys.Ingersoll@Sun.COM * Input 967*12720SWyllys.Ingersoll@Sun.COM * ----- 968*12720SWyllys.Ingersoll@Sun.COM * i_sDirectoryName Name of directory 969*12720SWyllys.Ingersoll@Sun.COM * 970*12720SWyllys.Ingersoll@Sun.COM * Output 971*12720SWyllys.Ingersoll@Sun.COM * ------ 972*12720SWyllys.Ingersoll@Sun.COM * o_pasFilenames Array of names of files found in this directory 973*12720SWyllys.Ingersoll@Sun.COM * 974*12720SWyllys.Ingersoll@Sun.COM * Return value Number of files on success, -1 on failure 975*12720SWyllys.Ingersoll@Sun.COM * 976*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 977*12720SWyllys.Ingersoll@Sun.COM int K_GetFilenamesInDirectory( 978*12720SWyllys.Ingersoll@Sun.COM const char* i_sDirectoryName, 979*12720SWyllys.Ingersoll@Sun.COM char*** o_pasFilenames ); 980*12720SWyllys.Ingersoll@Sun.COM 981*12720SWyllys.Ingersoll@Sun.COM 982*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 983*12720SWyllys.Ingersoll@Sun.COM * Function: K_FreeFilenames 984*12720SWyllys.Ingersoll@Sun.COM * 985*12720SWyllys.Ingersoll@Sun.COM * Description: 986*12720SWyllys.Ingersoll@Sun.COM * Deallocates the memory allocated in a successful call to 987*12720SWyllys.Ingersoll@Sun.COM * K_GetFilenamesInDirectory. 988*12720SWyllys.Ingersoll@Sun.COM * 989*12720SWyllys.Ingersoll@Sun.COM * Input 990*12720SWyllys.Ingersoll@Sun.COM * ----- 991*12720SWyllys.Ingersoll@Sun.COM * i_asFilenames Array of names of files 992*12720SWyllys.Ingersoll@Sun.COM * 993*12720SWyllys.Ingersoll@Sun.COM * Output 994*12720SWyllys.Ingersoll@Sun.COM * ------ 995*12720SWyllys.Ingersoll@Sun.COM * (none) 996*12720SWyllys.Ingersoll@Sun.COM * 997*12720SWyllys.Ingersoll@Sun.COM * Return value (none) 998*12720SWyllys.Ingersoll@Sun.COM * 999*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 1000*12720SWyllys.Ingersoll@Sun.COM void K_FreeFilenames( char** i_asFilenames ); 1001*12720SWyllys.Ingersoll@Sun.COM 1002*12720SWyllys.Ingersoll@Sun.COM 1003*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 1004*12720SWyllys.Ingersoll@Sun.COM * Function: K_AdjustLocalClock 1005*12720SWyllys.Ingersoll@Sun.COM * 1006*12720SWyllys.Ingersoll@Sun.COM * Description: 1007*12720SWyllys.Ingersoll@Sun.COM * The K_AdjustLocalClock function gradually adjusts the system clock by 1008*12720SWyllys.Ingersoll@Sun.COM * the given number of seconds. A positive number adjusts the system 1009*12720SWyllys.Ingersoll@Sun.COM * clock forward; a negative number adjusts the system clock backward. 1010*12720SWyllys.Ingersoll@Sun.COM * 1011*12720SWyllys.Ingersoll@Sun.COM * Input 1012*12720SWyllys.Ingersoll@Sun.COM * ----- 1013*12720SWyllys.Ingersoll@Sun.COM * i_iAdjustmentInSeconds Number of seconds by which to adjust the 1014*12720SWyllys.Ingersoll@Sun.COM * system clock 1015*12720SWyllys.Ingersoll@Sun.COM * Output 1016*12720SWyllys.Ingersoll@Sun.COM * ------ 1017*12720SWyllys.Ingersoll@Sun.COM * (none) 1018*12720SWyllys.Ingersoll@Sun.COM * 1019*12720SWyllys.Ingersoll@Sun.COM * Return value 1 if successful, 0 on error 1020*12720SWyllys.Ingersoll@Sun.COM * 1021*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 1022*12720SWyllys.Ingersoll@Sun.COM int K_AdjustLocalClock( int i_iNumberOfSeconds ); 1023*12720SWyllys.Ingersoll@Sun.COM 1024*12720SWyllys.Ingersoll@Sun.COM 1025*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 1026*12720SWyllys.Ingersoll@Sun.COM * Function: K_SetRootPassword 1027*12720SWyllys.Ingersoll@Sun.COM * 1028*12720SWyllys.Ingersoll@Sun.COM * Description: 1029*12720SWyllys.Ingersoll@Sun.COM * The K_SetRootPassword function sets the password for the root user via 1030*12720SWyllys.Ingersoll@Sun.COM * Pluggable Authentication Module (PAM). This function is interactive. 1031*12720SWyllys.Ingersoll@Sun.COM * 1032*12720SWyllys.Ingersoll@Sun.COM * Input 1033*12720SWyllys.Ingersoll@Sun.COM * ----- 1034*12720SWyllys.Ingersoll@Sun.COM * i_sPassword Password to set 1035*12720SWyllys.Ingersoll@Sun.COM * 1036*12720SWyllys.Ingersoll@Sun.COM * Output 1037*12720SWyllys.Ingersoll@Sun.COM * ------ 1038*12720SWyllys.Ingersoll@Sun.COM * (none) 1039*12720SWyllys.Ingersoll@Sun.COM * 1040*12720SWyllys.Ingersoll@Sun.COM * Return value 0 if successful, -1 on error 1041*12720SWyllys.Ingersoll@Sun.COM * 1042*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 1043*12720SWyllys.Ingersoll@Sun.COM int K_SetRootPassword( const char* i_sPassword ); 1044*12720SWyllys.Ingersoll@Sun.COM 1045*12720SWyllys.Ingersoll@Sun.COM 1046*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 1047*12720SWyllys.Ingersoll@Sun.COM * Function: K_Alarm 1048*12720SWyllys.Ingersoll@Sun.COM * 1049*12720SWyllys.Ingersoll@Sun.COM * Description: 1050*12720SWyllys.Ingersoll@Sun.COM * Calls alarm(2) on Unix in order to cause the operating system to generate 1051*12720SWyllys.Ingersoll@Sun.COM * a SIGALRM signal for this process after the given number of real-time 1052*12720SWyllys.Ingersoll@Sun.COM * seconds. Does nothing on Windows. 1053*12720SWyllys.Ingersoll@Sun.COM * 1054*12720SWyllys.Ingersoll@Sun.COM * Input 1055*12720SWyllys.Ingersoll@Sun.COM * ----- 1056*12720SWyllys.Ingersoll@Sun.COM * i_iSeconds Number of seconds after which to generate a SIGALRM 1057*12720SWyllys.Ingersoll@Sun.COM * signal 1058*12720SWyllys.Ingersoll@Sun.COM * 1059*12720SWyllys.Ingersoll@Sun.COM * Output 1060*12720SWyllys.Ingersoll@Sun.COM * ------ 1061*12720SWyllys.Ingersoll@Sun.COM * (none) 1062*12720SWyllys.Ingersoll@Sun.COM * 1063*12720SWyllys.Ingersoll@Sun.COM * Return value If a previous alarm request is pending, then it returns 1064*12720SWyllys.Ingersoll@Sun.COM * the number of seconds until this previous request would 1065*12720SWyllys.Ingersoll@Sun.COM * have generated a SIGALRM signal. Otherwise, returns 0. 1066*12720SWyllys.Ingersoll@Sun.COM * 1067*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 1068*12720SWyllys.Ingersoll@Sun.COM unsigned int K_Alarm( unsigned int i_iSeconds ); 1069*12720SWyllys.Ingersoll@Sun.COM 1070*12720SWyllys.Ingersoll@Sun.COM 1071*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 1072*12720SWyllys.Ingersoll@Sun.COM * Function: K_GetExtendedVersionFromBase 1073*12720SWyllys.Ingersoll@Sun.COM * 1074*12720SWyllys.Ingersoll@Sun.COM * Description: 1075*12720SWyllys.Ingersoll@Sun.COM * This KMS-specific function prepends the timestamp value to the specified 1076*12720SWyllys.Ingersoll@Sun.COM * base replication schema version and returns this value as an extended 1077*12720SWyllys.Ingersoll@Sun.COM * replication schema version. 1078*12720SWyllys.Ingersoll@Sun.COM * 1079*12720SWyllys.Ingersoll@Sun.COM * Input 1080*12720SWyllys.Ingersoll@Sun.COM * ----- 1081*12720SWyllys.Ingersoll@Sun.COM * i_iBaseSchemaVersion Base replication schema version 1082*12720SWyllys.Ingersoll@Sun.COM * 1083*12720SWyllys.Ingersoll@Sun.COM * Output 1084*12720SWyllys.Ingersoll@Sun.COM * ------ 1085*12720SWyllys.Ingersoll@Sun.COM * (none) 1086*12720SWyllys.Ingersoll@Sun.COM * 1087*12720SWyllys.Ingersoll@Sun.COM * Return value Extended replication schema version 1088*12720SWyllys.Ingersoll@Sun.COM * 1089*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 1090*12720SWyllys.Ingersoll@Sun.COM unsigned int K_GetExtendedVersionFromBase( unsigned int i_iBaseSchemaVersion ); 1091*12720SWyllys.Ingersoll@Sun.COM 1092*12720SWyllys.Ingersoll@Sun.COM 1093*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 1094*12720SWyllys.Ingersoll@Sun.COM * Function: K_ParseTimestampFromExtendedVersion 1095*12720SWyllys.Ingersoll@Sun.COM * 1096*12720SWyllys.Ingersoll@Sun.COM * Description: 1097*12720SWyllys.Ingersoll@Sun.COM * This KMS-specific function parses the timestamp value from the given 1098*12720SWyllys.Ingersoll@Sun.COM * extended replication schema version and returns this timestamp value. 1099*12720SWyllys.Ingersoll@Sun.COM * 1100*12720SWyllys.Ingersoll@Sun.COM * Input 1101*12720SWyllys.Ingersoll@Sun.COM * ----- 1102*12720SWyllys.Ingersoll@Sun.COM * i_iExtendedSchemaVersion Extended replication schema version 1103*12720SWyllys.Ingersoll@Sun.COM * 1104*12720SWyllys.Ingersoll@Sun.COM * Output 1105*12720SWyllys.Ingersoll@Sun.COM * ------ 1106*12720SWyllys.Ingersoll@Sun.COM * (none) 1107*12720SWyllys.Ingersoll@Sun.COM * 1108*12720SWyllys.Ingersoll@Sun.COM * Return value Timestamp value 1109*12720SWyllys.Ingersoll@Sun.COM * 1110*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 1111*12720SWyllys.Ingersoll@Sun.COM unsigned int K_ParseTimestampFromExtendedVersion( 1112*12720SWyllys.Ingersoll@Sun.COM unsigned int i_iExtendedSchemaVersion ); 1113*12720SWyllys.Ingersoll@Sun.COM 1114*12720SWyllys.Ingersoll@Sun.COM 1115*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 1116*12720SWyllys.Ingersoll@Sun.COM * Function: K_ParseBaseFromExtendedVersion 1117*12720SWyllys.Ingersoll@Sun.COM * 1118*12720SWyllys.Ingersoll@Sun.COM * Description: 1119*12720SWyllys.Ingersoll@Sun.COM * This KMS-specific function parses the base replication schema value from 1120*12720SWyllys.Ingersoll@Sun.COM * the given extended replication schema version and returns this base value. 1121*12720SWyllys.Ingersoll@Sun.COM * 1122*12720SWyllys.Ingersoll@Sun.COM * Input 1123*12720SWyllys.Ingersoll@Sun.COM * ----- 1124*12720SWyllys.Ingersoll@Sun.COM * i_iExtendedSchemaVersion Extended replication schema version 1125*12720SWyllys.Ingersoll@Sun.COM * 1126*12720SWyllys.Ingersoll@Sun.COM * Output 1127*12720SWyllys.Ingersoll@Sun.COM * ------ 1128*12720SWyllys.Ingersoll@Sun.COM * (none) 1129*12720SWyllys.Ingersoll@Sun.COM * 1130*12720SWyllys.Ingersoll@Sun.COM * Return value Base replication schema value 1131*12720SWyllys.Ingersoll@Sun.COM * 1132*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 1133*12720SWyllys.Ingersoll@Sun.COM 1134*12720SWyllys.Ingersoll@Sun.COM unsigned int K_ParseBaseFromExtendedVersion( 1135*12720SWyllys.Ingersoll@Sun.COM unsigned int i_iExtendedSchemaVersion ); 1136*12720SWyllys.Ingersoll@Sun.COM 1137*12720SWyllys.Ingersoll@Sun.COM 1138*12720SWyllys.Ingersoll@Sun.COM /*--------------------------------------------------------------------------- 1139*12720SWyllys.Ingersoll@Sun.COM * Function: K_System 1140*12720SWyllys.Ingersoll@Sun.COM * 1141*12720SWyllys.Ingersoll@Sun.COM * Description: 1142*12720SWyllys.Ingersoll@Sun.COM * This function is a thread-safe replacement for the unsafe system(3C) call. 1143*12720SWyllys.Ingersoll@Sun.COM * See the popen(3C) man page for more information. 1144*12720SWyllys.Ingersoll@Sun.COM * 1145*12720SWyllys.Ingersoll@Sun.COM * Input 1146*12720SWyllys.Ingersoll@Sun.COM * ----- 1147*12720SWyllys.Ingersoll@Sun.COM * i_sCmd Command to execute 1148*12720SWyllys.Ingersoll@Sun.COM * 1149*12720SWyllys.Ingersoll@Sun.COM * Output 1150*12720SWyllys.Ingersoll@Sun.COM * ------ 1151*12720SWyllys.Ingersoll@Sun.COM * (none) 1152*12720SWyllys.Ingersoll@Sun.COM * 1153*12720SWyllys.Ingersoll@Sun.COM * Return value Termination status of the command language interpreter 1154*12720SWyllys.Ingersoll@Sun.COM * if successful, -1 on failure 1155*12720SWyllys.Ingersoll@Sun.COM * 1156*12720SWyllys.Ingersoll@Sun.COM *--------------------------------------------------------------------------*/ 1157*12720SWyllys.Ingersoll@Sun.COM 1158*12720SWyllys.Ingersoll@Sun.COM int K_System( const char *i_sCmd ); 1159*12720SWyllys.Ingersoll@Sun.COM 1160*12720SWyllys.Ingersoll@Sun.COM #define K_system K_System 1161*12720SWyllys.Ingersoll@Sun.COM 1162*12720SWyllys.Ingersoll@Sun.COM #ifdef __cplusplus 1163*12720SWyllys.Ingersoll@Sun.COM } 1164*12720SWyllys.Ingersoll@Sun.COM #endif 1165*12720SWyllys.Ingersoll@Sun.COM 1166*12720SWyllys.Ingersoll@Sun.COM #endif 1167*12720SWyllys.Ingersoll@Sun.COM 1168*12720SWyllys.Ingersoll@Sun.COM 1169