Home | History | Annotate | Line # | Download | only in bfd
      1 /* sysdep.h -- handle host dependencies for the BFD library
      2    Copyright (C) 1995-2026 Free Software Foundation, Inc.
      3    Written by Cygnus Support.
      4 
      5    This file is part of BFD, the Binary File Descriptor library.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program; if not, write to the Free Software
     19    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20    MA 02110-1301, USA.  */
     21 
     22 #ifndef BFD_SYSDEP_H
     23 #define BFD_SYSDEP_H
     24 
     25 #ifdef PACKAGE
     26 #error sysdep.h must be included in lieu of config.h
     27 #endif
     28 
     29 #include "config.h"
     30 #include <stdio.h>
     31 
     32 #ifdef HAVE_SYS_TYPES_H
     33 #include <sys/types.h>
     34 #endif
     35 
     36 #include <stdlib.h>
     37 #include <stddef.h>
     38 #include <string.h>
     39 
     40 #ifdef HAVE_STRINGS_H
     41 #include <strings.h>
     42 #endif
     43 
     44 #ifdef HAVE_UNISTD_H
     45 #include <unistd.h>
     46 #endif
     47 
     48 #include <errno.h>
     49 #include <time.h>
     50 
     51 #ifdef HAVE_SYS_RESOURCE_H
     52 #include <sys/resource.h>
     53 #endif /* HAVE_SYS_RESOURCE_H */
     54 
     55 #ifdef USE_BINARY_FOPEN
     56 #include "fopen-bin.h"
     57 #else
     58 #include "fopen-same.h"
     59 #endif
     60 
     61 #ifdef HAVE_FCNTL_H
     62 #include <fcntl.h>
     63 #else
     64 #ifdef HAVE_SYS_FILE_H
     65 #include <sys/file.h>
     66 #endif
     67 #endif
     68 
     69 #ifndef O_RDONLY
     70 #define O_RDONLY 0
     71 #endif
     72 #ifndef O_WRONLY
     73 #define O_WRONLY 1
     74 #endif
     75 #ifndef O_RDWR
     76 #define O_RDWR 2
     77 #endif
     78 #ifndef O_ACCMODE
     79 #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
     80 #endif
     81 /* Systems that don't already define this, don't need it.  */
     82 #ifndef O_BINARY
     83 #define O_BINARY 0
     84 #endif
     85 
     86 #ifndef SEEK_SET
     87 #define SEEK_SET 0
     88 #endif
     89 #ifndef SEEK_CUR
     90 #define SEEK_CUR 1
     91 #endif
     92 
     93 #ifdef HAVE_MMAP
     94 #include <sys/mman.h>
     95 #endif
     96 
     97 #ifndef MAP_FILE
     98 #define MAP_FILE 0
     99 #endif
    100 
    101 #ifndef MAP_FAILED
    102 #define MAP_FAILED ((void *) -1)
    103 #endif
    104 
    105 #ifndef MAP_ANONYMOUS
    106 #define MAP_ANONYMOUS  MAP_ANON
    107 #endif
    108 
    109 #include "filenames.h"
    110 
    111 #if !HAVE_DECL_FFS
    112 extern int ffs (int);
    113 #endif
    114 
    115 #if !HAVE_DECL_STPCPY
    116 extern char *stpcpy (char *__dest, const char *__src);
    117 #endif
    118 
    119 #if !HAVE_DECL_STRTOULL
    120 extern unsigned long long strtoull(const char *, char **, int);
    121 #endif
    122 
    123 #ifdef HAVE_FTELLO
    124 #if !HAVE_DECL_FTELLO
    125 extern off_t ftello (FILE *stream);
    126 #endif
    127 #endif
    128 
    129 #ifdef HAVE_FTELLO64
    130 #if !HAVE_DECL_FTELLO64
    131 extern off64_t ftello64 (FILE *stream);
    132 #endif
    133 #endif
    134 
    135 #ifdef HAVE_FSEEKO
    136 #if !HAVE_DECL_FSEEKO
    137 extern int fseeko (FILE *stream, off_t offset, int whence);
    138 #endif
    139 #endif
    140 
    141 #ifdef HAVE_FSEEKO64
    142 #if !HAVE_DECL_FSEEKO64
    143 extern int fseeko64 (FILE *stream, off64_t offset, int whence);
    144 #endif
    145 #endif
    146 
    147 /* Define offsetof for those systems which lack it */
    148 
    149 #ifndef offsetof
    150 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
    151 #endif
    152 
    153 #ifndef ENABLE_NLS
    154   /* The Solaris version of locale.h always includes libintl.h.  If we have
    155      been configured with --disable-nls then ENABLE_NLS will not be defined
    156      and the dummy definitions of bindtextdomain (et al) below will conflict
    157      with the defintions in libintl.h.  So we define these values to prevent
    158      the bogus inclusion of libintl.h.  */
    159 # define _LIBINTL_H
    160 # define _LIBGETTEXT_H
    161 #endif
    162 #include <locale.h>
    163 
    164 #ifdef ENABLE_NLS
    165 # include <libintl.h>
    166 /* Note the redefinition of gettext and ngettext here to use PACKAGE.
    167 
    168    This is because the code in this directory is used to build a
    169    library which will be linked with code in other directories to form
    170    programs.  We want to maintain a separate translation file for this
    171    directory however, rather than being forced to merge it with that
    172    of any program linked to libbfd.  This is a library, so it cannot
    173    depend on the catalog currently loaded.
    174 
    175    In order to do this, we have to make sure that when we extract
    176    messages we use the BFD domain rather than the domain of the
    177    program that included the bfd library, (eg OBJDUMP).  Hence we use
    178    dgettext (PACKAGE, String) and define PACKAGE to be 'bfd'.
    179    (See the code in configure).  */
    180 # undef gettext
    181 # define gettext(Msgid) dgettext (PACKAGE, Msgid)
    182 # undef ngettext
    183 # define ngettext(Msgid1, Msgid2, n) dngettext (PACKAGE, Msgid1, Msgid2, n)
    184 # define _(String) gettext (String)
    185 # ifdef gettext_noop
    186 #  define N_(String) gettext_noop (String)
    187 # else
    188 #  define N_(String) (String)
    189 # endif
    190 #else
    191 # define gettext(Msgid) (Msgid)
    192 # define dgettext(Domainname, Msgid) (Msgid)
    193 # define dcgettext(Domainname, Msgid, Category) (Msgid)
    194 # define ngettext(Msgid1, Msgid2, n) \
    195   (n == 1 ? Msgid1 : Msgid2)
    196 # define dngettext(Domainname, Msgid1, Msgid2, n) \
    197   (n == 1 ? Msgid1 : Msgid2)
    198 # define dcngettext(Domainname, Msgid1, Msgid2, n, Category) \
    199   (n == 1 ? Msgid1 : Msgid2)
    200 # define textdomain(Domainname) do {} while (0)
    201 # define bindtextdomain(Domainname, Dirname) do {} while (0)
    202 # define _(String) (String)
    203 # define N_(String) (String)
    204 #endif
    205 
    206 #ifndef HAVE_GETUID
    207 #define getuid() 0
    208 #endif
    209 
    210 #ifndef HAVE_GETGID
    211 #define getgid() 0
    212 #endif
    213 
    214 #define POISON_BFD_BOOLEAN 1
    215 
    216 #endif /* ! defined (BFD_SYSDEP_H) */
    217