2006-05-07 15:19:52 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 - 2006, Digium, Inc.
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*! \file
|
|
|
|
*
|
|
|
|
* \brief Compatibility functions for strsep and strtoq missing on Solaris
|
|
|
|
*/
|
2004-12-14 23:36:30 +00:00
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
2004-12-14 23:36:30 +00:00
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
#ifndef HAVE_STRSEP
|
2006-05-07 15:19:52 +00:00
|
|
|
char *strsep(char **str, const char *delims)
|
2004-12-14 23:36:30 +00:00
|
|
|
{
|
2006-05-07 15:19:52 +00:00
|
|
|
char *token;
|
2004-12-14 23:36:30 +00:00
|
|
|
|
2006-05-07 15:19:52 +00:00
|
|
|
if (!*str) {
|
2004-12-14 23:36:30 +00:00
|
|
|
/* No more tokens */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-05-07 15:19:52 +00:00
|
|
|
token = *str;
|
|
|
|
while (**str != '\0') {
|
|
|
|
if (strchr(delims, **str)) {
|
|
|
|
**str = '\0';
|
2004-12-14 23:36:30 +00:00
|
|
|
(*str)++;
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
(*str)++;
|
|
|
|
}
|
2006-05-07 15:19:52 +00:00
|
|
|
|
2004-12-14 23:36:30 +00:00
|
|
|
/* There is no other token */
|
2006-05-07 15:19:52 +00:00
|
|
|
*str = NULL;
|
|
|
|
|
2004-12-14 23:36:30 +00:00
|
|
|
return token;
|
|
|
|
}
|
2006-04-24 17:11:45 +00:00
|
|
|
#endif
|
2004-12-14 23:36:30 +00:00
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
#ifndef HAVE_SETENV
|
2004-12-14 23:36:30 +00:00
|
|
|
int setenv(const char *name, const char *value, int overwrite)
|
|
|
|
{
|
|
|
|
unsigned char *buf;
|
2006-03-19 21:40:42 +00:00
|
|
|
int buflen;
|
2004-12-14 23:36:30 +00:00
|
|
|
|
|
|
|
buflen = strlen(name) + strlen(value) + 2;
|
2006-05-10 13:22:15 +00:00
|
|
|
buf = alloca(buflen);
|
2004-12-14 23:36:30 +00:00
|
|
|
|
|
|
|
if (!overwrite && getenv(name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
snprintf(buf, buflen, "%s=%s", name, value);
|
|
|
|
|
2006-03-19 21:40:42 +00:00
|
|
|
return putenv(buf);
|
2004-12-14 23:36:30 +00:00
|
|
|
}
|
2006-04-24 17:11:45 +00:00
|
|
|
#endif
|
2005-03-17 23:12:15 +00:00
|
|
|
|
2006-04-24 17:11:45 +00:00
|
|
|
#ifndef HAVE_UNSETENV
|
2006-03-29 04:14:12 +00:00
|
|
|
int unsetenv(const char *name)
|
2005-03-17 23:12:15 +00:00
|
|
|
{
|
2006-03-29 04:14:12 +00:00
|
|
|
return setenv(name, "", 0);
|
2005-03-17 23:12:15 +00:00
|
|
|
}
|
2006-04-24 17:11:45 +00:00
|
|
|
#endif
|