[svn-commits] branch oej/metermaids r11307 -
/team/oej/metermaids/include/asterisk/utils.h
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Mon Feb 27 09:35:13 MST 2006
Author: oej
Date: Mon Feb 27 10:35:11 2006
New Revision: 11307
URL: http://svn.digium.com/view/asterisk?rev=11307&view=rev
Log:
Update
Modified:
team/oej/metermaids/include/asterisk/utils.h
Modified: team/oej/metermaids/include/asterisk/utils.h
URL: http://svn.digium.com/view/asterisk/team/oej/metermaids/include/asterisk/utils.h?rev=11307&r1=11306&r2=11307&view=diff
==============================================================================
--- team/oej/metermaids/include/asterisk/utils.h (original)
+++ team/oej/metermaids/include/asterisk/utils.h Mon Feb 27 10:35:11 2006
@@ -25,6 +25,7 @@
#include "asterisk/compat.h"
+#include <stdlib.h>
#include <netinet/in.h>
#include <arpa/inet.h> /* we want to override inet_ntoa */
#include <netdb.h>
@@ -33,6 +34,7 @@
#include "asterisk/lock.h"
#include "asterisk/time.h"
#include "asterisk/strings.h"
+#include "asterisk/logger.h"
/*! \note
\verbatim
@@ -143,6 +145,9 @@
/* ast_md5_hash
\brief Produces MD5 hash based on input string */
void ast_md5_hash(char *output, char *input);
+/* ast_sha1_hash
+ \brief Produces SHA1 hash based on input string */
+void ast_sha1_hash(char *output, char *input);
int ast_base64encode(char *dst, const unsigned char *src, int srclen, int max);
int ast_base64decode(unsigned char *dst, const char *src, int max);
@@ -235,4 +240,171 @@
int getloadavg(double *list, int nelem);
#endif
+#ifdef linux
+#define ast_random random
+#else
+long int ast_random(void);
+#endif
+
+/*!
+ \brief A wrapper for malloc()
+
+ ast_malloc() is a wrapper for malloc() that will generate an Asterisk log
+ message in the case that the allocation fails.
+
+ The argument and return value are the same as malloc()
+*/
+#define ast_malloc(len) \
+ _ast_malloc((len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+AST_INLINE_API(
+void *_ast_malloc(size_t len, const char *file, int lineno, const char *func),
+{
+ void *p;
+
+ p = malloc(len);
+
+ if (!p)
+ ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file);
+
+ return p;
+}
+)
+
+/*!
+ \brief A wrapper for calloc()
+
+ ast_calloc() is a wrapper for calloc() that will generate an Asterisk log
+ message in the case that the allocation fails.
+
+ The arguments and return value are the same as calloc()
+*/
+#define ast_calloc(num, len) \
+ _ast_calloc((num), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+AST_INLINE_API(
+void *_ast_calloc(size_t num, size_t len, const char *file, int lineno, const char *func),
+{
+ void *p;
+
+ p = calloc(num, len);
+
+ if (!p)
+ ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file);
+
+ return p;
+}
+)
+
+/*!
+ \brief A wrapper for realloc()
+
+ ast_realloc() is a wrapper for realloc() that will generate an Asterisk log
+ message in the case that the allocation fails.
+
+ The arguments and return value are the same as realloc()
+*/
+#define ast_realloc(p, len) \
+ _ast_realloc((p), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+AST_INLINE_API(
+void *_ast_realloc(void *p, size_t len, const char *file, int lineno, const char *func),
+{
+ void *newp;
+
+ newp = realloc(p, len);
+
+ if (!newp)
+ ast_log(LOG_ERROR, "Memory Allocation Failure - '%d' bytes in function %s at line %d of %s\n", (int)len, func, lineno, file);
+
+ return newp;
+}
+)
+
+/*!
+ \brief A wrapper for strdup()
+
+ ast_strdup() is a wrapper for strdup() that will generate an Asterisk log
+ message in the case that the allocation fails.
+
+ ast_strdup(), unlike strdup(), can safely accept a NULL argument. If a NULL
+ argument is provided, ast_strdup will return NULL without generating any
+ kind of error log message.
+
+ The argument and return value are the same as strdup()
+*/
+#define ast_strdup(str) \
+ _ast_strdup((str), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+AST_INLINE_API(
+char *_ast_strdup(const char *str, const char *file, int lineno, const char *func),
+{
+ char *newstr = NULL;
+
+ if (str) {
+ newstr = strdup(str);
+
+ if (!newstr)
+ ast_log(LOG_ERROR, "Memory Allocation Failure - Could not duplicate '%s' in function %s at line %d of %s\n", str, func, lineno, file);
+ }
+
+ return newstr;
+}
+)
+
+/*!
+ \brief A wrapper for strndup()
+
+ ast_strndup() is a wrapper for strndup() that will generate an Asterisk log
+ message in the case that the allocation fails.
+
+ ast_strndup(), unlike strndup(), can safely accept a NULL argument for the
+ string to duplicate. If a NULL argument is provided, ast_strdup will return
+ NULL without generating any kind of error log message.
+
+ The arguments and return value are the same as strndup()
+*/
+#define ast_strndup(str, len) \
+ _ast_strndup((str), (len), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
+AST_INLINE_API(
+char *_ast_strndup(const char *str, size_t len, const char *file, int lineno, const char *func),
+{
+ char *newstr = NULL;
+
+ if (str) {
+ newstr = strndup(str, len);
+
+ if (!newstr)
+ ast_log(LOG_ERROR, "Memory Allocation Failure - Could not duplicate '%d' bytes of '%s' in function %s at line %d of %s\n", (int)len, str, func, lineno, file);
+ }
+
+ return newstr;
+}
+)
+
+#if !defined(ast_strdupa) && defined(__GNUC__)
+/*!
+ \brief duplicate a string in memory from the stack
+ \param s The string to duplicate
+
+ This macro will duplicate the given string. It returns a pointer to the stack
+ allocatted memory for the new string.
+*/
+#define ast_strdupa(s) \
+ (__extension__ \
+ ({ \
+ const char *__old = (s); \
+ size_t __len = strlen(__old) + 1; \
+ char *__new = __builtin_alloca(__len); \
+ if (__builtin_expect(!__new, 0)) \
+ ast_log(LOG_ERROR, "Stack Allocation Error in" \
+ "function '%s' at line '%d' of '%s'!\n", \
+ __PRETTY_FUNCTION__, __LINE__, __FILE__); \
+ else \
+ memcpy (__new, __old, __len); \
+ __new; \
+ }))
+#endif
+
#endif /* _ASTERISK_UTILS_H */
More information about the svn-commits
mailing list