~pac72/ubuntu/lucid/ddd/devel

« back to all changes in this revision

Viewing changes to libiberty/strerror.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Schepler
  • Date: 2004-07-22 03:49:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040722034937-cysl08t1jvba4jrx
Tags: 1:3.3.9-3
USERINFO has been renamed to USERINFO.txt; adjust debian/rules code
to match, to get correct information on the About DDD dialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   incompatible with our later declaration, perhaps by using const
14
14
   attributes.  So we hide the declaration in errno.h (if any) using a
15
15
   macro. */
 
16
#define sys_nerr sys_nerr__
16
17
#define sys_errlist sys_errlist__
17
18
#endif
18
19
 
20
21
#include <errno.h>
21
22
 
22
23
#ifdef HAVE_SYS_ERRLIST
 
24
#undef sys_nerr
23
25
#undef sys_errlist
24
26
#endif
25
27
 
26
28
/*  Routines imported from standard C runtime libraries. */
27
29
 
28
 
#ifdef __STDC__
29
 
#include <stddef.h>
30
 
extern void *malloc (size_t size);                              /* 4.10.3.3 */
31
 
extern void *memset (void *s, int c, size_t n);                 /* 4.11.6.1 */
32
 
#else   /* !__STDC__ */
33
 
extern char *malloc ();         /* Standard memory allocater */
34
 
extern char *memset ();
35
 
#endif  /* __STDC__ */
 
30
#ifdef HAVE_STDLIB_H
 
31
#include <stdlib.h>
 
32
#else
 
33
extern PTR malloc ();
 
34
#endif
 
35
 
 
36
#ifdef HAVE_STRING_H
 
37
#include <string.h>
 
38
#else
 
39
extern PTR memset ();
 
40
#endif
36
41
 
37
42
#ifndef MAX
38
43
#  define MAX(a,b) ((a) > (b) ? (a) : (b))
53
58
 
54
59
struct error_info
55
60
{
56
 
  int value;            /* The numeric value from <errno.h> */
57
 
  const char *name;     /* The equivalent symbolic value */
 
61
  const int value;              /* The numeric value from <errno.h> */
 
62
  const char *const name;       /* The equivalent symbolic value */
58
63
#ifndef HAVE_SYS_ERRLIST
59
 
  const char *msg;      /* Short message about this value */
 
64
  const char *const msg;        /* Short message about this value */
60
65
#endif
61
66
};
62
67
 
457
462
 
458
463
#ifndef HAVE_SYS_ERRLIST
459
464
 
 
465
#define sys_nerr sys_nerr__
 
466
#define sys_errlist sys_errlist__
460
467
static int sys_nerr;
461
468
static const char **sys_errlist;
462
469
 
467
474
 
468
475
#endif
469
476
 
470
 
 
471
477
/*
472
478
 
473
479
NAME
557
563
 
558
564
/*
559
565
 
560
 
NAME
561
 
 
562
 
        errno_max -- return the max errno value
563
 
 
564
 
SYNOPSIS
565
 
 
566
 
        int errno_max ();
567
 
 
568
 
DESCRIPTION
569
 
 
570
 
        Returns the maximum errno value for which a corresponding symbolic
571
 
        name or message is available.  Note that in the case where
572
 
        we use the sys_errlist supplied by the system, it is possible for
573
 
        there to be more symbolic names than messages, or vice versa.
574
 
        In fact, the manual page for perror(3C) explicitly warns that one
575
 
        should check the size of the table (sys_nerr) before indexing it,
576
 
        since new error codes may be added to the system before they are
577
 
        added to the table.  Thus sys_nerr might be smaller than value
578
 
        implied by the largest errno value defined in <errno.h>.
579
 
 
580
 
        We return the maximum value that can be used to obtain a meaningful
581
 
        symbolic name or message.
 
566
 
 
567
@deftypefn Extension int errno_max (void)
 
568
 
 
569
Returns the maximum @code{errno} value for which a corresponding
 
570
symbolic name or message is available.  Note that in the case where we
 
571
use the @code{sys_errlist} supplied by the system, it is possible for
 
572
there to be more symbolic names than messages, or vice versa.  In
 
573
fact, the manual page for @code{perror(3C)} explicitly warns that one
 
574
should check the size of the table (@code{sys_nerr}) before indexing
 
575
it, since new error codes may be added to the system before they are
 
576
added to the table.  Thus @code{sys_nerr} might be smaller than value
 
577
implied by the largest @code{errno} value defined in @code{<errno.h>}.
 
578
 
 
579
We return the maximum value that can be used to obtain a meaningful
 
580
symbolic name or message.
 
581
 
 
582
@end deftypefn
582
583
 
583
584
*/
584
585
 
599
600
 
