Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Mar 2001 17:37:10 +0000
From:      thinker <thinker@branda.to>
To:        Alfred Perlstein <bright@wintelcom.net>
Cc:        freebsd-current@freebsd.org
Subject:   Re: patch /bin/ls again, for mb supporting.
Message-ID:  <20010320173710.A14702@hell.branda.to>
In-Reply-To: <20010320011246.O29888@fw.wintelcom.net>; from bright@wintelcom.net on Tue, Mar 20, 2001 at 01:12:46AM -0800
References:  <20010320164901.A14424@hell.branda.to> <20010320011246.O29888@fw.wintelcom.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Mar 20, 2001 at 01:12:46AM -0800, Alfred Perlstein wrote:
...... skip .......
> > +	size_t sz;
> > +	wchar_t c;
> 
> C has allowed for identifiers larger than 6 characters for quite
> some time, any chance on you making use of this feature?  Or at
> least adding a comment here and there?
Ok.. I would add a comment here and there.
> 
> > +	p = s;
> > +	dc = len = strlen(s);
> > +	ri = r = (char *)malloc(len + 1);
> 
> Where is the check for malloc failing?
Yes, it is good idea. Although, I don't think that we can't alloc
a memory block that less than 256+1 bytes.
> 
> > +	while (dc) {
> > +		sz = mbtowc(&c, p, dc);
> > +		if (sz < 0) {
> > +			p++;
> > +			dc--;
> > +			*ri++ = '?';
> > +		} else {
> > +			dc -= sz;
> > +			if (isprint(c)) {
> > +				while(sz--)
> > +					*ri++ = *p++;
> > +			} else {
> > +				p += sz;
> > +				while(sz--)
> > +					*ri++ = '?';
> 
> Why didn't you use strlcpy/memcpy as suggested?
As I can see, most codeset don't use more any 4 bytes to represent
a character. For proformance reason, strlcpy/memcpy is not a good
choice. For easy reading, I don't which one is better. For size,
I think function call is more expensive. If we use strlcpy/memcpy,
it mean we use strlcpy/memcpy to copy a block of memory that less
than 4 bytes. I don't think it is good example to demo strlcpy/memcpy.

> 
> > +			}
> > +		}
> > +	}
> > +	*ri = 0;
> 
>         *ri = '\0';
For easy reading?? ok..
> 
> > +	printf("%s", r);
> > +	free(r);
> > +	return len;
> 
> return (len);
> 
...... skip ..........

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




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