]> git.saurik.com Git - apple/xnu.git/blame - bsd/hfs/MacOSStubs.c
xnu-344.49.tar.gz
[apple/xnu.git] / bsd / hfs / MacOSStubs.c
CommitLineData
1c79356b 1/*
9bccf70c 2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
1c79356b
A
25#include <sys/param.h>
26#include <sys/systm.h>
27#include <sys/kernel.h>
1c79356b 28#include <sys/malloc.h>
1c79356b 29#include <sys/types.h>
9bccf70c 30
1c79356b
A
31#include "hfs.h"
32#include "hfs_dbg.h"
1c79356b
A
33#include "hfscommon/headers/FileMgrInternal.h"
34
1c79356b
A
35
36/*
37 * gTimeZone should only be used for HFS volumes!
38 * It is initialized when an HFS volume is mounted.
39 */
40struct timezone gTimeZone = {8*60,1};
41
1c79356b
A
42/*
43 * GetTimeUTC - get the GMT Mac OS time (in seconds since 1/1/1904)
44 *
45 * called by the Catalog Manager when creating/updating HFS Plus records
46 */
47UInt32 GetTimeUTC(void)
48{
49 return (time.tv_sec + MAC_GMT_FACTOR);
50}
51
1c79356b
A
52
53/*
54 * LocalToUTC - convert from Mac OS local time to Mac OS GMT time.
55 * This should only be called for HFS volumes (not for HFS Plus).
56 */
57UInt32 LocalToUTC(UInt32 localTime)
58{
59 UInt32 gtime = localTime;
60
61 if (gtime != 0) {
62 gtime += (gTimeZone.tz_minuteswest * 60);
63 /*
64 * We no longer do DST adjustments here since we don't
65 * know if time supplied needs adjustment!
66 *
67 * if (gTimeZone.tz_dsttime)
68 * gtime -= 3600;
69 */
70 }
71 return (gtime);
72}
73
74/*
75 * UTCToLocal - convert from Mac OS GMT time to Mac OS local time.
76 * This should only be called for HFS volumes (not for HFS Plus).
77 */
78UInt32 UTCToLocal(UInt32 utcTime)
79{
80 UInt32 ltime = utcTime;
81
82 if (ltime != 0) {
83 ltime -= (gTimeZone.tz_minuteswest * 60);
84 /*
85 * We no longer do DST adjustments here since we don't
86 * know if time supplied needs adjustment!
87 *
88 * if (gTimeZone.tz_dsttime)
89 * ltime += 3600;
90 */
91 }
92 return (ltime);
93}
94
95/*
96 * to_bsd_time - convert from Mac OS time (seconds since 1/1/1904)
97 * to BSD time (seconds since 1/1/1970)
98 */
99u_int32_t to_bsd_time(u_int32_t hfs_time)
100{
101 u_int32_t gmt = hfs_time;
102
103 if (gmt > MAC_GMT_FACTOR)
104 gmt -= MAC_GMT_FACTOR;
105 else
106 gmt = 0; /* don't let date go negative! */
107
108 return gmt;
109}
110
111/*
112 * to_hfs_time - convert from BSD time (seconds since 1/1/1970)
113 * to Mac OS time (seconds since 1/1/1904)
114 */
115u_int32_t to_hfs_time(u_int32_t bsd_time)
116{
117 u_int32_t hfs_time = bsd_time;
118
119 /* don't adjust zero - treat as uninitialzed */
120 if (hfs_time != 0)
121 hfs_time += MAC_GMT_FACTOR;
122
123 return (hfs_time);
124}
125
126
1c79356b
A
127Ptr NewPtrSysClear (Size byteCount)
128{
129 Ptr tmptr;
130 MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK);
131 if (tmptr)
132 bzero(tmptr, byteCount);
133 return tmptr;
134}
135
136
137
138Ptr NewPtr (Size byteCount)
139{
140 Ptr tmptr;
141 MALLOC (tmptr, Ptr, byteCount, M_TEMP, M_WAITOK);
142 return tmptr;
143}
144
145
146void DisposePtr (Ptr p)
147{
148 FREE (p, M_TEMP);
149}
150
151
152void DebugStr (ConstStr255Param debuggerMsg)
153{
154 kprintf ("*** Mac OS Debugging Message: %s\n", &debuggerMsg[1]);
155 DEBUG_BREAK;
156}
157