2 * Copyright (c) 1998 Robert Nordier
3 * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
6 * Redistribution and use in source and binary forms are freely
7 * permitted provided that the above copyright notice and this
8 * paragraph and the following disclaimer are duplicated in all
11 * This software is provided "AS IS" and without any express or
12 * implied warranties, including, without limitation, the implied
13 * warranties of merchantability and fitness for a particular
17 #include <sys/cdefs.h>
18 __FBSDID("$FreeBSD$");
20 #include <sys/param.h>
28 memcpy(void *dst
, const void *src
, int len
)
38 memset(void *b
, int c
, size_t len
)
43 *bp
++ = (unsigned char)c
;
47 memcmp(const void *b1
, const void *b2
, size_t len
)
49 const unsigned char *p1
, *p2
;
51 for (p1
= b1
, p2
= b2
; len
> 0; len
--, p1
++, p2
++) {
53 return ((*p1
) - (*p2
));
59 strcmp(const char *s1
, const char *s2
)
62 for (; *s1
== *s2
&& *s1
!= '\0'; s1
++, s2
++)
64 return ((unsigned char)*s1
- (unsigned char)*s2
);
68 strncmp(const char *s1
, const char *s2
, size_t len
)
71 for (; len
> 0 && *s1
== *s2
&& *s1
!= '\0'; len
--, s1
++, s2
++)
73 return (len
== 0 ? 0 : (unsigned char)*s1
- (unsigned char)*s2
);
77 strcpy(char *dst
, const char *src
)
86 strcat(char *dst
, const char *src
)
97 strchr(const char *s
, char ch
)
100 for (; *s
!= '\0'; s
++) {
102 return ((char *)(uintptr_t)(const void *)s
);
108 strlen(const char *s
)
118 printf(const char *fmt
, ...)
121 const char *hex
= "0123456789abcdef";
124 unsigned long long u
;
128 while ((c
= *fmt
++) != '\0') {
141 putchar(va_arg(ap
, int));
144 for (s
= va_arg(ap
, char *); *s
!= '\0'; s
++)
147 case 'S': /* Assume console can cope with wide chars */
148 for (S
= va_arg(ap
, uint16_t *); *S
!= 0; S
++)
151 case 'd': /* A lie, always prints unsigned */
156 u
= va_arg(ap
, unsigned long long);
159 u
= va_arg(ap
, unsigned long);
162 u
= va_arg(ap
, unsigned int);
166 if (c
== 'd' || c
== 'u') {
168 *s
++ = '0' + (u
% 10U);
172 *s
++ = hex
[u
& 0xfu
];