util.c revision e7dd673d1e0acfe5420599588c559fd85a3a9e8f
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/*
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* Copyright (C) 2012-2013 Kay Sievers <kay@vrfy.org>
* Copyright (C) 2012 Harald Hoyer <harald@redhat.com>
*/
#include <efi.h>
#include <efilib.h>
#include "util.h"
/*
* Allocated random UUID, intended to be shared across tools that implement
* the (ESP)\loader\entries\<vendor>-<revision>.conf convention and the
* associated EFI variables.
*/
static const EFI_GUID loader_guid = { 0x4a67b082, 0x0a4c, 0x41cf, {0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f} };
#ifdef __x86_64__
UINT64 a, d;
return (d << 32) | a;
}
#else
return val;
}
#endif
/* count TSC ticks during a millisecond delay */
ticks_start = ticks_read();
ticks_end = ticks_read();
}
ticks = ticks_read();
if (ticks == 0)
return 0;
if (freq == 0) {
freq = ticks_freq();
if (freq == 0)
return 0;
}
}
EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, CHAR16 *name, CHAR8 *buf, UINTN size, BOOLEAN persistent) {
if (persistent)
}
return efivar_set_raw(&loader_guid, name, (CHAR8 *)value, value ? (StrLen(value)+1) * sizeof(CHAR16) : 0, persistent);
}
}
return err;
if (!val) {
return EFI_OUT_OF_RESOURCES;
}
return EFI_SUCCESS;
}
}
return err;
}
UINTN l;
l = sizeof(CHAR16 *) * EFI_MAXIMUM_VARIABLE_SIZE;
buf = AllocatePool(l);
if (!buf)
return EFI_OUT_OF_RESOURCES;
if (size)
*size = l;
} else
return err;
}
if (usec == 0)
if (usec == 0)
return;
}
UINTN i;
if (stra[0] < 0x80)
len = 1;
len = 2;
len = 3;
len = 4;
len = 5;
len = 6;
else
return -1;
switch (len) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
}
for (i = 1; i < len; i++) {
return -1;
unichar <<= 6;
}
*c = unichar;
return len;
}
UINTN i;
strlen = 0;
i = 0;
while (i < len) {
if (utf8len <= 0) {
/* invalid utf8 sequence, skip the garbage */
i++;
continue;
}
strlen++;
i += utf8len;
}
return str;
}
UINTN i;
str[0] = '\\';
strlen = 1;
i = 0;
while (i < len) {
if (utf8len <= 0) {
/* invalid utf8 sequence, skip the garbage */
i++;
continue;
}
/* skip double slashes */
i += utf8len;
continue;
}
strlen++;
i += utf8len;
}
return str;
}
do {
if (*s == c)
return s;
} while (*s++);
return NULL;
}
return err;
if (size == 0) {
} else
if (off > 0) {
return err;
}
} else {
}
return len;
}