Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Nov 2001 19:59:29 +0000
From:      David Malone <dwmalone@maths.tcd.ie>
To:        Ruslan Ermilov <ru@FreeBSD.ORG>
Cc:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: misc/32296: brk() has illegal prototype 
Message-ID:   <200111261959.aa10803@salmon.maths.tcd.ie>
In-Reply-To: Your message of "Mon, 26 Nov 2001 20:26:07 %2B0200." <20011126202607.B38902@sunbay.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
> >  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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi? <200111261959.aa10803>