Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 31 Dec 2006 09:37:54 -0300
From:      Daniel Molina Wegener <dmw@unete.cl>
To:        freebsd-hackers@freebsd.org
Cc:        perryh@pluto.rain.com
Subject:   Re: how to deal with const
Message-ID:  <200612310937.55142.dmw@unete.cl>
In-Reply-To: <45975e1c.zZgcyHPeHeBwZNlg%perryh@pluto.rain.com>
References:  <45975e1c.zZgcyHPeHeBwZNlg%perryh@pluto.rain.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sunday 31 December 2006 03:52, perryh@pluto.rain.com wrote:
> I'm working on a kernel project that needs strstr(3).
>
> It looks as if most of the str* functions in libkern are very
> similar, if not identical, to their counterparts in
> libc/string, but that approach does not seem to work for
> strstr (#s added):
>
>  1: char *
>  2: strstr(s, find)
>  3:         const char *s, *find;
>  4: {
>  5:         char c, sc;
>  6:         size_t len;
>  7:
>  8:         if ((c = *find++) != 0) {
>  9:                 len = strlen(find);
> 10:                 do {
> 11:                         do {
> 12:                                 if ((sc = *s++) == 0)
> 13:                                         return (NULL);
> 14:                         } while (sc != c);
> 15:                 } while (strncmp(s, find, len) != 0);
> 16:                 s--;
> 17:         }
> 18:         return ((char *)s);
> 19: }
>
> I get a "warning: cast discards qualifiers from pointer
> target type" on line 18.  If I remove the cast, changing it
> to just "return (s);", I get "warning: return discards
> qualifiers from pointer target type" (and because this is the
> kernel, those "warning" messages are actually treated as
> errors).

  If you need strstr(3) in your project is allready defined
in libkern. The implementation is identical, but using the
__DECONST macro.

  Take a look in /usr/src/sys/libkern/strstr.c for the function 
definition and /usr/src/sys/geom/label/g_label.c for usage.

  The function prototype is defined in sys/libkern.h

Best regards...
-- 
 . 0 . | Daniel Molina Wegener
 . . 0 | dmw at unete dot cl
 0 0 0 | FreeBSD User



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200612310937.55142.dmw>