PatchworkOS  2ca1c69
A non-POSIX operating system.
Loading...
Searching...
No Matches
mid.c
Go to the documentation of this file.
2
3aml_object_t* aml_mid(aml_state_t* state, aml_object_t* bufferString, aml_uint_t index, aml_uint_t length)
4{
5 if (state == NULL || bufferString == NULL || (bufferString->type != AML_BUFFER && bufferString->type != AML_STRING))
6 {
8 return NULL;
9 }
10
11 aml_object_t* result = aml_object_new();
12 if (result == NULL)
13 {
14 return NULL;
15 }
16 DEREF_DEFER(result);
17
18 if (bufferString->type == AML_BUFFER)
19 {
20 if (aml_buffer_set_empty(result, length) == ERR)
21 {
22 return NULL;
23 }
24 }
25 else
26 {
27 if (aml_string_set_empty(result, length) == ERR)
28 {
29 return NULL;
30 }
31 }
32
33 uint64_t objectLength =
34 bufferString->type == AML_BUFFER ? bufferString->buffer.length : bufferString->string.length;
35 if (index >= objectLength)
36 {
37 return REF(result);
38 }
39
40 if (index + length > objectLength)
41 {
42 length = objectLength - index;
43 }
44
45 if (bufferString->type == AML_BUFFER)
46 {
47 memcpy(result->buffer.content, &bufferString->buffer.content[index], length);
48 }
49 else
50 {
51 memcpy(result->string.content, &bufferString->string.content[index], length);
52 result->string.content[length] = '\0';
53 }
54
55 return REF(result);
56}
#define DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
Definition ref.h:54
#define REF(ptr)
Increment reference count.
Definition ref.h:65
#define EINVAL
Invalid argument.
Definition errno.h:142
#define errno
Error number variable.
Definition errno.h:27
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
uint64_t aml_uint_t
AML Integer type.
Definition integer.h:20
aml_object_t * aml_mid(aml_state_t *state, aml_object_t *bufferString, aml_uint_t index, aml_uint_t length)
Performs a "mid" operation, extracting a portion of a buffer or string.
Definition mid.c:3
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
Definition object.c:62
uint64_t aml_buffer_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty buffer with the given length.
Definition object.c:533
uint64_t aml_string_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty string with the given length.
Definition object.c:1026
@ AML_STRING
Definition object.h:85
@ AML_BUFFER
Definition object.h:61
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
Definition memcpy.c:61
uint64_t length
Definition object.h:216
uint8_t * content
Definition object.h:215
ACPI object.
Definition object.h:447
aml_buffer_t buffer
Definition object.h:453
aml_string_t string
Definition object.h:467
AML State.
Definition state.h:25
uint64_t length
Definition object.h:393
char * content
Definition object.h:392