Hi,
I was just looking into the setenv / unsetenv stuff in APR, and found
that we assume that unsetenv doesnt have a return value on all
platforms. I have searched a bit, and found these:
http://linux.die.net/man/3/setenv
http://www.manpagez.com/man/3/unsetenv/
from that it seems that there are newer versions of unsetenv() out which
return an int and set errno. I've tested this on Linux 2.6.27.29, and I
dont get an error back when I try to unsetenv a non-existent var ...
now I would like to get some info about how MacOSX and *BSD platforms
behave - see attached sample for a quick test. Form the docu at least
MacOSX should return EINVAL for a non-existent var ...

thanks, Gün.

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(void) {
  char *envvar = "FOOBAR_EMPTY";
  char *value = "";
  int rv;

  rv = setenv(envvar, value, 1);
  printf("setenv(%s) rv = %d, errno = %d\n", envvar, rv, errno);

  rv = unsetenv(envvar);
  printf("unsetenv(%s) rv = %d, errno = %d\n", envvar, rv, errno);

  envvar = "FOOBAR_NONEXISTING";
  rv = unsetenv(envvar);
  printf("unsetenv(%s) rv = %d, errno = %d\n", envvar, rv, errno);

  return 0;
}

Reply via email to