X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=libiberty%2Fhex.c;h=5eeafdbd15860f55457ac635cda89237db6e3652;hb=44a8b4df1d6f5b8096f01787751fd51c42e78fc6;hp=5f8229253494de21455e83b86766ca9e5002de11;hpb=7dd4d42a604c4a50b7d1b6356b4f33fd6c0695b2;p=deliverable%2Fbinutils-gdb.git diff --git a/libiberty/hex.c b/libiberty/hex.c index 5f82292534..5eeafdbd15 100644 --- a/libiberty/hex.c +++ b/libiberty/hex.c @@ -14,11 +14,19 @@ Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with libiberty; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ #include /* for EOF */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "libiberty.h" +#include "safe-ctype.h" /* for HOST_CHARSET_ASCII */ + +#if EOF != -1 + #error "hex.c requires EOF == -1" +#endif /* @@ -39,13 +47,19 @@ or zero if it is not. Note that the value you pass will be cast to @end deftypefn -@deftypefn Extension int hex_value (int @var{c}) +@deftypefn Extension {unsigned int} hex_value (int @var{c}) Returns the numeric equivalent of the given character when interpreted -as a hexidecimal digit. The result is undefined if you pass an +as a hexadecimal digit. The result is undefined if you pass an invalid hex digit. Note that the value you pass will be cast to @code{unsigned char} within the macro. +The @code{hex_value} macro returns @code{unsigned int}, rather than +signed @code{int}, to make it easier to use in parsing addresses from +hex dump files: a signed @code{int} would be sign-extended when +converted to a wider unsigned type --- like @code{bfd_vma}, on some +systems. + @end deftypefn @undocumented _hex_array_size @@ -56,11 +70,9 @@ invalid hex digit. Note that the value you pass will be cast to /* Are we ASCII? */ -#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \ - && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \ - && EOF == -1 +#if HOST_CHARSET == HOST_CHARSET_ASCII -const char _hex_value[_hex_array_size] = +const unsigned char _hex_value[_hex_array_size] = { _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* NUL SOH STX ETX */ _hex_bad, _hex_bad, _hex_bad, _hex_bad, /* EOT ENQ ACK BEL */ @@ -139,12 +151,12 @@ const char _hex_value[_hex_array_size] = #else -char _hex_value[_hex_array_size]; +unsigned char _hex_value[_hex_array_size]; #endif /* not ASCII */ void -hex_init () +hex_init (void) { #ifndef HEX_TABLE_INITIALIZED int i;