[BACK]Return to strdup.c CVS log [TXT][DIR] Up to [local] / ircnowd / src / portab

File: [local] / ircnowd / src / portab / strdup.c (download)

Revision 1.1, Thu May 16 11:07:06 2024 UTC (4 months ago) by tomglok
Branch point for: MAIN

Initial revision

/*
 * ngIRCd -- The Next Generation IRC Daemon
 */

#include "portab.h"

/**
 * @file
 * strdup() implementation. Public domain.
 */

#ifndef HAVE_STRDUP

#include <string.h>
#include <stdlib.h>
#include <sys/types.h>

GLOBAL char *
strdup(const char *s)
{
	char *dup;
	size_t len = strlen(s);
	size_t alloc = len + 1;

	if (len >= alloc)
		return NULL;
	dup = malloc(alloc);
	if (dup)
		strlcpy(dup, s, alloc );

	return dup;
}

#endif