| 
									
										
										
										
											2004-12-14 23:36:30 +00:00
										 |  |  | /* Compatibility functions for strsep and strtoq missing on Solaris */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-22 13:11:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-08 02:19:02 +00:00
										 |  |  | #include "asterisk/compat.h"
 | 
					
						
							| 
									
										
										
										
											2004-12-14 23:36:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | char* strsep(char** str, const char* delims) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     char* token; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (*str==NULL) { | 
					
						
							|  |  |  |         /* No more tokens */ | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     token=*str; | 
					
						
							|  |  |  |     while (**str!='\0') { | 
					
						
							|  |  |  |         if (strchr(delims,**str)!=NULL) { | 
					
						
							|  |  |  |             **str='\0'; | 
					
						
							|  |  |  |             (*str)++; | 
					
						
							|  |  |  |             return token; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         (*str)++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     /* There is no other token */ | 
					
						
							|  |  |  |     *str=NULL; | 
					
						
							|  |  |  |     return token; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int setenv(const char *name, const char *value, int overwrite) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned char *buf; | 
					
						
							| 
									
										
										
										
											2006-03-28 20:22:05 +00:00
										 |  |  | 	int buflen; | 
					
						
							| 
									
										
										
										
											2004-12-14 23:36:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	buflen = strlen(name) + strlen(value) + 2; | 
					
						
							| 
									
										
										
										
											2006-03-28 20:22:05 +00:00
										 |  |  | 	if (!(buf = alloca(buflen))) | 
					
						
							| 
									
										
										
										
											2004-12-14 23:36:30 +00:00
										 |  |  |  		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!overwrite && getenv(name)) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	snprintf(buf, buflen, "%s=%s", name, value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-03-28 20:22:05 +00:00
										 |  |  | 	return putenv(buf); | 
					
						
							| 
									
										
										
										
											2004-12-14 23:36:30 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-03-17 23:12:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | int unsetenv(const char *name) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-03-29 04:15:11 +00:00
										 |  |  | 	return setenv(name, "", 0); | 
					
						
							| 
									
										
										
										
											2005-03-17 23:12:15 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 |