xref: /dragonfly/contrib/grep/lib/error.c (revision 09d4459f)
195b7b453SJohn Marino /* Error handler for noninteractive utilities
2*09d4459fSDaniel Fojt    Copyright (C) 1990-1998, 2000-2007, 2009-2020 Free Software Foundation, Inc.
395b7b453SJohn Marino    This file is part of the GNU C Library.
495b7b453SJohn Marino 
595b7b453SJohn Marino    This program is free software: you can redistribute it and/or modify
695b7b453SJohn Marino    it under the terms of the GNU General Public License as published by
795b7b453SJohn Marino    the Free Software Foundation; either version 3 of the License, or
895b7b453SJohn Marino    (at your option) any later version.
995b7b453SJohn Marino 
1095b7b453SJohn Marino    This program is distributed in the hope that it will be useful,
1195b7b453SJohn Marino    but WITHOUT ANY WARRANTY; without even the implied warranty of
1295b7b453SJohn Marino    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1395b7b453SJohn Marino    GNU General Public License for more details.
1495b7b453SJohn Marino 
1595b7b453SJohn Marino    You should have received a copy of the GNU General Public License
16*09d4459fSDaniel Fojt    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
1795b7b453SJohn Marino 
1895b7b453SJohn Marino /* Written by David MacKenzie <djm@gnu.ai.mit.edu>.  */
1995b7b453SJohn Marino 
2095b7b453SJohn Marino #if !_LIBC
2195b7b453SJohn Marino # include <config.h>
2295b7b453SJohn Marino #endif
2395b7b453SJohn Marino 
2495b7b453SJohn Marino #include "error.h"
2595b7b453SJohn Marino 
2695b7b453SJohn Marino #include <stdarg.h>
2795b7b453SJohn Marino #include <stdio.h>
2895b7b453SJohn Marino #include <stdlib.h>
2995b7b453SJohn Marino #include <string.h>
3095b7b453SJohn Marino 
3195b7b453SJohn Marino #if !_LIBC && ENABLE_NLS
3295b7b453SJohn Marino # include "gettext.h"
3395b7b453SJohn Marino # define _(msgid) gettext (msgid)
3495b7b453SJohn Marino #endif
3595b7b453SJohn Marino 
3695b7b453SJohn Marino #ifdef _LIBC
3795b7b453SJohn Marino # include <libintl.h>
3895b7b453SJohn Marino # include <stdbool.h>
3995b7b453SJohn Marino # include <stdint.h>
4095b7b453SJohn Marino # include <wchar.h>
4195b7b453SJohn Marino # define mbsrtowcs __mbsrtowcs
42dc7c36e4SJohn Marino # define USE_UNLOCKED_IO 0
43dc7c36e4SJohn Marino # define _GL_ATTRIBUTE_FORMAT_PRINTF(a, b)
44dc7c36e4SJohn Marino # define _GL_ARG_NONNULL(a)
45*09d4459fSDaniel Fojt #else
46*09d4459fSDaniel Fojt # include "getprogname.h"
4795b7b453SJohn Marino #endif
4895b7b453SJohn Marino 
4995b7b453SJohn Marino #if USE_UNLOCKED_IO
5095b7b453SJohn Marino # include "unlocked-io.h"
5195b7b453SJohn Marino #endif
5295b7b453SJohn Marino 
5395b7b453SJohn Marino #ifndef _
5495b7b453SJohn Marino # define _(String) String
5595b7b453SJohn Marino #endif
5695b7b453SJohn Marino 
5795b7b453SJohn Marino /* If NULL, error will flush stdout, then print on stderr the program
5895b7b453SJohn Marino    name, a colon and a space.  Otherwise, error will call this
5995b7b453SJohn Marino    function without parameters instead.  */
6095b7b453SJohn Marino void (*error_print_progname) (void);
6195b7b453SJohn Marino 
62cf28ed85SJohn Marino /* This variable is incremented each time 'error' is called.  */
6395b7b453SJohn Marino unsigned int error_message_count;
6495b7b453SJohn Marino 
6595b7b453SJohn Marino #ifdef _LIBC
6695b7b453SJohn Marino /* In the GNU C library, there is a predefined variable for this.  */
6795b7b453SJohn Marino 
6895b7b453SJohn Marino # define program_name program_invocation_name
6995b7b453SJohn Marino # include <errno.h>
7095b7b453SJohn Marino # include <limits.h>
7195b7b453SJohn Marino # include <libio/libioP.h>
7295b7b453SJohn Marino 
73cf28ed85SJohn Marino /* In GNU libc we want do not want to use the common name 'error' directly.
7495b7b453SJohn Marino    Instead make it a weak alias.  */
7595b7b453SJohn Marino extern void __error (int status, int errnum, const char *message, ...)
7695b7b453SJohn Marino      __attribute__ ((__format__ (__printf__, 3, 4)));
7795b7b453SJohn Marino extern void __error_at_line (int status, int errnum, const char *file_name,
7895b7b453SJohn Marino                              unsigned int line_number, const char *message,
7995b7b453SJohn Marino                              ...)
80dc7c36e4SJohn Marino      __attribute__ ((__format__ (__printf__, 5, 6)));
8195b7b453SJohn Marino # define error __error
8295b7b453SJohn Marino # define error_at_line __error_at_line
8395b7b453SJohn Marino 
8495b7b453SJohn Marino # include <libio/iolibio.h>
85dc7c36e4SJohn Marino # define fflush(s) _IO_fflush (s)
8695b7b453SJohn Marino # undef putc
87dc7c36e4SJohn Marino # define putc(c, fp) _IO_putc (c, fp)
8895b7b453SJohn Marino 
8995b7b453SJohn Marino # include <bits/libc-lock.h>
9095b7b453SJohn Marino 
9195b7b453SJohn Marino #else /* not _LIBC */
9295b7b453SJohn Marino 
9395b7b453SJohn Marino # include <fcntl.h>
9495b7b453SJohn Marino # include <unistd.h>
9595b7b453SJohn Marino 
96*09d4459fSDaniel Fojt # if defined _WIN32 && ! defined __CYGWIN__
97cf28ed85SJohn Marino /* Get declarations of the native Windows API functions.  */
9895b7b453SJohn Marino #  define WIN32_LEAN_AND_MEAN
9995b7b453SJohn Marino #  include <windows.h>
100cf28ed85SJohn Marino /* Get _get_osfhandle.  */
101*09d4459fSDaniel Fojt #  if GNULIB_MSVC_NOTHROW
102cf28ed85SJohn Marino #   include "msvc-nothrow.h"
103*09d4459fSDaniel Fojt #  else
104*09d4459fSDaniel Fojt #   include <io.h>
105*09d4459fSDaniel Fojt #  endif
10695b7b453SJohn Marino # endif
10795b7b453SJohn Marino 
10895b7b453SJohn Marino /* The gnulib override of fcntl is not needed in this file.  */
10995b7b453SJohn Marino # undef fcntl
11095b7b453SJohn Marino 
111*09d4459fSDaniel Fojt # if !(GNULIB_STRERROR_R_POSIX || HAVE_DECL_STRERROR_R)
11295b7b453SJohn Marino #  ifndef HAVE_DECL_STRERROR_R
11395b7b453SJohn Marino "this configure-time declaration test was not run"
11495b7b453SJohn Marino #  endif
115200fbe8dSJohn Marino #  if STRERROR_R_CHAR_P
116*09d4459fSDaniel Fojt char *strerror_r (int errnum, char *buf, size_t buflen);
117200fbe8dSJohn Marino #  else
118*09d4459fSDaniel Fojt int strerror_r (int errnum, char *buf, size_t buflen);
119200fbe8dSJohn Marino #  endif
12095b7b453SJohn Marino # endif
12195b7b453SJohn Marino 
122*09d4459fSDaniel Fojt # define program_name getprogname ()
12395b7b453SJohn Marino 
124*09d4459fSDaniel Fojt # if GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r
12595b7b453SJohn Marino #  define __strerror_r strerror_r
126*09d4459fSDaniel Fojt # endif /* GNULIB_STRERROR_R_POSIX || HAVE_STRERROR_R || defined strerror_r */
12795b7b453SJohn Marino #endif  /* not _LIBC */
12895b7b453SJohn Marino 
12995b7b453SJohn Marino #if !_LIBC
13095b7b453SJohn Marino /* Return non-zero if FD is open.  */
131680a9cb8SJohn Marino static int
is_open(int fd)13295b7b453SJohn Marino is_open (int fd)
13395b7b453SJohn Marino {
134*09d4459fSDaniel Fojt # if defined _WIN32 && ! defined __CYGWIN__
135cf28ed85SJohn Marino   /* On native Windows: The initial state of unassigned standard file
136cf28ed85SJohn Marino      descriptors is that they are open but point to an INVALID_HANDLE_VALUE.
137cf28ed85SJohn Marino      There is no fcntl, and the gnulib replacement fcntl does not support
138cf28ed85SJohn Marino      F_GETFL.  */
13995b7b453SJohn Marino   return (HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE;
14095b7b453SJohn Marino # else
14195b7b453SJohn Marino #  ifndef F_GETFL
14295b7b453SJohn Marino #   error Please port fcntl to your platform
14395b7b453SJohn Marino #  endif
14495b7b453SJohn Marino   return 0 <= fcntl (fd, F_GETFL);
14595b7b453SJohn Marino # endif
14695b7b453SJohn Marino }
14795b7b453SJohn Marino #endif
14895b7b453SJohn Marino 
149680a9cb8SJohn Marino static void
flush_stdout(void)15095b7b453SJohn Marino flush_stdout (void)
15195b7b453SJohn Marino {
15295b7b453SJohn Marino #if !_LIBC
15395b7b453SJohn Marino   int stdout_fd;
15495b7b453SJohn Marino 
15595b7b453SJohn Marino # if GNULIB_FREOPEN_SAFER
15695b7b453SJohn Marino   /* Use of gnulib's freopen-safer module normally ensures that
15795b7b453SJohn Marino        fileno (stdout) == 1
15895b7b453SJohn Marino      whenever stdout is open.  */
15995b7b453SJohn Marino   stdout_fd = STDOUT_FILENO;
16095b7b453SJohn Marino # else
16195b7b453SJohn Marino   /* POSIX states that fileno (stdout) after fclose is unspecified.  But in
16295b7b453SJohn Marino      practice it is not a problem, because stdout is statically allocated and
16395b7b453SJohn Marino      the fd of a FILE stream is stored as a field in its allocated memory.  */
16495b7b453SJohn Marino   stdout_fd = fileno (stdout);
16595b7b453SJohn Marino # endif
16695b7b453SJohn Marino   /* POSIX states that fflush (stdout) after fclose is unspecified; it
16795b7b453SJohn Marino      is safe in glibc, but not on all other platforms.  fflush (NULL)
16895b7b453SJohn Marino      is always defined, but too draconian.  */
16995b7b453SJohn Marino   if (0 <= stdout_fd && is_open (stdout_fd))
17095b7b453SJohn Marino #endif
17195b7b453SJohn Marino     fflush (stdout);
17295b7b453SJohn Marino }
17395b7b453SJohn Marino 
17495b7b453SJohn Marino static void
print_errno_message(int errnum)17595b7b453SJohn Marino print_errno_message (int errnum)
17695b7b453SJohn Marino {
17795b7b453SJohn Marino   char const *s;
17895b7b453SJohn Marino 
179*09d4459fSDaniel Fojt #if _LIBC || GNULIB_STRERROR_R_POSIX || defined HAVE_STRERROR_R
18095b7b453SJohn Marino   char errbuf[1024];
181*09d4459fSDaniel Fojt # if _LIBC || (!GNULIB_STRERROR_R_POSIX && STRERROR_R_CHAR_P)
18295b7b453SJohn Marino   s = __strerror_r (errnum, errbuf, sizeof errbuf);
18395b7b453SJohn Marino # else
18495b7b453SJohn Marino   if (__strerror_r (errnum, errbuf, sizeof errbuf) == 0)
18595b7b453SJohn Marino     s = errbuf;
18695b7b453SJohn Marino   else
18795b7b453SJohn Marino     s = 0;
18895b7b453SJohn Marino # endif
18995b7b453SJohn Marino #else
19095b7b453SJohn Marino   s = strerror (errnum);
19195b7b453SJohn Marino #endif
19295b7b453SJohn Marino 
19395b7b453SJohn Marino #if !_LIBC
19495b7b453SJohn Marino   if (! s)
19595b7b453SJohn Marino     s = _("Unknown system error");
19695b7b453SJohn Marino #endif
19795b7b453SJohn Marino 
19895b7b453SJohn Marino #if _LIBC
19995b7b453SJohn Marino   __fxprintf (NULL, ": %s", s);
20095b7b453SJohn Marino #else
20195b7b453SJohn Marino   fprintf (stderr, ": %s", s);
20295b7b453SJohn Marino #endif
20395b7b453SJohn Marino }
20495b7b453SJohn Marino 
205680a9cb8SJohn Marino static void _GL_ATTRIBUTE_FORMAT_PRINTF (3, 0) _GL_ARG_NONNULL ((3))
error_tail(int status,int errnum,const char * message,va_list args)20695b7b453SJohn Marino error_tail (int status, int errnum, const char *message, va_list args)
20795b7b453SJohn Marino {
20895b7b453SJohn Marino #if _LIBC
20995b7b453SJohn Marino   if (_IO_fwide (stderr, 0) > 0)
21095b7b453SJohn Marino     {
21195b7b453SJohn Marino       size_t len = strlen (message) + 1;
21295b7b453SJohn Marino       wchar_t *wmessage = NULL;
21395b7b453SJohn Marino       mbstate_t st;
21495b7b453SJohn Marino       size_t res;
21595b7b453SJohn Marino       const char *tmp;
21695b7b453SJohn Marino       bool use_malloc = false;
21795b7b453SJohn Marino 
21895b7b453SJohn Marino       while (1)
21995b7b453SJohn Marino         {
22095b7b453SJohn Marino           if (__libc_use_alloca (len * sizeof (wchar_t)))
22195b7b453SJohn Marino             wmessage = (wchar_t *) alloca (len * sizeof (wchar_t));
22295b7b453SJohn Marino           else
22395b7b453SJohn Marino             {
22495b7b453SJohn Marino               if (!use_malloc)
22595b7b453SJohn Marino                 wmessage = NULL;
22695b7b453SJohn Marino 
22795b7b453SJohn Marino               wchar_t *p = (wchar_t *) realloc (wmessage,
22895b7b453SJohn Marino                                                 len * sizeof (wchar_t));
22995b7b453SJohn Marino               if (p == NULL)
23095b7b453SJohn Marino                 {
23195b7b453SJohn Marino                   free (wmessage);
23295b7b453SJohn Marino                   fputws_unlocked (L"out of memory\n", stderr);
23395b7b453SJohn Marino                   return;
23495b7b453SJohn Marino                 }
23595b7b453SJohn Marino               wmessage = p;
23695b7b453SJohn Marino               use_malloc = true;
23795b7b453SJohn Marino             }
23895b7b453SJohn Marino 
23995b7b453SJohn Marino           memset (&st, '\0', sizeof (st));
24095b7b453SJohn Marino           tmp = message;
24195b7b453SJohn Marino 
24295b7b453SJohn Marino           res = mbsrtowcs (wmessage, &tmp, len, &st);
24395b7b453SJohn Marino           if (res != len)
24495b7b453SJohn Marino             break;
24595b7b453SJohn Marino 
246dc7c36e4SJohn Marino           if (__builtin_expect (len >= SIZE_MAX / sizeof (wchar_t) / 2, 0))
24795b7b453SJohn Marino             {
24895b7b453SJohn Marino               /* This really should not happen if everything is fine.  */
24995b7b453SJohn Marino               res = (size_t) -1;
25095b7b453SJohn Marino               break;
25195b7b453SJohn Marino             }
25295b7b453SJohn Marino 
25395b7b453SJohn Marino           len *= 2;
25495b7b453SJohn Marino         }
25595b7b453SJohn Marino 
25695b7b453SJohn Marino       if (res == (size_t) -1)
25795b7b453SJohn Marino         {
25895b7b453SJohn Marino           /* The string cannot be converted.  */
25995b7b453SJohn Marino           if (use_malloc)
26095b7b453SJohn Marino             {
26195b7b453SJohn Marino               free (wmessage);
26295b7b453SJohn Marino               use_malloc = false;
26395b7b453SJohn Marino             }
26495b7b453SJohn Marino           wmessage = (wchar_t *) L"???";
26595b7b453SJohn Marino         }
26695b7b453SJohn Marino 
26795b7b453SJohn Marino       __vfwprintf (stderr, wmessage, args);
26895b7b453SJohn Marino 
26995b7b453SJohn Marino       if (use_malloc)
27095b7b453SJohn Marino         free (wmessage);
27195b7b453SJohn Marino     }
27295b7b453SJohn Marino   else
27395b7b453SJohn Marino #endif
27495b7b453SJohn Marino     vfprintf (stderr, message, args);
27595b7b453SJohn Marino 
27695b7b453SJohn Marino   ++error_message_count;
27795b7b453SJohn Marino   if (errnum)
27895b7b453SJohn Marino     print_errno_message (errnum);
27995b7b453SJohn Marino #if _LIBC
28095b7b453SJohn Marino   __fxprintf (NULL, "\n");
28195b7b453SJohn Marino #else
28295b7b453SJohn Marino   putc ('\n', stderr);
28395b7b453SJohn Marino #endif
28495b7b453SJohn Marino   fflush (stderr);
28595b7b453SJohn Marino   if (status)
28695b7b453SJohn Marino     exit (status);
28795b7b453SJohn Marino }
28895b7b453SJohn Marino 
28995b7b453SJohn Marino 
29095b7b453SJohn Marino /* Print the program name and error message MESSAGE, which is a printf-style
29195b7b453SJohn Marino    format string with optional args.
29295b7b453SJohn Marino    If ERRNUM is nonzero, print its corresponding system error message.
29395b7b453SJohn Marino    Exit with status STATUS if it is nonzero.  */
29495b7b453SJohn Marino void
error(int status,int errnum,const char * message,...)29595b7b453SJohn Marino error (int status, int errnum, const char *message, ...)
29695b7b453SJohn Marino {
29795b7b453SJohn Marino   va_list args;
29895b7b453SJohn Marino 
29995b7b453SJohn Marino #if defined _LIBC && defined __libc_ptf_call
30095b7b453SJohn Marino   /* We do not want this call to be cut short by a thread
30195b7b453SJohn Marino      cancellation.  Therefore disable cancellation for now.  */
30295b7b453SJohn Marino   int state = PTHREAD_CANCEL_ENABLE;
30395b7b453SJohn Marino   __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
30495b7b453SJohn Marino                    0);
30595b7b453SJohn Marino #endif
30695b7b453SJohn Marino 
30795b7b453SJohn Marino   flush_stdout ();
30895b7b453SJohn Marino #ifdef _LIBC
30995b7b453SJohn Marino   _IO_flockfile (stderr);
31095b7b453SJohn Marino #endif
31195b7b453SJohn Marino   if (error_print_progname)
31295b7b453SJohn Marino     (*error_print_progname) ();
31395b7b453SJohn Marino   else
31495b7b453SJohn Marino     {
31595b7b453SJohn Marino #if _LIBC
31695b7b453SJohn Marino       __fxprintf (NULL, "%s: ", program_name);
31795b7b453SJohn Marino #else
31895b7b453SJohn Marino       fprintf (stderr, "%s: ", program_name);
31995b7b453SJohn Marino #endif
32095b7b453SJohn Marino     }
32195b7b453SJohn Marino 
32295b7b453SJohn Marino   va_start (args, message);
32395b7b453SJohn Marino   error_tail (status, errnum, message, args);
324*09d4459fSDaniel Fojt   va_end (args);
32595b7b453SJohn Marino 
32695b7b453SJohn Marino #ifdef _LIBC
32795b7b453SJohn Marino   _IO_funlockfile (stderr);
32895b7b453SJohn Marino # ifdef __libc_ptf_call
32995b7b453SJohn Marino   __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
33095b7b453SJohn Marino # endif
33195b7b453SJohn Marino #endif
33295b7b453SJohn Marino }
33395b7b453SJohn Marino 
33495b7b453SJohn Marino /* Sometimes we want to have at most one error per line.  This
33595b7b453SJohn Marino    variable controls whether this mode is selected or not.  */
33695b7b453SJohn Marino int error_one_per_line;
33795b7b453SJohn Marino 
33895b7b453SJohn Marino void
error_at_line(int status,int errnum,const char * file_name,unsigned int line_number,const char * message,...)33995b7b453SJohn Marino error_at_line (int status, int errnum, const char *file_name,
34095b7b453SJohn Marino                unsigned int line_number, const char *message, ...)
34195b7b453SJohn Marino {
34295b7b453SJohn Marino   va_list args;
34395b7b453SJohn Marino 
34495b7b453SJohn Marino   if (error_one_per_line)
34595b7b453SJohn Marino     {
34695b7b453SJohn Marino       static const char *old_file_name;
34795b7b453SJohn Marino       static unsigned int old_line_number;
34895b7b453SJohn Marino 
34995b7b453SJohn Marino       if (old_line_number == line_number
35095b7b453SJohn Marino           && (file_name == old_file_name
351dc7c36e4SJohn Marino               || (old_file_name != NULL
352dc7c36e4SJohn Marino                   && file_name != NULL
353dc7c36e4SJohn Marino                   && strcmp (old_file_name, file_name) == 0)))
354dc7c36e4SJohn Marino 
35595b7b453SJohn Marino         /* Simply return and print nothing.  */
35695b7b453SJohn Marino         return;
35795b7b453SJohn Marino 
35895b7b453SJohn Marino       old_file_name = file_name;
35995b7b453SJohn Marino       old_line_number = line_number;
36095b7b453SJohn Marino     }
36195b7b453SJohn Marino 
36295b7b453SJohn Marino #if defined _LIBC && defined __libc_ptf_call
36395b7b453SJohn Marino   /* We do not want this call to be cut short by a thread
36495b7b453SJohn Marino      cancellation.  Therefore disable cancellation for now.  */
36595b7b453SJohn Marino   int state = PTHREAD_CANCEL_ENABLE;
36695b7b453SJohn Marino   __libc_ptf_call (pthread_setcancelstate, (PTHREAD_CANCEL_DISABLE, &state),
36795b7b453SJohn Marino                    0);
36895b7b453SJohn Marino #endif
36995b7b453SJohn Marino 
37095b7b453SJohn Marino   flush_stdout ();
37195b7b453SJohn Marino #ifdef _LIBC
37295b7b453SJohn Marino   _IO_flockfile (stderr);
37395b7b453SJohn Marino #endif
37495b7b453SJohn Marino   if (error_print_progname)
37595b7b453SJohn Marino     (*error_print_progname) ();
37695b7b453SJohn Marino   else
37795b7b453SJohn Marino     {
37895b7b453SJohn Marino #if _LIBC
37995b7b453SJohn Marino       __fxprintf (NULL, "%s:", program_name);
38095b7b453SJohn Marino #else
38195b7b453SJohn Marino       fprintf (stderr, "%s:", program_name);
38295b7b453SJohn Marino #endif
38395b7b453SJohn Marino     }
38495b7b453SJohn Marino 
38595b7b453SJohn Marino #if _LIBC
386dc7c36e4SJohn Marino   __fxprintf (NULL, file_name != NULL ? "%s:%u: " : " ",
38795b7b453SJohn Marino               file_name, line_number);
38895b7b453SJohn Marino #else
389dc7c36e4SJohn Marino   fprintf (stderr, file_name != NULL ? "%s:%u: " : " ",
39095b7b453SJohn Marino            file_name, line_number);
39195b7b453SJohn Marino #endif
39295b7b453SJohn Marino 
39395b7b453SJohn Marino   va_start (args, message);
39495b7b453SJohn Marino   error_tail (status, errnum, message, args);
395*09d4459fSDaniel Fojt   va_end (args);
39695b7b453SJohn Marino 
39795b7b453SJohn Marino #ifdef _LIBC
39895b7b453SJohn Marino   _IO_funlockfile (stderr);
39995b7b453SJohn Marino # ifdef __libc_ptf_call
40095b7b453SJohn Marino   __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
40195b7b453SJohn Marino # endif
40295b7b453SJohn Marino #endif
40395b7b453SJohn Marino }
40495b7b453SJohn Marino 
40595b7b453SJohn Marino #ifdef _LIBC
40695b7b453SJohn Marino /* Make the weak alias.  */
40795b7b453SJohn Marino # undef error
40895b7b453SJohn Marino # undef error_at_line
40995b7b453SJohn Marino weak_alias (__error, error)
41095b7b453SJohn Marino weak_alias (__error_at_line, error_at_line)
41195b7b453SJohn Marino #endif
412