Example #1
0
int
fprintf(FILE *iop, char *format, ...)
{
	unsigned char localbuf[BUFSIZ];
	int count;
	va_list ap;

	if (!(iop->_flag & _IOWRT)) {
		/* if no write flag */
		if (iop->_flag & _IORW) {
			/* if ok, cause read-write */
			iop->_flag |= _IOWRT;
		} else {
			/* else error */
			return EOF;
		}
	}
	va_start(ap, format);
	if (iop->_flag & _IONBF) {
		iop->_flag &= ~_IONBF;
		iop->_ptr = iop->_base = localbuf;
		iop->_bufsiz = BUFSIZ;
		count = _doprnt(format, ap, iop);
		fflush(iop);
		iop->_flag |= _IONBF;
		iop->_base = NULL;
		iop->_bufsiz = 0;
		iop->_cnt = 0;
	} else {
		count = _doprnt(format, ap, iop);
	}
	va_end(ap);
	return (count);
}
Example #2
0
void sysfatal(char * const s, ...)
{
    va_list ap;
    FILE *stream;

    stream = stderr;

    int err_num = errno;
    errno = 0;

    char *err_str = strerror(err_num);
    
    if (err_num == EEOF) {
	fprintf(stream, "%s: %s, ", tool_name, "unexpected end of file");
    }
    else if (errno == 0) {
	fprintf(stream, "%s: %s, ", tool_name, strerror(errno));
    }
    else {
	fprintf(stream, "%s: error code %d, ", tool_name, err_num);
    }

    va_start(ap, s);
    _doprnt(s, ap, stream);
    fprintf(stream, " [%s]", infile);
    fputs(".\n", stream);

    exit(1);
}
Example #3
0
void
panic(const char *str, ...)
{
	va_list	listp;
	spl_t	s;
	boolean_t	old_doprnt_hide_pointers = doprnt_hide_pointers;


	/* panic_caller is initialized to 0.  If set, don't change it */
	if ( ! panic_caller )
		panic_caller = (unsigned long)(char *)__builtin_return_address(0);
	
	s = panic_prologue(str);

	/* Never hide pointers from panic logs. */
	doprnt_hide_pointers = FALSE;

	kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller);
	if (str) {
		va_start(listp, str);
		_doprnt(str, &listp, consdebug_putc, 0);
		va_end(listp);
	}
	kdb_printf("\n");

	/*
	 * Release panicwait indicator so that other cpus may call Debugger().
	 */
	panicwait = 0;
	Debugger("panic");

	doprnt_hide_pointers = old_doprnt_hide_pointers;

	panic_epilogue(s);
}
Example #4
0
void
graph_error(const char *fmt, va_dcl)
#endif
{
#ifdef VA_START
    va_list args;
#endif

    multiplot = FALSE;
    term_end_plot();

#ifdef VA_START
    VA_START(args, fmt);
    /* HBB 20001120: instead, copy the core code from int_error() to
     * here: */
    PRINT_SPACES_UNDER_PROMPT;
    PRINT_FILE_AND_LINE;

# if defined(HAVE_VFPRINTF) || _LIBC
    vfprintf(stderr, fmt, args);
# else
    _doprnt(fmt, args, stderr);
# endif
    va_end(args);
    fputs("\n\n", stderr);

    bail_to_command_line();
    va_end(args);
#else
    int_error(NO_CARET, fmt, a1, a2, a3, a4, a5, a6, a7, a8);
#endif

}
Example #5
0
int my_snprintf(char *str, int n, char *f, ...)
{
	int i;
	va_list l;
	if (!n) return -1;
	va_start(l, f);
#ifdef HAVE_VPRINTF
	vsprintf(snprtintf_buffer, f, l);
#elif defined(HAVE_DOPRNT)
	{
		struct _iobuf strbuf;
		strbuf._flag = _IOWRT+_IOSTRG;
		strbuf._ptr = snprtintf_buffer;
		strbuf._cnt = 32767;
		_doprnt(f, l, &strbuf);
		putc('\0', &strbuf);
	}
#else
	fatal_exit("No vsprintf!");
#endif
	va_end(l);
	i = strlen(snprtintf_buffer);
	if (i >= B_SZ) {
		fatal_exit("String size too large!");
	}
	if (i >= n) {
		memcpy(str, snprtintf_buffer, n);
		str[n - 1] = 0;
		return -1;
	}
	strcpy(str, snprtintf_buffer);
	return i;
}
Example #6
0
void
int_error(int t_num, const char str[], va_dcl)
#endif
{
#ifdef VA_START
    va_list args;
#endif

    char error_message[128] = {'\0'};

    /* reprint line if screen has been written to */

    if (t_num == DATAFILE) {
	df_showdata();
    } else if (t_num != NO_CARET) { /* put caret under error */
	if (!screen_ok)
	    PRINT_MESSAGE_TO_STDERR;

	PRINT_SPACES_UNDER_PROMPT;
	PRINT_SPACES_UPTO_TOKEN;
	PRINT_CARET;
    }
    PRINT_SPACES_UNDER_PROMPT;
    PRINT_FILE_AND_LINE;

#ifdef VA_START
    VA_START(args, str);
# if defined(HAVE_VFPRINTF) || _LIBC
    vsnprintf(error_message, sizeof(error_message), str, args);
    fprintf(stderr,"%.120s",error_message);
# else
    _doprnt(str, args, stderr);
# endif
    va_end(args);
#else
    fprintf(stderr, str, a1, a2, a3, a4, a5, a6, a7, a8);
#ifdef HAVE_SNPRINTF
    snprintf(error_message, sizeof(error_message), str, a1, a2, a3, a4, a5, a6, a7, a8);
#else
    sprintf(error_message, str, a1, a2, a3, a4, a5, a6, a7, a8);
#endif
#endif

    fputs("\n\n", stderr);

    /* We are bailing out of nested context without ever reaching */
    /* the normal cleanup code. Reset any flags before bailing.   */
    df_reset_after_error();
    eval_reset_after_error();
    clause_reset_after_error();
    parse_reset_after_error();
    scanning_range_in_progress = FALSE;
    inside_zoom = FALSE;

    /* Load error state variables */
    update_gpval_variables(2);
    fill_gpval_string("GPVAL_ERRMSG", error_message);

    bail_to_command_line();
}
Example #7
0
int __nemo_dprintf(int debug, const_string fmt, ...)
{
    va_list ap;
    int nret = -1;
    static bool print_head = TRUE;

    if (debug <= debug_level) {		/* print this debug message? */

        /* START changes WD 12th June 2008 */
        if(print_head) {
	    if(mpi_proc)
	        fprintf(stderr,"### nemo Debug Info @%d: ",mpi_rank);
	    else
	        fprintf(stderr,"### nemo Debug Info: ");
	    if(debug_file && debug_level >= DEBUG_LEVEL_FOR_REPORTING_FILE)
	        fprintf(stderr,"[%s:%d]: ",debug_file,debug_line);
	}
	/* END   changes WD 12th June 2008 */

        va_start(ap, fmt);	
#if defined(NEED_DOPRNT)
	_doprnt(fmt, ap, stderr);	/*   use low-level interface */
#else
	nret= vfprintf(stderr, fmt, ap);/*   this should be ok on sun for now */
#endif
					/*   may become vprintf in ANSI C */
	fflush(stderr);			/*   drain std error buffer */
        va_end(ap);
	print_head = fmt && fmt[strlen(fmt)-1] == '\n';
    }
    return nret;
}
Example #8
0
void
panic(const char *errormsg, ...) {
    va_list list;
    kprintf("\nKERNEL PANIC: ");
    if (can_use_serial) {
        bool early = false;
        if (rdmsr64(MSR_IA32_GS_BASE) == 0 && enable == false) {
            early = true;
        }
        if (early) {
            va_start(list, errormsg);
            _doprnt_log(errormsg, &list, serial_putc, 16);
            va_end(list);
            goto panicing;
        } else {
        normal_print:
            va_start(list, errormsg);
            _doprnt(errormsg, &list, putc, 16);
            va_end(list);
            goto panicing;
        }
    } else {
        goto normal_print;
    }
panicing:
    kprintf("\nCPU Halted");
    pal_stop_cpu(true);
}
Example #9
0
  va_dcl
