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 #if !defined(HAVE_VSNPRINTF)
102 static inline int vsnprintf(char * buf, /*@unused@*/ int nb,
103 const char * fmt, va_list ap)
105 return vsprintf(buf, fmt, ap);
109 static void vrpmlog (unsigned code, const char *fmt, va_list ap)
111 int pri = RPMLOG_PRI(code);
112 int mask = RPMLOG_MASK(pri);
113 /*@unused@*/ int fac = RPMLOG_FAC(code);
115 int msgnb = BUFSIZ, nb;
116 FILE * msgout = stderr;
119 if ((mask & rpmlogMask) == 0)
122 msgbuf = xmalloc(msgnb);
125 /* Allocate a sufficently large buffer for output. */
128 nb = vsnprintf(msgbuf, msgnb, fmt, ap);
130 if (nb > -1 && nb < msgnb)
132 if (nb > -1) /* glibc 2.1 */
136 msgbuf = xrealloc(msgbuf, msgnb);
138 msgbuf[msgnb - 1] = '\0';
141 /* Save copy of all messages at warning (or below == "more important"). */
142 if (pri <= RPMLOG_WARNING) {
145 recs = xmalloc((nrecs+2) * sizeof(*recs));
147 recs = xrealloc(recs, (nrecs+2) * sizeof(*recs));
148 recs[nrecs+1].code = 0;
149 recs[nrecs+1].message = NULL;
154 rec->message = msgbuf;
157 if (_rpmlogCallback) {
161 return; /* XXX Preserve legacy rpmError behavior. */
165 /* rpmMessage behavior */
176 case RPMLOG_ERR: /* XXX Legacy rpmError behavior used stdout w/o prefix. */
182 /* Silly FORTRAN-like carriage control. */
185 else if (rpmlogMsgPrefix[pri] && *rpmlogMsgPrefix[pri])
186 fputs(_(rpmlogMsgPrefix[pri]), msgout);
192 if (pri <= RPMLOG_CRIT)
196 void rpmlog (int code, const char *fmt, ...)
201 vrpmlog(code, fmt, ap);
205 int rpmErrorCode(void)
210 const char * rpmErrorString(void)
212 return rpmlogMessage();
215 rpmlogCallback rpmErrorSetCallback(rpmlogCallback cb)
217 return rpmlogSetCallback(cb);