Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 25 Apr 2012 06:55:03 -0500 Message-ID: <4F97E61A.464@mindspring.com> Date: Wed, 25 Apr 2012 07:55:06 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: What standard library functions must deal with allocated memory? References: <4f9598df$0$20194$426a74cc@news.free.fr> <14459967.23.1335253094679.JavaMail.geo-discussion-forums@yndm3> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Lines: 66 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.228.95 X-Trace: sv3-Zcoq4H1l0iMOAGp2yrIdhoUqGMRqOVRua6WMIP/++CwG01v4cPdzcladmQpEO5W/RUoqTmTC9xkZREp!zait8IJXCXtuTP1XkmffQN03Se2W+H2I312WzJ15aKy6RoRtJjRT5oGoV7Mmru07vJACYq5TTs8S!aoLX9zXr X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2868 X-Received-Bytes: 3009 Xref: csiph.com comp.lang.c:19899 Stephen Sprunk wrote: > > On 24-Apr-12 02:38, Malcolm McLean wrote: > > בתאריך יום ש× י, 23 באפריל 2012 19:01:49 UTC+1, מאת Francois Grieu: > >> I'm trying to list all the standard > >> C99/C2011 library functions that, by > >> design, must deal with allocated memory in any way. > >> > >> I've seen calloc malloc realloc free. Is there any other? > >> If strdup was a standard function (it is not), > >> it would be in my list. > > > > None of them, except for malloc(), realloc() and free() themselves. > > > > This appears to have been a deliberate design decision. > > strdup() is an obvious candidate for a library function, > > but including it would make > > the string library dependent on an allocation > > package being available. > > I thought it was a combination of wanting memory-allocation > functions to be clearly identifiable as such > and avoiding functions that were trivial > combinations of other primitive functions already provided. There's already at least a couple of string functions which are trivial combinations of other primitive functions already provided. char * strcat(char *s1, const char *s2) { strcpy(strlen(s1) + s1, s2); return s1; } char * strpbrk(const char *s1, const char *s2) { s1 += strcspn(s1, s2); return *s1 != '\0' ? (char *)s1 : NULL; } There's also some trivial repackaging declared in stdio.h int vprintf(const char *format, va_list arg) { return vfprintf(stdout, format, arg); } and also declared in ctype.h int isalpha(int c) { return islower(c) || isupper(c); } int isalnum(int c) { return isdigit(c) || isalpha(c); } -- pete