File: stretchy.cpp

package info (click to toggle)
cgdb 0.8.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,468 kB
  • sloc: cpp: 12,169; ansic: 10,042; sh: 4,383; exp: 640; makefile: 197
file content (31 lines) | stat: -rw-r--r-- 757 bytes parent folder | download | duplicates (2)
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
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */

#include "sys_util.h"
#include "stretchy.h"

/* stb__sbgrowf: internal stretchy buffer grow function. */
int stb__sbgrowf(void **arr, int increment, int itemsize)
{
    int m = *arr ? 2 * stb__sbm( *arr ) + increment : increment + 1;
    void *p = cgdb_realloc( *arr ? stb__sbraw( *arr ) : 0,
                            itemsize * m + sizeof( int ) * 2 );

    if ( !*arr )
        ( ( int * )p )[ 1 ] = 0;
    *arr = ( void * )( ( int * )p + 2 );
    stb__sbm( *arr ) = m;

    return 0;
}

void stb__shlf(void **arr, int itemsize)
{
    int n = stb__sbn(*arr);
    char *arrptr = (char *)(*arr);

    memmove(arrptr, arrptr + itemsize, itemsize * (n - 1));

    stb__sbn(*arr) = n - 1;
}