home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
LIBSRC.ZOO
/
libsrc
/
local
/
fstat.c
< prev
next >
Wrap
Text File
|
1992-03-06
|
2KB
|
102 lines
#define INCL_DOSFILEMGR
#define INCL_DOSERRORS
#include <os2.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <errno.h>
ULONG Dos32QueryFileInfo() asm ("Dos32QueryFileInfo");
ULONG Dos32QueryHType() asm ("Dos32QueryHType");
int fstat (int fd, struct stat *buf)
{
FILESTATUS fs;
ULONG rc;
struct tm tim;
ULONG HandType;
ULONG FlagWord;
rc = Dos32QueryFileInfo (fd, 1, (PBYTE)&fs, sizeof (FILESTATUS));
if (rc)
{
if (rc == ERROR_ACCESS_DENIED)
{
errno = EACCES;
return (-1);
}
if (rc == ERROR_INVALID_HANDLE)
{
errno = EBADF;
return (-1);
}
errno = EIO;
return (-1);
}
tim.tm_sec = fs.ftimeCreation.twosecs;
tim.tm_min = fs.ftimeCreation.minutes;
tim.tm_hour = fs.ftimeCreation.hours;
tim.tm_mday = fs.fdateCreation.day;
tim.tm_mon = fs.fdateCreation.month;
tim.tm_year = fs.fdateCreation.year;
buf -> st_ctime = mktime (&tim);
tim.tm_sec = fs.ftimeLastAccess.twosecs;
tim.tm_min = fs.ftimeLastAccess.minutes;
tim.tm_hour = fs.ftimeLastAccess.hours;
tim.tm_mday = fs.fdateLastAccess.day;
tim.tm_mon = fs.fdateLastAccess.month;
tim.tm_year = fs.fdateLastAccess.year;
buf -> st_atime = mktime (&tim);
tim.tm_sec = fs.ftimeLastWrite.twosecs;
tim.tm_min = fs.ftimeLastWrite.minutes;
tim.tm_hour = fs.ftimeLastWrite.hours;
tim.tm_mday = fs.fdateLastWrite.day;
tim.tm_mon = fs.fdateLastWrite.month;
tim.tm_year = fs.fdateLastWrite.year;
buf -> st_mtime = mktime (&tim);
buf -> st_size = fs.cbFile;
buf -> st_blksize = 4096;
buf -> st_ino = 0;
buf -> st_nlink = 1;
buf -> st_uid = 0;
buf -> st_gid = 0;
rc = Dos32QueryHType (fd, &HandType, &FlagWord);
if (rc)
{
errno = EBADF;
return (-1);
}
switch (HandType & 0xff)
{
case 0:
buf -> st_mode = S_IFREG;
break;
case 1:
buf -> st_mode = S_IFCHR;
break;
case 2:
buf -> st_mode = S_IFIFO;
break;
}
return (0);
}