Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  OS/2 implementation of fstat().
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include "widechar.h"
  34. #include <stddef.h>
  35. #include <stdio.h>
  36. #include <io.h>
  37. #include <time.h>
  38. #include <sys/types.h>
  39. #include <sys/stat.h>
  40. #include <errno.h>
  41. #include <direct.h>
  42. #include "iomode.h"
  43. #include "rtcheck.h"
  44. #include "seterrno.h"
  45. #include "kolibri.h"
  46.  
  47. typedef struct
  48. {
  49.   char     *name;
  50.   unsigned int offset;
  51. }__file_handle;
  52.  
  53.  
  54. static unsigned short at2mode( int attr )
  55. /***************************************/
  56.     {
  57.         register unsigned short         mode;
  58.  
  59.         if( attr & 0x10 ) {
  60.             mode = S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
  61.         } else {
  62.             mode = S_IFREG;
  63.         }
  64.         mode |= S_IRUSR | S_IRGRP | S_IROTH;
  65.         if( !(attr & (0x04 | 0x01 ) ) ) {
  66.             mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  67.         }
  68.         return( mode );
  69.     }
  70.  
  71.  
  72. #ifdef __WIDECHAR__
  73. _WCRTLINK int _wfstat( int handle, struct _stat *buf )
  74. #else
  75. _WCRTLINK int fstat( int handle, struct stat *buf )
  76. #endif
  77.     {
  78.         __file_handle   *fh;
  79.         FILEINFO        info;
  80.         int err;
  81.         struct tm time;
  82.        
  83.         __handle_check( handle, -1 );
  84.  
  85.         fh = (__file_handle*) __getOSHandle(handle);
  86.         err = get_fileinfo(fh->name,&info);
  87.  
  88.         if(err)
  89.           return (-1);
  90.  
  91.         buf->st_mode = at2mode(info.attr);
  92.        
  93.         time.tm_sec   = info.ctime.sec;
  94.         time.tm_min   = info.ctime.min;
  95.         time.tm_hour  = info.ctime.hour;
  96.         time.tm_mday  = info.cdate.day;
  97.         time.tm_mon   = info.cdate.month;
  98.         time.tm_year  = info.cdate.year - 1900;
  99.         time.tm_isdst = -1;
  100.         buf->st_ctime = mktime(&time);
  101.  
  102.         time.tm_sec   = info.atime.sec;
  103.         time.tm_min   = info.atime.min;
  104.         time.tm_hour  = info.atime.hour;
  105.         time.tm_mday  = info.adate.day;
  106.         time.tm_mon   = info.adate.month;
  107.         time.tm_year  = info.adate.year - 1900;
  108.         time.tm_isdst = -1;
  109.         buf->st_atime = mktime(&time);
  110.        
  111.         time.tm_sec   = info.mtime.sec;
  112.         time.tm_min   = info.mtime.min;
  113.         time.tm_hour  = info.mtime.hour;
  114.         time.tm_mday  = info.mdate.day;
  115.         time.tm_mon   = info.mdate.month;
  116.         time.tm_year  = info.mdate.year - 1900;
  117.         time.tm_isdst = -1;
  118.         buf->st_mtime = mktime(&time);
  119.  
  120.         buf->st_size  = info.size;
  121.         buf->st_dev   = buf->st_rdev = 0;
  122.         buf->st_attr  = info.attr;
  123.         buf->st_nlink = 1;
  124.         buf->st_ino   = handle;
  125.         buf->st_uid   = buf->st_gid = 0;
  126.  
  127.         buf->st_btime = buf->st_mtime;
  128.         buf->st_archivedID = 0;
  129.         buf->st_updatedID = 0;
  130.         buf->st_inheritedRightsMask = 0;
  131.         buf->st_originatingNameSpace = 0;
  132.        
  133.         return( 0 );
  134. };
  135.  
  136.