1 /* This file is part of the Project Athena Zephyr Notification System.
2 * It is one of the source files comprising zwgc, the Zephyr WindowGram
5 * Created by: Marc Horowitz <marc@athena.mit.edu>
9 * Copyright (c) 1989 by the Massachusetts Institute of Technology.
10 * For copying and distribution information, see the file
16 #if (!defined(lint) && !defined(SABER))
17 static const char rcsid_file_c[] = "$Id$";
20 #include <zephyr/mit-copyright.h>
23 #include "new_memory.h"
24 #include "new_string.h"
28 * char *get_home_directory()
30 * Effects: Attempts to locate the user's (by user, the owner of this
31 * process is meant) home directory & return its pathname.
32 * Returns NULL if unable to do so. Does so by first checking
33 * the environment variable HOME. If it is unset, falls back
34 * on the user's password entry.
35 * Note: The returned pointer may point to a static buffer & hence
36 * go away on further calls to getenv, get_home_directory,
37 * getpwuid, or related calls. The caller should copy it
41 char *get_home_directory(void)
44 struct passwd *passwd_entry;
46 result = getenv("HOME");
50 if (!(passwd_entry = getpwuid(getuid())))
53 return(passwd_entry->pw_dir);
60 FILE *locate_file(char *override_filename,
61 char *home_dir_filename,
62 char *fallback_filename)
69 if (override_filename) {
70 if (string_Eq(override_filename, "-"))
73 result = fopen(override_filename, "r");
74 if (!(result = fopen(override_filename, "r"))) {
76 fprintf(stderr, "zwgc: error while opening %s for reading: ",
83 if (home_dir_filename) {
84 filename = get_home_directory();
86 filename = string_Concat(filename, "/");
87 filename = string_Concat2(filename, home_dir_filename);
88 result = fopen(filename, "r");
93 if (errno != ENOENT) {
95 fprintf(stderr, "zwgc: error while opening %s for reading: ",
103 ERROR("unable to find your home directory.\n");
106 if (fallback_filename) {
107 if (!(result = fopen(fallback_filename, "r"))) {
109 fprintf(stderr, "zwgc: error while opening %s for reading: ",