Mon Mar 20 08:20:14 2006

Asterisk developer's documentation


Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

strcompat.c

Go to the documentation of this file.
00001 /* Compatibility functions for strsep and strtoq missing on Solaris */
00002 
00003 #include <sys/types.h>
00004 #include <stdio.h>
00005 
00006 #include "asterisk/compat.h"
00007 
00008 char* strsep(char** str, const char* delims)
00009 {
00010     char* token;
00011 
00012     if (*str==NULL) {
00013         /* No more tokens */
00014         return NULL;
00015     }
00016 
00017     token=*str;
00018     while (**str!='\0') {
00019         if (strchr(delims,**str)!=NULL) {
00020             **str='\0';
00021             (*str)++;
00022             return token;
00023         }
00024         (*str)++;
00025     }
00026     /* There is no other token */
00027     *str=NULL;
00028     return token;
00029 }
00030 
00031 
00032 
00033 int setenv(const char *name, const char *value, int overwrite)
00034 {
00035    unsigned char *buf;
00036    int buflen, ret;
00037 
00038    buflen = strlen(name) + strlen(value) + 2;
00039    if ((buf = malloc(buflen)) == NULL)
00040       return -1;
00041 
00042    if (!overwrite && getenv(name))
00043       return 0;
00044 
00045    snprintf(buf, buflen, "%s=%s", name, value);
00046    ret = putenv(buf);
00047 
00048    free(buf);
00049 
00050    return ret;
00051 }
00052 
00053 int unsetenv(const char *name)
00054 {
00055   setenv(name,"",0);
00056 }
00057 

Generated on Mon Mar 20 08:20:14 2006 for Asterisk - the Open Source PBX by  doxygen 1.3.9.1