10 /*@access rpmlogRec @*/
13 static /*@only@*/ /*@null@*/ rpmlogRec recs = NULL;
15 int rpmlogGetNrecs(void)
23 return recs[nrecs-1].code;
28 const char * rpmlogMessage(void)
31 return recs[nrecs-1].message;
32 return _("(no error)");
35 void rpmlogPrint(FILE *f)
42 for (i = 0; i < nrecs; i++) {
43 rpmlogRec rec = recs + i;
44 if (rec->message && *rec->message)
45 fprintf(f, " %s", rec->message);
49 void rpmlogClose (void)
53 for (i = 0; i < nrecs; i++) {
54 rpmlogRec rec = recs + i;
56 free((void *)rec->message);
65 void rpmlogOpen (/*@unused@*/ const char *ident, /*@unused@*/ int option,
66 /*@unused@*/ int facility)
70 static int rpmlogMask = RPMLOG_UPTO( RPMLOG_NOTICE );
71 static /*@unused@*/ int rpmlogFacility = RPMLOG_USER;
73 int rpmlogSetMask (int mask)
75 int omask = rpmlogMask;
81 static /*@null@*/ rpmlogCallback _rpmlogCallback = NULL;
83 rpmlogCallback rpmlogSetCallback(rpmlogCallback cb)
85 rpmlogCallback ocb = _rpmlogCallback;
90 static char *rpmlogMsgPrefix[] = {
91 N_("fatal error: "),/*!< RPMLOG_EMERG */
92 N_("fatal error: "),/*!< RPMLOG_ALERT */
93 N_("fatal error: "),/*!< RPMLOG_CRIT */
94 N_("error: "), /*!< RPMLOG_ERR */
95 N_("warning: "), /*!< RPMLOG_WARNING */
96 "", /*!< RPMLOG_NOTICE */
97 "", /*!< RPMLOG_INFO */
98 "D: ", /*!< RPMLOG_DEBUG */
101 static void vrpmlog (unsigned code, const char *fmt, va_list ap)
103 int pri = RPMLOG_PRI(code);
104 int mask = RPMLOG_MASK(pri);
105 /*@unused@*/ int fac = RPMLOG_FAC(code);
107 int msgnb = BUFSIZ, nb;
108 FILE * msgout = stderr;
111 if ((mask & rpmlogMask) == 0)
114 msgbuf = xmalloc(msgnb);
117 /* Allocate a sufficently large buffer for output. */
120 nb = vsnprintf(msgbuf, msgnb, fmt, ap);
122 if (nb > -1 && nb < msgnb)
124 if (nb > -1) /* glibc 2.1 */
128 msgbuf = xrealloc(msgbuf, msgnb);
130 msgbuf[msgnb - 1] = '\0';
133 /* Save copy of all messages at warning (or below == "more important"). */
134 if (pri <= RPMLOG_WARNING) {
137 recs = xmalloc((nrecs+2) * sizeof(*recs));
139 recs = xrealloc(recs, (nrecs+2) * sizeof(*recs));
140 recs[nrecs+1].code = 0;
141 recs[nrecs+1].message = NULL;
146 rec->message = msgbuf;
149 if (_rpmlogCallback) {
153 return; /* XXX Preserve legacy rpmError behavior. */
157 /* rpmMessage behavior */
168 case RPMLOG_ERR: /* XXX Legacy rpmError behavior used stdout w/o prefix. */
174 /* Silly FORTRAN-like carriage control. */
177 else if (rpmlogMsgPrefix[pri] && *rpmlogMsgPrefix[pri])
178 fputs(_(rpmlogMsgPrefix[pri]), msgout);
184 if (pri <= RPMLOG_CRIT)
188 void rpmlog (int code, const char *fmt, ...)
193 vrpmlog(code, fmt, ap);
197 int rpmErrorCode(void)
202 const char * rpmErrorString(void)
204 return rpmlogMessage();
207 rpmlogCallback rpmErrorSetCallback(rpmlogCallback cb)
209 return rpmlogSetCallback(cb);