OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [libiberty/] [fdmatch.c] - Diff between revs 579 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 579 Rev 1765
/* Compare two open file descriptors to see if they refer to the same file.
/* Compare two open file descriptors to see if they refer to the same file.
   Copyright (C) 1991 Free Software Foundation, Inc.
   Copyright (C) 1991 Free Software Foundation, Inc.
 
 
This file is part of the libiberty library.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
version 2 of the License, or (at your option) any later version.
 
 
Libiberty is distributed in the hope that it will be useful,
Libiberty is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.
Library General Public License for more details.
 
 
You should have received a copy of the GNU Library General Public
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB.  If
License along with libiberty; see the file COPYING.LIB.  If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */
Boston, MA 02111-1307, USA.  */
 
 
 
 
/*
/*
 
 
NAME
NAME
 
 
        fdmatch -- see if two file descriptors refer to same file
        fdmatch -- see if two file descriptors refer to same file
 
 
SYNOPSIS
SYNOPSIS
 
 
        int fdmatch (int fd1, int fd2)
        int fdmatch (int fd1, int fd2)
 
 
DESCRIPTION
DESCRIPTION
 
 
        Check to see if two open file descriptors refer to the same file.
        Check to see if two open file descriptors refer to the same file.
        This is useful, for example, when we have an open file descriptor
        This is useful, for example, when we have an open file descriptor
        for an unnamed file, and the name of a file that we believe to
        for an unnamed file, and the name of a file that we believe to
        correspond to that fd.  This can happen when we are exec'd with
        correspond to that fd.  This can happen when we are exec'd with
        an already open file (stdout for example) or from the SVR4 /proc
        an already open file (stdout for example) or from the SVR4 /proc
        calls that return open file descriptors for mapped address spaces.
        calls that return open file descriptors for mapped address spaces.
        All we have to do is open the file by name and check the two file
        All we have to do is open the file by name and check the two file
        descriptors for a match, which is done by comparing major&minor
        descriptors for a match, which is done by comparing major&minor
        device numbers and inode numbers.
        device numbers and inode numbers.
 
 
BUGS
BUGS
 
 
        (FIXME: does this work for networks?)
        (FIXME: does this work for networks?)
        It works for NFS, which assigns a device number to each mount.
        It works for NFS, which assigns a device number to each mount.
 
 
*/
*/
 
 
#include "ansidecl.h"
#include "ansidecl.h"
#include "libiberty.h"
#include "libiberty.h"
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
 
 
int fdmatch (fd1, fd2)
int fdmatch (fd1, fd2)
        int fd1;
        int fd1;
        int fd2;
        int fd2;
{
{
  struct stat sbuf1;
  struct stat sbuf1;
  struct stat sbuf2;
  struct stat sbuf2;
 
 
  if ((fstat (fd1, &sbuf1) == 0) &&
  if ((fstat (fd1, &sbuf1) == 0) &&
      (fstat (fd2, &sbuf2) == 0) &&
      (fstat (fd2, &sbuf2) == 0) &&
      (sbuf1.st_dev == sbuf2.st_dev) &&
      (sbuf1.st_dev == sbuf2.st_dev) &&
      (sbuf1.st_ino == sbuf2.st_ino))
      (sbuf1.st_ino == sbuf2.st_ino))
    {
    {
      return (1);
      return (1);
    }
    }
  else
  else
    {
    {
      return (0);
      return (0);
    }
    }
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.