$NetBSD: patch-ar,v 1.3 2013/01/11 13:24:32 joerg Exp $ --- icb/serverlist.c.orig 1995-02-24 21:20:29.000000000 +0000 +++ icb/serverlist.c @@ -1,4 +1,6 @@ #include +#include +#include #include #include #include "icb.h" @@ -14,15 +16,14 @@ static FILE *serverfile = NULL; FILE *openserverfile() { struct stat statbuf; - char *personalsl; - char command[256]; - char pwd[256]; + char *personalsl, *home; + char pwd[MAXPATHLEN+1]; FILE *ret; #ifdef sgi #undef SYSV #endif -#ifndef SYSV +#if !defined(SYSV) && !(defined(BSD) && BSD >= 199306) && !defined(__linux__) getwd(pwd); #else /* SYSV */ getcwd(pwd, MAXPATHLEN+1); @@ -30,11 +31,20 @@ FILE *openserverfile() #ifdef sgi #define SYSV #endif - chdir(getenv("HOME")); + if ((home = getenv("HOME")) == NULL) { + struct passwd *pw; + if ((pw = getpwuid(getuid())) == NULL) + home = "."; + home = pw->pw_dir; + } + chdir(home); if (!stat(PERSONALSL,&statbuf)) { - sprintf(command,"/bin/cat %s %s\n", PERSONALSL, SERVERLIST); + char *command = malloc(strlen("/bin/cat \n") + + strlen(PERSONALSL) + strlen(SERVERLIST) + 1); + sprintf(command, "/bin/cat %s %s\n", PERSONALSL, SERVERLIST); ret= popen(command,"r"); + free(command); } else ret= fopen(SERVERLIST,"r");