#else /*__STDC__*/
# include <stdarg.h>
# define VSTART(l,a)	va_start(l, a)
void
panic(const char *str, ...)
#endif /* __STDC__ */
{
  va_list iggy;

  fprintf(stderr, "%s: ", myname);
  VSTART(iggy, str);
#ifndef HAVE_VPRINTF
# ifndef HAVE_DOPRNT
  fputs(str, stderr);	/* not great, but perhaps better than nothing... */
# else /* HAVE_DOPRNT */
  _doprnt(str, &iggy, stderr);
# endif /* HAVE_DOPRNT */
#else /* HAVE_VFPRINTF */
  vfprintf(stderr, str, iggy);
#endif /* HAVE_VFPRINTF */
  va_end(iggy);
  putc('\n', stderr);
  exit(4);
}
Example #10
0
int
printf(const char *fmt, ...)
{
    int outsize;
    va_list ap;

    /* return failure if format is NULL pointer */ 
    if (!fmt)
        return -1;

    _LOCK_FILE(stdout);

    va_start(ap,fmt);
    outsize=_doprnt (fmt, ap, _theputchar, stdout);
    va_end(ap);

#if defined(__ADSP21000__)
    // Always flush output on SHARC, where streams aren't flushed at exit.
    _fflush(stdout);
#endif

    _UNLOCK_FILE(stdout);

    return outsize;
}
Example #11
0
void
panic_context(unsigned int reason, void *ctx, const char *str, ...)
{
	va_list	listp;
	spl_t	s;


	/* panic_caller is initialized to 0.  If set, don't change it */
	if ( ! panic_caller )
		panic_caller = (unsigned long)(char *)__builtin_return_address(0);
	
	s = panic_prologue(str);
	kdb_printf("panic(cpu %d caller 0x%lx): ", (unsigned) paniccpu, panic_caller);
	if (str) {
		va_start(listp, str);
		_doprnt(str, &listp, consdebug_putc, 0);
		va_end(listp);
	}
	kdb_printf("\n");

	/*
	 * Release panicwait indicator so that other cpus may call Debugger().
	 */
	panicwait = 0;
	DebuggerWithContext(reason, ctx, "panic");
	panic_epilogue(s);
}
Example #12
0
void kprintf(const char *fmt, ...)
{
	va_list   listp;
	boolean_t state;

	if (!disable_serial_output) {
		boolean_t early = FALSE;
		if (rdmsr64(MSR_IA32_GS_BASE) == 0) {
			early = TRUE;
		}
		/* If PE_kputc has not yet been initialized, don't
		 * take any locks, just dump to serial */
		if (!PE_kputc || early) {
			va_start(listp, fmt);
			_doprnt(fmt, &listp, pal_serial_putc, 16);
			va_end(listp);
			return;
		}

		/*
		 * Spin to get kprintf lock but re-enable interrupts while
		 * failing.
		 * This allows interrupts to be handled while waiting but
		 * interrupts are disabled once we have the lock.
		 */
		state = ml_set_interrupts_enabled(FALSE);

		pal_preemption_assert();

		while (!simple_lock_try(&kprintf_lock)) {
			ml_set_interrupts_enabled(state);
			ml_set_interrupts_enabled(FALSE);
		}

		if (cpu_number() != cpu_last_locked) {
			MP_DEBUG_KPRINTF("[cpu%d...]\n", cpu_number());
			cpu_last_locked = cpu_number();
		}

		va_start(listp, fmt);
		_doprnt(fmt, &listp, PE_kputc, 16);
		va_end(listp);

		simple_unlock(&kprintf_lock);
		ml_set_interrupts_enabled(state);
	}
}
Example #13
0
static void _kprintf(const char *format, ...)
{
	va_list   listp;

        va_start(listp, format);
        _doprnt(format, &listp, PE_kputc, 16);
        va_end(listp);
}
Example #14
0
int cons_vprintf(const char *fmt, va_list args)
{
	int len = 0;
	
	_doprnt(fmt, args, 0, (void (*)()) writechar_cons, (char *)&len);
	
	return len;
}
Example #15
0
void
kdbprintf(char *fmt, ...)
{
	va_list	listp;

	va_start(listp, fmt);
	_doprnt(fmt, &listp, db_putchar, db_radix);
	va_end(listp);
}
Example #16
0
/*------------------------------------------------------------------------
 * kprintf  -  use polled I/O to print formatted output on the console
 *------------------------------------------------------------------------
 */
