WRAPPERS to I/O file operations

WRAPPERS to I/O file operations

Post by A.Lab » Thu, 28 Sep 1995 04:00:00



Hi,
Platform : SunOS 4.1,
compiler : gcc

I m writting wrapper functions for file operations ( open, close, ...) .
When the calls are in the same file where  the wrapper functions are : it works well.
But when I put them in a different file, it does no longer work !!!!

In the following example, In the case
1) where the function "calls()" is in FILE1.c : it works;
2) where the function "calls()" is in FILE2.c : it doesn t work .

EXPLE :

/******************************************************************
                    FILE1.c
******************************************************************/

int open( const char *path, int flags, ...)
{

        va_list ap;
        int             creat_mode = 0;
        int             fd;
        int             status;

        printf("----- IN OPEN -----------\n");

        if( flags & O_CREAT )
        {
                va_start( ap, flags );
                creat_mode = va_arg( ap, int );
        }

        fd = syscall( SYS_open, path, flags, creat_mode );

        return(fd);

Quote:}

/*********************************/

int
close( int fd )
{
        printf("----- IN CLOSE -----------\n");

        return syscall( SYS_close, fd );

Quote:}

/******************************************************************
                      The Calls :
******************************************************************/

int
calls()
{

  int fd1, fd2;

  FILE *fp1, *fp2;

  int z_res;
  char buf[100];

  fd1 = open("zfil1" , 0, 777);
  printf("fd1 = %d nbr_open = %d \n" , fd1, nbr_open);

  fd2 = open("zfil2" , 0, 777);
  printf("fd2 = %d nbr_open = %d \n" , fd2, nbr_open);

  strcpy(buf, "" );
  z_res = read(fd1, buf, 99);
  printf("XXXX buf = %s XXXX \n" , buf);

  close(fd1);
  printf("nbr_open = %d \n" , nbr_open);

  close(fd2);
  printf("nbr_open = %d \n" , nbr_open);

Quote:}

/******************************************************************
                     FILE2.c
******************************************************************/

main()
{

  calls();

Quote:}

Thank you very much.

  ---------------------------------------------------------------------------
  A. LABED

  Addresse : E.H.E.I. , UFR Mathematique et Informatique
             Universite Rene Descartes
             45, Rue des Saints Peres
             Paris.  
  ---------------------------------------------------------------------------

 
 
 

WRAPPERS to I/O file operations

Post by Jeff Dicks » Sat, 30 Sep 1995 04:00:00




>>Hi,
>>Platform : SunOS 4.1,
>>compiler : gcc

>>I m writting wrapper functions for file operations ( open, close, ...) .
>>When the calls are in the same file where  the wrapper functions are : it works well.
>>But when I put them in a different file, it does no longer work !!!!

>>In the following example, In the case
>>1) where the function "calls()" is in FILE1.c : it works;
>>2) where the function "calls()" is in FILE2.c : it doesn t work .

>>EXPLE :

>>/******************************************************************
>>                    FILE1.c
>>******************************************************************/

>>int open( const char *path, int flags, ...)
>[ snipp ]
>>int
>>close( int fd )
>open() and close() are system calls, see man open(2) and man close(2).
>When you compile the file using your versions of open and close the
>compiler finds the addresses of the corresponding calls and fills that in.
>When you compile the file and your versions of open and close are on a
>separate file, the compiler marks the calls as unresolved to be filled in
>by ld which in turn uses the system calls.
>I do not know wether it is possible to force ld to use your versions,
>but I'm cure someone will fill that in...

I believe that library symbols can be over ridden if the names of the replace-
ments are preceeded with an underscore (e.g. _open).

Jeff S.*son