strcompat.c 951 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Compatibility functions for strsep and strtoq missing on Solaris */
  2. #include <sys/types.h>
  3. #include <stdio.h>
  4. #include "asterisk/compat.h"
  5. char* strsep(char** str, const char* delims)
  6. {
  7. char* token;
  8. if (*str==NULL) {
  9. /* No more tokens */
  10. return NULL;
  11. }
  12. token=*str;
  13. while (**str!='\0') {
  14. if (strchr(delims,**str)!=NULL) {
  15. **str='\0';
  16. (*str)++;
  17. return token;
  18. }
  19. (*str)++;
  20. }
  21. /* There is no other token */
  22. *str=NULL;
  23. return token;
  24. }
  25. int setenv(const char *name, const char *value, int overwrite)
  26. {
  27. unsigned char *buf;
  28. int buflen, ret;
  29. buflen = strlen(name) + strlen(value) + 2;
  30. if ((buf = malloc(buflen)) == NULL)
  31. return -1;
  32. if (!overwrite && getenv(name))
  33. return 0;
  34. snprintf(buf, buflen, "%s=%s", name, value);
  35. ret = putenv(buf);
  36. free(buf);
  37. return ret;
  38. }
  39. int unsetenv(const char *name)
  40. {
  41. setenv(name,"",0);
  42. }