2 Return a string for a uuconf error.
4 Copyright (C) 1992 Ian Lance Taylor
6 This file is part of the Taylor UUCP uuconf library.
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public License
10 as published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details.
18 You should have received a copy of the GNU Library General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 The author of the program may be contacted at ian@airs.com or
23 c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
29 const char _uuconf_errstr_rcsid[] = "$FreeBSD$";
32 static char *zeprint_num P((char *zbuf, size_t cbuf, int ival));
34 /* Return an error string for a uuconf error. This does not return a
35 uuconf error code, but instead returns the total buffer length. */
38 uuconf_error_string (pglobal, ierr, zbuf, cbuf)
44 struct sglobal *qglobal = (struct sglobal *) pglobal;
58 /* The format of the message is
60 filename:lineno: message: errno
62 If there is no filename, the trailing colon is not output. If
63 there is no linenumber, the trailing colon is not output. If
64 there is no filename, the linenumber is not output, and neither
65 is the space before message. If there is no errno, the
66 preceeding colon and space are not output. */
68 /* Get the filename to put in the error message, if any. */
69 if ((ierr & UUCONF_ERROR_FILENAME) == 0
71 || qglobal->zfilename == NULL)
78 zfile = qglobal->zfilename;
79 cfile = strlen (zfile) + 1;
82 /* Get the line number to put in the error message, if any. */
84 || (ierr & UUCONF_ERROR_LINENO) == 0
86 || qglobal->ilineno <= 0)
93 zlineno = zeprint_num (ablineno, sizeof ablineno, qglobal->ilineno);
94 clineno = strlen (zlineno) + 1;
97 /* Get the main message. */
98 switch (UUCONF_ERROR_VALUE (ierr))
103 case UUCONF_NOT_FOUND:
106 case UUCONF_FOPEN_FAILED:
109 case UUCONF_FSEEK_FAILED:
112 case UUCONF_MALLOC_FAILED:
115 case UUCONF_SYNTAX_ERROR:
116 zmsg = "syntax error";
119 zmsg = zeprint_num (abmsg, sizeof abmsg, UUCONF_ERROR_VALUE (ierr));
120 zmsg -= sizeof "error " - 1;
121 memcpy ((pointer) zmsg, (pointer) "error ", sizeof "error " - 1);
125 cmsg = strlen (zmsg);
129 /* Get the errno string. Note that strerror is not necessarily
131 if ((ierr & UUCONF_ERROR_ERRNO) == 0
139 zerrno = strerror (qglobal->ierrno);
140 cerrno = strlen (zerrno) + 2;
143 cret = cfile + clineno + cmsg + cerrno + 1;
148 /* Leave room for the null byte. */
156 memcpy ((pointer) zbuf, (pointer) zfile, ccopy);
171 memcpy ((pointer) zbuf, (pointer) zlineno, ccopy);
181 if (cbuf > 0 && cfile > 0)
190 memcpy ((pointer) zbuf, (pointer) zmsg, ccopy);
209 memcpy ((pointer) zbuf, (pointer) zerrno, ccopy);
219 /* Turn a number into a string. This should really call sprintf, but
220 since nothing else in the uuconf library calls any print routine,
221 it's more interesting to not call it here either. */
224 zeprint_num (ab, c, i)