File: 10_config.c-HOME-fix.patch

package info (click to toggle)
xloadimage 4.1-27
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,880 kB
  • sloc: ansic: 36,063; makefile: 306; asm: 284; sh: 144
file content (60 lines) | stat: -rw-r--r-- 1,289 bytes parent folder | download | duplicates (2)
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
54
55
56
57
58
59
60
From: Austin Donnelly <and1000@debian.org>
Subject: Gracefully handle lack of HOME env. variable.

--- a/config.c
+++ b/config.c
@@ -15,11 +15,13 @@
 #include <sys/stat.h>
 #ifndef VMS
 #include <pwd.h>
+#include <sys/types.h>
 #endif
 #include <errno.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
+#include <stdlib.h>
 
 /* SUPPRESS 530 */
 /* SUPPRESS 560 */
@@ -433,14 +435,29 @@ void showConfiguration()
     printf("No filters\n");
 }
 
+/* Work out where this user's home directory is, or default to '/' */
+/* XXX needs a VMS guru to supply something plausable for VMS */
+static char *homedir()
+{ char *p;
+  struct passwd *pw;
+
+  p = getenv("HOME");
+  if (p) return p;
+
+  /* try for a password file lookup instead */
+  pw = getpwuid(getuid());
+  if (!pw)
+    return "/"; /* XXX maybe print message? */
+  else
+    return pw->pw_dir;
+}
+
 char *expandPath(p)
      char *p;
 { char buf1[BUFSIZ], buf2[BUFSIZ];
   int b1, b2, var;
   char *ptr;
 
-  char *getenv();
-
   buf1[0] = '\0';
   buf2[0] = '\0';
   b1 = 0;
@@ -454,7 +471,7 @@ char *expandPath(p)
 #endif
     else if(*p == '~') {
       buf1[b1] = '\0';
-      strlcat(buf1, getenv("HOME"), sizeof(buf1));
+      strlcat(buf1, homedir(), sizeof(buf1));
       b1 = strlen(buf1);
       var = 0;
     }