Date: Wed, 10 Oct 2001 20:16:27 +0400 (MSD) From: "Andrew L. Neporada" <andrew@nas.dgap.mipt.ru> To: Mike Barcroft <mike@FreeBSD.ORG> Cc: audit@FreeBSD.ORG Subject: Re: strnstr(3) - New libc function for review Message-ID: <Pine.BSF.4.21.0110101958250.51458-200000@nas.dgap.mipt.ru> In-Reply-To: <20011010115210.E49828@coffee.q9media.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <andrew@nas.dgap.mipt.ru> 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: <Pine.BSF.4.21.0110102016270.51458@nas.dgap.mipt.ru> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0110101958250.51458-200000>