source: trunk/lib/smb_deps.c @ 147

Last change on this file since 147 was 147, checked in by tim, 15 years ago

added talloc library

incorporated talloc into winsec and lru_cache modules

introduced talloc into SK caching system

  • Property svn:keywords set to Id
File size: 4.0 KB
Line 
1/*
2 * This file contains miscellaneous pieces of code which regfio.c
3 * depends upon, from the Samba Subversion tree.  See:
4 *   http://websvn.samba.org/cgi-bin/viewcvs.cgi/trunk/source/
5 *
6 * Copyright (C) 2005-2006,2009 Timothy D. Morgan
7 * Copyright (C) 1992-2005 Samba development team
8 *               (see individual files under Subversion for details.)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 3 of the License.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 * $Id: smb_deps.c 147 2009-02-22 19:31:52Z tim $
24 */
25
26#include "smb_deps.h"
27
28
29/* These act as replacements for numerous Samba memory allocation
30 *   functions.
31 */
32void* zalloc(size_t size)
33{
34  void* ret_val = NULL;
35  if((size > 0) && (ret_val = (void*)malloc(size)) != NULL)
36    memset(ret_val, 0, size);
37
38  return ret_val;
39}
40
41void* zcalloc(size_t size, unsigned int count)
42{
43  return zalloc(size*count);
44}
45
46/* From lib/time.c */
47
48/****************************************************************************
49 Put a 8 byte filetime from a time_t
50 This takes real GMT as input and converts to kludge-GMT
51****************************************************************************/
52void unix_to_nt_time(NTTIME *nt, time_t t)
53{
54  double d;
55 
56  if (t==0) 
57  {
58    nt->low = 0;
59    nt->high = 0;
60    return;
61  }
62 
63  if (t == TIME_T_MAX) 
64  {
65    nt->low = 0xffffffff;
66    nt->high = 0x7fffffff;
67    return;
68  }             
69 
70  if (t == -1) 
71  {
72    nt->low = 0xffffffff;
73    nt->high = 0xffffffff;
74    return;
75  }             
76 
77  /* this converts GMT to kludge-GMT */
78  /* XXX: This was removed due to difficult dependency requirements. 
79   *      So far, times appear to be correct without this adjustment, but
80   *      that may be proven wrong with adequate testing.
81   */
82  /* t -= TimeDiff(t) - get_serverzone(); */
83 
84  d = (double)(t);
85  d += TIME_FIXUP_CONSTANT;
86  d *= 1.0e7;
87 
88  nt->high = (uint32)(d * (1.0/(4.0*(double)(1<<30))));
89  nt->low  = (uint32)(d - ((double)nt->high)*4.0*(double)(1<<30));
90}
91
92
93/****************************************************************************
94 Interpret an 8 byte "filetime" structure to a time_t
95 It's originally in "100ns units since jan 1st 1601"
96
97 An 8 byte value of 0xffffffffffffffff will be returned as (time_t)0.
98
99 It appears to be kludge-GMT (at least for file listings). This means
100 its the GMT you get by taking a localtime and adding the
101 serverzone. This is NOT the same as GMT in some cases. This routine
102 converts this to real GMT.
103****************************************************************************/
104time_t nt_time_to_unix(const NTTIME* nt)
105{
106  double d;
107  time_t ret;
108  /* The next two lines are a fix needed for the
109     broken SCO compiler. JRA. */
110  time_t l_time_min = TIME_T_MIN;
111  time_t l_time_max = TIME_T_MAX;
112 
113  if (nt->high == 0 || (nt->high == 0xffffffff && nt->low == 0xffffffff))
114    return(0);
115 
116  d = ((double)nt->high)*4.0*(double)(1<<30);
117  d += (nt->low&0xFFF00000);
118  d *= 1.0e-7;
119 
120  /* now adjust by 369 years to make the secs since 1970 */
121  d -= TIME_FIXUP_CONSTANT;
122 
123  if (d <= l_time_min)
124    return (l_time_min);
125 
126  if (d >= l_time_max)
127    return (l_time_max);
128 
129  ret = (time_t)(d+0.5);
130 
131  /* this takes us from kludge-GMT to real GMT */
132  /* XXX: This was removed due to difficult dependency requirements. 
133   *      So far, times appear to be correct without this adjustment, but
134   *      that may be proven wrong with adequate testing.
135   */
136  /*
137    ret -= get_serverzone();
138    ret += LocTimeDiff(ret);
139  */
140
141  return(ret);
142}
143
144/* End of stuff from lib/time.c */
Note: See TracBrowser for help on using the repository browser.