From owner-freebsd-audit Wed Oct 10 9:16:36 2001 Delivered-To: freebsd-audit@freebsd.org Received: from nas.dgap.mipt.ru (nas.dgap.mipt.ru [194.85.81.203]) by hub.freebsd.org (Postfix) with ESMTP id 5595337B40E; Wed, 10 Oct 2001 09:16:31 -0700 (PDT) Received: from localhost (andrew@localhost) by nas.dgap.mipt.ru (8.11.6/8.11.6) with ESMTP id f9AGGTA51578; Wed, 10 Oct 2001 20:16:29 +0400 (MSD) (envelope-from andrew@nas.dgap.mipt.ru) Date: Wed, 10 Oct 2001 20:16:27 +0400 (MSD) From: "Andrew L. Neporada" To: Mike Barcroft Cc: audit@FreeBSD.ORG Subject: Re: strnstr(3) - New libc function for review In-Reply-To: <20011010115210.E49828@coffee.q9media.com> Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-2138966051-1002730587=:51458" Sender: owner-freebsd-audit@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. Send mail to mime@docserver.cac.washington.edu for more info. --0-2138966051-1002730587=:51458 Content-Type: TEXT/PLAIN; charset=US-ASCII On Wed, 10 Oct 2001, Mike Barcroft wrote: > [-hackers removed from CC] > > Andrew L. Neporada writes: > > I think you should write in ststr.3 that strnstr locates first occurrence > > of null-terminated string 'little' in ___null-terminated___ string 'big'. > > No, that's inconsistent with existing strn...() functions and totally > defeats the purpose of my addition. > Check attached test program. It prints "NULL". So either implementation or man page is wrong. > To quote from my patch: > : Add a new libc function, strnstr(3), which allows one to limit the > : number of characters that are searched. This is especially useful > : with file operations and non-NUL terminated strings. > > > P.S. Because str(n)str functions deal with null-terminated strings > > (i.e. we don't know sizes of strings), it is impossible to write > > algorithm, that will work faster (in average) than current implementation. > > See above. > > > P.P.S. In the case of binary strings it is possible to implement faster > > search -- see attachment. > > Yes. Could you please comment my bstrstr implementation? > > > Best regards, > Mike Barcroft > Andrew. --0-2138966051-1002730587=:51458 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="strnstr_test.c" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: strnstr_test.c Content-Disposition: attachment; filename="strnstr_test.c" I2luY2x1ZGUgPHN0cmluZy5oPg0KI2luY2x1ZGUgPHN0ZGlvLmg+DQoNCi8q DQogKiBGaW5kIHRoZSBmaXJzdCBvY2N1cnJlbmNlIG9mIGZpbmQgaW4gcywg d2hlcmUgdGhlIHNlYXJjaCBpcyBsaW1pdGVkIHRvIHRoZQ0KICogZmlyc3Qg c2xlbiBjaGFyYWN0ZXJzIG9mIHMuDQogKi8NCmNoYXIgKg0Kc3RybnN0cihz LCBmaW5kLCBzbGVuKQ0KCWNvbnN0IGNoYXIgKnM7DQoJY29uc3QgY2hhciAq ZmluZDsNCglzaXplX3Qgc2xlbjsNCnsNCgljaGFyIGMsIHNjOw0KCXNpemVf dCBsZW47DQoNCglpZiAoKGMgPSAqZmluZCsrKSAhPSAnXDAnKSB7DQoJCWxl biA9IHN0cmxlbihmaW5kKTsNCgkJZG8gew0KCQkJZG8gew0KCQkJCWlmICgo c2MgPSAqcysrKSA9PSAnXDAnIHx8IHNsZW4tLSA8IDEpDQoJCQkJCXJldHVy biAoTlVMTCk7DQoJCQl9IHdoaWxlIChzYyAhPSBjKTsNCgkJCWlmIChsZW4g PiBzbGVuKQ0KCQkJCXJldHVybiAoTlVMTCk7DQoJCX0gd2hpbGUgKHN0cm5j bXAocywgZmluZCwgbGVuKSAhPSAwKTsNCgkJcy0tOw0KCX0NCglyZXR1cm4g KChjaGFyICopcyk7DQp9DQoNCmludA0KbWFpbih2b2lkKQ0Kew0KCWNoYXIJ c3RyWzEwXSA9IHsnYScsICdiJywgJ2MnLCAnXDAnLCAnYScsICdiJywgJ2Mn LCAnZCcsICdlJywgJ2YnfTsNCgljaGFyCSpwYXQgPSAiYWJjZCI7DQoJY2hh cgkqcHRyOw0KDQoJcHRyID0gc3RybnN0cihzdHIsIHBhdCwgMTApOw0KCQ0K CWlmIChwdHIgPT0gTlVMTCkNCgkJcHJpbnRmKCJOVUxMXG4iKTsNCgllbHNl DQoJCXByaW50ZigiJXNcbiIpOw0KCWV4aXQoMCk7DQp9DQo= --0-2138966051-1002730587=:51458-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-audit" in the body of the message