From owner-freebsd-hackers@FreeBSD.ORG Sun Dec 31 07:38:54 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 CBD2C16A407 for ; Sun, 31 Dec 2006 07:38:54 +0000 (UTC) (envelope-from perryh@pluto.rain.com) Received: from agora.rdrop.com (agora.rdrop.com [199.26.172.34]) by mx1.freebsd.org (Postfix) with ESMTP id B077C13C43E for ; Sun, 31 Dec 2006 07:38:54 +0000 (UTC) (envelope-from perryh@pluto.rain.com) Received: from agora.rdrop.com (66@localhost [127.0.0.1]) by agora.rdrop.com (8.13.1/8.12.7) with ESMTP id kBV72K83005061 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Sat, 30 Dec 2006 23:02:20 -0800 (PST) (envelope-from perryh@pluto.rain.com) Received: (from uucp@localhost) by agora.rdrop.com (8.13.1/8.12.9/Submit) with UUCP id kBV72Kwf005060 for freebsd-hackers@freebsd.org; Sat, 30 Dec 2006 23:02:20 -0800 (PST) Received: from fbsd61 ([192.168.200.61]) by pluto.rain.com (4.1/SMI-4.1-pluto-M2060407) id AA25615; Sat, 30 Dec 06 22:50:26 PST Date: Sat, 30 Dec 2006 22:52:12 -0800 From: perryh@pluto.rain.com To: freebsd-hackers@freebsd.org Message-Id: <45975e1c.zZgcyHPeHeBwZNlg%perryh@pluto.rain.com> User-Agent: nail 11.25 7/29/05 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: how to deal with const X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list 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 07:38:54 -0000 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). What is the accepted method of dealing with this sort of thing?