From owner-freebsd-hackers Wed Oct 10 4:29:23 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from nas.dgap.mipt.ru (nas.dgap.mipt.ru [194.85.81.203]) by hub.freebsd.org (Postfix) with ESMTP id 00D1C37B409; Wed, 10 Oct 2001 04:29:12 -0700 (PDT) Received: from localhost (andrew@localhost) by nas.dgap.mipt.ru (8.11.6/8.11.6) with ESMTP id f9ABT1m50064; Wed, 10 Oct 2001 15:29:01 +0400 (MSD) (envelope-from andrew@nas.dgap.mipt.ru) Date: Wed, 10 Oct 2001 15:29:00 +0400 (MSD) From: "Andrew L. Neporada" To: Mike Barcroft Cc: audit@FreeBSD.ORG, freebsd-hackers@FreeBSD.ORG Subject: Re: strnstr(3) - New libc function for review In-Reply-To: <20011004215706.B34530@coffee.q9media.com> Message-ID: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-1603302548-1002713340=:50053" Sender: owner-freebsd-hackers@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-1603302548-1002713340=:50053 Content-Type: TEXT/PLAIN; charset=US-ASCII I think you should write in ststr.3 that strnstr locates first occurrence of null-terminated string 'little' in ___null-terminated___ string 'big'. Andrew. 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. P.P.S. In the case of binary strings it is possible to implement faster search -- see attachment. On Thu, 4 Oct 2001, Mike Barcroft wrote: > [BCC'd to -hackers for additional comments.] > > Hello, > I would appreciate comments/reviews of the following new addition to > libc. It is largely based off the current strstr(3) implementation. > > Patch attached and also available at: > http://people.FreeBSD.org/~mike/patches/strnstr.diff > > > Best regards, > Mike Barcroft > --0-1603302548-1002713340=:50053 Content-Type: TEXT/PLAIN; charset=US-ASCII; name="strstr.c" Content-Transfer-Encoding: BASE64 Content-ID: Content-Description: bstrstr.c Content-Disposition: attachment; filename="strstr.c" I2luY2x1ZGUgPHN5cy90eXBlcy5oPg0KI2luY2x1ZGUgPHN5cy90aW1lLmg+ DQojaW5jbHVkZSA8bGltaXRzLmg+DQojaW5jbHVkZSA8c3RkaW8uaD4NCiNp bmNsdWRlIDxzdGRsaWIuaD4NCiNpbmNsdWRlIDxzdHJpbmcuaD4NCg0KI2Rl ZmluZQlTVFJTWgkoMTAwKjEwMjQpDQojZGVmaW5lCVBBVFNaCTUwMA0KI2Rl ZmluZQlUUllTCTEwMA0KDQp2b2lkICoNCmJzdHJzdHIocywgc2xlbiwgcCwg cGxlbikNCglyZWdpc3RlciBjb25zdCB2b2lkCSpzLCAqcDsNCglzaXplX3QJ CQlzbGVuLCBwbGVuOw0Kew0KCXJlZ2lzdGVyIGNvbnN0IHVfY2hhciAJKnN0 ciwgKnN1YnN0cjsNCglyZWdpc3RlciBzaXplX3QJCWksIG1heF9zaGlmdCwg Y3Vycl9zaGlmdDsNCg0KCXNpemVfdAkJCXNoaWZ0W1VDSEFSX01BWCArIDFd Ow0KDQoJaWYgKHMgPT0gTlVMTCB8fCBwID09IE5VTEwgfHwgcGxlbiA+IHNs ZW4gfHwgc2xlbiA9PSAwIHx8IHBsZW4gPT0gMCkNCgkJcmV0dXJuIChOVUxM KTsNCg0KCXN0ciA9IChjb25zdCB1X2NoYXIgKilzOw0KCXN1YnN0ciA9IChj b25zdCB1X2NoYXIgKilwOw0KDQoJZm9yIChpID0gMDsgaSA8PSBVQ0hBUl9N QVg7IGkrKykgc2hpZnRbaV0gPSBwbGVuICsgMTsNCglmb3IgKGkgPSAwOyBp IDwgcGxlbjsgaSsrKSBzaGlmdFtzdWJzdHJbaV1dID0gcGxlbiAtIGk7DQoN CglpID0gMDsNCgltYXhfc2hpZnQgPSBzbGVuIC0gcGxlbjsNCgl3aGlsZSAo aSA8PSBtYXhfc2hpZnQpIHsNCgkJ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0 ZXIudHZfc2VjICsgYWZ0ZXIudHZfdXNlYy8xMDAwMDAwLjApL1RSWVMpOw0K DQoJZ2V0dGltZW9mZGF5KCZiZWZvcmUsIE5VTEwpOw0KCWZvciAoaSA9IDA7 IGkgPCBUUllTOyBpKyspDQoJCWJzdHJzdHIoc3RyLCBTVFJTWiArIFBBVFNa LCBzdHIgKyBTVFJTWiwgUEFUU1opOw0KCWdldHRpbWVvZmRheSgmYWZ0ZXIs IE5VTEwpOw0KCWFmdGVyLnR2X3NlYyAtPSBiZWZvcmUudHZfc2VjOw0KCWFm dGVyLnR2X3VzZWMgLT0gYmVmb3JlLnR2X3VzZWM7DQoJcHJpbnRmKCJOZXc6 ICVmIHNlY1xuIiwgKGFmdGVyLnR2X3NlYyArIGFmdGVyLnR2X3VzZWMvMTAw MDAwMC4wKS9UUllTKTsNCglmcmVlKHN0cik7DQoJcmV0dXJuICgwKTsNCn0N Cg== --0-1603302548-1002713340=:50053-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message