Hi!
I have run into some problems installing Hiawatha on a HP-UX computer. The problem is that the functions
setenv and
unsetenv are not defined on some UNIX systems (older HP-UX and Solaris for example). I solved the problem by creating my own
setenv and
unsetenv, using the existing
putenv and
getenv. Here is the code, maybe someone else needs it, or maybe it will be included in the next version:
int alt_setenv(const char *name, const char *value, int overwrite) {
char *buf;
int lenn, lenv;
if(getenv(name) == NULL || overwrite) {
lenn = strlen(name);
lenv = strlen(value);
buf = (char *) malloc((lenn + lenv + 1) * sizeof(char));
if(buf == NULL) {
return -1;
}
buf[0] = \'\\0\';
strncat(buf, name, lenn);
buf[lenn] = \'=\';
buf[lenn + 1] = \'\\0\';
strncat(buf, value, lenv);
return putenv(buf);
}
return 0;
}
int alt_setenv(const char *name, const char *value, int overwrite) {
char *buf;
int lenn, lenv;
if(getenv(name) == NULL || overwrite) {
lenn = strlen(name);
lenv = strlen(value);
buf = (char *) malloc((lenn + lenv + 1) * sizeof(char));
if(buf == NULL) {
return -1;
}
buf[0] = \'\\0\';
strncat(buf, name, lenn);
buf[lenn] = \'=\';
buf[lenn + 1] = \'\\0\';
strncat(buf, value, lenv);
return putenv(buf);
}
return 0;
}