From 317bccd134e8301a3354803dd148ef0e7931408a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 14 Dec 2001 13:37:08 +0000 Subject: [PATCH] * util.h (digitp, hexdigitp): New ctype like macros. (atoi_1,atoi_2,atoi_4,xtoi_1,xtoi_2): New. --- common/ChangeLog | 17 +++++++++++++++++ common/util.h | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 common/ChangeLog diff --git a/common/ChangeLog b/common/ChangeLog new file mode 100644 index 000000000..70bc1cc8a --- /dev/null +++ b/common/ChangeLog @@ -0,0 +1,17 @@ +2001-12-14 Werner Koch + + * util.h (digitp, hexdigitp): New ctype like macros. + (atoi_1,atoi_2,atoi_4,xtoi_1,xtoi_2): New. + + + Copyright 2001 Free Software Foundation, Inc. + + This file is free software; as a special exception the author gives + unlimited permission to copy and/or distribute it, with or without + modifications, as long as this notice is preserved. + + This file is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY, to the extent permitted by law; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + diff --git a/common/util.h b/common/util.h index 485cc1c05..e30923330 100644 --- a/common/util.h +++ b/common/util.h @@ -55,6 +55,21 @@ int map_kbx_err (int err); int map_assuan_err (int err); +/* some macros to replace ctype ones and avoid locale problems */ +#define digitp(p) (*(p) >= '0' && *(p) <= '9') +#define hexdigitp(a) (digitp (a) \ + || ((a) >= 'A' && (a) <= 'F') \ + || ((a) >= 'a' && (a) <= 'f')) +/* the atoi macros assume that the buffer has only valid digits */ +#define atoi_1(p) (*(p) - '0' ) +#define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1)) +#define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2)) +#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ + *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) +#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) + + + #endif /*GNUPG_COMMON_UTIL_H*/