X11 Work Bench Toolkit  1.0
platform_helper.c File Reference

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 <dlfcn.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <time.h>
#include <locale.h>
#include "platform_helper.h"
#include "window_helper.h"
#include "file_help.h"

Go to the source code of this file.

Macros

#define WB_ALLOC_TAG   (*((const unsigned int *)szWBAllocTag)) /*< tag indicating it's a __malloc_header__ **/
 
#define PMALLOC_FLAG   (&mallocFlagMalloc) /*< when pPrev and pNext point to THIS, it's a "malloc'd" pointer **/
 
#define INITIAL_INTERNAL_ATOM_SIZE   4096
 
#define INITIAL_INTERNAL_ATOM_STRING_SIZE   262144
 
#define MAX_XPM_COLOR_CHAR_SIZE   4
 
#define NEXT_INT(iW, pX, pY, pZ)
 
#define WBRUNRESULT_BUFFER_MINSIZE   65536
 
#define WBRUNRESULT_BYTES_TO_READ   256
 

Typedefs

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)
 
void WBPlatformOnInit (void)
 Resource initialization on startup. More...
 
void WBPlatformOnExit (void)
 Resource 'free-up' on exit (must call) 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...
 
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 * 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...
 
char * WBSearchPath (const char *szFileName)
 Run an application asynchronously. 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)
 
char * WBRunResult (const char *szAppName,...)
 Run an application synchronously, returning 'stdout' output in a character buffer. More...
 
char * WBRunResultPipe (const char *szStdInBuf, const char *szAppName,...)
 Run an application synchronously, 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)
 Loads a shared library, DLL, module, or whatever you call it on your operating system. 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)
 
unsigned int WBInterlockedIncrement (volatile unsigned int *pValue)
 
unsigned int WBInterlockedExchange (volatile unsigned int *pValue, unsigned int nNewVal)
 
unsigned int WBInterlockedRead (volatile unsigned int *pValue)
 
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
 
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
 

Detailed Description

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.

Macro Definition Documentation

#define NEXT_INT (   iW,
  pX,
  pY,
  pZ 
)
Value:
{int iLen; NEXT_WORD(pX,pY,pZ); \
iLen=pZ - pY > sizeof(tbuf) - 1 ? sizeof(tbuf) - 1 : pZ - pY; \
if(iLen>0){memcpy(tbuf,pY,iLen);} tbuf[iLen]=0; iW=atoi(tbuf);}