Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
fstat.c
Go to the documentation of this file.
00001 /*
00002 
00003   Copyright (C) 2000, 2001, Silicon Graphics, Inc.  All Rights Reserved.
00004 
00005   This program is free software; you can redistribute it and/or modify it
00006   under the terms of version 2.1 of the GNU Lesser General Public License 
00007   as published by the Free Software Foundation.
00008 
00009   This program is distributed in the hope that it would be useful, but
00010   WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
00012 
00013   Further, this software is distributed without any warranty that it is
00014   free of the rightful claim of any third person regarding infringement 
00015   or the like.  Any license provided herein, whether implied or 
00016   otherwise, applies only to this software file.  Patent licenses, if
00017   any, provided herein do not apply to combinations of this program with 
00018   other software, or any other product whatsoever.  
00019 
00020   You should have received a copy of the GNU Lesser General Public 
00021   License along with this program; if not, write the Free Software 
00022   Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, 
00023   USA.
00024 
00025   Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
00026   Mountain View, CA 94043, or:
00027 
00028   http://www.sgi.com
00029 
00030   For further information regarding this notice, see:
00031 
00032   http://oss.sgi.com/projects/GenInfo/NoticeExplan
00033 
00034 */
00035 
00036 
00037 
00038 #pragma ident "@(#) libf/fio/fstat.c    92.2    08/02/99 10:38:18"
00039  
00040 /*
00041  * get file status
00042  *
00043  * calling sequence:
00044  *
00045  *      integer fstat, statb(12), iunit
00046  *      call fstat (iunit, statb)
00047  *
00048  * where:
00049  *
00050  *      'statb' will receive the stat structure for file 'iunit'.
00051  *      actually it will contain most of the same information as the
00052  *      stat structure, there are some missing fields.
00053  *
00054  * __fstat_f90 will be called when there is no compatibility module
00055  * __fstat64_f90 will be called when there is no compatibility module
00056  * fstatf90_ will be called when there is a compatibility module
00057  * fstatf90_8_ will be called when there is a compatibility module
00058  */
00059 
00060 #include <stdio.h>
00061 #include <foreign.h>
00062 #include <errno.h>
00063 #include <liberrno.h>
00064 #include <sys/types.h>
00065 #include <sys/stat.h>
00066 #include "fio.h"
00067 
00068 extern int __fstat_f90(int *u, int *stbuf);
00069 extern _f_int fstatf90_(_f_int *u, _f_int *stbuf);
00070 extern int __fstat64_f90(int *u, _f_int8 *stbuf);
00071 extern _f_int fstatf90_4_4_8_(_f_int *u, _f_int8 *stbuf);
00072 extern _f_int8 fstatf90_8_(_f_int8 *u, _f_int8 *stbuf);
00073 
00074 int 
00075 __fstat_f90(int *u, int *stbuf)
00076 {
00077         return fstatf90_(u,stbuf);
00078 }
00079 
00080 _f_int 
00081 fstatf90_(_f_int *u, _f_int *stbuf)
00082 {
00083         int             n, retval;
00084         unum_t          unum;
00085         unit            *cup;
00086         struct stat     buf;
00087         struct fiostate cfs;
00088 
00089         unum    = *u;
00090         STMT_BEGIN(unum, 0, T_INQU, NULL, &cfs, cup);
00091 
00092         if (cup == NULL && !GOOD_UNUM(unum))
00093                 _ferr(&cfs, FEIVUNIT, unum);    /* invalid unit number */
00094 
00095         if (cup == NULL)
00096                 retval  = -1;           /* unit is not open */
00097         else if (cup->usysfd == -1)
00098                 retval  = -1;           /* file is not disk-resident */
00099         else {
00100                 n       = fstat(cup->usysfd, &buf);
00101                 if (n < 0)
00102                         _ferr(&cfs, errno);
00103                 *stbuf++ = buf.st_dev;
00104                 *stbuf++ = buf.st_ino;
00105                 *stbuf++ = buf.st_mode;
00106                 *stbuf++ = buf.st_nlink;
00107                 *stbuf++ = buf.st_uid;
00108                 *stbuf++ = buf.st_gid;
00109                 *stbuf++ = buf.st_rdev;
00110                 *stbuf++ = buf.st_size;         /* may be inaccurate */
00111                 *stbuf++ = buf.st_atime;        /* ??? - this compiles??? */
00112                 *stbuf++ = buf.st_mtime;        /* ??? */
00113                 *stbuf++ = buf.st_ctime;        /* ??? */
00114                 *stbuf++ = buf.st_blksize;      /* ??? */
00115                 retval  = 0;
00116         }
00117 
00118         STMT_END(cup, T_INQU, NULL, &cfs);      /* unlock the unit */
00119         return(retval);
00120 }
00121 
00122 int 
00123 __fstat64_f90(int *u, _f_int8 *stbuf)
00124 {
00125         return fstatf90_4_4_8_(u,stbuf);
00126 }
00127 
00128 _f_int 
00129 fstatf90_4_4_8_(_f_int *u, _f_int8 *stbuf)
00130 {
00131         int             n, retval;
00132         unum_t          unum;
00133         unit            *cup;
00134 #if     defined(_LITTLE_ENDIAN) && !defined(__sv2)
00135         struct stat     buf;
00136 #else
00137         struct stat64   buf;
00138 #endif
00139         struct fiostate cfs;
00140 
00141         unum = *u;
00142         STMT_BEGIN(unum, 0, T_INQU, NULL, &cfs, cup);
00143 
00144         if (cup == NULL && !GOOD_UNUM(unum))
00145                 _ferr(&cfs, FEIVUNIT, unum);    /* invalid unit number */
00146 
00147         if (cup == NULL)
00148                 retval  = -1;           /* unit is not open */
00149         else if (cup->usysfd == -1)
00150                 retval  = -1;           /* file is not disk-resident */
00151         else {
00152                 n       = fstat64(cup->usysfd, &buf);
00153                 if (n < 0)
00154                         _ferr(&cfs, errno);
00155                 *stbuf++ = buf.st_dev;
00156                 *stbuf++ = buf.st_ino;
00157                 *stbuf++ = buf.st_mode;
00158                 *stbuf++ = buf.st_nlink;
00159                 *stbuf++ = buf.st_uid;
00160                 *stbuf++ = buf.st_gid;
00161                 *stbuf++ = buf.st_rdev;
00162                 *stbuf++ = buf.st_size;         /* may be inaccurate */
00163                 *stbuf++ = buf.st_atime;        /* ??? - this compiles??? */
00164                 *stbuf++ = buf.st_mtime;        /* ??? */
00165                 *stbuf++ = buf.st_ctime;        /* ??? */
00166                 *stbuf++ = buf.st_blksize;      /* ??? */
00167                 retval  = 0;
00168         }
00169 
00170         STMT_END(cup, T_INQU, NULL, &cfs);      /* unlock the unit */
00171         return(retval);
00172 }
00173 
00174 _f_int8
00175 fstatf90_8_(_f_int8 *u, _f_int8 *stbuf)
00176 {
00177         int             n, retval;
00178         unum_t          unum;
00179         unit            *cup;
00180 #if     defined(_LITTLE_ENDIAN) && !defined(__sv2)
00181         struct stat     buf;
00182 #else
00183         struct stat64   buf;
00184 #endif
00185         struct fiostate cfs;
00186 
00187         unum = *u;
00188         STMT_BEGIN(unum, 0, T_INQU, NULL, &cfs, cup);
00189 
00190         if (cup == NULL && !GOOD_UNUM(unum))
00191                 _ferr(&cfs, FEIVUNIT, unum);    /* invalid unit number */
00192 
00193         if (cup == NULL)
00194                 retval  = -1;           /* unit is not open */
00195         else if (cup->usysfd == -1)
00196                 retval  = -1;           /* file is not disk-resident */
00197         else {
00198                 n       = fstat64(cup->usysfd, &buf);
00199                 if (n < 0)
00200                         _ferr(&cfs, errno);
00201                 *stbuf++ = buf.st_dev;
00202                 *stbuf++ = buf.st_ino;
00203                 *stbuf++ = buf.st_mode;
00204                 *stbuf++ = buf.st_nlink;
00205                 *stbuf++ = buf.st_uid;
00206                 *stbuf++ = buf.st_gid;
00207                 *stbuf++ = buf.st_rdev;
00208                 *stbuf++ = buf.st_size;         /* may be inaccurate */
00209                 *stbuf++ = buf.st_atime;        /* ??? - this compiles??? */
00210                 *stbuf++ = buf.st_mtime;        /* ??? */
00211                 *stbuf++ = buf.st_ctime;        /* ??? */
00212                 *stbuf++ = buf.st_blksize;      /* ??? */
00213                 retval  = 0;
00214         }
00215 
00216         STMT_END(cup, T_INQU, NULL, &cfs);      /* unlock the unit */
00217         return( (_f_int8)retval );
00218 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines