From owner-freebsd-current Tue Mar 20 1:35: 0 2001 Delivered-To: freebsd-current@freebsd.org Received: from hell.branda.to (61-216-80-81.HINET-IP.hinet.net [61.216.80.81]) by hub.freebsd.org (Postfix) with ESMTP id D777B37B721 for ; Tue, 20 Mar 2001 01:34:53 -0800 (PST) (envelope-from thinker@branda.to) Received: from localhost (localhost [127.0.0.1]) (uid 1000) by hell.branda.to with local; Tue, 20 Mar 2001 17:37:10 +0000 Date: Tue, 20 Mar 2001 17:37:10 +0000 From: thinker To: Alfred Perlstein Cc: freebsd-current@freebsd.org Subject: Re: patch /bin/ls again, for mb supporting. Message-ID: <20010320173710.A14702@hell.branda.to> References: <20010320164901.A14424@hell.branda.to> <20010320011246.O29888@fw.wintelcom.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20010320011246.O29888@fw.wintelcom.net>; from bright@wintelcom.net on Tue, Mar 20, 2001 at 01:12:46AM -0800 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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