#ifdef MACH_BSD
#include <sys/msgbuf.h>
#endif
+#include <console/serial_protos.h>
#ifdef __ppc__
#include <ppc/Firmware.h>
#define MAXBUF (sizeof(long long int) * 8) /* enough for binary */
static char digs[] = "0123456789abcdef";
+
+#if CONFIG_NO_PRINTF_STRINGS
+#undef printf(x, ...)
+#endif
+
static int
printnum(
- register unsigned long long int u, /* number to print */
- register int base,
+ unsigned long long int u, /* number to print */
+ int base,
void (*putc)(int, void *),
void *arg)
{
char buf[MAXBUF]; /* build number here */
- register char * p = &buf[MAXBUF-1];
+ char * p = &buf[MAXBUF-1];
int nprinted = 0;
do {
int
__doprnt(
- register const char *fmt,
+ const char *fmt,
va_list *argp,
/* character output routine */
void (*putc)(int, void *arg),
int sign_char;
boolean_t altfmt, truncate;
int base;
- register char c;
+ char c;
int capitals;
int long_long;
int nprinted = 0;
case 's':
{
- register char *p;
- register char *p2;
+ register const char *p;
+ register const char *p2;
if (prec == -1)
prec = 0x7fffffff; /* MAXINT */
p = va_arg(*argp, char *);
- if (p == (char *)0)
+ if (p == NULL)
p = "";
if (length > 0 && !ladjust) {
char buf[MAXBUF]; /* build number here */
register char * p = &buf[MAXBUF-1];
static char digits[] = "0123456789abcdef0123456789ABCDEF";
- char *prefix = 0;
+ const char *prefix = NULL;
if (truncate) u = (long long)((int)(u));
if (sign_char)
length--;
if (prefix)
- length -= strlen((const char *) prefix);
+ length -= strlen(prefix);
if (padc == ' ' && !ladjust) {
/* blank padding goes before prefix */
decl_simple_lock_data(,printf_lock)
decl_simple_lock_data(,bsd_log_spinlock)
-decl_mutex_data(,sprintf_lock)
extern void bsd_log_init(void);
void bsd_log_lock(void);
void bsd_log_unlock(void);
simple_lock_init(&printf_lock, 0);
simple_lock_init(&bsd_log_spinlock, 0);
bsd_log_init();
- mutex_init(&sprintf_lock, 0);
}
void
-bsd_log_lock()
+bsd_log_lock(void)
{
simple_lock(&bsd_log_spinlock);
}
void
-bsd_log_unlock()
+bsd_log_unlock(void)
{
simple_unlock(&bsd_log_spinlock);
}
}
}
+extern int disableConsoleOutput;
+
void
conslog_putc(
char c)
{
- extern unsigned int debug_mode, disableDebugOuput, disableConsoleOutput;
-
- if ((debug_mode && !disableDebugOuput) || !disableConsoleOutput)
+ if ((debug_mode && !disable_debug_output) || !disableConsoleOutput)
cnputc(c);
#ifdef MACH_BSD
#endif
}
+#if MACH_KDB
+extern void db_putchar(char c);
+#endif
+
void
-dbugprintf(const char *fmt, ...)
+dbugprintf(__unused const char *fmt, ...)
{
#if MACH_KDB
-
- extern void db_putchar(char c);
va_list listp;
va_start(listp, fmt);
return;
}
-void
+int
printf(const char *fmt, ...)
{
va_list listp;
- disable_preemption();
- va_start(listp, fmt);
- _doprnt(fmt, &listp, conslog_putc, 16);
- va_end(listp);
- enable_preemption();
+ if (fmt) {
+ disable_preemption();
+ va_start(listp, fmt);
+ _doprnt(fmt, &listp, conslog_putc, 16);
+ va_end(listp);
+ enable_preemption();
+ }
+ return 0;
}
-extern unsigned int disableSerialOuput;
-
void
-consdebug_putc(
- char c)
+consdebug_putc(char c)
{
- extern unsigned int debug_mode, disableDebugOuput, disableConsoleOutput;
-
- if ((debug_mode && !disableDebugOuput) || !disableConsoleOutput)
+ if ((debug_mode && !disable_debug_output) || !disableConsoleOutput)
cnputc(c);
debug_putc(c);
if (!console_is_serial())
- if (!disableSerialOuput)
+ if (!disable_serial_output)
PE_kputc(c);
}
-void
+int
kdb_printf(const char *fmt, ...)
{
va_list listp;
va_start(listp, fmt);
_doprnt(fmt, &listp, consdebug_putc, 16);
va_end(listp);
+ return 0;
}
-static char *copybyte_str;
-
static void
-copybyte(
- char byte)
+copybyte(int c, void *arg)
{
- *copybyte_str++ = byte;
- *copybyte_str = '\0';
+ /*
+ * arg is a pointer (outside pointer) to the pointer
+ * (inside pointer) which points to the character.
+ * We pass a double pointer, so that we can increment
+ * the inside pointer.
+ */
+ char** p = arg; /* cast outside pointer */
+ **p = c; /* store character */
+ (*p)++; /* increment inside pointer */
}
+/*
+ * Deprecation Warning:
+ * sprintf() is being deprecated. Please use snprintf() instead.
+ */
int
sprintf(char *buf, const char *fmt, ...)
{
va_list listp;
+ char *copybyte_str;
va_start(listp, fmt);
- mutex_lock(&sprintf_lock);
copybyte_str = buf;
- _doprnt(fmt, &listp, copybyte, 16);
- mutex_unlock(&sprintf_lock);
+ __doprnt(fmt, &listp, copybyte, ©byte_str, 16);
va_end(listp);
+ *copybyte_str = '\0';
return strlen(buf);
}