[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Busy box / tolower, ctype issues: ctype, isspace, tolower all-glibc routines




This is a contribution for all that have issues with ctype routines and version of their glibc.
(specially at the border of 2.2 and 2.3!)
They are not internationalized, and they bring a (very) small code overhead
Eventually, you can insert your native ctype.h in the empty else branch for futur use
cut the rest of that email and save it under ctype.h

May it help

Olivier Delouya

/*
        this file = ctype.h
*/

/*******************************************************************************************************
*                                                                                                                                                        *
*        The jeep of ctype.h versions! avoid linkage issues with glibc_xxx !!                                                *
*        - Olivier Delouya (olivier_delouya@hotmail.com) - Feb 28 2005                                                        *
*        come back to the good old time of Unix ctype defs (remember, small is beautifull?)                        *
*        with further experience in addition..                                                                                                *
*        select the level you need on your target                                                                                        *
*        first one is the pre-historic form..                                                                                                *
*        The second one takes care of modifying the parameter in macro call.                                                *
*        None of them resist to the (dirty) assumption that the defs are functions and not macros..                *
*        The third, yes, with only few code overhead (~ 700 bytes on busybox binary..)                                *
*        Of course, they are NOT internationalized! if your application need to interface with foreign           *
*        users (customer devices), undef CTYPE_MACROS and good luck with your compiler/linker/loader!                *
*                                                                                                                                                        *
*******************************************************************************************************/

#ifndef _CTYPE_H
#define _CTYPE_H

#  define CTYPE_MACROS                 1
#  define CTYPE_MACROS_SAFE        2
#  define CTYPE_MACROS_INLINE        3
/* undef  CTYPE_MACROS                 if you are happy with the native compiler defs */

#ifndef CTYPE_DEFS
#define CTYPE_DEFS        CTYPE_MACROS_INLINE
#endif

#if (CTYPE_DEFS == CTYPE_MACROS)

#        define isalnum(c)  (isalpha(c) || isdigit(c))
#        define isalpha(c)  {isupper(c) || islower(c))
#        define isascii(c)  (c > 0 && c <= 0x7f)
#        define iscntrl(c)  ((c >= 0) && ((c <= 0x1F) || (c == 0x7f)))
#        define isdigit(c)  (c >= '0' && c <= '9')
#        define isgraph(c)  (c != ' ' && isprint(c))
#        define islower(c)  (c >=  'a' && c <= 'z')
#        define isprint(c)  (c >= ' ' && c <= '~')
#        define ispunct(c)  ((c > ' ' && c <= '~') && !isalnum(c))
#        define isspace(c)  (c ==  ' ' || c == '\f' || c == '\n' || c == '\r' ||\
                                c == '\t' || c == '\v')
#        define isupper(c)  (c >=  'A' && c <= 'Z')
#        define isxdigit(c) (isxupper(c) || isxlower(c))
#        define isxlower(c) (isdigit(c) || (c >= 'a' && c <= 'f'))
#        define isxupper(c) (isdigit(c) || (c >= 'A' && c <= 'F'))
#        define tolower(c)  (isupper(c) ? ( c - 'A' + 'a') : (c))
#        define toupper(c)  (islower(c) ? (c - 'a' + 'A') : (c))

#elif (CTYPE_DEFS == CTYPE_MACROS_SAFE)

#        define isalnum(c)  ({ int __c = c; isalpha(__c) || isdigit(__c); })
#        define isalpha(c)  ({ int __c = c; isupper(__c) || islower(__c); })
#        define isascii(c)  ({ int __c = c; __c > 0 && __c <= 0x7f; })
#        define iscntrl(c)  ({ int __c = c; \
                                (__c >= 0) && ((__c <= 0x1F) || (__c == 0x7f)); })
#        define isdigit(c)  ({ int __c = c; __c >= '0' && __c <= '9'; })
#        define isgraph(c)  ({ int __c = c; __c != ' ' && isprint(__c); })
#        define islower(c)  ({ int __c = c; __c >=  'a' && __c <= 'z'; })
#        define isprint(c)  ({ int __c = c; __c >= ' ' && __c <= '~'; })
#        define ispunct(c)  ({ int __c = c; \
                                (__c > ' ' && __c <= '~') && !isalnum(__c); })
