mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 19:52:48 +00:00
make inlinable functions only need the function body in one file, and respond properly to LOW_MEMORY being defined
make ast_copy_string inlinable, and ast_tvdiff_ms LOW_MEMORY aware git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5992 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -136,10 +136,13 @@ struct ast_hostent {
|
|||||||
\param str the input string
|
\param str the input string
|
||||||
\return a pointer to the first non-whitespace character
|
\return a pointer to the first non-whitespace character
|
||||||
*/
|
*/
|
||||||
#ifdef LOW_MEMORY
|
#if defined(LOW_MEMORY)
|
||||||
char *ast_skip_blanks(char *str);
|
char *ast_skip_blanks(char *str);
|
||||||
#else
|
#else
|
||||||
static inline char *ast_skip_blanks(char *str)
|
static inline
|
||||||
|
#endif
|
||||||
|
#if !defined(LOW_MEMORY) || defined(AST_API_MODULE)
|
||||||
|
char *ast_skip_blanks(char *str)
|
||||||
{
|
{
|
||||||
while (*str && *str < 33)
|
while (*str && *str < 33)
|
||||||
str++;
|
str++;
|
||||||
@@ -152,10 +155,13 @@ static inline char *ast_skip_blanks(char *str)
|
|||||||
\param str the input string
|
\param str the input string
|
||||||
\return a pointer to the NULL following the string
|
\return a pointer to the NULL following the string
|
||||||
*/
|
*/
|
||||||
#ifdef LOW_MEMORY
|
#if defined(LOW_MEMORY)
|
||||||
char *ast_trim_blanks(char *str);
|
char *ast_trim_blanks(char *str);
|
||||||
#else
|
#else
|
||||||
static inline char *ast_trim_blanks(char *str)
|
static inline
|
||||||
|
#endif
|
||||||
|
#if !defined(LOW_MEMORY) || defined(AST_API_MODULE)
|
||||||
|
char *ast_trim_blanks(char *str)
|
||||||
{
|
{
|
||||||
char *work = str;
|
char *work = str;
|
||||||
|
|
||||||
@@ -179,10 +185,13 @@ static inline char *ast_trim_blanks(char *str)
|
|||||||
\param str the input string
|
\param str the input string
|
||||||
\return a pointer to the first whitespace character
|
\return a pointer to the first whitespace character
|
||||||
*/
|
*/
|
||||||
#ifdef LOW_MEMORY
|
#if defined(LOW_MEMORY)
|
||||||
char *ast_skip_nonblanks(char *str);
|
char *ast_skip_nonblanks(char *str);
|
||||||
#else
|
#else
|
||||||
static inline char *ast_skip_nonblanks(char *str)
|
static inline
|
||||||
|
#endif
|
||||||
|
#if !defined(LOW_MEMORY) || defined(AST_API_MODULE)
|
||||||
|
char *ast_skip_nonblanks(char *str)
|
||||||
{
|
{
|
||||||
while (*str && *str > 32)
|
while (*str && *str > 32)
|
||||||
str++;
|
str++;
|
||||||
@@ -199,10 +208,13 @@ static inline char *ast_skip_nonblanks(char *str)
|
|||||||
characters from the input string, and returns a pointer to
|
characters from the input string, and returns a pointer to
|
||||||
the resulting string. The string is modified in place.
|
the resulting string. The string is modified in place.
|
||||||
*/
|
*/
|
||||||
#ifdef LOW_MEMORY
|
#if defined(LOW_MEMORY)
|
||||||
char *ast_strip(char *s);
|
char *ast_strip(char *s);
|
||||||
#else
|
#else
|
||||||
static inline char *ast_strip(char *s)
|
static inline
|
||||||
|
#endif
|
||||||
|
#if !defined(LOW_MEMORY) || defined(AST_API_MODULE)
|
||||||
|
char *ast_strip(char *s)
|
||||||
{
|
{
|
||||||
s = ast_skip_blanks(s);
|
s = ast_skip_blanks(s);
|
||||||
if (s)
|
if (s)
|
||||||
@@ -301,7 +313,23 @@ extern char *ast_strcasestr(const char *, const char *);
|
|||||||
reduced buffer size to this function (unlike \a strncpy), and the buffer does not need
|
reduced buffer size to this function (unlike \a strncpy), and the buffer does not need
|
||||||
to be initialized to zeroes prior to calling this function.
|
to be initialized to zeroes prior to calling this function.
|
||||||
*/
|
*/
|
||||||
|
#if defined(LOW_MEMORY)
|
||||||
void ast_copy_string(char *dst, const char *src, size_t size);
|
void ast_copy_string(char *dst, const char *src, size_t size);
|
||||||
|
#else
|
||||||
|
static inline
|
||||||
|
#endif
|
||||||
|
#if !defined(LOW_MEMORY) || defined(AST_API_MODULE)
|
||||||
|
void ast_copy_string(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
while (*src && size) {
|
||||||
|
*dst++ = *src++;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
if (__builtin_expect(!size, 0))
|
||||||
|
dst--;
|
||||||
|
*dst = '\0';
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Build a string in a buffer, designed to be called repeatedly
|
\brief Build a string in a buffer, designed to be called repeatedly
|
||||||
@@ -324,9 +352,17 @@ int ast_build_string(char **buffer, size_t *space, const char *fmt, ...) __attri
|
|||||||
* \param end the end of the time period
|
* \param end the end of the time period
|
||||||
* \return the difference in milliseconds
|
* \return the difference in milliseconds
|
||||||
*/
|
*/
|
||||||
static inline int ast_tvdiff_ms(struct timeval *start, struct timeval *end)
|
#if defined(LOW_MEMORY)
|
||||||
|
int ast_tvdiff_ms(const struct timeval *start, const struct timeval *end);
|
||||||
|
#else
|
||||||
|
static inline
|
||||||
|
#endif
|
||||||
|
#if !defined(LOW_MEMORY) || defined(AST_API_MODULE)
|
||||||
|
int ast_tvdiff_ms(const struct timeval *start, const struct timeval *end)
|
||||||
{
|
{
|
||||||
return ((end->tv_sec - start->tv_sec) * 1000) + ((end->tv_usec - start->tv_usec) / 1000);
|
return ((end->tv_sec - start->tv_sec) * 1000) + ((end->tv_usec - start->tv_usec) / 1000);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef AST_API_MODULE
|
||||||
#endif /* _ASTERISK_UTILS_H */
|
#endif /* _ASTERISK_UTILS_H */
|
||||||
|
57
utils.c
57
utils.c
@@ -29,56 +29,16 @@
|
|||||||
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
||||||
|
|
||||||
#include "asterisk/lock.h"
|
#include "asterisk/lock.h"
|
||||||
#include "asterisk/utils.h"
|
|
||||||
#include "asterisk/io.h"
|
#include "asterisk/io.h"
|
||||||
#include "asterisk/logger.h"
|
#include "asterisk/logger.h"
|
||||||
#include "asterisk/md5.h"
|
#include "asterisk/md5.h"
|
||||||
|
|
||||||
|
#define AST_API_MODULE /* ensure that inlinable API functions will be built in this module if required */
|
||||||
|
#include "asterisk/utils.h"
|
||||||
|
|
||||||
static char base64[64];
|
static char base64[64];
|
||||||
static char b2a[256];
|
static char b2a[256];
|
||||||
|
|
||||||
#ifdef LOW_MEMORY
|
|
||||||
char *ast_skip_blanks(char *str)
|
|
||||||
{
|
|
||||||
while (*str && *str < 33)
|
|
||||||
str++;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ast_trim_blanks(char *str)
|
|
||||||
{
|
|
||||||
char *work = str;
|
|
||||||
|
|
||||||
if (work) {
|
|
||||||
work += strlen(work) - 1;
|
|
||||||
/* It's tempting to only want to erase after we exit this loop,
|
|
||||||
but since ast_trim_blanks *could* receive a constant string
|
|
||||||
(which we presumably wouldn't have to touch), we shouldn't
|
|
||||||
actually set anything unless we must, and it's easier just
|
|
||||||
to set each position to \0 than to keep track of a variable
|
|
||||||
for it */
|
|
||||||
while ((work >= str) && *work < 33)
|
|
||||||
*(work--) = '\0';
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ast_skip_nonblanks(char *str)
|
|
||||||
{
|
|
||||||
while (*str && *str > 32)
|
|
||||||
str++;
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ast_strip(char *s)
|
|
||||||
{
|
|
||||||
s = ast_skip_blanks(s);
|
|
||||||
if (s)
|
|
||||||
ast_trim_blanks(s);
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char *ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
|
char *ast_strip_quoted(char *s, const char *beg_quotes, const char *end_quotes)
|
||||||
{
|
{
|
||||||
char *e;
|
char *e;
|
||||||
@@ -473,17 +433,6 @@ int ast_wait_for_input(int fd, int ms)
|
|||||||
return poll(pfd, 1, ms);
|
return poll(pfd, 1, ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_copy_string(char *dst, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
while (*src && size) {
|
|
||||||
*dst++ = *src++;
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
if (__builtin_expect(!size, 0))
|
|
||||||
dst--;
|
|
||||||
*dst = '\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
int ast_build_string(char **buffer, size_t *space, const char *fmt, ...)
|
int ast_build_string(char **buffer, size_t *space, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
Reference in New Issue
Block a user