ITEM: E8569L

Need file stats from Fortran program


Question:

I am needing to get file characteristics from within a Fortran program.
In particular, I want to access a filename which is a logical link to
another file and be able to determine what the original name is.  I think
I need something like "stat", "lstat" , or "readlink" C functions but for
Fortran. Any advice or direction would be appreciated.

Response:

I faxed to the customer an example c and fortran program that
illustrate one way of returning the absolute path of a file to which
an input file is symbolically linked.  The faxed information follows.

The sample program contained in this document shows you one way to
return the full pathname of a file that is symbolically linked to
another file.  The sample C language routine does not prevent failure
in the event of improper input, etc, and is intended to demonstrate a
method.  It is supplied as-is.

FILE makefile:  
nuts: ctest.o ftest.o
         xlf -o $@ ftest.o ctest.o

ftest.o: ftest.f
         xlf -c ftest.f

ctest.o: ctest.c
         cc -c ctest.c

FILE ctest.c:  
\#include \ 
\#include \ 
\#define ERR -1

/*
 * How to use the readlink subroutine
 *
 * prototype:
 * int readlink( char *path, char *buffer, int buffersize)
 */

int linkread( char *input, char *output, int *buffersize) {
  int retval = 0;
  char *p = NULL;
  char *q = strdup( input);

  if(( p = strstr( input, " ")) == NULL)
    return( ERR);

  strcpy( p, ' ');

  if((retval = readlink( input, output, *buffersize)) \< 0)
    perror( " linkread error ");
  fprintf( stdout, " LINKREAD:   Call returned ==%d\==0, retval);
  fprintf( stdout, "          Input path was   ==>%s\<==0, q);
  fprintf( stdout, " Modified input path was   ==%s\==0, input);
  fprintf( stdout, "          Path resolved to ==>%s\<==0, output);

  return( retval); }

FILE ftest.f         
        program ftest

        external linkread

        character*80 output, input

        integer retval, size

        input = '/unix'         size = 80

        retval = linkread( input, output, size)

        write( 6, 100) input, output, retval

100     format( ' FORTRAN:',/,
     $          '          Input path was   ==',  a,'\==',/,
     $          '         Output path was   ==',  a,'\==',/,
     $          '   The returned size was   ==', i4,'\==')
        end


Support Line: Need file stats from Fortran program ITEM: E8569L
Dated: November 1993 Category: N/A
This HTML file was generated 99/06/24~13:30:53
Comments or suggestions? Contact us