]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/boot/arm/at91/libat91/printf.c
Fix the return types for printf and putchar to match their libc and
[FreeBSD/FreeBSD.git] / sys / boot / arm / at91 / libat91 / printf.c
1 /*-
2  * Copyright (c) 1998 Robert Nordier
3  * All rights reserved.
4  * Copyright (c) 2006 M. Warner Losh
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms are freely
8  * permitted provided that the above copyright notice and this
9  * paragraph and the following disclaimer are duplicated in all
10  * such forms.
11  *
12  * This software is provided "AS IS" and without any express or
13  * implied warranties, including, without limitation, the implied
14  * warranties of merchantability and fitness for a particular
15  * purpose.
16  *
17  * $FreeBSD$
18  */
19
20 #include <stdarg.h>
21 #include "lib.h"
22
23 int
24 printf(const char *fmt,...)
25 {
26         va_list ap;
27         const char *hex = "0123456789abcdef";
28         char buf[10];
29         const char *fmt_orig = fmt;
30         char *s;
31         unsigned u;
32         int c;
33
34         va_start(ap, fmt);
35         while ((c = *fmt++)) {
36                 if (c == '%') {
37                         c = *fmt++;
38                         switch (c) {
39                         case 'c':
40                                 xputchar(va_arg(ap, int));
41                                 continue;
42                         case 's':
43                                 for (s = va_arg(ap, char *); *s; s++)
44                                         xputchar(*s);
45                                 continue;
46                         case 'd':       /* A lie, always prints unsigned */
47                         case 'u':
48                                 u = va_arg(ap, unsigned);
49                                 s = buf;
50                                 do
51                                         *s++ = '0' + u % 10U;
52                                 while (u /= 10U);
53                         dumpbuf:;
54                                 while (--s >= buf)
55                                         xputchar(*s);
56                                 continue;
57                         case 'x':
58                                 u = va_arg(ap, unsigned);
59                                 s = buf;
60                                 do
61                                         *s++ = hex[u & 0xfu];
62                                 while (u >>= 4);
63                                 goto dumpbuf;
64                         }
65                 }
66                 xputchar(c);
67         }
68         va_end(ap);
69
70         return (int)(fmt - fmt_orig);
71 }