freetdm: windows fixes

This commit is contained in:
Moises Silva
2010-04-29 10:52:42 -04:00
parent b472913683
commit 110bd5cdb1
10 changed files with 931 additions and 860 deletions
+50
View File
@@ -48,17 +48,67 @@ extern "C" {
#include <unistd.h>
#endif
/*! \brief sleep x amount of milliseconds */
#ifdef __WINDOWS__
#define ftdm_sleep(x) Sleep(x)
#else
#define ftdm_sleep(x) usleep(x * 1000)
#endif
/*! \brief strncpy replacement */
#define ftdm_copy_string(x,y,z) strncpy(x, y, z - 1)
/*! \brief strncpy into a fixed-length buffer */
#define ftdm_set_string(x,y) strncpy(x, y, sizeof(x)-1)
/*! \brief check for null or zero length string buffer */
#define ftdm_strlen_zero(s) (!s || *s == '\0')
/*! \brief check for zero length string buffer */
#define ftdm_strlen_zero_buf(s) (*s == '\0')
/*! \brief The memory handler.
Do not use directly this variable, use the memory macros and ftdm_global_set_memory_handler to override */
FT_DECLARE_DATA extern ftdm_memory_handler_t g_ftdm_mem_handler;
/*!
\brief Allocate uninitialized memory
\param chunksize the chunk size
*/
#define ftdm_malloc(chunksize) g_ftdm_mem_handler.malloc(g_ftdm_mem_handler.pool, chunksize)
/*!
\brief Reallocates memory
\param buff the buffer
\param chunksize the chunk size
*/
#define ftdm_realloc(buff, chunksize) g_ftdm_mem_handler.realloc(g_ftdm_mem_handler.pool, buff, chunksize)
/*!
\brief Allocate initialized memory
\param chunksize the chunk size
*/
#define ftdm_calloc(elements, chunksize) g_ftdm_mem_handler.calloc(g_ftdm_mem_handler.pool, elements, chunksize)
/*!
\brief Free chunk of memory
\param chunksize the chunk size
*/
#define ftdm_free(chunk) g_ftdm_mem_handler.free(g_ftdm_mem_handler.pool, chunk)
/*!
\brief Free a pointer and set it to NULL unless it already is NULL
\param it the pointer
*/
#define ftdm_safe_free(it) if (it) { ftdm_free(it); it = NULL; }
/*! \brief Duplicate string */
FT_DECLARE(char *) ftdm_strdup(const char *str);
/*! \brief Duplicate string with limit */
FT_DECLARE(char *) ftdm_strndup(const char *str, ftdm_size_t inlen);
#ifdef __cplusplus
} /* extern C */
#endif