home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
BTMTSRC3.ZIP
/
FSTAT.C
< prev
next >
Wrap
Text File
|
1991-07-22
|
4KB
|
133 lines
/*PLF Mon 05-08-1989 10:12:15 */
/* This code from the MSC 5.10 Runtime Source had a bug in it. It was
* incorrectly classifing a network file as a device. I have fixed
* the bug. You will need the include files from the MSC 5.10 Runtime
* Library Source disks to compile it.
* I changed the line with *PLF in the comment. (apx line 111)
*/
#define DEVICE 0x0001
/***
*fstat.c - OS/2 return file status info
*
* Copyright (c) 1985-1988, Microsoft Corporation. All rights reserved.
*
*Purpose:
* defines fstat() - return file status info
*
*******************************************************************************/
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include "e:\msc_src\include\register.h"
#include "e:\msc_src\include\msdos.h"
#include <dos.h>
#include "e:\msc_src\include\dostypes.h"
#include <io.h>
#include "e:\msc_src\include\internal.h"
#include <stddef.h>
#include <doscalls.h>
#define IO_DEVNBR 0x3f
/***
*int fstat(fildes, buf) - fills supplied buffer with status info
*
*Purpose:
* Fills the supplied buffer with status information on the
* file represented by the specified file designator.
* WARNING: the dev/rdev fields are zero for files. This is
* incompatible with DOS 3 version of this routine.
*
*Entry:
* int filedes - file descriptor
* struct stat *buf - buffer to store result in
*
*Exit:
* fills in buffer pointed to by buf
* returns 0 if successful
* returns -1 and sets errno if unsuccessful
*
*Exceptions:
*
*******************************************************************************/
fstat(fildes, buf)
REG2 int fildes;
REG1 struct stat *buf;
{
long cpos;
int isdev; /* 0 for a file, 1 for a device */
int descrip; /* device descriptor word */
struct FileStatus fs ;
/* Check the validity of the fildes by doing a get-device-info call.
* This also gives us other information we may need later
*/
if (DOSQHANDTYPE(fildes, (unsigned far *)&isdev,
(unsigned far *)&descrip))
{
errno = EBADF;
return(-1); /* error from DOS call - bad file designator */
}
/* set the common fields */
buf->st_ino = buf->st_uid = buf->st_gid = buf->st_mode = 0;
buf->st_nlink = 1;
buf->st_mode |= (_osfile[fildes] & FRDONLY)
? (S_IREAD + (S_IREAD >> 3) + (S_IREAD >> 6))
: ((S_IREAD|S_IWRITE) +
((S_IREAD|S_IWRITE) >> 3)
+ ((S_IREAD|S_IWRITE) >> 6));
/* set file date fields - NOTE for code below, it should be
* remembered that calls to QFILEINFO cannot fail since the file
* handle is known to be good since we got by the QHANDTYPE call.
*/
(void) DOSQFILEINFO(fildes, 1, (char far *) & fs, sizeof(fs));
buf->st_mtime = XTIME(fs.write_date, fs.write_time);
if (fs.access_date || fs.access_time)
buf->st_atime = XTIME(fs.access_date, fs.access_time);
else
buf->st_atime = buf->st_mtime ;
if (fs.create_date || fs.create_time)
buf->st_ctime = XTIME(fs.create_date, fs.create_time);
else
buf->st_ctime = buf->st_mtime ;
buf->st_mtime = XTIME(fs.write_date, fs.write_time);
/* check for device or file */
if (isdev & DEVICE) { /*PLF Mon 05-08-1989 10:14:27 */
/* file designator refers to a device - set file size to 0 */
buf->st_size = 0;
buf->st_mode |= S_IFCHR;
buf->st_rdev = buf->st_dev = fildes;
}
else {
/* file designator refers to a file - set actual file size */
cpos = lseek(fildes, 0L, 1);
buf->st_size = lseek(fildes, 0L, 2);
lseek(fildes, cpos, 0);
buf->st_mode |= S_IFREG;
buf->st_rdev = buf->st_dev = 0; /* This is a BUG! */
}
return(0);
}