summaryrefslogtreecommitdiff
path: root/chat/icb/patches/patch-ar
blob: ead46d4fc85d9711f0acd4860302b05a48199910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$NetBSD: patch-ar,v 1.2 2008/12/17 02:19:59 christos Exp $

--- icb/serverlist.c.orig	1995-02-24 16:20:29.000000000 -0500
+++ icb/serverlist.c	2008-12-16 20:18:00.000000000 -0500
@@ -1,4 +1,6 @@
 #include <stdio.h>
+#include <stdlib.h>
+#include <pwd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include "icb.h"
@@ -14,15 +16,14 @@
 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 @@
 #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");