This source file includes following definitions.
- __libc_scratch_buffer_grow_preserve
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #ifndef _LIBC
20 # include <libc-config.h>
21 #endif
22
23 #include <scratch_buffer.h>
24 #include <errno.h>
25 #include <string.h>
26
27 bool
28 __libc_scratch_buffer_grow_preserve (struct scratch_buffer *buffer)
29 {
30 size_t new_length = 2 * buffer->length;
31 void *new_ptr;
32
33 if (buffer->data == buffer->__space.__c)
34 {
35
36
37 new_ptr = malloc (new_length);
38 if (new_ptr == NULL)
39 return false;
40 memcpy (new_ptr, buffer->__space.__c, buffer->length);
41 }
42 else
43 {
44
45 if (__glibc_likely (new_length >= buffer->length))
46 new_ptr = realloc (buffer->data, new_length);
47 else
48 {
49 __set_errno (ENOMEM);
50 new_ptr = NULL;
51 }
52
53 if (__glibc_unlikely (new_ptr == NULL))
54 {
55
56 free (buffer->data);
57 scratch_buffer_init (buffer);
58 return false;
59 }
60 }
61
62
63 buffer->data = new_ptr;
64 buffer->length = new_length;
65 return true;
66 }
67 libc_hidden_def (__libc_scratch_buffer_grow_preserve)