Blame src/xmalloc.h

Packit Service a2489d
/*
Packit Service a2489d
 * lftp - file transfer program
Packit Service a2489d
 *
Packit Service a2489d
 * Copyright (c) 1996-2016 by Alexander V. Lukyanov (lav@yars.free.net)
Packit Service a2489d
 *
Packit Service a2489d
 * This program is free software; you can redistribute it and/or modify
Packit Service a2489d
 * it under the terms of the GNU General Public License as published by
Packit Service a2489d
 * the Free Software Foundation; either version 3 of the License, or
Packit Service a2489d
 * (at your option) any later version.
Packit Service a2489d
 *
Packit Service a2489d
 * This program is distributed in the hope that it will be useful,
Packit Service a2489d
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service a2489d
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service a2489d
 * GNU General Public License for more details.
Packit Service a2489d
 *
Packit Service a2489d
 * You should have received a copy of the GNU General Public License
Packit Service a2489d
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit Service a2489d
 */
Packit Service a2489d
Packit Service a2489d
#ifndef XMALLOC_H
Packit Service a2489d
#define XMALLOC_H
Packit Service a2489d
Packit Service a2489d
#include <stdlib.h>
Packit Service a2489d
Packit Service a2489d
#ifdef DBMALLOC
Packit Service a2489d
#include "dbmalloc.h"
Packit Service a2489d
#endif
Packit Service a2489d
Packit Service a2489d
void *xmalloc(size_t);
Packit Service a2489d
void *xrealloc(void *,size_t);
Packit Service a2489d
char *xstrdup(const char *s,int spare=0);
Packit Service a2489d
char *xstrset(char *&mem,const char *s);
Packit Service a2489d
char *xstrset(char *&mem,const char *s,size_t n);
Packit Service a2489d
#define alloca_strdup(s) alloca_strdup2((s),0)
Packit Service a2489d
#define alloca_strdup2(s,n) (strcpy((char*)alloca(strlen((s))+1+(n)),(s)))
Packit Service a2489d
#define alloca_append(s1,s2) strcat(alloca_strdup2((s1),strlen((s2))),(s2));
Packit Service a2489d
Packit Service a2489d
void xfree(void *p);
Packit Service a2489d
void xmalloc_register_block(void *);
Packit Service a2489d
Packit Service a2489d
#include "xstring.h"
Packit Service a2489d
Packit Service a2489d
static inline void *xmemdup(const void *m,int len)
Packit Service a2489d
{
Packit Service a2489d
   if(!m) return 0;
Packit Service a2489d
   void *buf=xmalloc(len);
Packit Service a2489d
   memcpy(buf,m,len);
Packit Service a2489d
   return buf;
Packit Service a2489d
}
Packit Service a2489d
Packit Service a2489d
#endif /* XMALLOC_H */