]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/device/subrs.c
a9c6e0beb47635d023f10da013b550852d6ad9f2
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 *(C)UNIX System Laboratories, Inc. all or some portions of this file are
35 *derived from material licensed to the University of California by
36 *American Telephone and Telegraph Co. or UNIX System Laboratories,
37 *Inc. and are reproduced herein with the permission of UNIX System
42 * Mach Operating System
43 * Copyright (c) 1993,1991,1990,1989,1988 Carnegie Mellon University
44 * All Rights Reserved.
46 * Permission to use, copy, modify and distribute this software and its
47 * documentation is hereby granted, provided that both the copyright
48 * notice and this permission notice appear in all copies of the
49 * software, derivative works or modified versions, and any portions
50 * thereof, and that both notices appear in supporting documentation.
52 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
53 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
54 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
56 * Carnegie Mellon requests users of this software to return to
58 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
59 * School of Computer Science
60 * Carnegie Mellon University
61 * Pittsburgh PA 15213-3890
63 * any improvements or extensions that they make and grant Carnegie Mellon
64 * the rights to redistribute these changes.
69 * Copyright (c) 1988 Regents of the University of California.
70 * All rights reserved.
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
75 * 1. Redistributions of source code must retain the above copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * This product includes software developed by the University of
83 * California, Berkeley and its contributors.
84 * 4. Neither the name of the University nor the names of its contributors
85 * may be used to endorse or promote products derived from this software
86 * without specific prior written permission.
88 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
89 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
90 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
91 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
92 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
93 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
94 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
95 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
96 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
97 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
101 * Random device subroutines and stubs.
104 #include <vm/vm_kern.h>
105 #include <kern/misc_protos.h>
107 /* String routines, from CMU */
118 * strcmp (s1, s2) compares the strings "s1" and "s2".
119 * It returns 0 if the strings are identical. It returns
120 * > 0 if the first character that differs in the two strings
121 * is larger in s1 than in s2 or if s1 is longer than s2 and
122 * the contents are identical up to the length of s2.
123 * It returns < 0 if the first differing character is smaller
124 * in s1 than in s2 or if s1 is shorter than s2 and the
125 * contents are identical upto the length of s1.
130 register const char *s1
,
131 register const char *s2
)
133 register unsigned int a
, b
;
139 return a
-b
; /* includes case when
140 'a' is zero and 'b' is not zero
144 return 0; /* both are zero */
149 * strncmp (s1, s2, n) compares the strings "s1" and "s2"
150 * in exactly the same way as strcmp does. Except the
151 * comparison runs for at most "n" characters.
156 register const char *s1
,
157 register const char *s2
,
160 register unsigned int a
, b
;
166 return a
-b
; /* includes case when
167 'a' is zero and 'b' is not zero
170 return 0; /* both are zero */
179 // Lame implementation just for use by strcasecmp/strncasecmp
182 tolower(unsigned char ch
)
184 if (ch
>= 'A' && ch
<= 'Z')
185 ch
= 'a' + (ch
- 'A');
191 strcasecmp(const char *s1
, const char *s2
)
193 const unsigned char *us1
= (const u_char
*)s1
,
194 *us2
= (const u_char
*)s2
;
196 while (tolower(*us1
) == tolower(*us2
++))
199 return (tolower(*us1
) - tolower(*--us2
));
203 strncasecmp(const char *s1
, const char *s2
, size_t n
)
206 const unsigned char *us1
= (const u_char
*)s1
,
207 *us2
= (const u_char
*)s2
;
210 if (tolower(*us1
) != tolower(*us2
++))
211 return (tolower(*us1
) - tolower(*--us2
));
222 * strcpy copies the contents of the string "from" including
223 * the null terminator to the string "to". A pointer to "to"
230 register const char *from
)
232 register char *ret
= to
;
234 while ((*to
++ = *from
++) != '\0')
243 * strncpy copies "count" characters from the "from" string to
244 * the "to" string. If "from" contains less than "count" characters
245 * "to" will be padded with null characters until exactly "count"
246 * characters have been written. The return value is a pointer
247 * to the "to" string.
260 if ((*s1
++ = *s2
++) == '\0')
261 for (i
++; i
< n
; i
++)
271 * This function converts an ascii string into an integer.
283 for (number
= 0; ('0' <= *cp
) && (*cp
<= '9'); cp
++)
284 number
= (number
* 10) + (*cp
- '0');
290 * convert an ASCII string (decimal radix) to an integer
293 * t char **, return a pointer to the cahr which terminates the
296 * integer value of the numeric string.
298 * pointer to terminating char.
323 while(*p
>= '0' && *p
<= '9')
324 n
= n
*10 + *p
++ - '0';
326 /* return pointer to terminating character */
334 * convert an integer to an ASCII string.
336 * num integer to be converted
337 * str string pointer.
340 * pointer to string start.
350 register char *cp
= str
;
358 *dp
++ = '0' + num
% 10;
361 while (dp
!= digits
) {
373 register const char *src
)
379 while (*dest
++ = *src
++)