2 * Copyright (C) 1999-2003 Hewlett-Packard Co.
3 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
5 * This file is part of the ELILO, the EFI Linux boot loader.
7 * ELILO is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * ELILO is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with ELILO; see the file COPYING. If not, write to the Free
19 * Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 * Please check out the elilo.txt for complete documentation on how
23 * to use this program.
29 //#define CHAR_NULL (CHAR16)'\0'
32 StrChr(IN const CHAR16 *s, IN const CHAR16 c)
34 for(; *s != c; ++s) if (*s == CHAR_NULL) return NULL;
40 StrnCpy(OUT CHAR16 *dst, IN const CHAR16 *src, IN UINTN size)
44 while (size-- && (*dst++ = *src++) != CHAR_NULL);
46 * does the null padding
48 while (size-- > 0) *dst++ = CHAR_NULL;
54 StrnXCpy(OUT CHAR8 *dst, IN const CHAR16 *src, IN UINTN size)
58 while (size-- && (*dst++ = (CHAR8)*src++) != '\0');
60 * does the null padding
62 while (size-- > 0) *dst++ = '\0';
68 U2ascii(CHAR16 *in, CHAR8 *out, UINTN maxlen)
70 while(maxlen-- > 1 && (*out++ = *in++));
75 strncpya(OUT CHAR8 *dst, IN const CHAR8 *src, IN UINTN size)
79 while (size-- && (*dst++ = *src++) != '\0');
81 * does the null padding
83 while (size-- > 0) *dst++ = '\0';
89 strcpya(CHAR8 *dst, const CHAR8 *src)
103 strchra(IN const CHAR8 *s, IN const CHAR8 c)
106 if (*s == 0) return NULL;
111 strcata(IN CHAR8 *dst,IN CHAR8 *src)
113 return strcpya(dst+strlena(dst), src);
117 strrchra(IN const CHAR8 *s, const INTN c)
119 CHAR8 *found, *p, ch = (CHAR8)c;
121 /* Since strchr is fast, we use it rather than the obvious loop. */
123 if (ch == '\0') return strchra(s, '\0');
126 while ((p = strchra(s, ch)) != NULL)
132 return (CHAR8 *) found;
136 strtok_simple(CHAR8 *in, CHAR8 c)
141 if (in == NULL) in = last;
143 if (in == NULL) return NULL;
147 tmp = strchra(in, c);
158 ascii2U(CHAR8 *in, CHAR16 *out, UINTN maxlen)
160 while(maxlen-- > 1 && (*out++ = *in++));