blob: 231f2a80d7da54269004245e65c502598b06a7b7 [file] [log] [blame]
Sean Nelson74aa7722010-01-07 20:21:58 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2009 Sean Nelson <audiohacked@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <stdio.h>
22#include <stdarg.h>
23#include "flash.h"
24
Carl-Daniel Hailfinger901a3ba2012-05-14 22:54:58 +000025/* Please note that level is the verbosity, not the importance of the message. */
26int print(enum msglevel level, const char *fmt, ...)
Sean Nelson74aa7722010-01-07 20:21:58 +000027{
28 va_list ap;
Carl-Daniel Hailfinger901a3ba2012-05-14 22:54:58 +000029 int ret = 0;
30 FILE *output_type = stdout;
Uwe Hermann43959702010-03-13 17:28:29 +000031
Carl-Daniel Hailfinger901a3ba2012-05-14 22:54:58 +000032 if (level == MSG_ERROR)
Sean Nelson74aa7722010-01-07 20:21:58 +000033 output_type = stderr;
Uwe Hermann43959702010-03-13 17:28:29 +000034
Carl-Daniel Hailfinger901a3ba2012-05-14 22:54:58 +000035 if (level <= verbose) {
36 va_start(ap, fmt);
37 ret = vfprintf(output_type, fmt, ap);
38 va_end(ap);
39 /* msg_*spew usually happens inside chip accessors in possibly
40 * time-critical operations. Don't slow them down by flushing.
41 */
42 if (level != MSG_SPEW)
43 fflush(output_type);
44 }
Sean Nelson74aa7722010-01-07 20:21:58 +000045 return ret;
46}