Sat Mar 24 23:26:06 2007

Asterisk developer's documentation


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;
00037 
00038    buflen = strlen(name) + strlen(value) + 2;
00039    if (!(buf = alloca(buflen)))
00040       return -1;
00041 
00042    if (!overwrite && getenv(name))
00043       return 0;
00044 
00045    snprintf(buf, buflen, "%s=%s", name, value);
00046 
00047    return putenv(buf);
00048 }
00049 
00050 int unsetenv(const char *name)
00051 {
00052    return setenv(name, "", 0);
00053 }
00054 

Generated on Sat Mar 24 23:26:06 2007 for Asterisk - the Open Source PBX by  doxygen 1.4.6