syscall kprintf(char *fmt, ...)
{
	va_list ap;

	va_start(ap, fmt);
	_doprnt(fmt, ap, (int (*)(int))kputc);
	va_end(ap);
	return OK;
}
Example #17
0
/**
 * kernel printf: formatted, unbuffered output to SERIAL0
 * @param *fmt pointer to string being printed
 * @return OK on success
 */
syscall kprintf(char *fmt, ...)
{
    va_list ap;

    va_start(ap, fmt);
    _doprnt(fmt, ap, (int (*)(int, int))kputc, (int)&devtab[SERIAL0]);
    va_end(ap);
    return OK;
}
Example #18
0
/*------------------------------------------------------------------------
 *  kprintf  --  kernel printf: formatted, unbuffered output to CONSOLE
 *------------------------------------------------------------------------
 */
int kprintf(char *fmt, int args)
{
	STATWORD	ps;

	disable(ps);
        _doprnt(fmt, &args, (void *)kputc, CONSOLE);
	restore(ps);
        return OK;
}
Example #19
0
void ptyPrintf(int ptyId, const char *fmt, ...) {
	/* Wait for the pty to become active */
	while(ptyId != activePtyId);
	
	va_list ap;
    
    va_start(ap, fmt);
    _doprnt((char *)fmt, ap, putc, stdout);
    va_end(ap);
}
Example #20
0
int
printf (const char * format, ...)
{
  va_list args;

  va_start(args,format);
  int n =_doprnt(format,args,__printf_char,0);
  va_end(args);

  return n;
}
Example #21
0
//------------------------------------------------------------------------
//  fprintf  --  print a formatted message on specified device (file)
//------------------------------------------------------------------------
int
fprintf(int dev, const char *fmt, ...)
{
	va_list args;

	va_start(args, fmt);
	_doprnt(fmt, args, putc, dev);
	va_end(args);

	return OK;
}
Example #22
0
/**
 * Print a formatted message on specified device (file)
 * @param dev device to write to
 * @param *fmt format string
 */
