Return a string for a uuconf error.
Copyright (C) 1992 Ian Lance Taylor
This file is part of the Taylor UUCP uuconf library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
as published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
The author of the program may be contacted at ian@airs.com or
c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
const char _uuconf_errstr_rcsid
[] = "$Id: errstr.c,v 1.1 1993/08/04 19:34:02 jtc Exp $";
static char *zeprint_num
P((char *zbuf
, size_t cbuf
, int ival
));
/* Return an error string for a uuconf error. This does not return a
uuconf error code, but instead returns the total buffer length. */
uuconf_error_string (pglobal
, ierr
, zbuf
, cbuf
)
struct sglobal
*qglobal
= (struct sglobal
*) pglobal
;
/* The format of the message is
filename:lineno: message: errno
If there is no filename, the trailing colon is not output. If
there is no linenumber, the trailing colon is not output. If
there is no filename, the linenumber is not output, and neither
is the space before message. If there is no errno, the
preceeding colon and space are not output. */
/* Get the filename to put in the error message, if any. */
if ((ierr
& UUCONF_ERROR_FILENAME
) == 0
|| qglobal
->zfilename
== NULL
)
zfile
= qglobal
->zfilename
;
cfile
= strlen (zfile
) + 1;
/* Get the line number to put in the error message, if any. */
|| (ierr
& UUCONF_ERROR_LINENO
) == 0
|| qglobal
->ilineno
<= 0)
zlineno
= zeprint_num (ablineno
, sizeof ablineno
, qglobal
->ilineno
);
clineno
= strlen (zlineno
) + 1;
/* Get the main message. */
switch (UUCONF_ERROR_VALUE (ierr
))
case UUCONF_FOPEN_FAILED
:
case UUCONF_FSEEK_FAILED
:
case UUCONF_MALLOC_FAILED
:
case UUCONF_SYNTAX_ERROR
:
zmsg
= zeprint_num (abmsg
, sizeof abmsg
, UUCONF_ERROR_VALUE (ierr
));
zmsg
-= sizeof "error " - 1;
memcpy ((pointer
) zmsg
, (pointer
) "error ", sizeof "error " - 1);
/* Get the errno string. Note that strerror is not necessarily
if ((ierr
& UUCONF_ERROR_ERRNO
) == 0
zerrno
= strerror (qglobal
->ierrno
);
cerrno
= strlen (zerrno
) + 2;
cret
= cfile
+ clineno
+ cmsg
+ cerrno
+ 1;
/* Leave room for the null byte. */
memcpy ((pointer
) zbuf
, (pointer
) zfile
, ccopy
);
memcpy ((pointer
) zbuf
, (pointer
) zlineno
, ccopy
);
if (cbuf
> 0 && cfile
> 0)
memcpy ((pointer
) zbuf
, (pointer
) zmsg
, ccopy
);
memcpy ((pointer
) zbuf
, (pointer
) zerrno
, ccopy
);
/* Turn a number into a string. This should really call sprintf, but
since nothing else in the uuconf library calls any print routine,
it's more interesting to not call it here either. */