]>
Commit | Line | Data |
---|---|---|
9385eb3d A |
1 | /* |
2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
9385eb3d A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
5b2abdfb A |
23 | /* |
24 | * Written by J.T. Conklin <jtc@netbsd.org>. | |
25 | * Public domain. | |
26 | */ | |
27 | ||
28 | #if defined(LIBC_SCCS) && !defined(lint) | |
29 | static char *rcsid = "$OpenBSD: l64a.c,v 1.3 1997/08/17 22:58:34 millert Exp $"; | |
30 | #endif /* LIBC_SCCS and not lint */ | |
31 | ||
32 | #include <errno.h> | |
33 | #include <stdlib.h> | |
34 | ||
35 | char * | |
36 | l64a(value) | |
37 | long value; | |
38 | { | |
39 | static char buf[8]; | |
40 | char *s = buf; | |
41 | int digit; | |
42 | int i; | |
43 | ||
44 | if (value < 0) { | |
45 | errno = EINVAL; | |
46 | return(NULL); | |
47 | } | |
48 | ||
49 | for (i = 0; value != 0 && i < 6; i++) { | |
50 | digit = value & 0x3f; | |
51 | ||
52 | if (digit < 2) | |
53 | *s = digit + '.'; | |
54 | else if (digit < 12) | |
55 | *s = digit + '0' - 2; | |
56 | else if (digit < 38) | |
57 | *s = digit + 'A' - 12; | |
58 | else | |
59 | *s = digit + 'a' - 38; | |
60 | ||
61 | value >>= 6; | |
62 | s++; | |
63 | } | |
64 | ||
65 | *s = '\0'; | |
66 | ||
67 | return(buf); | |
68 | } | |
69 |