int fprintf(int dev, char *fmt, ...)
{
	va_list ap;
	int putc(int, char);

	va_start(ap, fmt);
    _doprnt(fmt, ap, putc, dev);
	va_end(ap);

    return OK;
}
Example #23
0
void
os_error(int t_num, const char *str, va_dcl)
#endif
{
#ifdef VA_START
    va_list args;
#endif
#ifdef VMS
    static status[2] = { 1, 0 };		/* 1 is count of error msgs */
#endif /* VMS */

    /* reprint line if screen has been written to */

    if (t_num == DATAFILE) {
        df_showdata();
    } else if (t_num != NO_CARET) {	/* put caret under error */
        if (!screen_ok)
            PRINT_MESSAGE_TO_STDERR;

        PRINT_SPACES_UNDER_PROMPT;
        PRINT_SPACES_UPTO_TOKEN;
        PRINT_CARET;
    }
    PRINT_SPACES_UNDER_PROMPT;

#ifdef VA_START
    VA_START(args, str);
# if defined(HAVE_VFPRINTF) || _LIBC
    vfprintf(stderr, str, args);
# else
    _doprnt(str, args, stderr);
# endif
    va_end(args);
#else
    fprintf(stderr, str, a1, a2, a3, a4, a5, a6, a7, a8);
#endif
    putc('\n', stderr);

    PRINT_SPACES_UNDER_PROMPT;
    PRINT_FILE_AND_LINE;

#ifdef VMS
    status[1] = vaxc$errno;
    sys$putmsg(status);
    (void) putc('\n', stderr);
#else /* VMS */
    perror("util.c");
    putc('\n', stderr);
#endif /* VMS */

    scanning_range_in_progress = FALSE;

    bail_to_command_line();
}
Example #24
0
static int
checkit (const char* format, ...)
{
  int result;
  va_list args;
  va_start (args, format);

  result = _doprnt (format, args, stdout);
  va_end (args);

  return result;
}
Example #25
0
int vsprintf(char *s, const char *fmt, va_list args)
{
	struct sprintf_state state;
	state.max = SPRINTF_UNLIMITED;
	state.len = 0;
	state.buf = s;

	_doprnt(fmt, args, 0, (void (*)()) savechar, (char *) &state);
	*(state.buf) = '\0';

	return state.len;
}
Example #26
0
int
fprintf (register FILE *iop, const char *fmt, ...)
{
	va_list ap;

	va_start (ap, fmt);
	if (iop->_flag & _IONBF) {
		iop->_flag &= ~_IONBF;
		iop->_ptr = iop->_base = alloca(BUFSIZ);
		iop->_bufsiz = BUFSIZ;
		_doprnt(fmt, ap, iop);
		fflush(iop);
		iop->_flag |= _IONBF;
		iop->_base = NULL;
		iop->_bufsiz = NULL;
		iop->_cnt = 0;
	} else
		_doprnt(fmt, ap, iop);
	va_end (ap);
	return(ferror(iop)? EOF: 0);
}
Example #27
0
int vsnprintf(char *s, int size, const char *fmt, va_list args)
{
	struct sprintf_state state;
	state.max = size - 1;
	state.len = 0;
	state.buf = s;

	_doprnt(fmt, args, 0, (void (*)()) savechar, (char *) &state);
	*(state.buf) = '\0';

	return state.len;
}
Example #28
0
/*
 * Printing (to console)
 */
int vfprintf(FILE *stream, const char *fmt, va_list args)
{
	struct printf_state state;

	state.stream = stream;
	state.index = 0;
	_doprnt(fmt, args, 0, (void (*)())dochar, (char *) &state);

	flush(&state);

	return 0;
}
Example #29
0
static int
checkit (const char* format, ...)
{
  int result;
  VA_OPEN (args, format);
  VA_FIXEDARG (args, char *, format);

  result = _doprnt (format, args, stdout);
  VA_CLOSE (args);

  return result;
}
Example #30
0
/*------------------------------------------------------------------------
 *  kprintf  --  kernel printf: formatted, unbuffered output to CONSOLE
 *------------------------------------------------------------------------
 */
int kprintf(char * fmt, ...)
{
  //	unsigned int	saveof;

  va_list ap;
  va_start(ap, fmt);
  
    //  _doprnt(fmt, &args, kputc, 0);

    _doprnt(fmt, (void *) ap,  kputc, 0);
  return 1;
}