memory.h 1.79 KB
/***************************************************************************
 * memory.h: Prototypes for default memory operations like memcpy and thus *
 *           on a win32 system nearly all CRT functions (CRT is the        *
 *           windows C RunTime, that is the normal libC) aren't thread-    *
 *           safe. As i build up tests this causes problems for example    *
 *           with strcpy. So i decided to write wrapper that use non CRT   *
 *           functions on Windows and normal libC ones on a posix system.  *
 *                                                                         *
 * Author:   Georg Steffers <georg@steffers.org>                           *
 * Date:     03/06/2006                                                    *
 ***************************************************************************/
#ifndef MEMORY_H
#define MEMORY_H

#include <windows.h>
#include <sys/types.h>

#include <scot_common.h>
#include <scot/scot_types.h>

#define SCOT_MEM_GET(s)       HeapAlloc (GetProcessHeap(), HEAP_ZERO_MEMORY, (s));
#define SCOT_MEM_FREE(p)      \
   if ((p)) {HeapFree(GetProcessHeap(), 0, (p)); (p)=NULL;}
#define SCOT_MEM_COPY(p,q,s)  (CopyMemory ((p), (q), (s)), (p))
#define SCOT_MEM_MOVE(p,q,s)  (MoveMemory ((p), (q), (s)), (p))
#define SCOT_MEM_FILL(p,v,s)  (FillMemory ((p), (s), (v)), (p))
#define SCOT_MEM_ZERO         ZeroMemory
#define SCOT_STR_LENGTH       str_length
#define SCOT_STR_COPY         str_copy
#define SCOT_STRN_COPY        strn_copy
#define SCOT_STR_CHAR         str_char
#define SCOT_STRR_CHAR        strr_char

SIZE_T   str_length (const char *);
char   * str_copy   (char *, const char *);
char   * strn_copy  (char *, const char *, SIZE_T);
char   * str_char   (const char *, int);
char   * strr_char  (const char *, int);

#endif /* MEMORY_H */