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 File Reference

#include "mit-copyright.h"
#include <pwd.h>
#include "main.h"
#include "new_string.h"
#include "error.h"

Go to the source code of this file.

Functions

char * get_home_directory ()
FILE * locate_file (char *override_filename, char *home_dir_filename, char *fallback_filename)


Function Documentation

char* get_home_directory  ) 
 

Definition at line 31 of file file.c.

References getenv().

Referenced by locate_file().

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 }

FILE* locate_file char *  override_filename,
char *  home_dir_filename,
char *  fallback_filename
 

Definition at line 51 of file file.c.

References errno, ERROR, get_home_directory(), string_Concat, string_Concat2, and string_Eq.

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