Re: Getting the file name from a FILE *



In article <g3vfoj086c@xxxxxxxxxxxxxxxxx>,
Chris Torek <nospam@xxxxxxxxx> wrote:

In article <Y3y8k.15793$E41.3023@xxxxxxxxxxxxxxxxxxxxxxxxx>
Bartc <bc@xxxxxxxxxx> wrote:

Use of fname() allows retrieval of a filename from any file opened with
fopen() from many millions of lines of existing code with /no changes/ to
those lines (which in some cases may not be accessible anyway).

The objections are:

There is an issue that I haven't observed being addressed in this
thread, which is that in general, what you want to present in error
messages (and the like) is not necessarily the file name that the file
was openned with, but rather some kind of user- meaningful identifying
string -- which might perhaps include the filename openned with, might
perhaps include the directory, might perhaps include a phrase such as
"configuration file", might perhaps include the phrase "temporary swap
file", might perhaps say "standard input" and so on.

If the idea is to have something to present for error/warning messages,
then an "identifying string" is more useful than just the file
name that might happened be passed to fopen -- e.g., the file name passed
might be relative to the current directory and so the name by itself
might not be very useful. [*]

Of course, passing in an identifying string for fopen to squirrel
away would require a change to the API to fopen(), which would
Not Be Cool considering the amount of code that presently uses fopen.
In theory, the API for fopen() could be extended by adding a varargs
parameter, but as there can be considerable differences in parameter
passing between non-varargs routines and varargs routines, taking
this approach would likely require a recompile / relink of lots of
existing code even though the code did not use the new facilities;
I expect that that recompile / relink step would not be considered
an acceptable cost for this functionality. There are work-arounds
to this issue, such as having fopen() record the filename
as the default identifying tag (as Jacob proposed), but also adding a
routine which could change the tag to something else after the
fopen().


([*] Note: in Unix and [I think] MS Windows with NTFS filesystems, there
can be files that you can open relatively but which you could not open
if you used the absolute path, because in Unix at least, you are given
authorization to access your home directory even if your user does not
have permission to traverse the directory tree to reach your home
directory. In Windows with NTFS Alternative Data Streams (ADS),
I believe that the effect of reading a file through one path could be
different than the effect of reading it through a different path,
since a component on the pathname could [if I understand
properly] have an ADS that could be (e.g.,) a decryptor or decompressor.)

--
"To all, to each! a fair good-night,
And pleasing dreams, and slumbers light" -- Sir Walter Scott
.



Relevant Pages

  • Re: Structure of large link libraries in f95
    ... Can't you just recompile the routines you're "monkeying with" and replace them in your library? ... corresponding interface block in your "interface block module". ... I use the f77 blas/lapack libraries in my f95 code and when I use various routines from them, I declare them EXTERNAL and link in the required library -- which was compiled once and pretty much forgotten about ... When Lahey later dropped support for its fine f77 compiler, I figured I'd better prepare a bridge to f90. ...
    (comp.lang.fortran)
  • Re: Trying to execute something stored in variable
    ... Public Function ExecuteMethods(ByVal prmMethodName As String, ... Dim objMethodInfo As MethodInfo ... Public Sub SubRoutine1() ... Please note that I cannot take full credit for these routines. ...
    (microsoft.public.dotnet.languages.vb)
  • Writing an Adventure game with HLA
    ... For an "adventure" style game, ... These two routines lexically scan13 a string and break it up into ... The create procedure is used to initialize a lookup table. ...
    (alt.lang.asm)
  • Re: Trying to execute something stored in variable
    ... Public Function ExecuteMethods(ByVal prmMethodName As String, ... Dim objMethodInfo As MethodInfo ... Public Sub SubRoutine1() ... Please note that I cannot take full credit for these routines. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Safer and Better C
    ... > which causes memory limit to be inadequate for the desired string ... Unfortunately the world is full of macho programmers who seem to ... providing routines that can be controlled is not such an avoidance. ... fiber to be a Red Sox fan" ...
    (comp.lang.c)