1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#include <locale.h>
#include <stdio.h>
#include <string.h>
#if WIN32
#include <Windows.h>
#endif
#include "../stack-c.h"
#include "../os_specific/Os_specific.h"
int C2F(intfilestat)(fname)
char * fname;
{
#ifdef WIN32
struct _stat buf;
#else
struct stat buf;
#endif
int result, m1, n1, l1 , l2,one=1,n;
#if WIN32
char DriveTemp[MAX_PATH];
#endif
CheckRhs(1,1);
CheckLhs(1,2);
GetRhsVar(1, "c", &m1, &n1, &l1); /* get file name */
n=m1*n1+256;
CreateVar(2,"c",&one,&n,&l2);
C2F(cluni0)(cstk(l1), cstk(l2), &m1,m1*n1,n);
/* Get data associated with "given file": */
#ifdef WIN32
{
char *path=cstk(l2);
wsprintf(DriveTemp,"%s",path);
if (path)
{
if ( (path[strlen(path)-1]=='/') || (path[strlen(path)-1]=='\\') )
{
path[strlen(path)-1]='\0';
}
}
result = _stat(path, &buf );
}
#else
result = stat(cstk(l2), &buf );
#endif
/* Check if statistics are valid: */
if( result != 0 )
{
#if WIN32
if ( (strlen(DriveTemp)==2) ||(strlen(DriveTemp)==3) )
{
UINT DriveType=GetDriveType(DriveTemp);
if ( (DriveType==DRIVE_UNKNOWN) || (DriveType==DRIVE_NO_ROOT_DIR) )
{
n1=0;
CreateVar(2,"d",&n1,&n1,&l2);
}
else
{
n1 = 13;
CreateVar(2,"d",&one,&n1,&l2);
*stk(l2+0) = 0.0;
*stk(l2+1) = 16895;
*stk(l2+2) = 0.0;
*stk(l2+3) = 0.0;
*stk(l2+4) = 0.0;
*stk(l2+5) = 0.0;
*stk(l2+6) = 0.0;
*stk(l2+7) = 0.0;
*stk(l2+8) = 0.0;
*stk(l2+9) = 0.0;
*stk(l2+10) = 0.0;
*stk(l2+11) = 0.0;
*stk(l2+12) = 0.0;
}
LhsVar(1) = 2;
if (Lhs==2)
{
CreateVar(3,"d",&one,&one,&l2);
*stk(l2) = (double) result;
LhsVar(2) = 3;
}
}
else
{
n1=0;
CreateVar(2,"d",&n1,&n1,&l2);
}
#else
n1=0;
CreateVar(2,"d",&n1,&n1,&l2);
#endif
}
else
{
n1 = 13;
CreateVar(2,"d",&one,&n1,&l2);
*stk(l2+0) = (double) buf.st_size;/* total size, in bytes */
*stk(l2+1) = (double) buf.st_mode;/* protection */
*stk(l2+2) = (double) buf.st_uid;/* user ID of owner */
*stk(l2+3) = (double) buf.st_gid;/* group ID of owner */
*stk(l2+4) = (double) buf.st_dev;/* device */
*stk(l2+5) = (double) buf.st_mtime;/* time of last modification */
*stk(l2+6) = (double) buf.st_ctime;/* time of last change */
*stk(l2+7) = (double) buf.st_atime;/* time of last access */
*stk(l2+8) = (double) buf.st_rdev;/* device type (if inode device) */
#ifdef WIN32
*stk(l2+9) = 0.0;
*stk(l2+10) = 0.0;
#else
*stk(l2+9) = (double) buf.st_blksize;/* blocksize for filesystem I/O */
*stk(l2+10) = (double) buf.st_blocks;/* number of blocks allocated */
#endif
*stk(l2+11) = (double) buf.st_ino;/* inode */
*stk(l2+12) = (double) buf.st_nlink;/* number of hard links */
}
LhsVar(1) = 2;
if (Lhs==2) {
CreateVar(3,"d",&one,&one,&l2);
*stk(l2) = (double) result;
LhsVar(2) = 3;
}
C2F(putlhsvar)();
return 0;
}
|