Change EFREE_... macros to functions

Reduces code size by ~4k.
This commit is contained in:
Kim Woelders 2018-02-22 08:33:27 +01:00
parent b9a9946a0a
commit 3226edc567
2 changed files with 29 additions and 4 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright (C) 2000-2007 Carsten Haitzler, Geoff Harrison and various contributors
* Copyright (C) 2005-2015 Kim Woelders
* Copyright (C) 2005-2018 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -29,6 +29,27 @@
#include "util.h"
void
EfreeNull(void **p)
{
Efree(*p);
*p = NULL;
}
void
EfreeSet(void **p, void *s)
{
Efree(*p);
*p = s;
}
void
EfreeDup(char **p, const char *s)
{
Efree(*p);
*p = Estrdup(s);
}
char *
Estrtrim(char *s)
{

View File

@ -83,9 +83,13 @@ const char *Estrcasestr(const char *haystack, const char *needle);
#define EMALLOC(type, num) (type*)Emalloc((num)*sizeof(type))
#define EREALLOC(type, ptr, num) (type*)Erealloc(ptr, (num)*sizeof(type))
#define EFREE_NULL(p) do { Efree(p); p = NULL; } while (0)
#define EFREE_SET(p, s) do { Efree(p); p = s; } while (0)
#define EFREE_DUP(p, s) do { Efree(p); p = Estrdup(s); } while (0)
void EfreeNull(void **p);
void EfreeSet(void **p, void *s);
void EfreeDup(char **p, const char *s);
#define EFREE_NULL(p) EfreeNull((void**)(&p))
#define EFREE_SET(p, s) EfreeSet((void**)(&p), s)
#define EFREE_DUP(p, s) EfreeDup(&p, s)
#define STRCPY(dst, src) do { src[sizeof(dst)-1] = '\0'; strcpy(dst, src); } while(0)