Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Oct 2001 15:29:00 +0400 (MSD)
From:      "Andrew L. Neporada" <andrew@nas.dgap.mipt.ru>
To:        Mike Barcroft <mike@FreeBSD.ORG>
Cc:        audit@FreeBSD.ORG, freebsd-hackers@FreeBSD.ORG
Subject:   Re: strnstr(3) - New libc function for review
Message-ID:  <Pine.BSF.4.21.0110101522160.50053-200000@nas.dgap.mipt.ru>
In-Reply-To: <20011004215706.B34530@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-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: <Pine.BSF.4.21.0110101529000.50053@nas.dgap.mipt.ru>
Content-Description: bstrstr.c
Content-Disposition: attachment; filename="strstr.c"

I2luY2x1ZGUgPHN5cy90eXBlcy5oPg0KI2luY2x1ZGUgPHN5cy90aW1lLmg+
DQojaW5jbHVkZSA8bGltaXRzLmg+DQojaW5jbHVkZSA8c3RkaW8uaD4NCiNp
bmNsdWRlIDxzdGRsaWIuaD4NC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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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0110101522160.50053-200000>