Kannel: Open Source WAP and SMS gateway  svn-r5335
gwmem-native.c File Reference
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "gwlib.h"

Go to the source code of this file.

Functions

void * gw_native_noop (void *ptr)
 
void * gw_native_malloc (size_t size)
 
void * gw_native_calloc (int nmemb, size_t size)
 
void * gw_native_realloc (void *ptr, size_t size)
 
void gw_native_free (void *ptr)
 
char * gw_native_strdup (const char *str)
 

Function Documentation

◆ gw_native_calloc()

void* gw_native_calloc ( int  nmemb,
size_t  size 
)

Definition at line 94 of file gwmem-native.c.

References calloc, gw_assert(), panic, and size.

95 {
96  void *ptr;
97 
98  /* ANSI C89 says malloc(0) is implementation-defined. Avoid it. */
99  gw_assert(size > 0);
100  gw_assert(nmemb > 0);
101 
102  ptr = calloc(nmemb, size);
103  if (ptr == NULL)
104  panic(errno, "Memory allocation failed");
105 
106  return ptr;
107 }
int size
Definition: wsasm.c:84
gw_assert(wtls_machine->packet_to_send !=NULL)
#define calloc(a, b)
Definition: gwmem.h:192
#define panic
Definition: log.h:87

◆ gw_native_free()

void gw_native_free ( void *  ptr)

Definition at line 123 of file gwmem-native.c.

References free().

Referenced by gw_backtrace().

124 {
125  free(ptr);
126 }
void free(void *)

◆ gw_native_malloc()

void* gw_native_malloc ( size_t  size)

Definition at line 80 of file gwmem-native.c.

References gw_assert(), malloc(), panic, and size.

Referenced by gw_native_strdup().

81 {
82  void *ptr;
83 
84  /* ANSI C89 says malloc(0) is implementation-defined. Avoid it. */
85  gw_assert(size > 0);
86 
87  ptr = malloc(size);
88  if (ptr == NULL)
89  panic(errno, "Memory allocation failed");
90 
91  return ptr;
92 }
int size
Definition: wsasm.c:84
gw_assert(wtls_machine->packet_to_send !=NULL)
void * malloc(YYSIZE_T)
#define panic
Definition: log.h:87

◆ gw_native_noop()

void* gw_native_noop ( void *  ptr)

Definition at line 78 of file gwmem-native.c.

78 { return ptr; }

◆ gw_native_realloc()

void* gw_native_realloc ( void *  ptr,
size_t  size 
)

Definition at line 109 of file gwmem-native.c.

References gw_assert(), panic, realloc, and size.

110 {
111  void *new_ptr;
112 
113  gw_assert(size > 0);
114 
115  new_ptr = realloc(ptr, size);
116  if (new_ptr == NULL)
117  panic(errno, "Memory re-allocation failed");
118 
119  return new_ptr;
120 }
int size
Definition: wsasm.c:84
gw_assert(wtls_machine->packet_to_send !=NULL)
#define realloc(p, n)
Definition: gwmem.h:193
#define panic
Definition: log.h:87

◆ gw_native_strdup()

char* gw_native_strdup ( const char *  str)

Definition at line 129 of file gwmem-native.c.

References gw_assert(), gw_native_malloc(), and size.

130 {
131  char *copy;
132  int size;
133 
134  gw_assert(str != NULL);
135  size = strlen(str) + 1;
136 
137  copy = gw_native_malloc(size);
138  memcpy(copy, str, size);
139  return copy;
140 }
int size
Definition: wsasm.c:84
gw_assert(wtls_machine->packet_to_send !=NULL)
void * gw_native_malloc(size_t size)
Definition: gwmem-native.c:80
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.