LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-28-2011, 08:58 AM   #1
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
how old is strnchr?


I am using this gcc:

gcc version 4.1.2 20071124 (Red Hat 4.1.2-42)

there appears to be no strnchr, strntok.

It's only 4 years old (gcc) so I am surprised they ain't there.

So i am forced to use the unsafe versions or roll my own.

anyone else found this?
 
Old 03-28-2011, 10:27 AM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
I'm running gcc 4.3.2, which is the one shipped for debian's current (lenny) release. It doesn't have strnchr, either.

What is this strnchr of which you speak? die.net doesn't know of it, either. A brief web search suggests that it's available within the kernel if you're coding a kernel module, but not in any userland standard.

For all ordinary purposes, there is no such thing, and never has been.

We have always been at war with Oceania.
 
Old 03-28-2011, 10:49 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Original Poster
Rep: Reputation: 239Reputation: 239Reputation: 239
hmm,
I'm sure i've used it on FreeBSD and that's gcc too.
I'll have to check when I get home.


I thought there were safe versions of all the old string functions,
like strnlen strncmp etc.
 
Old 03-28-2011, 10:54 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by wje_lq View Post
debian's current (lenny) release
OFFTOPIC:
Just a sidenote, Debian's current release is Squeeze, Lenny is oldstable.
 
Old 03-28-2011, 01:07 PM   #5
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by TobiSGD View Post
Debian's current release is Squeeze
(*grumble*)(*snort*)(*grumble*)upgrade time(*grumble*)(*grumble*)
 
Old 03-28-2011, 02:03 PM   #6
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
There's a version in the Mozilla nspr4 library (PL_strnchr) that is, in the header file, noted as being unsafe because, just like the K&R strnchr, no verification that the destination buffer is large enough to hold the string being copied is possible.

If you're concerned about buffer overrun exploits, I would suggest you use safer methods than strncpy.
 
Old 03-28-2011, 02:14 PM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Original Poster
Rep: Reputation: 239Reputation: 239Reputation: 239
yes, well I tried BSD and it ain't there either.

I must be cracking up!
Memory going.

Where are my keys?
 
Old 03-28-2011, 05:01 PM   #8
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Quote:
Originally Posted by bigearsbilly View Post
Where are my keys?
If they're public keys, no problem. Everybody has them.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration