@@ -29,31 +29,12 @@ void ffStrbufInitCopy(FFstrbuf* strbuf, const FFstrbuf* src)
2929 ffStrbufAppend (strbuf , src );
3030}
3131
32- static void setCapacity ( FFstrbuf * strbuf , uint32_t capacity )
32+ uint32_t ffStrbufGetFree ( const FFstrbuf * strbuf )
3333{
3434 if (strbuf -> allocated == 0 )
35- {
36- strbuf -> chars = malloc (sizeof (* strbuf -> chars ) * capacity );
37- strbuf -> chars [0 ] = '\0' ;
38- }
39- else
40- strbuf -> chars = realloc (strbuf -> chars , sizeof (* strbuf -> chars ) * capacity );
41-
42- strbuf -> allocated = capacity ;
43- }
44-
45- void ffStrbufEnsureCapacity (FFstrbuf * strbuf , uint32_t capacity )
46- {
47- if (strbuf -> allocated > capacity || capacity == 0 )
48- return ;
49-
50- if (capacity == UINT32_MAX )
51- {
52- fputs ("Warning: ffStrbufEnsureCapacity called with UINT32_MAX. Highest allowed value is UINT32_MAX - 1. Exiting.\n" , stderr );
53- exit (812 );
54- }
35+ return 0 ;
5536
56- setCapacity ( strbuf , capacity + 1 ) ; // + 1 for the null byte
37+ return strbuf -> allocated - strbuf -> length - 1 ; // - 1 for the null byte
5738}
5839
5940void ffStrbufEnsureFree (FFstrbuf * strbuf , uint32_t free )
@@ -68,15 +49,15 @@ void ffStrbufEnsureFree(FFstrbuf* strbuf, uint32_t free)
6849 while ((strbuf -> length + free + 1 ) > allocate ) // + 1 for the null byte
6950 allocate *= 2 ;
7051
71- setCapacity (strbuf , allocate );
72- }
73-
74- uint32_t ffStrbufGetFree (const FFstrbuf * strbuf )
75- {
7652 if (strbuf -> allocated == 0 )
77- return 0 ;
53+ {
54+ strbuf -> chars = malloc (sizeof (* strbuf -> chars ) * allocate );
55+ strbuf -> chars [0 ] = '\0' ;
56+ }
57+ else
58+ strbuf -> chars = realloc (strbuf -> chars , sizeof (* strbuf -> chars ) * allocate );
7859
79- return strbuf -> allocated - strbuf -> length - 1 ; // - 1 for the null byte
60+ strbuf -> allocated = allocate ;
8061}
8162
8263void ffStrbufClear (FFstrbuf * strbuf )
0 commit comments