[Libclc-developers] Re: contribution(?): string function ultostr()
Status: Planning
Brought to you by:
augestad
|
From: Jan E. <je...@li...> - 2003-03-17 16:56:13
|
>> /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
>> ultostr
>> by Jan "Hirogen2" Engelhardt <hirogen2 at gmx de>, 2003
>> -- distributed under the Frontier Artistic License and GNU General P=
ublic
>> -- License. See doc/FAL1.txt and doc/GPL2.txt for details.
>
>The license must be changed to BSD.
What's the thing about BSD?
>> NAME
>> ultostr - convert an unsigned long integer to a string
>The name must be prefixed with clc_ .
Was just straight forward copied from my lib, so there is not anything cl=
c
related in it ;)
>> SYNOPSIS
>> unsigned char *ultostr(unsigned long num, unsigned long base,
>> unsigned char *ptr, size_t size);
>unsigned long base is pretty long for the range 2..36 :-) strtoul uses
>int for base.
woho... heh right, that probably should have been unsigned char.
>Unsigned char* are very uncommon in C libraries, and its buddy function
>strtoul uses char*.
And? I like it. It's probably because I cannot feel comfortable when they
assign the '=F6' a value of -10.
>I assume that you mean that errno is set to ERANGE? I guess we won't
Whatever. Take EDOM.
>have to test for legal base. strtoul sets errno to EINVAL if base is out
Oh yeah I know that, but it looks like I swapped EINVAL and EFAULT. Every=
where
where I looked.
>/* Proper libclc format guidelines (unpublished :-)) applied */
this is the thing nobody can really agree to, the discussion for such is =
way
too long.
The major aspects of my style are
>unsigned char *ultostr(
> unsigned long num,
> unsigned long base,
> unsigned char *ptr,
> size_t size)
- one row, or indent-by-1 if longer than 79 chars
>{
- as well as keeping any { on the line
> unsigned char *sym =3D "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
>
> clc_assert_not_null(ultostr, ptr);
> clc_assert_arg(ultostr, base >=3D 2 && base <=3D 36);
>
> *startp =3D ptr + size - 2;
> if(base < 2 || base > 36) {
> errno =3D ERANGE;
> return NULL;
> }
>
> while(--size > 0) {
> *ptr =3D sym[num % base];
> num /=3D base;
> --ptr;
> }
>
> return ptr;
>}
>
>I fail to see where startp is defined.
imagine ptr is startp
>Very good documentation!
Indeed stolen from strtoul
- Jan Engelhardt
|