]>
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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 *(C)UNIX System Laboratories, Inc. all or some portions of this file are
27 *derived from material licensed to the University of California by
28 *American Telephone and Telegraph Co. or UNIX System Laboratories,
29 *Inc. and are reproduced herein with the permission of UNIX System
34 * Mach Operating System
35 * Copyright (c) 1993,1991,1990,1989,1988 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
61 * Copyright (c) 1988 Regents of the University of California.
62 * All rights reserved.
64 * Redistribution and use in source and binary forms, with or without
65 * modification, are permitted provided that the following conditions
67 * 1. Redistributions of source code must retain the above copyright
68 * notice, this list of conditions and the following disclaimer.
69 * 2. Redistributions in binary form must reproduce the above copyright
70 * notice, this list of conditions and the following disclaimer in the
71 * documentation and/or other materials provided with the distribution.
72 * 3. All advertising materials mentioning features or use of this software
73 * must display the following acknowledgement:
74 * This product includes software developed by the University of
75 * California, Berkeley and its contributors.
76 * 4. Neither the name of the University nor the names of its contributors
77 * may be used to endorse or promote products derived from this software
78 * without specific prior written permission.
80 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
81 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
82 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
83 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
84 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
85 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
86 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
87 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
88 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
89 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
93 * Random device subroutines and stubs.
96 #include <vm/vm_kern.h>
97 #include <kern/misc_protos.h>
99 /* String routines, from CMU */
110 * strcmp (s1, s2) compares the strings "s1" and "s2".
111 * It returns 0 if the strings are identical. It returns
112 * > 0 if the first character that differs in the two strings
113 * is larger in s1 than in s2 or if s1 is longer than s2 and
114 * the contents are identical up to the length of s2.
115 * It returns < 0 if the first differing character is smaller
116 * in s1 than in s2 or if s1 is shorter than s2 and the
117 * contents are identical upto the length of s1.
122 register const char *s1
,
123 register const char *s2
)
125 register unsigned int a
, b
;
131 return a
-b
; /* includes case when
132 'a' is zero and 'b' is not zero
136 return 0; /* both are zero */
141 * strncmp (s1, s2, n) compares the strings "s1" and "s2"
142 * in exactly the same way as strcmp does. Except the
143 * comparison runs for at most "n" characters.
148 register const char *s1
,
149 register const char *s2
,
152 register unsigned int a
, b
;
158 return a
-b
; /* includes case when
159 'a' is zero and 'b' is not zero
162 return 0; /* both are zero */
171 * strcpy copies the contents of the string "from" including
172 * the null terminator to the string "to". A pointer to "to"
179 register const char *from
)
181 register char *ret
= to
;
183 while ((*to
++ = *from
++) != '\0')
192 * strncpy copies "count" characters from the "from" string to
193 * the "to" string. If "from" contains less than "count" characters
194 * "to" will be padded with null characters until exactly "count"
195 * characters have been written. The return value is a pointer
196 * to the "to" string.
209 if ((*s1
++ = *s2
++) == '\0')
210 for (i
++; i
< n
; i
++)
218 #if !defined(__alpha)
222 * strlen returns the number of characters in "string" preceeding
223 * the terminating null character.
228 register const char *string
)
230 register const char *ret
= string
;
232 while (*string
++ != '\0')
234 return string
- 1 - ret
;
236 #endif /* !defined(__alpha) */
241 * This function converts an ascii string into an integer.
253 for (number
= 0; ('0' <= *cp
) && (*cp
<= '9'); cp
++)
254 number
= (number
* 10) + (*cp
- '0');
260 * convert an ASCII string (decimal radix) to an integer
263 * t char **, return a pointer to the cahr which terminates the
266 * integer value of the numeric string.
268 * pointer to terminating char.
293 while(*p
>= '0' && *p
<= '9')
294 n
= n
*10 + *p
++ - '0';
296 /* return pointer to terminating character */
304 * convert an integer to an ASCII string.
306 * num integer to be converted
307 * str string pointer.
310 * pointer to string start.
320 register char *cp
= str
;
328 *dp
++ = '0' + num
% 10;
331 while (dp
!= digits
) {
343 register const char *src
)
349 while (*dest
++ = *src
++)