blob: 5347aa8a8b7df33a2ff1aee26cbbd3cd1a775ec5 (
plain) (
blame)
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
|
#ifndef UNS_FORMAT_C89_H
#define UNS_FORMAT_C89_H
/* Copyright (C) 2024 Peter McGoron
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include "uns.h"
/* This is a strictly C89+ header format with relocation pointers and
* lengths.
*
* Forwarding pointers need to be stored in the header because in strict
* C, arithmetic on pointers is undefined for pointers not pointing into
* the same object.
*
* The length of the string is limited to "len" bytes and is stored as
* a `uns_sword`. If the word is negative, then the region is a record,
* and if the number is positive then the region is just bytes.
*/
struct uns_c89_relo_hdr {
void *relo;
uns_sword len;
};
#define uns_c89_relo_get_hdr(p)((struct uns_c89_relo_hdr *)(p) - 1)
size_t uns_c89_relo_get_len(void *p);
size_t uns_c89_relo_get_record_len(void *p);
#define uns_c89_relo_get_relo(p) (uns_c89_relo_get_hdr(p)->relo)
#define uns_c89_relo_set_relo(p, v) (uns_c89_relo_get_relo(p) = (v))
#define uns_c89_relo_is_record(p) (uns_c89_relo_get_hdr(p)->len < 0)
void *uns_c89_relo_init(void *p, size_t len_size, int is_record);
void uns_c89_relo_record_set(void *rec, size_t i, void *v);
void *uns_c89_relo_record_get(void *rec, size_t i);
#endif
|