Xref: utzoo unix-pc.general:3085 comp.lang.c:19382 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!bbn!diamond.bbn.com!mlandau From: mlandau@bbn.com (Matt Landau) Newsgroups: unix-pc.general,comp.lang.c Subject: Re: strdup() "need source" Keywords: big.banner Message-ID: <12876@jade.BBN.COM> Date: 15 Jun 89 21:14:43 GMT References: <124@sssphx.UUCP> Reply-To: mlandau@bbn.com (Matt Landau) Distribution: usa Organization: BBN Systems and Technologies Corporation, Cambridge, MA Lines: 27 Not that it's any big deal, and not that we won't have 250 different people each posting his or her own pet version of strdup to comp.lang.c, but here's a minimalist version: /* strdup(): Return a copy of the argument string. */ char *strdup(s) char *s; { extern char *malloc(), *strcpy(); char *p; if (s && (p = malloc(strlen(s) + 1))) return (strcpy(p, s)); return (NULL); } Although one can get even more minimalist with return (s && (p = malloc(strlen(s) + 1))) ? strcpy(p, s) : NULL; :-) -- Matt Landau mlandau@bbn.com Diplomacy is the art of saying "nice doggy" until you can find a rock.