use LDFLAGS and LIBS properly, and allow dependencies to provide LDFLAGS if needed...
[asterisk-bristuff.git] / strcompat.c
blob59da2d24e0df9465d211aa7476912edd198a297e
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2006, Digium, Inc.
6 * See http://www.asterisk.org for more information about
7 * the Asterisk project. Please do not directly contact
8 * any of the maintainers of this project for assistance;
9 * the project provides a web site, mailing lists and IRC
10 * channels for your use.
12 * This program is free software, distributed under the terms of
13 * the GNU General Public License Version 2. See the LICENSE file
14 * at the top of the source tree.
17 /*! \file
19 * \brief Compatibility functions for strsep and strtoq missing on Solaris
22 #include "asterisk.h"
24 #include <sys/types.h>
25 #include <stdio.h>
27 #ifndef HAVE_STRSEP
28 char *strsep(char **str, const char *delims)
30 char *token;
32 if (!*str) {
33 /* No more tokens */
34 return NULL;
37 token = *str;
38 while (**str != '\0') {
39 if (strchr(delims, **str)) {
40 **str = '\0';
41 (*str)++;
42 return token;
44 (*str)++;
47 /* There is no other token */
48 *str = NULL;
50 return token;
52 #endif
54 #ifndef HAVE_SETENV
55 int setenv(const char *name, const char *value, int overwrite)
57 unsigned char *buf;
58 int buflen;
60 buflen = strlen(name) + strlen(value) + 2;
61 buf = alloca(buflen);
63 if (!overwrite && getenv(name))
64 return 0;
66 snprintf(buf, buflen, "%s=%s", name, value);
68 return putenv(buf);
70 #endif
72 #ifndef HAVE_UNSETENV
73 int unsetenv(const char *name)
75 return setenv(name, "", 0);
77 #endif