From owner-freebsd-hackers@FreeBSD.ORG Sun Dec 31 13:04:29 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 9659016A407 for ; Sun, 31 Dec 2006 13:04:29 +0000 (UTC) (envelope-from dmw@unete.cl) Received: from qmail0.ifxnetworks.com (qmail0.ifxnetworks.com [200.110.128.5]) by mx1.freebsd.org (Postfix) with ESMTP id 41D9D13C448 for ; Sun, 31 Dec 2006 13:04:29 +0000 (UTC) (envelope-from dmw@unete.cl) Received: (qmail 16662 invoked from network); 31 Dec 2006 12:37:47 -0000 X-Spam-DCC: sonic.net: qmail0.ifxnetworks.com 1156; Body=1 Fuz1=1 Fuz2=1 X-Spam-Checker-Version: SpamAssassin 3.1.7 (2006-10-05) on qmail0.ifxnetworks.com X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.7 Received: from host232.200.73.29.dynamic.ifxnw.cl (HELO daemon) (dmw@unete.cl@[200.73.29.232]) (envelope-sender ) by qmail0.ifxnetworks.com (qmail-ldap-1.03) with SMTP for ; 31 Dec 2006 12:37:47 -0000 From: Daniel Molina Wegener Organization: DMW To: freebsd-hackers@freebsd.org Date: Sun, 31 Dec 2006 09:37:54 -0300 User-Agent: KMail/1.9.1 References: <45975e1c.zZgcyHPeHeBwZNlg%perryh@pluto.rain.com> In-Reply-To: <45975e1c.zZgcyHPeHeBwZNlg%perryh@pluto.rain.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200612310937.55142.dmw@unete.cl> Cc: perryh@pluto.rain.com Subject: Re: how to deal with const X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: dmw@unete.cl List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Dec 2006 13:04:29 -0000 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