diff options
| author | Warner Losh <imp@FreeBSD.org> | 2017-03-09 00:24:01 +0000 |
|---|---|---|
| committer | Warner Losh <imp@FreeBSD.org> | 2017-03-09 00:24:01 +0000 |
| commit | bea9d78b2d4f2581b0d707a3635856cc8b931f88 (patch) | |
| tree | 0941e160efb02001a1195b32fac395b825d7bfc4 /lib | |
| parent | c3e412c083332764a680da896e5d291821cc98bc (diff) | |
Notes
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/libefivar/Makefile | 8 | ||||
| -rw-r--r-- | lib/libefivar/efivar.c | 11 | ||||
| -rw-r--r-- | lib/libefivar/libefivar.c | 188 | ||||
| -rw-r--r-- | lib/libefivar/libefivar_int.h | 35 |
4 files changed, 12 insertions, 230 deletions
diff --git a/lib/libefivar/Makefile b/lib/libefivar/Makefile index c3ad3615e9d6..808087818eb6 100644 --- a/lib/libefivar/Makefile +++ b/lib/libefivar/Makefile @@ -26,13 +26,19 @@ .include <src.opts.mk> +EFIBOOT=${SRCTOP}/sys/boot/efi + +.PATH: ${EFIBOOT}/libefi + PACKAGE=lib${LIB} LIB= efivar -SRCS= efivar.c libefivar.c +SRCS= efivar.c efichar.c INCS= efivar.h SHLIB_MAJOR= 1 MAN= efivar.3 +CFLAGS+= -I${EFIBOOT}/include + MLINKS+=efivar.3 efi_set_variables_supported.3 \ efivar.3 efi_del_variable.3 \ efivar.3 efi_get_variable.3 \ diff --git a/lib/libefivar/efivar.c b/lib/libefivar/efivar.c index ad638a33e4aa..bce4a1449ab2 100644 --- a/lib/libefivar/efivar.c +++ b/lib/libefivar/efivar.c @@ -36,8 +36,7 @@ __FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> -#include "efivar.h" -#include "libefivar_int.h" +#include "efichar.h" static int efi_fd = -2; @@ -174,7 +173,7 @@ efi_get_variable(efi_guid_t guid, const char *name, return -1; efi_var_reset(&var); - rv = libefi_utf8_to_ucs2(name, &var.name, &var.namesize); + rv = utf8_to_ucs2(name, &var.name, &var.namesize); if (rv != 0) goto errout; var.vendor = guid; @@ -237,7 +236,7 @@ again: *buf = 0; /* GUID zeroed in var_reset */ } else { - rv = libefi_utf8_to_ucs2(*name, &var.name, &size); + rv = utf8_to_ucs2(*name, &var.name, &size); if (rv != 0) goto errout; var.vendor = **guid; @@ -261,7 +260,7 @@ again: if (rv == 0) { *name = NULL; /* XXX */ var.name[var.namesize / sizeof(efi_char)] = 0; /* EFI doesn't NUL terminate */ - rv = libefi_ucs2_to_utf8(var.name, name); + rv = ucs2_to_utf8(var.name, name); if (rv != 0) goto errout; retguid = var.vendor; @@ -359,7 +358,7 @@ efi_set_variable(efi_guid_t guid, const char *name, return -1; efi_var_reset(&var); - rv = libefi_utf8_to_ucs2(name, &var.name, &var.namesize); + rv = utf8_to_ucs2(name, &var.name, &var.namesize); if (rv != 0) goto errout; var.vendor = guid; diff --git a/lib/libefivar/libefivar.c b/lib/libefivar/libefivar.c deleted file mode 100644 index 951c484f5e3a..000000000000 --- a/lib/libefivar/libefivar.c +++ /dev/null @@ -1,188 +0,0 @@ -/*- - * Copyright (c) 2010 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); - -#include <sys/types.h> -#include <errno.h> -#include <stddef.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <sys/efi.h> -#include <machine/efi.h> - -#include "libefivar_int.h" - -#include <stdio.h> - -/* - * If nm were converted to utf8, what what would strlen - * return on the resulting string? - */ -static size_t -utf8_len_of_ucs2(const efi_char *nm) -{ - size_t len; - efi_char c; - - len = 0; - while (*nm) { - c = *nm++; - if (c > 0x7ff) - len += 3; - else if (c > 0x7f) - len += 2; - else - len++; - } - - return (len); -} - -int -libefi_ucs2_to_utf8(const efi_char *nm, char **name) -{ - size_t len, sz; - efi_char c; - char *cp; - int freeit = *name == NULL; - - sz = utf8_len_of_ucs2(nm) + 1; - len = 0; - if (*name != NULL) - cp = *name; - else - cp = *name = malloc(sz); - if (*name == NULL) - return (ENOMEM); - - while (*nm) { - c = *nm++; - if (c > 0x7ff) { - if (len++ < sz) - *cp++ = (char)(0xE0 | (c >> 12)); - if (len++ < sz) - *cp++ = (char)(0x80 | ((c >> 6) & 0x3f)); - if (len++ < sz) - *cp++ = (char)(0x80 | (c & 0x3f)); - } else if (c > 0x7f) { - if (len++ < sz) - *cp++ = (char)(0xC0 | ((c >> 6) & 0x1f)); - if (len++ < sz) - *cp++ = (char)(0x80 | (c & 0x3f)); - } else { - if (len++ < sz) - *cp++ = (char)(c & 0x7f); - } - } - - if (len >= sz) { - /* Absent bugs, we'll never return EOVERFLOW */ - if (freeit) - free(*name); - return (EOVERFLOW); - } - *cp++ = '\0'; - - return (0); -} - -int -libefi_utf8_to_ucs2(const char *name, efi_char **nmp, size_t *len) -{ - efi_char *nm; - size_t sz; - uint32_t ucs4; - int c, bytes; - int freeit = *nmp == NULL; - - sz = strlen(name) * 2 + 2; - if (*nmp == NULL) - *nmp = malloc(sz); - nm = *nmp; - *len = sz; - - ucs4 = 0; - bytes = 0; - while (sz > 1 && *name != '\0') { - c = *name++; - /* - * Conditionalize on the two major character types: - * initial and followup characters. - */ - if ((c & 0xc0) != 0x80) { - /* Initial characters. */ - if (bytes != 0) { - if (freeit) - free(nm); - return (EILSEQ); - } - if ((c & 0xf8) == 0xf0) { - ucs4 = c & 0x07; - bytes = 3; - } else if ((c & 0xf0) == 0xe0) { - ucs4 = c & 0x0f; - bytes = 2; - } else if ((c & 0xe0) == 0xc0) { - ucs4 = c & 0x1f; - bytes = 1; - } else { - ucs4 = c & 0x7f; - bytes = 0; - } - } else { - /* Followup characters. */ - if (bytes > 0) { - ucs4 = (ucs4 << 6) + (c & 0x3f); - bytes--; - } else if (bytes == 0) { - if (freeit) - free(nm); - return (EILSEQ); - } - } - if (bytes == 0) { - if (ucs4 > 0xffff) { - if (freeit) - free(nm); - return (EILSEQ); - } - *nm++ = (efi_char)ucs4; - sz -= 2; - } - } - if (sz < 2) { - if (freeit) - free(nm); - return (EDOOFUS); - } - sz -= 2; - *nm = 0; - *len -= sz; - return (0); -} diff --git a/lib/libefivar/libefivar_int.h b/lib/libefivar/libefivar_int.h deleted file mode 100644 index 276ab19dcffb..000000000000 --- a/lib/libefivar/libefivar_int.h +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * Copyright (c) 2010 Marcel Moolenaar - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * $FreeBSD$ - */ - -#ifndef _LIBEFI_INT_H_ -#define _LIBEFI_INT_H_ - -int libefi_ucs2_to_utf8(const efi_char *, char **); -int libefi_utf8_to_ucs2(const char *, efi_char **, size_t *); - -#endif /* _LIBEFI_INT_H_ */ |
