]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/device/subrs.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
29 *(C)UNIX System Laboratories, Inc. all or some portions of this file are
30 *derived from material licensed to the University of California by
31 *American Telephone and Telegraph Co. or UNIX System Laboratories,
32 *Inc. and are reproduced herein with the permission of UNIX System
37 * Mach Operating System
38 * Copyright (c) 1993,1991,1990,1989,1988 Carnegie Mellon University
39 * All Rights Reserved.
41 * Permission to use, copy, modify and distribute this software and its
42 * documentation is hereby granted, provided that both the copyright
43 * notice and this permission notice appear in all copies of the
44 * software, derivative works or modified versions, and any portions
45 * thereof, and that both notices appear in supporting documentation.
47 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
48 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
49 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
51 * Carnegie Mellon requests users of this software to return to
53 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
54 * School of Computer Science
55 * Carnegie Mellon University
56 * Pittsburgh PA 15213-3890
58 * any improvements or extensions that they make and grant Carnegie Mellon
59 * the rights to redistribute these changes.
64 * Copyright (c) 1988 Regents of the University of California.
65 * All rights reserved.
67 * Redistribution and use in source and binary forms, with or without
68 * modification, are permitted provided that the following conditions
70 * 1. Redistributions of source code must retain the above copyright
71 * notice, this list of conditions and the following disclaimer.
72 * 2. Redistributions in binary form must reproduce the above copyright
73 * notice, this list of conditions and the following disclaimer in the
74 * documentation and/or other materials provided with the distribution.
75 * 3. All advertising materials mentioning features or use of this software
76 * must display the following acknowledgement:
77 * This product includes software developed by the University of
78 * California, Berkeley and its contributors.
79 * 4. Neither the name of the University nor the names of its contributors
80 * may be used to endorse or promote products derived from this software
81 * without specific prior written permission.
83 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
84 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
85 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
86 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
87 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
88 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
89 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
90 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
91 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
92 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
96 * Random device subroutines and stubs.
99 #include <vm/vm_kern.h>
100 #include <kern/misc_protos.h>
102 /* String routines, from CMU */
113 * strcmp (s1, s2) compares the strings "s1" and "s2".
114 * It returns 0 if the strings are identical. It returns
115 * > 0 if the first character that differs in the two strings
116 * is larger in s1 than in s2 or if s1 is longer than s2 and
117 * the contents are identical up to the length of s2.
118 * It returns < 0 if the first differing character is smaller
119 * in s1 than in s2 or if s1 is shorter than s2 and the
120 * contents are identical upto the length of s1.
125 register const char *s1
,
126 register const char *s2
)
128 register unsigned int a
, b
;
134 return a
-b
; /* includes case when
135 'a' is zero and 'b' is not zero
139 return 0; /* both are zero */
144 * strncmp (s1, s2, n) compares the strings "s1" and "s2"
145 * in exactly the same way as strcmp does. Except the
146 * comparison runs for at most "n" characters.
151 register const char *s1
,
152 register const char *s2
,
155 register unsigned int a
, b
;
161 return a
-b
; /* includes case when
162 'a' is zero and 'b' is not zero
165 return 0; /* both are zero */
174 * strcpy copies the contents of the string "from" including
175 * the null terminator to the string "to". A pointer to "to"
182 register const char *from
)
184 register char *ret
= to
;
186 while ((*to
++ = *from
++) != '\0')
195 * strncpy copies "count" characters from the "from" string to
196 * the "to" string. If "from" contains less than "count" characters
197 * "to" will be padded with null characters until exactly "count"
198 * characters have been written. The return value is a pointer
199 * to the "to" string.
212 if ((*s1
++ = *s2
++) == '\0')
213 for (i
++; i
< n
; i
++)
223 * This function converts an ascii string into an integer.
235 for (number
= 0; ('0' <= *cp
) && (*cp
<= '9'); cp
++)
236 number
= (number
* 10) + (*cp
- '0');
242 * convert an ASCII string (decimal radix) to an integer
245 * t char **, return a pointer to the cahr which terminates the
248 * integer value of the numeric string.
250 * pointer to terminating char.
275 while(*p
>= '0' && *p
<= '9')
276 n
= n
*10 + *p
++ - '0';
278 /* return pointer to terminating character */
286 * convert an integer to an ASCII string.
288 * num integer to be converted
289 * str string pointer.
292 * pointer to string start.
302 register char *cp
= str
;
310 *dp
++ = '0' + num
% 10;
313 while (dp
!= digits
) {
325 register const char *src
)
331 while (*dest
++ = *src
++)