Jabber WindowGram Client (JWGC)

Introduction Screenshots Installation Downloads
Documentation Browse Source Resources Project Site

Stable Version
-none-

Latest Version
beta5



Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

file.c

Go to the documentation of this file.
00001 /*
00002  *      Copyright (c) 1989 by the Massachusetts Institute of Technology.
00003  *      For copying and distribution information, see the file
00004  *      "mit-copyright.h".
00005  *
00006  *      Modified for jwgc by Daniel Henninger.
00007  */
00008 
00009 #include "mit-copyright.h"
00010 
00011 #include <pwd.h>
00012 #include "main.h"
00013 #include "new_string.h"
00014 #include "error.h"
00015 
00016 /*
00017  *    char *get_home_directory()
00018  *
00019  *        Effects: Attempts to locate the user's (by user, the owner of this
00020  *                 process is meant) home directory & return its pathname.
00021  *                 Returns NULL if unable to do so.  Does so by first checking
00022  *                 the environment variable HOME.  If it is unset, falls back
00023  *                 on the user's password entry.
00024  *         Note: The returned pointer may point to a static buffer & hence
00025  *               go away on further calls to getenv, get_home_directory,
00026  *               getpwuid, or related calls.  The caller should copy it
00027  *               if necessary.
00028  */
00029 
00030 char *
00031 get_home_directory()
00032 {
00033         char *result;
00034         char *getenv();
00035         struct passwd *passwd_entry;
00036 
00037         if ((result = getenv("HOME")))
00038                 return (result);
00039 
00040         if (!(passwd_entry = getpwuid(getuid())))
00041                 return (NULL);
00042 
00043         return (passwd_entry->pw_dir);
00044 }
00045 
00046 /*
00047  *
00048  */
00049 
00050 FILE *
00051 locate_file(override_filename, home_dir_filename, fallback_filename)
00052         char *override_filename;
00053         char *home_dir_filename;
00054         char *fallback_filename;
00055 {
00056         char *filename;
00057         FILE *result;
00058 
00059         errno = 0;
00060 
00061         if (override_filename) {
00062                 if (string_Eq(override_filename, "-"))
00063                         return (stdin);
00064 
00065                 result = fopen(override_filename, "r");
00066                 if (!(result = fopen(override_filename, "r"))) {
00067                         /* <<<>>> */
00068                         fprintf(stderr, "jwgc: error while opening %s for reading: ",
00069                                 override_filename);
00070                         perror("");
00071                 }
00072                 return (result);
00073         }
00074 
00075         if (home_dir_filename) {
00076                 if ((filename = get_home_directory())) {
00077                         filename = string_Concat(filename, "/");
00078                         filename = string_Concat2(filename, home_dir_filename);
00079                         result = fopen(filename, "r");
00080                         if (result) {
00081                                 free(filename);
00082                                 return (result);
00083                         }
00084                         if (errno != ENOENT) {
00085                                 fprintf(stderr, "jwgc: error while opening %s for reading: ",
00086                                         filename);
00087                                 perror("");
00088                                 free(filename);
00089                                 return (result);
00090                         }
00091                         free(filename);
00092                 }
00093                 else
00094                         ERROR("unable to find your home directory.\n");
00095         }
00096 
00097         if (fallback_filename) {
00098                 if (!(result = fopen(fallback_filename, "r"))) {
00099                         /* <<<>>> */
00100                         fprintf(stderr, "jwgc: error while opening %s for reading: ",
00101                                 fallback_filename);
00102                         perror("");
00103                 }
00104                 return (result);
00105         }
00106 
00107         return (NULL);
00108 }


Last updated at Tue Dec 18 21:07:42 PST 2007. This site and project hosted by...SourceForge.net Logo
Source Perspective by Fisheye