This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

small fixes for fnmatch.c



Hi Ulrich,

I assume fnmatch.c in glibc is meant to be useful for the fileutils,
shellutils etc., for use on non-GNU systems. So I compiled them on
Solaris 2.7 and made the following errors and warnings disappear.

                        Bruno


$ gcc -I. -O -S -Wall fnmatch.c -DHAVE_STRING_H -DHAVE_WCTYPE_H \
  -DHAVE_WCHAR_H -DHAVE_MBSTATE_T -DHAVE_MBSRTOWCS -DSTDC_HEADERS
fnmatch_loop.c:227: warning: implicit declaration of function `__iswctype'
fnmatch_loop.c:227: warning: implicit declaration of function `__btowc'
fnmatch.c:232: warning: implicit declaration of function `__wctype'
fnmatch_loop.c:100: warning: implicit declaration of function `__wcschrnul'
fnmatch.c: In function `fnmatch':
fnmatch.c:217: `mstate_t' undeclared (first use in this function)

        * fnmatch.c (ISWCTYPE): New macro.
          (__wcschrnul): New function.
          (BTOWC): New macro. Define it instead of __btowc.
          (is_char_class) [!_LIBC]: Fix 'mstate_t' typo. Fix 2nd arg to
          wcsrtombs. Call wctype, not __wctype.
        * fnmatch_loop.c (FCT): Use ISWCTYPE instead of __iswctype, and BTOWC
          instead of __btowc.

*** posix/fnmatch.c.bak	Tue Jan 18 19:05:52 2000
--- posix/fnmatch.c	Tue Jan 18 19:59:53 2000
***************
*** 106,111 ****
--- 106,117 ----
  #   define IS_CHAR_CLASS(string) wctype (string)
  #  endif
  
+ #  ifdef _LIBC
+ #   define ISWCTYPE(WC, WT)	__iswctype (WC, WT)
+ #  else
+ #   define ISWCTYPE(WC, WT)	iswctype (WC, WT)
+ #  endif
+ 
  #  if (HAVE_MBSTATE_T && HAVE_MBSRTOWCS) || _LIBC
  /* In this case we are implementing the multibyte character handling.  */
  #   define HANDLE_MULTIBYTE	1
***************
*** 149,154 ****
--- 155,173 ----
  }
  # endif
  
+ # if HANDLE_MULTIBYTE && !defined HAVE___STRCHRNUL && !defined _LIBC
+ static wchar_t *
+ __wcschrnul (s, c)
+      const wchar_t *s;
+      wint_t c;
+ {
+   wchar_t *result = wcschr (s, c);
+   if (result == NULL)
+     result = wcschr (s, '\0');
+   return result;
+ }
+ # endif
+ 
  # ifndef internal_function
  /* Inside GNU libc we mark some function in a special way.  In other
     environments simply ignore the marking.  */
***************
*** 165,170 ****
--- 184,194 ----
  # define UCHAR	unsigned char
  # define FCT	internal_fnmatch
  # define L(CS)	CS
+ # ifdef _LIBC
+ #  define BTOWC(C)	__btowc (C)
+ # else
+ #  define BTOWC(C)	btowc (C)
+ # endif
  # define STRCHR(S, C)	strchr (S, C)
  # define STRCHRNUL(S, C) __strchrnul (S, C)
  # include "fnmatch_loop.c"
***************
*** 181,187 ****
  #  define UCHAR	wint_t
  #  define FCT	internal_fnwmatch
  #  define L(CS)	L##CS
! #  define __btowc(wc)	wc
  #  define STRCHR(S, C)	wcschr (S, C)
  #  define STRCHRNUL(S, C) __wcschrnul (S, C)
  
--- 205,211 ----
  #  define UCHAR	wint_t
  #  define FCT	internal_fnwmatch
  #  define L(CS)	L##CS
! #  define BTOWC(C)	(C)
  #  define STRCHR(S, C)	wcschr (S, C)
  #  define STRCHRNUL(S, C) __wcschrnul (S, C)
  
***************
*** 214,235 ****
  static wctype_t
  is_char_class (const wchar_t *wcs)
  {
!   mstate_t ps;
    char *s;
    size_t n;
  
    memset (&ps, '\0', sizeof (ps));
  
!   n = wcsrtombs (NULL, wcs, 0, &ps);
    if (n == (size_t) -1)
      /* Something went wrong.  */
      return 0;
  
    s = alloca (n + 1);
    assert (mbsinit (&ps));
!   (void) wcsrtombs (s, wcs, n + 1, &ps);
  
!   return __wctype (s);
  }
  #  endif
  #  define IS_CHAR_CLASS(string) is_char_class (string)
--- 238,262 ----
  static wctype_t
  is_char_class (const wchar_t *wcs)
  {
!   mbstate_t ps;
!   const wchar_t *pwc;
    char *s;
    size_t n;
  
    memset (&ps, '\0', sizeof (ps));
  
!   pwc = wcs;
!   n = wcsrtombs (NULL, &pwc, 0, &ps);
    if (n == (size_t) -1)
      /* Something went wrong.  */
      return 0;
  
    s = alloca (n + 1);
    assert (mbsinit (&ps));
!   pwc = wcs;
!   (void) wcsrtombs (s, &pwc, n + 1, &ps);
  
!   return wctype (s);
  }
  #  endif
  #  define IS_CHAR_CLASS(string) is_char_class (string)
*** posix/fnmatch_loop.c.bak	Tue Jan 18 02:41:20 2000
--- posix/fnmatch_loop.c	Tue Jan 18 19:51:20 2000
***************
*** 224,230 ****
  		      /* Invalid character class name.  */
  		      return FNM_NOMATCH;
  
! 		    if (__iswctype (__btowc ((UCHAR) *n), wt))
  		      goto matched;
  # else
  		    if ((STREQ (str, L("alnum")) && ISALNUM ((UCHAR) *n))
--- 224,230 ----
  		      /* Invalid character class name.  */
  		      return FNM_NOMATCH;
  
! 		    if (ISWCTYPE (BTOWC ((UCHAR) *n), wt))
  		      goto matched;
  # else
  		    if ((STREQ (str, L("alnum")) && ISALNUM ((UCHAR) *n))
***************
*** 325,330 ****
--- 325,331 ----
      return 0;
  
    return FNM_NOMATCH;
+ }
  
  #undef FOLD
  #undef CHAR
***************
*** 333,336 ****
  #undef STRCHR
  #undef STRCHRNUL
  #undef L
! }
--- 334,337 ----
  #undef STRCHR
  #undef STRCHRNUL
  #undef L
! #undef BTOWC

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]