#        define isspace(c)  ({ int __c = c; \
                                __c == ' ' || __c == '\f' || __c == '\n' || __c == '\r' || \
                                __c == '\t' || __c == '\v'; })
#        define isupper(c)  ({ int __c = c; __c >=  'A' && __c <= 'Z'; })
#        define isxdigit(c) ({ int __c = c; isxupper(__c) || isxlower(__c); })
#        define isxlower(c) ({ int __c = c; \
                                isdigit(__c) || (__c >= 'a' && __c <= 'f'); })
#        define isxupper(c) ({ int __c = c; \
                                isdigit(__c) || (__c >= 'A' && __c <= 'F'); })
#        define toascii(c)  (c & 0x7f)
#        define tolower(c)  ({ int __c = c; \
                                isupper(__c) ? ( __c - 'A' + 'a') : (__c); })
#        define toupper(c)  ({ int __c = c; \
                                islower(__c) ? (__c - 'a' + 'A') : (__c); })

#elif (CTYPE_DEFS == CTYPE_MACROS_INLINE)

        static inline int isalnum(int c)  { return isalpha(c) || isdigit(c); }
        static inline int isalpha(int c)  { return isupper(c) || islower(c); }
        static inline int isascii(int c)  { return c > 0 && c <= 0x7f; }
        static inline int iscntrl(int c)  { return (c >= 0) && ((c <= 0x1F) || (c == 0x7f)); }
        static inline int isdigit(int c)  { return c >= '0' && c <= '9'; }
        static inline int isgraph(int c)  { return c != ' ' && isprint(c); }
        static inline int islower(int c)  { return c >=  'a' && c <= 'z'; }
        static inline int isprint(int c)  { return c >= ' ' && c <= '~'; }
        static inline int ispunct(int c)  { return (c > ' ' && c <= '~') && !isalnum(c); }
        static inline int isspace(int c)  { return c ==  ' ' || c == '\f' || c == '\n' || c == '\r' ||
                                                               c == '\t' || c == '\v' ; }
        static inline int isupper(int c)  { return c >=  'A' && c <= 'Z'; }
        static inline int isxdigit(int c) { return isxupper(c) || isxlower(c); }
        static inline int isxlower(int c) { return isdigit(c) || (c >= 'a' && c <= 'f'); }
        static inline int isxupper(int c) { return isdigit(c) || (c >= 'A' && c <= 'F'); }
        static inline int tolower(int c)  { return isupper(c) ? ( c - 'A' + 'a') : (c); }
        static inline int toupper(int c)  { return islower(c) ? (c - 'a' + 'A') : (c); }

#else        /* Put here the standards defs of your compiler.. */

/* ..... */

#endif

#endif /* ctype.h */


___________________________________________________________________

On Feb 04, 2005 6.36PM, Olivier Delouya wrote

>Hi all,
>
>With the helps of some of you - thanks to them - I have been able to obtain busybox.
>I installed the sources and get the package compiled seamlessly.
>Then I ran through a very classical issue (according to google), that I was not able to solve:
>At execution time, the loader complains that it does not find GLIBC 2.3.
>Which is true, we use a GLIBC 2.2
>
>After investigating with nm, it appears that it remains three undefs in the binary, labelled
>__ctype_b_loc@@GLIBC_2.3
>__ctype_tolower_loc@@GLIBC_2.3
>__ctype_toupper_loc@@GLIBC_2.3
>
>google says that this is a problem with ctype functions that was first enhanced to support
>international languages, then rolled back to the old implementation because of a potential
>security hole (as far as I understand)
>
>Anyway, I don't understand why, although the symbols __ctype_xxx_loc  exist in the libc.so.6
>that we use on the target , the compiler generates the "decorated" symbols __ctype_xxx_loc@@GLIBC_2.3?
>
>I did try to rollback to the __ctype_xxx functions (not localized) in the ctype.h.
>It worked for __ctype_tolower and __ctype_toupper but not for __ctype_b, although it exists in
>the lib..
>And this time, the failure happens already at link time, not on the target..
>
>Finally, it raises an issue that we did not catch before here:
>the libc that we use to cross compile commands (that is in the armgcc folder) is not at the same
>level than the one that we use on the target for execution, and that does not sound good to me.
>Does any one can advise on that? Should we override the libc of the compiler with the one that
>we load on the target, or vice versa?
>
>Thanks in advance
>
>Bye
>
>Olivier Delouya
Reply to: