X11workbench Toolkit
1.0
|
Platform-specific utility functions. More...
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <memory.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <signal.h>
#include <time.h>
#include <sys/time.h>
#include <dlfcn.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <locale.h>
#include "platform_helper.h"
#include "window_helper.h"
#include "file_help.h"
Go to the source code of this file.
Typedefs | |
typedef struct __profile_info__ | PROFILE_INFO |
typedef struct __pointer_hash__ | POINTER_HASH |
typedef struct _MY_XPM_COLOR_ | MY_XPM_COLOR |
Functions | |
static void | WBFreePointerHashes (void) |
static void | __add_to_temp_file_list (const char *szFile) |
int | main (int argc, char *argv0[], char *envp0[]) __attribute__((weak)) __attribute__((section("text_main"))) |
int | WBMain (int argc, char *argv0[], char *envp0[]) __attribute__((weak)) __attribute__((section("text_wbmain"))) |
Startup function, equivalent to 'main()' - provided for convenience. More... | |
void | WBUsage (void) |
Optional startup function, sends 'usage' (help) info to stderr - application-defined function. More... | |
void | WBPlatformOnInit (void) |
Resource initialization on startup. More... | |
void | WBPlatformOnExit (void) |
Resource 'free-up' on exit (must call) More... | |
int | WBParseStandardArguments (int *pargc, char ***pargv, char ***penvp) |
parses standard C arguments as passed to 'main()' More... | |
void | WBToolkitUsage (void) |
Displays 'usage' for toolkit options to stderr. More... | |
const char * | GetStartupAppName (void) |
returns a pointer to a copy of the application name from argv[0] More... | |
void | WBSetDebugLevel (unsigned int iNew) |
set debug level More... | |
void | WBDebugPrint (const char *fmt,...) |
void | WBDebugDump (const char *szTitle, void *pData, int cbData) |
conditionally dumps binary data to debug message output More... | |
int | WBRegisterProfileVar (const char *szFile, int nLine, const char *szFunction, const char *szName, const char *szDesc) |
void | WBStartProfile (int nProfileID) |
void | WBStopProfile (int nProfileID) |
void | WBDumpProfileData (void) |
WB_UINT64 | WBGetTimeIndex (void) |
Returns the current 'time index' (in microseconds) More... | |
void | WBDelay (uint32_t uiDelay) |
Delay for a specified period in microseconds. More... | |
int | WBCPUCount (void) |
Get the number of available CPU cores. More... | |
void * | WBAlloc (int nSize) |
High performance memory sub-allocator 'allocate'. More... | |
int | WBAllocUsableSize (void *pBuf) |
High performance memory sub-allocator, similar to 'malloc_usable_size'. More... | |
void | WBFree (void *pBuf) |
High performance memory sub-allocator 'free'. More... | |
void * | WBReAlloc (void *pBuf, int nNewSize) |
High performance memory sub-allocator 're-allocate'. More... | |
void | WBSubAllocTrashMasher (void) |
High performance memory sub-allocator 'trash masher' - call periodically to minimize wasted memory. More... | |
char * | WBCopyString (const char *pSrc) |
A simple utility that returns a WBAlloc() copy of a 0-byte terminated string. More... | |
char * | WBCopyStringN (const char *pSrc, unsigned int nMaxChars) |
A simple utility that returns a WBAlloc() copy of a string up to a maximum length (can also be 0-byte terminated) More... | |
void | WBCatString (char **ppDest, const char *pSrc) |
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string. More... | |
void | WBCatStringN (char **ppDest, const char *pSrc, unsigned int nMaxChars) |
A simple utility that concatenates a string onto the end of a 0-byte terminated WBAlloc() string up to a maximum length (can also be 0-byte terminated) More... | |
void | WBDeQuoteString (char *pString) |
De-Quote a string 'in place', that is modifying the original string by removing quotes. More... | |
static char | __amp_char (char **ppSpot) |
void | WBNormalizeXMLString (char *pString) |
De-Quote and 'normalize' an XML string 'in place', that is modifying the original string by removing quotes and translationg things like '&' '>' etc. More... | |
int | WBStringLineCount (const char *pSrc, unsigned int nMaxChars) |
Determine how many 'lines' are in a block of text by counting 'linefeed' characters. More... | |
const char * | WBStringNextLine (const char *pSrc, unsigned int *pnMaxChars) |
Locate the next line in a block of text, returning its pointer (and updating remaining length) More... | |
WB_UINT32 | WBCreatePointerHash (void *pPointer) |
Create/obtain a 32-bit 'secure' hash for a pointer. More... | |
void | WBDestroyPointerHash (WB_UINT32 uiHash) |
Destroy a 32-bit 'secure' hash for a pointer. More... | |
void | WBDestroyPointerHashPtr (void *pPointer) |
Destroy a 32-bit 'secure' hash for a pointer regardless of reference count. More... | |
void * | WBGetPointerFromHash (WB_UINT32 uiHash) |
Obtain a pointer from a 32-bit 'secure' pointer hash value. More... | |
Atom | WBGetAtom (Display *pDisplay, const char *szAtomName) |
Lookup and/or allocate an internal Atom for a named string (lookups include X11 atoms) More... | |
Atom | WBLookupAtom (Display *pDisplay, const char *szAtomName) |
Lookup (but do not allocate) an internal (or X11) Atom for a named string. More... | |
char * | WBGetAtomName (Display *pDisplay, Atom aAtom) |
Lookup and/or allocate an internal Atom for a named string. More... | |
static void | MyQuickSort2 (struct my_qsort_data *pData, int iLow, int iHigh) |
void | my_qsort_r (void *base, int nmemb, int size, void *thunk, int(*compar)(void *, const void *, const void *)) |
Local implementation of qsort_r() for operating systems that do not have it. More... | |
static __inline__ void * | ElementFromIndex (struct my_qsort_data *pData, int iElement) |
static int | DoCompareI (struct my_qsort_data *pData, int iLeft, int iRight) |
static int | DoCompareP (struct my_qsort_data *pData, int iLeft, void *pRight) |
static void | DoSwapData (struct my_qsort_data *pData, int iLeft, int iRight) |
static int | MyXPMColorCompare (const void *p1, const void *p2) |
static char * | MyXPMToData (const char *pXPM[], int *piW, int *piH, char **ppTransparency) |
int | MyLoadPixmapFromData (Display *pDisplay, Window wID, char *aData[], Pixmap *pPixmap, Pixmap *pMask, XPM_ATTRIBUTES *pAttr) |
Alternate for XpmCreatePixmapFromData() whenever libXpm is not being used. More... | |
int | WBMkDir (const char *szFileName, int flags) |
a wrapper for 'mkdir' that makes directories recursively (as needed) More... | |
char * | WBSearchPath (const char *szFileName) |
search for a file using the PATH environment variable More... | |
char * | WBTempFile0 (const char *szExt) |
Get the name for a new, unique temporary file, creating the file in the process. More... | |
char * | WBTempFile (const char *szExt) |
Get the name for a new, unique temporary file, creating the file in the process, and save its name for later deletion. More... | |
WB_PROCESS_ID | WBRunAsyncPipeV (WB_FILE_HANDLE hStdIn, WB_FILE_HANDLE hStdOut, WB_FILE_HANDLE hStdErr, const char *szAppName, va_list va) |
Run an application asynchronously, specifying file handles for STDIN, STDOUT, and STDERR, using a va_list for the program's parameters. More... | |
WB_PROCESS_ID | WBRunAsync (const char *szAppName,...) |
Run an application asynchronously. More... | |
WB_PROCESS_ID | WBRunAsyncPipe (WB_FILE_HANDLE hStdIn, WB_FILE_HANDLE hStdOut, WB_FILE_HANDLE hStdErr, const char *szAppName,...) |
Run an application asynchronously, specifying file handles for STDIN, STDOUT, and STDERR. More... | |
static char * | WBRunResultInternal (WB_FILE_HANDLE hStdIn, const char *szAppName, va_list va) |
int | WBGetProcessState (WB_PROCESS_ID idProcess, WB_INT32 *pExitCode) |
Check on a running process, and return its state, and optionally the exit code. More... | |
char * | WBRunResult (const char *szAppName,...) |
Run an application synchronously, returning 'stdout' output in a character buffer. More... | |
char * | WBRunResultWithInput (const char *szStdInBuf, const char *szAppName,...) |
Run an application synchronously, supplying an input buffer for 'stdin', and returning 'stdout' output in a character buffer. More... | |
WB_MODULE | WBLoadLibrary (const char *szModuleName) |
Loads a shared library, DLL, module, or whatever you call it on your operating system. More... | |
void | WBFreeLibrary (WB_MODULE hModule) |
Frees a shared library, DLL, module, or whatever, that was loaded via 'WBLoadLibrary()'. More... | |
WB_PROCADDRESS | WBGetProcAddress (WB_MODULE hModule, const char *szProcName) |
Obtains a function pointer for an exported function symbol in a shared library (or DLL) More... | |
void * | WBGetDataAddress (WB_MODULE hModule, const char *szDataName) |
Obtains a data pointer for an exported data symbol in a shared library (or DLL) More... | |
WB_THREAD_KEY | WBThreadAllocLocal (void) |
Allocate 'thread local' storage. More... | |
void | WBThreadFreeLocal (WB_THREAD_KEY keyVal) |
Free 'thread local' storage allocated by WBThreadAllocLocal() More... | |
void * | WBThreadGetLocal (WB_THREAD_KEY keyVal) |
Get 'thread local' data identified by 'keyVal'. More... | |
void | WBThreadSetLocal (WB_THREAD_KEY keyVal, void *pValue) |
Get 'thread local' data identified by 'keyVal'. More... | |
WB_THREAD | WBThreadGetCurrent (void) |
Get 'current thread' identifier. More... | |
WB_THREAD | WBThreadCreate (void *(*function)(void *), void *pParam) |
Create a new thread, returning its WB_THREAD identifier. More... | |
void * | WBThreadWait (WB_THREAD hThread) |
Wait for a specified threat to exit. More... | |
int | WBThreadRunning (WB_THREAD hThread) |
Determine whether a thread is running (can be suspended) More... | |
void | WBThreadExit (void *pRval) |
Exit the current thread immediately, specifying return code. More... | |
void | WBThreadClose (WB_THREAD hThread) |
Close the specified WB_THREAD identifier. More... | |
int | WBCondCreate (WB_COND *pCond) |
Create a signallable condition. More... | |
int | WBMutexCreate (WB_MUTEX *pMtx) |
Create a lockable mutex. More... | |
void | WBCondFree (WB_COND *pCond) |
Free a signallable condition. More... | |
void | WBMutexFree (WB_MUTEX *pMtx) |
Free a lockable mutex. More... | |
int | WBMutexLock (WB_MUTEX *pMtx, int nTimeout) |
Wait for and lock a mutex, blocking until it is available. More... | |
int | WBMutexUnlock (WB_MUTEX *pMtx) |
Unlock a previously locked mutex. More... | |
int | WBCondSignal (WB_COND *pCond) |
Signal a condition (event) More... | |
int | WBCondWait (WB_COND *pCond, int nTimeout) |
Wait for a signal on a condition (event) More... | |
int | WBCondWaitMutex (WB_COND *pCond, WB_MUTEX *pMtx, int nTimeout) |
Wait for a signal on a condition (event) More... | |
unsigned int | WBInterlockedDecrement (volatile unsigned int *pValue) |
Interlocked 'atomic' decrement of an unsigned integer. More... | |
unsigned int | WBInterlockedIncrement (volatile unsigned int *pValue) |
Interlocked 'atomic' increment of an unsigned integer. More... | |
unsigned int | WBInterlockedExchange (volatile unsigned int *pValue, unsigned int nNewVal) |
Interlocked 'atomic' exchange of an unsigned integer with a specified value. More... | |
unsigned int | WBInterlockedRead (volatile unsigned int *pValue) |
Interlocked 'atomic' read of an unsigned integer. More... | |
int | WBPrintPostScriptFile (const char *szPrinterName, const char *szFileName) |
Send postscript file to a printer (using lpr-cups or lpr on POSIX systems) More... | |
char * | WBGetPrinterList (void) |
Get a list of printer names. More... | |
Variables | |
static char * | pTempFileList = NULL |
static char * | pTempFileListEnd = NULL |
unsigned long | cbTempFileList |
static volatile int | fInterlockedRWLockInitFlag = 0 |
static pthread_rwlock_t | xInterlockedRWLock |
int | bQuitFlag |
'Quit' Flag - you should check this periodically in your main (message) loop and exit whenever it is TRUE (non-zero) More... | |
WB_UINT64 | iWBDebugLevel = 0 |
static char | szAppName [PATH_MAX *2] ="" |
static PROFILE_INFO * | paProfileInfo = NULL |
static int | nProfileInfo = 0 |
static int | nMaxProfileInfo = 0 |
static const char | szWBAllocTag [] ="WB_M" |
static struct __malloc_header__ | mallocFlagMalloc |
static POINTER_HASH * | pPointerHashes = NULL |
static int | nPointerHash = 0 |
static int | nMaxPointerHash = 0 |
static WB_UINT32 | uiPointerHashSpinlock = 0 |
static volatile WB_UINT32 | lInternalAtomSpinner = 0L |
static char ** | ppInternalAtoms = NULL |
static char * | pszAtomNames = NULL |
static unsigned int | cbAtomNames = 0 |
static unsigned int | cbMaxAtomNames = 0 |
static unsigned int | nInternalAtoms = 0 |
static unsigned int | nMaxInternalAtoms = 0 |
Platform-specific utility functions.
Everything that a platform implentation might need in order to build goes in here, particularly local implementations of API functions, libraries, stubs, and any kind of platform-specific utilities.
Definition in file platform_helper.c.
#define NEXT_INT | ( | iW, | |
pX, | |||
pY, | |||
pZ | |||
) |