summaryrefslogtreecommitdiff
path: root/brillo_uefi_x86_64/boot_loader/bub_util.h
blob: 74b32f30fadbccce74e47f08e3b5f8035fab5051 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef BUB_UTIL_H_
#define BUB_UTIL_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Converts a UTF-8 string, |utf8_data|, to UCS-2 stored in |ucs2_data|. Caller
 * must specify |utf8_num_bytes| as the number of bytes of the null-terminated
 * |utf8_data|. Caller must have allocated enough bytes for the resulting UCS-2
 * specified by |ucs2_data_capacity_num_bytes|. 2 * len(|utf8_data|) + 1 would
 * be the upper bound of |ucs2_data_capacity_num_bytes|.
 *
 */
int utf8_to_ucs2(const uint8_t* utf8_data,
                 size_t utf8_num_bytes,
                 uint16_t* ucs2_data,
                 size_t ucs2_data_capacity_num_bytes);

/* Allocates |size| bytes set to all zeros. Returns NULL if no memory is
 * available, otherwise a pointer to the allocated memory.
 *
 * The memory is not initialized.
 *
 * The pointer returned is guaranteed to be word-aligned.
 *
 * The memory should be freed with bub_free() when you are done with it.
 */
void* bub_calloc(size_t size);

/* Converts a 32-bit unsigned integer from big-endian to host byte order. */
uint32_t bub_be32toh(uint32_t in);

/* Converts a 64-bit unsigned integer from big-endian to host byte order. */
uint64_t bub_be64toh(uint64_t in);

/* Calculates and returns crc32 value of |data| given byte size, |data_size|. */
uint32_t bub_crc32(const uint8_t* data, size_t data_size);

#ifdef __cplusplus
}
#endif

#endif /* BUB_UTIL_H_ */