163
166
#endif /* ANDROID */
170
static EMSG_RECORD_DESC *emsg_record_desc_root; /* A root to the message records descriptior */
173
* DESCRIPTION: Message record compare routine
183
static int __msgcmp (const void *a, const void *b)
185
const EMSG_RECORD *m1 = a, *m2 = b;
188
return ( (int)m1->sts - (int)m2->sts);
193
* DESCRIPTION: Sorting message records according <sts> field as a key,
194
* link message records descriptor in to the global list.
195
* This routine is should be called once at task initialization time before any
196
* consecutive $GETMSG/$PUTMSG calls!
199
* emsg_record_desc_root
202
* msgdsc: Message Records Descriptior
211
* STS$K_WARN - non-principal error
214
unsigned __util$inimsg (EMSG_RECORD_DESC *msgdsc)
216
EMSG_RECORD_DESC *md;
221
/* At first level we try to find the message records descriptor by using facility number */
222
for (md = emsg_record_desc_root; md; md = md->link)
223
if ( md->facno == msgdsc->facno)
227
qsort(msgdsc->msgrec, msgdsc->msgnr, sizeof(EMSG_RECORD), __msgcmp);
229
msgdsc->link = emsg_record_desc_root;
230
emsg_record_desc_root = msgdsc;
232
return STS$K_SUCCESS;
237
* DESCRIPTION: Retreive message record by using message number code.
240
* emsg_record_desc_root
243
* sts: condition code/message number code
246
* outmsg: A found message record
249
* STS$K_SUCCESS - outmsg contains an address of the has been found mssage record
252
unsigned __util$getmsg (unsigned sts, EMSG_RECORD **outmsg )
255
EMSG_RECORD_DESC *msgdsc;
258
/* At first level we try to find the message records descriptor by using facility number */
260
for (msgdsc = emsg_record_desc_root; msgdsc; msgdsc = msgdsc->link)
261
if ( msgdsc->facno == facno)
265
return STS$K_ERROR; /* RNF */
267
/* We found message records descriptor for the facility,
268
* so we can try to find the message record with the given <msgno>
270
if ( !(msgrec = bsearch(&sts, msgdsc->msgrec, msgdsc->msgnr, sizeof(EMSG_RECORD), __msgcmp)) )
271
return STS$K_ERROR; /* RNF */
275
return STS$K_SUCCESS;
279
* DESCRIPTION: Format a message to be output on the SYS$OUTPUT by using a format from the message record
282
* emsg_record_desc_root
285
* sts: condition code/message number code
286
* ...: Additional parameters, according the FAO of the message
294
unsigned __util$putmsg
302
const char lfmt [] = "%02u-%02u-%04u %02u:%02u:%02u.%03u " PID_FMT " ";
303
const char defmsgfao[] = {"NONAME-%c-NOMSG, Message number %08X, fac=%#x/%d, sev=%#x/%d, msgno=%#x/%d"};
304
const char severity[]= { 'W', 'S', 'E', 'I', 'F', '?', '?', '?'};
305
char pref[128], out[1024];
309
struct iovec iov [3];
313
** Out to buffer "DD-MM-YYYY HH:MM:SS.msec <PID/TID> " prefix
318
localtime_s(&_tm, (time_t *)&now);
320
localtime_r((time_t *)&now, &_tm);
323
olen = snprintf (pref, sizeof(pref), lfmt, /* Format a prefix part of the message: time + PID ... */
324
_tm.tm_mday, _tm.tm_mon + 1, 1900 + _tm.tm_year,
325
_tm.tm_hour, _tm.tm_min, _tm.tm_sec, (unsigned) now.tv_nsec/TIMSPECDEVIDER,
326
(unsigned) gettid());
328
iov[0].iov_base = pref;
329
iov[0].iov_len = olen;
331
if ( 1 & __util$getmsg(sts, &msgrec) ) /* Retrive the message record */
333
va_start (arglist, sts); /* Fromat text message */
334
olen = vsnprintf(out, sizeof(out), msgrec->text, arglist);
337
else { /* Format text message with the default FAO */
339
olen = snprintf(out, sizeof(out), defmsgfao, severity[sev], sts,
340
$FAC(sts), $FAC(sts), sev, sev, $MSG(sts), $MSG(sts));
343
iov[1].iov_base = out;
344
iov[1].iov_len = olen;
347
/* Add <LF> at end of record*/
348
iov[2].iov_base = "\n";
351
/* Write to file and flush buffer depending on severity level */
352
writev (logoutput, iov, $ARRSZ(iov) );
354
/* ARL - for android logcat */
356
__android_log_print(ANDROID_LOG_VERBOSE, fac, "%.*s", olen, out);
168
365
* Description: a simplified analog of the C RTL syslog() routine is supposed to used to