Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/stdlib.cfa

    re3fea42 r76e2113  
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  4 08:27:08 2020
    13 // Update Count     : 486
     12// Last Modified On : Thu Apr 16 22:43:33 2020
     13// Update Count     : 498
    1414//
    1515
     
    2020#define _XOPEN_SOURCE 600                                                               // posix_memalign, *rand48
    2121#include <string.h>                                                                             // memcpy, memset
    22 #include <malloc.h>                                                                             // malloc_usable_size
    2322//#include <math.h>                                                                             // fabsf, fabs, fabsl
    2423#include <complex.h>                                                                    // _Complex_I
     
    3837        } // alloc_set
    3938
     39        T * alloc_set( T ptr[], size_t dim, T fill ) {          // realloc array with fill
     40                size_t olen = malloc_usable_size( ptr );                // current allocation
     41                void * nptr = (void *)realloc( (void *)ptr, dim * sizeof(T) ); // C realloc
     42                size_t nlen = malloc_usable_size( nptr );               // new allocation
     43                if ( nlen > olen ) {                                                    // larger ?
     44                        for ( i; malloc_size( ptr ) / sizeof(T) ~ dim ) {
     45                                memcpy( &ptr[i], &fill, sizeof(T) );    // initialize with fill value
     46                        } // for
     47                } // if
     48                return (T *)nptr;
     49        } // alloc_align_set
     50
    4051        T * alloc_align_set( T ptr[], size_t align, char fill ) { // aligned realloc with fill
    4152                size_t olen = malloc_usable_size( ptr );                // current allocation
     
    4556                if ( nlen > olen ) {                                                    // larger ?
    4657                        memset( (char *)nptr + olen, (int)fill, nlen - olen ); // initialize added storage
     58                } // if
     59                return (T *)nptr;
     60        } // alloc_align_set
     61
     62        T * alloc_align_set( T ptr[], size_t align, size_t dim, T fill ) { // aligned realloc with fill
     63                size_t olen = malloc_usable_size( ptr );                // current allocation
     64                void * nptr = (void *)realloc( (void *)ptr, align, sizeof(T) ); // CFA realloc
     65                // char * nptr = alloc_align( ptr, align );
     66                size_t nlen = malloc_usable_size( nptr );               // new allocation
     67                if ( nlen > olen ) {                                                    // larger ?
     68                        for ( i; dim ) { memcpy( &ptr[i], &fill, sizeof(T) ); } // initialize with fill value
    4769                } // if
    4870                return (T *)nptr;
Note: See TracChangeset for help on using the changeset viewer.