intfilestat.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 
00003 /*-----------------------------------------------------------------------------------*/
00004 #include <sys/types.h>
00005 #include <sys/stat.h>
00006 #include <time.h>
00007 #include <locale.h>
00008 #include <stdio.h>
00009 #include <string.h>
00010 
00011 #ifdef _MSC_VER
00012 #include <Windows.h>
00013 #endif
00014 
00015 #include "stack-c.h"
00016 #include "intfilestat.h"
00017 /*-----------------------------------------------------------------------------------*/
00018 extern int C2F(cluni0) __PARAMS((char *name, char *nams, integer *ln, long int name_len,long int nams_len));  
00019 /*-----------------------------------------------------------------------------------*/
00020 int C2F(intfilestat)(char * fname)
00021 {
00022 #ifdef _MSC_VER
00023    struct _stat buf;
00024 #else
00025    struct stat buf;
00026 #endif
00027    int result, m1, n1, l1 , l2,one=1,n;
00028 #ifdef _MSC_VER
00029    char DriveTemp[MAX_PATH];
00030 #endif
00031    CheckRhs(1,1);
00032    CheckLhs(1,2);
00033    GetRhsVar(1, "c", &m1, &n1, &l1); /* get file name */
00034 
00035    n=m1*n1+256;
00036    CreateVar(2,"c",&one,&n,&l2);
00037    C2F(cluni0)(cstk(l1), cstk(l2), &m1,m1*n1,n);
00038    /* Get data associated with "given file": */
00039 #ifdef _MSC_VER
00040    {
00041                 char *path=cstk(l2);
00042                 wsprintf(DriveTemp,"%s",path);
00043                 if (path)
00044                 {
00045                         if ( (path[strlen(path)-1]=='/') || (path[strlen(path)-1]=='\\') )
00046                         {
00047                                 path[strlen(path)-1]='\0';
00048                         }
00049 
00050                 }
00051                 result = _stat(path, &buf );
00052    }
00053 #else
00054    result = stat(cstk(l2), &buf );
00055 #endif
00056    /* Check if statistics are valid: */
00057    if( result != 0 ) 
00058    {
00059 #ifdef _MSC_VER
00060          if ( (strlen(DriveTemp)==2) ||(strlen(DriveTemp)==3) )
00061          {
00062                  UINT DriveType=GetDriveType(DriveTemp);
00063                  if ( (DriveType==DRIVE_UNKNOWN) || (DriveType==DRIVE_NO_ROOT_DIR) )
00064                  {
00065                          n1=0;
00066                          CreateVar(2,"d",&n1,&n1,&l2);
00067                  }
00068                  else
00069                  {
00070                          n1 = 13;
00071                          CreateVar(2,"d",&one,&n1,&l2);
00072 
00073                          *stk(l2+0) =  0.0;
00074                          *stk(l2+1) =  16895;
00075                          *stk(l2+2) =  0.0;
00076                          *stk(l2+3) =  0.0;
00077                          *stk(l2+4) =  0.0;
00078                          *stk(l2+5) =  0.0;
00079                          *stk(l2+6) =  0.0;
00080                          *stk(l2+7) =  0.0;
00081                          *stk(l2+8) =  0.0;
00082                          *stk(l2+9) =  0.0;
00083                          *stk(l2+10) = 0.0;
00084                          *stk(l2+11) = 0.0;
00085                          *stk(l2+12) = 0.0;
00086                  }
00087                  LhsVar(1) = 2;
00088                  if (Lhs==2) 
00089                  {
00090                          CreateVar(3,"d",&one,&one,&l2);
00091                          *stk(l2) = (double) result;
00092                          LhsVar(2) = 3;
00093                  }
00094          }
00095          else
00096          {
00097                  n1=0;
00098                  CreateVar(2,"d",&n1,&n1,&l2);
00099          }
00100      
00101 #else
00102          n1=0;
00103          CreateVar(2,"d",&n1,&n1,&l2);
00104 #endif
00105    }
00106    else
00107    {
00108      n1 = 13;
00109      CreateVar(2,"d",&one,&n1,&l2);
00110 
00111      *stk(l2+0) = (double) buf.st_size;/* total size, in bytes */
00112      *stk(l2+1) = (double) buf.st_mode;/* protection */
00113      *stk(l2+2) = (double) buf.st_uid;/* user ID of owner */
00114      *stk(l2+3) = (double) buf.st_gid;/* group ID of owner */
00115      *stk(l2+4) = (double) buf.st_dev;/* device */
00116      *stk(l2+5) = (double) buf.st_mtime;/* time of last modification */
00117      *stk(l2+6) = (double) buf.st_ctime;/* time of last change */
00118      *stk(l2+7) = (double) buf.st_atime;/* time of last access */
00119      *stk(l2+8) = (double) buf.st_rdev;/* device type (if inode device) */
00120 #ifdef _MSC_VER
00121      *stk(l2+9) = 0.0;
00122      *stk(l2+10) = 0.0;
00123 #else 
00124      *stk(l2+9) = (double) buf.st_blksize;/* blocksize for filesystem I/O */
00125      *stk(l2+10) = (double) buf.st_blocks;/* number of blocks allocated */
00126 #endif 
00127      *stk(l2+11) = (double) buf.st_ino;/* inode */
00128      *stk(l2+12) = (double) buf.st_nlink;/* number of hard links */
00129 
00130    }
00131   LhsVar(1) = 2;
00132   if (Lhs==2) {
00133     CreateVar(3,"d",&one,&one,&l2);
00134     *stk(l2) = (double) result;
00135     LhsVar(2) = 3;
00136   }
00137   C2F(putlhsvar)();
00138   return 0;
00139 }
00140 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:57 2007 for Scilab [trunk] by  doxygen 1.5.1