
#include <stdlib.h>

#if defined(ultrix) || defined(hpux) || defined(sun) || defined(_AIX) || defined(sgi)
#undef  USE_PUTENV
#define USE_PUTENV 1
#endif

void add_path_to_search_path(path)
char *path;
{
    char *old, *new;

    old = getenv("XFILESEARCHPATH");
    if (old) {
#ifdef USE_PUTENV
	/* +1 for =, +2 for :, +3 for null */
	new = malloc(strlen("XFILESEARCHPATH") + strlen(old) +
		     strlen(path) + 3);
	strcpy(new, "XFILESEARCHPATH");
	strcat(new, "=");
	strcat(new, old);
	strcat(new, ":");
	strcat(new, path);
	putenv(new);
#else
	/* +1 for colon, +2 for null */
	new = malloc(strlen(old) + strlen(path) + 2);
	strcpy(new, old);
	strcat(new, ":");
	strcat(new, path);
	setenv("XFILESEARCHPATH", new, 1);
#endif
    } else {
#ifdef USE_PUTENV
	new = malloc(strlen("XFILESEARCHPATH") + strlen(path) + 2);
	strcpy(new, "XFILESEARCHPATH");
	strcat(new, "=");
	strcat(new, path);
	putenv(new);
#else
	setenv("XFILESEARCHPATH", path, 1);
#endif
    }
}
