From owner-freebsd-bugs Mon Nov 26 11:59:35 2001 Delivered-To: freebsd-bugs@freebsd.org Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by hub.freebsd.org (Postfix) with SMTP id 6329037B405; Mon, 26 Nov 2001 11:59:30 -0800 (PST) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 26 Nov 2001 19:59:29 +0000 (GMT) To: Ruslan Ermilov Cc: freebsd-bugs@FreeBSD.ORG Subject: Re: misc/32296: brk() has illegal prototype In-reply-to: Your message of "Mon, 26 Nov 2001 20:26:07 +0200." <20011126202607.B38902@sunbay.com> X-Request-Do: Date: Mon, 26 Nov 2001 19:59:29 +0000 From: David Malone Message-ID: <200111261959.aa10803@salmon.maths.tcd.ie> Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org > > brk seems to have been returning a char * on BSD for at least the > > last 10 years. It makes more sense for it to return an int, but > > that could cause binary compatability problems for platforms where > > an int and a char * are not the same size (eg. the alpha). > But it can't actually return a "char *", because all syscalls return > "int". :-) I did actually go check if there was any magic glue which did a case, but realised that I probably wouldn't be able to tell from the i386 assembly. > FWIW, NetBSD has changed the brk()'s prototype to return "int". I guess there is probably no harm in changing it then. As Joerg pointed out to me in private mail the bit pattern for 0 and -1 are the same in 2's compliment so as long as sizeof(int) >= sizeof(char *) then it's unlikely that we'll see any binary compatability problems. I'll try building a world with the patch below and if there are no objections I'll commit them in a week or so. David. Index: include/unistd.h =================================================================== RCS file: /cvs/FreeBSD-CVS/src/include/unistd.h,v retrieving revision 1.45 diff -u -r1.45 unistd.h --- include/unistd.h 13 Nov 2001 09:07:31 -0000 1.45 +++ include/unistd.h 26 Nov 2001 19:50:26 -0000 @@ -118,7 +118,7 @@ #endif int acct __P((const char *)); int async_daemon __P((void)); -char *brk __P((const char *)); +int brk __P((const char *)); int chroot __P((const char *)); size_t confstr __P((int, char *, size_t)); char *crypt __P((const char *, const char *)); Index: lib/libc/sys/brk.2 =================================================================== RCS file: /cvs/FreeBSD-CVS/src/lib/libc/sys/brk.2,v retrieving revision 1.22 diff -u -r1.22 brk.2 --- lib/libc/sys/brk.2 1 Oct 2001 16:09:01 -0000 1.22 +++ lib/libc/sys/brk.2 26 Nov 2001 19:53:19 -0000 @@ -43,7 +43,7 @@ .Lb libc .Sh SYNOPSIS .In unistd.h -.Ft char * +.Ft int .Fn brk "const char *addr" .Ft char * .Fn sbrk "int incr" @@ -116,16 +116,7 @@ for the definition of .Va etext ) . .Sh RETURN VALUES -The -.Fn brk -function returns -.Po Vt "char *" Pc Ns 0 -if successful; -otherwise the value -.Po Vt "char *" Pc Ns \-1 -is returned and the global variable -.Va errno -is set to indicate the error. +.Rv -std brk .Pp The .Fn sbrk To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message