2005-04-16 11:20:53 +02:00
|
|
|
/*
|
|
|
|
* ngIRCd -- The Next Generation IRC Daemon
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portab.h"
|
|
|
|
|
2010-12-27 17:14:14 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* strdup() implementation. Public domain.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HAVE_STRDUP
|
|
|
|
|
2005-04-16 11:20:53 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
GLOBAL char *
|
2014-03-16 22:59:03 +01:00
|
|
|
strdup(const char *s)
|
2005-04-16 11:20:53 +02:00
|
|
|
{
|
2014-03-16 22:59:03 +01:00
|
|
|
char *dup;
|
|
|
|
size_t len = strlen(s);
|
|
|
|
size_t alloc = len + 1;
|
2005-04-16 11:20:53 +02:00
|
|
|
|
2014-03-16 22:59:03 +01:00
|
|
|
if (len >= alloc)
|
|
|
|
return NULL;
|
|
|
|
dup = malloc(alloc);
|
|
|
|
if (dup)
|
|
|
|
strlcpy(dup, s, alloc );
|
2005-04-16 11:20:53 +02:00
|
|
|
|
2014-03-16 22:59:03 +01:00
|
|
|
return dup;
|
2005-04-16 11:20:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|