Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / pdisk / util.c
blobe29232d054d7e7b9badc81ca3d5a1d6e0db537f3
1 /*
2 * util.c -
4 * Written by Eryk Vershen
5 */
7 /*
8 * Copyright 1997,1998 by Apple Computer, Inc.
9 * All Rights Reserved
11 * Permission to use, copy, modify, and distribute this software and
12 * its documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appears in all copies and
14 * that both the copyright notice and this permission notice appear in
15 * supporting documentation.
17 * APPLE COMPUTER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
18 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19 * FOR A PARTICULAR PURPOSE.
21 * IN NO EVENT SHALL APPLE COMPUTER BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
22 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
23 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
24 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
25 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 // for sprintf()
30 #include <stdio.h>
31 // for tolower()
32 #include <ctype.h>
34 #include "version.h"
35 #include "util.h"
39 * Defines
41 #define NumToolboxTraps() ( \
42 (NGetTrapAddress(_InitGraf, ToolTrap) \
43 == NGetTrapAddress(0xAA6E, ToolTrap)) \
44 ? 0x200 : 0x400 \
46 #define GetTrapType(theTrap) ( \
47 (((theTrap) & 0x800) != 0) ? ToolTrap : OSTrap \
52 * Types
57 * Global Constants
62 * Global Variables
64 static char dynamic_version[10];
67 * Forward declarations
72 * Routines
74 void
75 clear_memory(void *dataPtr, unsigned long size)
77 char *ptr;
79 ptr = (char *) dataPtr;
80 while (size > 0) {
81 *ptr++ = 0;
82 --size;
87 #if !defined(__linux__) && !defined(__unix__)
88 /* (see Inside Mac VI 3-8) */
89 int
90 TrapAvailable(short theTrap)
92 TrapType trapType;
94 trapType = GetTrapType(theTrap);
96 if (trapType == ToolTrap) {
97 theTrap &= 0x07FF;
98 if (theTrap >= NumToolboxTraps())
99 theTrap = _Unimplemented;
102 return (
103 NGetTrapAddress(theTrap, trapType)
104 != NGetTrapAddress(_Unimplemented, ToolTrap)
107 #endif
110 /* Ascii case-insensitive string comparison */
112 istrncmp(const char *x, const char *y, long len)
114 const unsigned char *p = (const unsigned char *)x;
115 const unsigned char *q = (const unsigned char *)y;
117 while (len > 0) {
118 if (tolower(*p) != tolower(*q)) {
119 return (*p - *q);
120 } else if (*p == 0) {
121 break;
123 p++;
124 q++;
125 len--;
127 return (0);
131 const char *
132 get_version_string(void)
134 int stage;
135 /* "copy" of stuff from SysTypes.r, since we can't include that*/
136 enum {development = 0x20, alpha = 0x40, beta = 0x60, final = 0x80, /* or */ release = 0x80};
138 switch (kVersionStage) {
139 case development: stage = 'd'; break;
140 case alpha: stage = 'a'; break;
141 case beta: stage = 'b'; break;
142 case final: stage = 'f'; break;
143 default: stage = '?'; break;
146 if (kVersionBugFix != 0) {
147 if (kVersionStage == final) {
148 snprintf(dynamic_version, sizeof(dynamic_version), "%d.%d.%d",
149 kVersionMajor, kVersionMinor, kVersionBugFix);
150 } else {
151 snprintf(dynamic_version, sizeof(dynamic_version), "%d.%d.%d%c%d",
152 kVersionMajor, kVersionMinor, kVersionBugFix, stage, kVersionDelta);
154 } else {
155 if (kVersionStage == final) {
156 snprintf(dynamic_version, sizeof(dynamic_version), "%d.%d",
157 kVersionMajor, kVersionMinor);
158 } else {
159 snprintf(dynamic_version, sizeof(dynamic_version), "%d.%d%c%d",
160 kVersionMajor, kVersionMinor, stage, kVersionDelta);
163 return dynamic_version;