diff options
author | Yaakov Selkowitz <yselkowi@redhat.com> | 2011-05-18 05:25:41 +0400 |
---|---|---|
committer | Yaakov Selkowitz <yselkowi@redhat.com> | 2011-05-18 05:25:41 +0400 |
commit | d470b53c98d32d2371d8d5465f849be11f80a696 (patch) | |
tree | cc44f6b2bd2b0947a0efd04b919e9e6653e0f9e8 /winsup/cygwin/errno.cc | |
parent | 7dd9fa7ffbcda908ac3724d5c41a98213d5c0598 (diff) |
* cygwin.din (error): Export.
(error_at_line): Export.
(error_message_count): Export.
(error_one_per_line): Export.
(error_print_progname): Export.
* errno.cc (error_message_count): Define.
(error_one_per_line): Define.
(error_print_progname): Define.
(_verror): New static function.
(error): New function.
(error_at_line): New function.
* posix.sgml (std-gnu): Add error, error_at_line.
* include/error.h: New header.
* include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
Diffstat (limited to 'winsup/cygwin/errno.cc')
-rw-r--r-- | winsup/cygwin/errno.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/winsup/cygwin/errno.cc b/winsup/cygwin/errno.cc index 79ec048ed..e881fc649 100644 --- a/winsup/cygwin/errno.cc +++ b/winsup/cygwin/errno.cc @@ -13,6 +13,13 @@ details. */ #define sys_nerr FOOsys_nerr #define _sys_errlist FOO_sys_errlist #define strerror_r FOO_strerror_r +#define __INSIDE_CYGWIN__ +#include <errno.h> +#include <error.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> #include "winsup.h" #include "cygtls.h" #include "ntdll.h" @@ -417,3 +424,67 @@ __xpg_strerror_r (int errnum, char *buf, size_t n) strcpy (buf, error); return result; } + +unsigned int error_message_count = 0; +int error_one_per_line = 0; +void (*error_print_progname) (void) = NULL; + +static void +_verror (int status, int errnum, const char *filename, unsigned int lineno, const char *fmt, va_list ap) +{ + error_message_count++; + + fflush (stdout); + + if (error_print_progname) + (*error_print_progname) (); + else + fprintf (stderr, "%s:%s", program_invocation_name, filename ? "" : " "); + + if (filename) + fprintf (stderr, "%s:%d: ", filename, lineno); + + vfprintf (stderr, fmt, ap); + + if (errnum != 0) + fprintf (stderr, ": %s", strerror (errnum)); + + fprintf (stderr, "\n"); + + if (status != 0) + exit (status); +} + +extern "C" void +error (int status, int errnum, const char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + _verror (status, errnum, NULL, 0, fmt, ap); + va_end (ap); +} + +extern "C" void +error_at_line (int status, int errnum, const char *filename, unsigned int lineno, const char *fmt, ...) +{ + va_list ap; + + if (error_one_per_line != 0) + { + static const char *last_filename; + static unsigned int last_lineno; + + /* strcmp(3) will SEGV if filename or last_filename are NULL */ + if (lineno == last_lineno + && ((!filename && !last_filename) + || (filename && last_filename && strcmp (filename, last_filename) == 0))) + return; + + last_filename = filename; + last_lineno = lineno; + } + + va_start (ap, fmt); + _verror (status, errnum, filename, lineno, fmt, ap); + va_end (ap); +} |