600
601
/*
601
602
 
602
 
NAME
603
 
 
604
 
        strerror -- map an error number to an error message string
605
 
 
606
 
SYNOPSIS
607
 
 
608
 
        char *strerror (int errnoval)
609
 
 
610
 
DESCRIPTION
611
 
 
612
 
        Maps an errno number to an error message string, the contents of
613
 
        which are implementation defined.  On systems which have the external
614
 
        variables sys_nerr and sys_errlist, these strings will be the same
615
 
        as the ones used by perror().
616
 
 
617
 
        If the supplied error number is within the valid range of indices
618
 
        for the sys_errlist, but no message is available for the particular
619
 
        error number, then returns the string "Error NUM", where NUM is the
620
 
        error number.
621
 
 
622
 
        If the supplied error number is not a valid index into sys_errlist,
623
 
        returns NULL.
624
 
 
625
 
        The returned string is only guaranteed to be valid only until the
626
 
        next call to strerror.
 
603
@deftypefn Supplemental char* strerror (int @var{errnoval})
 
604
 
 
605
Maps an @code{errno} number to an error message string, the contents
 
606
of which are implementation defined.  On systems which have the
 
607
external variables @code{sys_nerr} and @code{sys_errlist}, these
 
608
strings will be the same as the ones used by @code{perror}.
 
609
 
 
610
If the supplied error number is within the valid range of indices for
 
611
the @code{sys_errlist}, but no message is available for the particular
 
612
error number, then returns the string @samp{Error @var{num}}, where
 
613
@var{num} is the error number.
 
614
 
 
615
If the supplied error number is not a valid index into
 
616
@code{sys_errlist}, returns @code{NULL}.
 
617
 
 
618
The returned string is only guaranteed to be valid only until the
 
619
next call to @code{strerror}.
 
620
 
 
621
@end deftypefn
627
622
 
628
623
*/
629
624
 
631
626
strerror (errnoval)
632
627
  int errnoval;
633
628
{
634
 
  char *msg;
 
629
  const char *msg;
635
630
  static char buf[32];
636
631
 
637
632
#ifndef HAVE_SYS_ERRLIST
673
668
 
674
669
/*
675
670
 
676
 
NAME
677
 
 
678
 
        strerrno -- map an error number to a symbolic name string
679
 
 
680
 
SYNOPSIS
681
 
 
682
 
        const char *strerrno (int errnoval)
683
 
 
684
 
DESCRIPTION
685
 
 
686
 
        Given an error number returned from a system call (typically
687
 
        returned in errno), returns a pointer to a string containing the
688
 
        symbolic name of that error number, as found in <errno.h>.
689
 
 
690
 
        If the supplied error number is within the valid range of indices
691
 
        for symbolic names, but no name is available for the particular
692
 
        error number, then returns the string "Error NUM", where NUM is
693
 
        the error number.
694
 
 
695
 
        If the supplied error number is not within the range of valid
696
 
        indices, then returns NULL.
697
 
 
698
 
BUGS
699
 
 
700
 
        The contents of the location pointed to are only guaranteed to be
701
 
        valid until the next call to strerrno.
 
671
@deftypefn Replacement {const char*} strerrno (int @var{errnum})
 
672
 
 
673
Given an error number returned from a system call (typically returned
 
674
in @code{errno}), returns a pointer to a string containing the
 
675
symbolic name of that error number, as found in @code{<errno.h>}.
 
676
 
 
677
If the supplied error number is within the valid range of indices for
 
678
symbolic names, but no name is available for the particular error
 
679
number, then returns the string @samp{Error @var{num}}, where @var{num}
 
680
is the error number.
 
681
 
 
682
If the supplied error number is not within the range of valid
 
683
indices, then returns @code{NULL}.
 
684
 
 
685
The contents of the location pointed to are only guaranteed to be
 
686
valid until the next call to @code{strerrno}.
 
687
 
 
688
@end deftypefn
702
689
 
703
690
*/
704
691
 
741
728
 
742
729
/*
743
730
 
744
 
NAME
745
 
 
746
 
        strtoerrno -- map a symbolic errno name to a numeric value
747
 
 
748
 
SYNOPSIS
749
 
 
750
 
        int strtoerrno (char *name)
751
 
 
752
 
DESCRIPTION
753
 
 
754
 
        Given the symbolic name of a error number, map it to an errno value.
755
 
        If no translation is found, returns 0.
 
731
@deftypefn Extension int strtoerrno (const char *@var{name})
 
732
 
 
733
Given the symbolic name of a error number (e.g., @code{EACCES}), map it
 
734
to an errno value.  If no translation is found, returns 0.
 
735
 
 
736
@end deftypefn
756
737
 
757
738
*/
758
739
 
803
784
  int errn;
804
785
  int errnmax;
805
786
  const char *name;
806
 
  char *msg;
 
787
  const char *msg;
807
788
  char *strerror ();
808
789
 
809
790
  errnmax = errno_max ();