thr_printf.c (876d357fa7bc8aeb8d050dd8fe227dd4fd8ed4df) | thr_printf.c (3a7d122f969141c213b64afe9b0d7dd8412051b2) |
---|---|
1/*- 2 * Copyright (c) 2002 Jonathan Mini <mini@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 38 unchanged lines hidden (view full) --- 47 * %s -> string 48 * %u -> unsigned int (base 10) 49 * %x -> unsigned int (base 16) 50 * %p -> unsigned int (base 16) 51 */ 52void 53_thread_printf(int fd, const char *fmt, ...) 54{ | 1/*- 2 * Copyright (c) 2002 Jonathan Mini <mini@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 38 unchanged lines hidden (view full) --- 47 * %s -> string 48 * %u -> unsigned int (base 10) 49 * %x -> unsigned int (base 16) 50 * %p -> unsigned int (base 16) 51 */ 52void 53_thread_printf(int fd, const char *fmt, ...) 54{ |
55 va_list ap; 56 57 va_start(ap, fmt); 58 _thread_vprintf(fd, fmt, ap); 59 va_end(ap); 60} 61 62void 63_thread_vprintf(int fd, const char *fmt, va_list ap) 64{ |
|
55 static const char digits[16] = "0123456789abcdef"; | 65 static const char digits[16] = "0123456789abcdef"; |
56 va_list ap; | |
57 char buf[20]; 58 char *s; 59 unsigned long r, u; 60 int c; 61 long d; 62 int islong; 63 | 66 char buf[20]; 67 char *s; 68 unsigned long r, u; 69 int c; 70 long d; 71 int islong; 72 |
64 va_start(ap, fmt); | |
65 while ((c = *fmt++)) { 66 islong = 0; 67 if (c == '%') { 68next: c = *fmt++; 69 if (c == '\0') | 73 while ((c = *fmt++)) { 74 islong = 0; 75 if (c == '%') { 76next: c = *fmt++; 77 if (c == '\0') |
70 goto out; | 78 return; |
71 switch (c) { 72 case 'c': 73 pchar(fd, va_arg(ap, int)); 74 continue; 75 case 's': 76 pstr(fd, va_arg(ap, char *)); 77 continue; 78 case 'l': --- 27 unchanged lines hidden (view full) --- 106 } while (u /= r); 107 while (--s >= buf) 108 pchar(fd, *s); 109 continue; 110 } 111 } 112 pchar(fd, c); 113 } | 79 switch (c) { 80 case 'c': 81 pchar(fd, va_arg(ap, int)); 82 continue; 83 case 's': 84 pstr(fd, va_arg(ap, char *)); 85 continue; 86 case 'l': --- 27 unchanged lines hidden (view full) --- 114 } while (u /= r); 115 while (--s >= buf) 116 pchar(fd, *s); 117 continue; 118 } 119 } 120 pchar(fd, c); 121 } |
114out: 115 va_end(ap); | |
116} 117 118/* 119 * Write a single character to stdout, in a thread-safe manner. 120 */ 121static void 122pchar(int fd, char c) 123{ --- 14 unchanged lines hidden --- | 122} 123 124/* 125 * Write a single character to stdout, in a thread-safe manner. 126 */ 127static void 128pchar(int fd, char c) 129{ --- 14 unchanged lines hidden --- |