-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.c
More file actions
86 lines (66 loc) · 2.06 KB
/
Copy pathmain.c
File metadata and controls
86 lines (66 loc) · 2.06 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* /////////////////////////////////////////////////////////////////////////
* File: examples/c/example.c.auto_buffer/main.c
*
* Purpose: Example illustrating borrowed buffer growth to the heap
* (`CSTRING_F_MEMORY_IS_BORROWED` +
* `CSTRING_F_MEMORY_CAN_GROW_TO_HEAP`).
*
* Created: 28th July 2011
* Updated: 2nd August 2026
*
* ////////////////////////////////////////////////////////////////////// */
/* cstring header files */
#include <cstring/cstring.h>
/* STLSoft header files */
#if 0
#include <stlsoft/stlsoft.h>
#if _STLSOFT_VER >= 0x0a000000
# if defined(_WIN32)
# include <winstl/diagnostics/output_debug_line.h>
# endif
#endif
#endif /* 0 */
/* Standard C header files */
#include <stdio.h>
#include <stdlib.h>
/* /////////////////////////////////////////////////////////////////////////
* main()
*/
int main(int argc, char* argv[])
{
/* Create on a fixed buffer. */
cstring_t cs;
char buff[10];
int flags = 0
| CSTRING_F_MEMORY_IS_BORROWED
| CSTRING_F_MEMORY_CAN_GROW_TO_HEAP
;
CSTRING_RC rc = cstring_createEx(&cs, "String-#1", flags, buff, sizeof(buff));
((void)&argc);
((void)&argv);
if (CSTRING_RC_SUCCESS != rc)
{
fprintf(stderr, "Error: %s\n", cstring_getStatusCodeString(rc));
return EXIT_FAILURE;
}
printf("cs=<len=%lu, capacity=%lu>: '%.*s'\n"
, (unsigned long)cs.len
, (unsigned long)cs.capacity
, (int)cs.len, cs.ptr
);
/* add some more to exceed capacity */
rc = cstring_append(&cs, " : something very long");
if (CSTRING_RC_SUCCESS != rc)
{
fprintf(stderr, "Error: %s\n", cstring_getStatusCodeString(rc));
return EXIT_FAILURE;
}
printf("cs=<len=%lu, capacity=%lu>: '%.*s'\n"
, (unsigned long)cs.len
, (unsigned long)cs.capacity
, (int)cs.len, cs.ptr
);
cstring_destroy(&cs);
return EXIT_SUCCESS;
}
/* ///////////////////////////// end of file //////////////////////////// */