]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/device/subrs.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 *(C)UNIX System Laboratories, Inc. all or some portions of this file are
33 *derived from material licensed to the University of California by
34 *American Telephone and Telegraph Co. or UNIX System Laboratories,
35 *Inc. and are reproduced herein with the permission of UNIX System
40 * Mach Operating System
41 * Copyright (c) 1993,1991,1990,1989,1988 Carnegie Mellon University
42 * All Rights Reserved.
44 * Permission to use, copy, modify and distribute this software and its
45 * documentation is hereby granted, provided that both the copyright
46 * notice and this permission notice appear in all copies of the
47 * software, derivative works or modified versions, and any portions
48 * thereof, and that both notices appear in supporting documentation.
50 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
51 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
52 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
54 * Carnegie Mellon requests users of this software to return to
56 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
57 * School of Computer Science
58 * Carnegie Mellon University
59 * Pittsburgh PA 15213-3890
61 * any improvements or extensions that they make and grant Carnegie Mellon
62 * the rights to redistribute these changes.
67 * Copyright (c) 1988 Regents of the University of California.
68 * All rights reserved.
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. All advertising materials mentioning features or use of this software
79 * must display the following acknowledgement:
80 * This product includes software developed by the University of
81 * California, Berkeley and its contributors.
82 * 4. Neither the name of the University nor the names of its contributors
83 * may be used to endorse or promote products derived from this software
84 * without specific prior written permission.
86 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
87 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
88 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
89 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
90 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
91 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
92 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
93 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
94 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
95 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
99 * Random device subroutines and stubs.
102 #include <vm/vm_kern.h>
103 #include <kern/misc_protos.h>
105 /* String routines, from CMU */
116 * strcmp (s1, s2) compares the strings "s1" and "s2".
117 * It returns 0 if the strings are identical. It returns
118 * > 0 if the first character that differs in the two strings
119 * is larger in s1 than in s2 or if s1 is longer than s2 and
120 * the contents are identical up to the length of s2.
121 * It returns < 0 if the first differing character is smaller
122 * in s1 than in s2 or if s1 is shorter than s2 and the
123 * contents are identical upto the length of s1.
128 register const char *s1
,
129 register const char *s2
)
131 register unsigned int a
, b
;
137 return a
-b
; /* includes case when
138 'a' is zero and 'b' is not zero
142 return 0; /* both are zero */
147 * strncmp (s1, s2, n) compares the strings "s1" and "s2"
148 * in exactly the same way as strcmp does. Except the
149 * comparison runs for at most "n" characters.
154 register const char *s1
,
155 register const char *s2
,
158 register unsigned int a
, b
;
164 return a
-b
; /* includes case when
165 'a' is zero and 'b' is not zero
168 return 0; /* both are zero */
177 // Lame implementation just for use by strcasecmp/strncasecmp
180 tolower(unsigned char ch
)
182 if (ch
>= 'A' && ch
<= 'Z')
183 ch
= 'a' + (ch
- 'A');
189 strcasecmp(const char *s1
, const char *s2
)
191 const unsigned char *us1
= (const u_char
*)s1
,
192 *us2
= (const u_char
*)s2
;
194 while (tolower(*us1
) == tolower(*us2
++))
197 return (tolower(*us1
) - tolower(*--us2
));
201 strncasecmp(const char *s1
, const char *s2
, size_t n
)
204 const unsigned char *us1
= (const u_char
*)s1
,
205 *us2
= (const u_char
*)s2
;
208 if (tolower(*us1
) != tolower(*us2
++))
209 return (tolower(*us1
) - tolower(*--us2
));
220 * strcpy copies the contents of the string "from" including
221 * the null terminator to the string "to". A pointer to "to"
228 register const char *from
)
230 register char *ret
= to
;
232 while ((*to
++ = *from
++) != '\0')
241 * strncpy copies "count" characters from the "from" string to
242 * the "to" string. If "from" contains less than "count" characters
243 * "to" will be padded with null characters until exactly "count"
244 * characters have been written. The return value is a pointer
245 * to the "to" string.
258 if ((*s1
++ = *s2
++) == '\0')
259 for (i
++; i
< n
; i
++)
269 * This function converts an ascii string into an integer.
281 for (number
= 0; ('0' <= *cp
) && (*cp
<= '9'); cp
++)
282 number
= (number
* 10) + (*cp
- '0');
288 * convert an ASCII string (decimal radix) to an integer
291 * t char **, return a pointer to the cahr which terminates the
294 * integer value of the numeric string.
296 * pointer to terminating char.
321 while(*p
>= '0' && *p
<= '9')
322 n
= n
*10 + *p
++ - '0';
324 /* return pointer to terminating character */
332 * convert an integer to an ASCII string.
334 * num integer to be converted
335 * str string pointer.
338 * pointer to string start.
348 register char *cp
= str
;
356 *dp
++ = '0' + num
% 10;
359 while (dp
!= digits
) {
371 register const char *src
)
377 while (*dest
++ = *src
++)