From guido@hal.stat.unipd.it  Thu Nov  4 09:50:55 1999
From: guido@hal.stat.unipd.it (guido@hal.stat.unipd.it)
Date: Thu, 4 Nov 1999 10:50:55 +0100 (MET)
Subject: R_OpenSiteFile: Do not use a null ptr as filename in fopen (PR#312)
Message-ID: <199911040950.KAA28506@pubhealth.ku.dk>

On Thu, Nov 04, 1999 at 10:09:05AM +0100, hoffmann@ehmgs2.et.tu-dresden.de wrote:
> 
> The reason is, that in unix/sys-common.c in R_OpenSiteFile() fopen 
> is called with a null ptr as filename (because this is the outcome 
> of getenv()).
> 
> Although most compilers seem to interpret this as "file not found",
> this is an undefined behavior concerning to all C standards I could get
> hold of.
> 
> A request in comp.lang.c gave the following response:
> ...
> Your program should crash. If you might get a NULL pointer as
> a filename, you should have a conditional statement to handle
> that case.
> ...
>

The same happens also under Windows where, for this reason, 
'R_fopen' is defined as
 
FILE *R_fopen(const char *filename, const char *mode)
{
    if (!filename)
	return NULL;
    return (fopen(filename, mode));
}

g.

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


R_OpenSiteFile: Do not use a null ptr as filename in fopen (PR#312)
guido@hal.stat.unipd.it