Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Aug 1997 17:05:55 +0200 (CEST)
From:      Mikael Karpberg <karpen@ocean.campus.luth.se>
To:        avalon@coombs.anu.edu.au (Darren Reed)
Cc:        hackers@FreeBSD.ORG
Subject:   Re: creating man 9f
Message-ID:  <199708101505.RAA12760@ocean.campus.luth.se>
In-Reply-To: <199708101321.GAA20590@hub.freebsd.org> from Darren Reed at "Aug 10, 97 11:07:54 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
According to Darren Reed:
> 
> I'd like to nominate the following man pages for duplication into section
> 9f (kernel functions):
> 
> bcmp, bcopy, bzero
> memcpy
> printf, vprintf (I'me sure there are some differences)
> putc
> free
> index, rindex
> inet_ntoa
> qsort
> random, srandom
> strcat (need to remove strncat or add it to the kernel*)
> strcmp, strncmp
> strcpy, strncpy
> strlen
> 
> ...just to start the man9 section off.  Comments ?
> 
> * - there's a noticable lack of the *nprintf functions from the kernel.
>     Given the number of buffer overflow problems and the trend towards their
>     use, shouldn't things like strncat & friends be put in the kernel too ?

Not really realted, but it's always annoyed me that all the strcat and strcpy
functions are so ineffective. They return a pointer to the buffer you
supply to the function (which is useless since you have it already) and
not a pointer to the trailing NUL. So if you want to add two strings you
use strcat twice, and thereby have the whole string walked through at least
too times too much. This always leads to me writing my own "xstrcpy()" or so,
which makes it possible to do:

ptr = xstrcpy(buffer, "first ");
ptr = xstrcpy(ptr,    "second");
ptr = xstrcpy(ptr,    "third");
..etc..

And having it an inline function you basically waste no CPU for meaningless
functioncalls and looping through something you've already looped through.

My point is... shouldn't the kernel, at least, be written with efficiency
in mind? No matter if it's not that big of a deal (I guess the kernel is not
doing too much string handling, anyway). But I guess this is not the only
case of inefficient code.

   /Mikael - mainly blowing off steam for RL stuff :-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199708101505.RAA12760>