3 * Copyright (C) 1999, 2000 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 * print() - prints unformatted text to stdout
30 for(i
=0; i
<strlen(str
); i
++)
35 * convert_to_ascii() - converts a number to it's ascii equivalent
37 * GRUB -- GRand Unified Bootloader
38 * Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
40 char *convert_to_ascii(char *buf
, int c
, ...)
42 unsigned long num
= *((&c
) + 1), mult
= 10;
48 if ((num
& 0x80000000uL
) && c
== 'd')
58 *(ptr
++) = ( (dig
> 9) ? dig
+ 'a' - 10 : '0' + dig
);
62 /* reorder to correct direction!! */
80 * printf() - prints formatted text to stdout
82 * GRUB -- GRand Unified Bootloader
83 * Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
85 void printf(char *format
, ... )
87 int *dataptr
= (int *) &format
;
88 char c
, *ptr
, str
[16];
92 while ((c
= *(format
++)))
97 switch (c
= *(format
++))
99 case 'd': case 'u': case 'x':
100 *convert_to_ascii(str
, c
, *((unsigned long *) dataptr
++)) = 0;
108 case 'c': putchar((*(dataptr
++))&0xff); break;
111 ptr
= (char *)(*(dataptr
++));
113 while ((c
= *(ptr
++)))
120 void sprintf(char *buffer
, char *format
, ... )
122 int *dataptr
= (int *) &format
;
123 char c
, *ptr
, str
[16];
128 while ((c
= *(format
++)))
136 switch (c
= *(format
++))
138 case 'd': case 'u': case 'x':
139 *convert_to_ascii(str
, c
, *((unsigned long *) dataptr
++)) = 0;
151 *p
= (*(dataptr
++))&0xff;
156 ptr
= (char *)(*(dataptr
++));
158 while ((c
= *(ptr
++)))
170 int strlen(char *str
)
174 for(len
=0; str
[len
] != '\0'; len
++);
179 char *itoa(int value
, char *string
, int radix
)
182 *convert_to_ascii(string
, 'x', value
) = 0;
184 *convert_to_ascii(string
, 'd', value
) = 0;
191 if((c
>= 'a') && (c
<= 'z'))
199 if((c
>= 'A') && (c
<= 'Z'))
205 int memcmp(const void *buf1
, const void *buf2
, size_t count
)
208 const char *buffer1
= buf1
;
209 const char *buffer2
= buf2
;
211 for(i
=0; i
<count
; i
++)
213 if(buffer1
[i
] == buffer2
[i
])
216 return (buffer1
[i
] - buffer2
[i
]);
222 void *memcpy(void *dest
, const void *src
, size_t count
)
226 const char *buf2
= src
;
228 for(i
=0; i
<count
; i
++)
234 void *memset(void *dest
, int c
, size_t count
)
239 for(i
=0; i
<count
; i
++)
245 char *strcpy(char *dest
, char *src
)
256 char *strcat(char *dest
, char *src
)
270 char *strchr(const char *s
, int c
)
284 int strcmp(const char *string1
, const char *string2
)
286 while(*string1
== *string2
)
295 return *(unsigned const char *)string1
- *(unsigned const char *)(string2
);
298 int stricmp(const char *string1
, const char *string2
)
300 while(tolower(*string1
) == tolower(*string2
))
309 return (int)tolower(*string1
) - (int)tolower(*string2
);
312 int _strnicmp(const char *string1
, const char *string2
, size_t length
)
318 if (toupper(*string1
) != toupper(*string2
++))
319 return toupper(*(unsigned const char *)string1
) - toupper(*(unsigned const char *)--string2
);
323 while (--length
!= 0);
327 char *fgets(char *string
, int n
, FILE *stream
)
331 for(i
=0; i
<(n
-1); i
++)
339 ReadFile(stream
, 1, string
+i
);
341 if(string
[i
] == '\n')
352 int atoi(char *string
)
358 if((string
[0] == '0') && (string
[1] == 'x'))
371 if((*str
< '0') || (*str
> '9'))
375 result
+= (*str
- '0');