summaryrefslogtreecommitdiff
path: root/utils.c
diff options
context:
space:
mode:
authorMark Spencer <markster@digium.com>2004-08-27 04:21:09 +0000
committerMark Spencer <markster@digium.com>2004-08-27 04:21:09 +0000
commitc7541bd6725c6c8e7322b767dbc02314c43ac2b0 (patch)
tree458e26edca6d97879795fa816de476ab034bc5ae /utils.c
parentc3c13114fb098979d30fb660d286a25af3f1294c (diff)
Merge "show applications" from corydon76 (bug #2291)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3665 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'utils.c')
-rwxr-xr-xutils.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/utils.c b/utils.c
index c1a03be5f..756cdfd19 100755
--- a/utils.c
+++ b/utils.c
@@ -9,6 +9,9 @@
* the GNU General Public License
*/
+#ifdef Linux /* For strcasestr */
+#define __USE_GNU
+#endif
#include <ctype.h>
#include <string.h>
#include <unistd.h>
@@ -20,6 +23,7 @@
#include <asterisk/lock.h>
#include <asterisk/utils.h>
#include <asterisk/logger.h>
+#include <alloca.h>
static char base64[64];
static char b2a[256];
@@ -363,3 +367,46 @@ int ast_pthread_create(pthread_t *thread, pthread_attr_t *attr, void *(*start_ro
return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */
}
#endif /* ! LINUX */
+
+static char *upper(const char *orig, char *buf, int bufsize)
+{
+ int i;
+ memset(buf, 0, bufsize);
+ for (i=0; i<bufsize - 1; i++) {
+ buf[i] = toupper(orig[i]);
+ if (orig[i] == '\0') {
+ break;
+ }
+ }
+ return buf;
+}
+
+/* Case-insensitive substring matching */
+#ifndef LINUX
+char *ast_strcasestr(const char *haystack, const char *needle)
+{
+ char *u1, *u2;
+ int u1len = strlen(haystack), u2len = strlen(needle);
+
+ u1 = alloca(u1len);
+ u2 = alloca(u2len);
+ if (u1 && u2) {
+ char *offset;
+ if (u2len > u1len) {
+ /* Needle bigger than haystack */
+ return NULL;
+ }
+ offset = strstr(upper(haystack, u1, u1len), upper(needle, u2, u2len));
+ if (offset) {
+ /* Return the offset into the original string */
+ return ((char *)((unsigned int)haystack + (unsigned int)(offset - u1)));
+ } else {
+ return NULL;
+ }
+ } else {
+ ast_log(LOG_ERROR, "Out of memory\n");
+ return NULL;
+ }
+}
+#endif
+