*BSD News Article 5909


Return to BSD News archive

Xref: sserve comp.unix.bsd:5957 comp.sys.ibm.pc.rt:1687 comp.unix.large:618
Path: sserve!manuel!munnari.oz.au!uunet!haven.umd.edu!darwin.sura.net!Sirius.dfn.de!fauern!btr0x1!mb3.tu-chemnitz.de!hrz.tu-chemnitz.de!wutcd
From: wutcd@chemnitz.guug.de (Joerg Wunsch)
Newsgroups: comp.unix.bsd,comp.sys.ibm.pc.rt,comp.unix.large
Subject: Re: strdup
Message-ID: <wutcd.717977812@hadrian>
Date: 1 Oct 92 22:16:52 GMT
References: <br.pct.52.717898310@RLG.Stanford.EDU>
Sender: bin@hrz.tu-chemnitz.de (Owner of all binaries)
Organization: tu-chemnitz
Lines: 32

br.pct@RLG.Stanford.EDU (Peter C. Tam) writes:


>	In BSD 4.3 C lib, there is no strdup that is provided in System 5,
>& I just happened to get a program that was supposed to be able to compile
>in BSD also. Can anyone tell me where I can get the strdup routine for
>BSD 4.3, especially, in ibm.pc.rt AOS.

This is an easy exercise. You'll find an example in K&R, here is my
version. (Of course, the function should be included into the libc.a.)

#include <strings.h>	/* strlen(), include a prototype for strdup here */
#include <stdlib.h>	/* malloc() */

char *
strdup(const char *src)
{
	char *rv;
	register char *dst;

	if(rv = dst = (char *)malloc(strlen(src) + 1))
		while(*dst++ = *src++) /* hmmm... */ ;
	return rv;
}

	J"org

--
J"org Wunsch, TCD GmbH Dresden, R"ahnitzgasse 18, D-O-8060 Dresden
                                                              \     ~.~. 
	joerg_wunsch%bonnie@hadrian.hrz.tu-chemnitz.de         \   ~  | ~ 
	voice: +49-351-5965 137                                 \    ===