Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:05

0001 /*-
0002  * Copyright 2016 Netflix, Inc.
0003  *
0004  * Redistribution and use in source and binary forms, with or without
0005  * modification, are permitted provided that the following conditions
0006  * are met:
0007  * 1. Redistributions of source code must retain the above copyright
0008  *    notice, this list of conditions and the following disclaimer.
0009  * 2. Redistributions in binary form must reproduce the above copyright
0010  *    notice, this list of conditions and the following disclaimer in the
0011  *    documentation and/or other materials provided with the distribution.
0012  *
0013  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
0014  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0016  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
0017  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0018  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0019  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0020  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0021  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0022  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0023  * SUCH DAMAGE.
0024  */
0025 
0026 #include <sys/cdefs.h>
0027 __FBSDID("$FreeBSD$");
0028 
0029 #include <efi.h>
0030 #include <efilib.h>
0031 
0032 /*
0033  * CHAR16 related functions moved from loader.
0034  * Perhaps we should move those to libsa afterall, but they are
0035  * needed only by UEFI.
0036  */
0037 
0038 int
0039 wcscmp(CHAR16 *a, CHAR16 *b)
0040 {
0041 
0042     while (*a && *b && *a == *b) {
0043         a++;
0044         b++;
0045     }
0046     return *a - *b;
0047 }
0048 
0049 /*
0050  * cpy8to16 copies a traditional C string into a CHAR16 string and
0051  * 0 terminates it. len is the size of *dst in bytes.
0052  */
0053 void
0054 cpy8to16(const char *src, CHAR16 *dst, size_t len)
0055 {
0056     len <<= 1;      /* Assume CHAR16 is 2 bytes */
0057     while (len > 0 && *src) {
0058         *dst++ = *src++;
0059         len--;
0060     }
0061     *dst++ = (CHAR16)0;
0062 }
0063 
0064 void
0065 cpy16to8(const CHAR16 *src, char *dst, size_t len)
0066 {
0067     size_t i;
0068 
0069     for (i = 0; i < len && src[i]; i++)
0070         dst[i] = (char)src[i];
0071     if (i < len)
0072         dst[i] = '\0';
0073 }