[PATCH 8/11] powerpc: Add strne2a() to convert a string from EBCDIC to ASCII

Olof Johansson olof at lixom.net
Wed Mar 22 05:11:05 EST 2006


On Tue, Mar 21, 2006 at 08:46:08PM +1100, Michael Ellerman wrote:
> Add strne2a() which converts a string from EBCDIC to ASCII.

Nitpick, since this isn't hot path:

> 
> Signed-off-by: Michael Ellerman <michael at ellerman.id.au>
> ---
> 
>  arch/powerpc/lib/e2a.c       |   10 ++++++++++
>  include/asm-powerpc/system.h |    2 ++
>  2 files changed, 12 insertions(+)
> 
> Index: to-merge/arch/powerpc/lib/e2a.c
> ===================================================================
> --- to-merge.orig/arch/powerpc/lib/e2a.c
> +++ to-merge/arch/powerpc/lib/e2a.c
> @@ -103,4 +103,14 @@ unsigned char e2a(unsigned char x)
>  }
>  EXPORT_SYMBOL(e2a);
>  
> +unsigned char* strne2a(unsigned char *dest, const unsigned char *src, size_t n)
> +{
> +	int i;
>  
> +	n = strnlen(src, n);
> +
> +	for (i = 0; i < n; i++)
> +		dest[i] = e2a(src[i]);

Why iterate over the string twice? Why not do 
	for (..; i < n && src[n]; ...)
instead?


-Olof



More information about the Linuxppc-dev mailing list