Current-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Some more setenv(3) update
On Tue, Oct 12, 2010 at 10:47:32PM +0100, Matthias Scheler wrote:
> On Tue, Oct 12, 2010 at 12:06:45PM +0200, Nicolas Joly wrote:
> > > for (cc = name; *cc && *cc != '='; ++cc) /* no `=' in name
> > > */
> > > continue;
> > >
> > > before the initial test, and then check for *cc instead of scanning the
> > > name twice, once in strchr and a second time in strlen.
>
> It will be cached the second time anyway.
>
> > Right, but we then need to handle case for NULL name.
>
> Which is exactly why your solution was better as it was simpler.
>
> >> + for (cc = name; cc && *cc && *cc != '='; ++cc)
> > + continue;
>
> It don't like this even a bit.
I'm not fond of it too; but wanted to give it a try.
> I would prefer this:
>
> if (name == NULL || value == NULL) {
> errno = EINVAL;
> return -1;
> }
>
> size = strcspn(name, "=");
> if (size == 0 || name[size] != '\0') {
> errno = EINVAL;
> return -1;
> }
>
> It only reads the string once and figures out the length and whether
> there is an equal sign in the name at the same time.
That's indeed much better, will use it. I didn't known about strcspn
function...
I plan to commit all of this in a few days unless someone objects. And
then have a look to putenv which require some care too.
Thanks.
--
Nicolas Joly
Biological Software and Databanks.
Institut Pasteur, Paris.
Home |
Main Index |
Thread Index |
Old Index