root/trunk/txlib/txfsattr.c

Revision 1, 5.8 kB (checked in by jvw, 3 years ago)

Initial check-in for TxWin? version 1.02 sources

Line 
1//
2//                     TxWin, Textmode Windowing Library
3//
4//   Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk
5//
6// ==========================================================================
7//
8// This file contains Original Code and/or Modifications of Original Code as
9// defined in and that are subject to the GNU Lesser General Public License.
10// You may not use this file except in compliance with the License.
11// BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE.
12// A copy of the License is provided with the Original Code and Modifications,
13// and is also available at http://www.dfsee.com/txwin/lgpl.htm
14//
15// This library is free software; you can redistribute it and/or modify
16// it under the terms of the GNU Lesser General Public License as published
17// by the Free Software Foundation; either version 2.1 of the License,
18// or (at your option) any later version.
19//
20// This library is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23// See the GNU Lesser General Public License for more details.
24//
25// You should have received a copy of the GNU Lesser General Public License
26// along with this library; (lgpl.htm) if not, write to the Free Software
27// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28//
29// Questions on TxWin licensing can be directed to: txwin@fsys.nl
30//
31// ==========================================================================
32//
33// Filesystem attribute handling functions
34//
35// Author: J. van Wijk
36//
37// JvW  13-06-2002 Initial version, split off from TXCON
38
39#include <txlib.h>
40
41
42// REXX value = d2x(((369*365+89)*86400)*10000000)
43#define  TXNTM_LO    ((ULONG) 0xd53e8000)       // delta between 1-1-1601 base
44#define  TXNTM_HI    ((ULONG) 0x019db1de)       // and ANSI 1-1-1970 (100 ns)
45
46#define  TXNTM_HI_M  ((double) 65536 * (double) (65536))
47#define  TXNTM_NS_D  ((double) 10000000)        // 100ns slots per second
48
49
50/*****************************************************************************/
51// Translate attributes (FAT) to 6-position string format
52/*****************************************************************************/
53void txFileAttr2String
54(
55   ULONG               data,                    // IN    data
56   char               *attrib                   // OUT   attribute string[6]
57)
58{
59   strcpy( attrib, "-----");
60   if (data & FATTR_ARCHIVED)  attrib[0] = 'A';
61   if (data & FATTR_DIRECTORY) attrib[1] = 'D';
62   if (data & FATTR_HIDDEN)    attrib[2] = 'H';
63   if (data & FATTR_READONLY)  attrib[3] = 'R';
64   if (data & FATTR_SYSTEM)    attrib[4] = 'S';
65}                                               // end 'txFileAttr2String'
66/*---------------------------------------------------------------------------*/
67
68
69/*****************************************************************************/
70// Convert Windows-NT/W2K/XP filetime (64 bit) to compiler time_t value
71/*****************************************************************************/
72time_t txWinFileTime2t                          // RET   time_t value
73(
74   NTIME              *nt,                      // IN    ptr NT time value
75   LONG                TimeZone                 // IN    TZ offset to GMT (min)
76)
77{
78   ULONG               lo;
79   ULONG               hi;
80   double              tstamp;
81
82   ENTER();
83
84   TRACES(("NT time value 64bit: %8.8lx %8.8lx\n", nt->hi, nt->lo));
85   lo = nt->lo - TXNTM_LO;
86   hi = nt->hi - TXNTM_HI;                        // subtract fixed 1-1-1970
87   if ( nt->lo < TXNTM_LO)
88   {
89      hi--;                                     // adjust for borrow-1
90   }
91   tstamp  = ((double) lo + ((double) hi * TXNTM_HI_M)) / TXNTM_NS_D;
92   tstamp += ((double) TimeZone * 60);          // correct for timezone
93
94   TRACES(("Seconds since 1970 : %lf\n", tstamp));
95   RETURN( (time_t) tstamp);
96}                                               // end 'txWinFileTime2t'
97/*---------------------------------------------------------------------------*/
98
99
100/*****************************************************************************/
101// Convert OS/2 and eCS filetime (2 * USHORT) to compiler time_t value
102/*****************************************************************************/
103time_t txOS2FileTime2t                          // RET   time_t value
104(
105   USHORT             *pd,                      // IN    USHORT OS2 coded date
106   USHORT             *pt                       // IN    USHORT OS2 coded time
107)
108{
109   double              tstamp = 0;
110   S_DATE             *date   = (S_DATE *) pd;
111   S_TIME             *time   = (S_TIME *) pt;
112   long                md = 0;                  // days difference from 1970
113   long                y,m;                     // year and month numbers
114   long                leaps;
115
116   ENTER();
117
118   TRACES(("OS2 date %4.4hx time %4.4hx\n", *pd, *pt));
119
120   y = date->year + 1980;                       // real year
121   leaps = (y - 1970) / 4 -1;                   // nr of leap-years since ...
122   md = ((y - 1970) * 365) + leaps + date->day; // days since 1-1-1970
123   for (m = 1; m < date->month; m++)
124   {
125      switch (m)
126      {
127         case 2:                           md += ((y%4)==0) ? 29 : 28; break;
128         case 4: case 6: case 9: case 11:  md +=                   30; break;
129         default:                          md +=                   31; break;
130      }
131   }
132   tstamp = ((double) ((((md * 24) +  time->hours)  * 60) + time->minutes) *
133             (double) 60) + (double) (time->twosecs * 2);
134
135   TRACES(("Seconds since 1970 : %lf\n", tstamp));
136   RETURN( (time_t) tstamp);
137}                                               // end 'txOS2FileTime2t'
138/*---------------------------------------------------------------------------*/
Note: See TracBrowser for help on using the browser.