7 /* expand %m embedded in string to system error text
9 /* #include <percentm.h>
11 /* char *percentm(const char *src, int err)
13 /* The percentm() routine makes a copy of the null-terminated string
14 /* given via the \fIsrc\fR argument, with %m sequences replaced by
15 /* the system error text corresponding to the \fIerr\fR argument.
16 /* The result is overwritten upon each successive call.
20 /* A null-terminated input string with zero or more %m sequences.
22 /* A legal \fIerrno\fR value. The text corresponding to this error
23 /* value is used when expanding %m sequences.
25 /* syslog(3) system logger library
29 /* A percentm() routine appears in the TCP Wrapper software
34 /* The Secure Mailer license must be distributed with this software.
37 /* IBM T.J. Watson Research
39 /* Yorktown Heights, NY 10598, USA
42 /* System libraries. */
47 /* Utility library. */
52 /* percentm - replace %m by error message corresponding to value in err */
54 char *percentm(const char *str
, int err
)
57 const unsigned char *ip
= (const unsigned char *) str
;
60 vp
= vstring_alloc(100); /* grows on demand */
66 VSTRING_ADDCH(vp
, *ip
++);
70 default: /* leave %<any> alone */
71 VSTRING_ADDCH(vp
, *ip
++);
73 case '\0': /* don't fall off end */
74 VSTRING_ADDCH(vp
, *ip
++);
76 case 'm': /* replace %m */
77 vstring_strcat(vp
, strerror(err
));
83 VSTRING_TERMINATE(vp
);
84 return (vstring_str(vp
));