[net.unix-wizards] Type of brk

ka@hou3c.UUCP (Kenneth Almquist) (05/14/84)

Brk() used to return the old break value if it succeeded and -1 if it
failed, just like sbrk().  In system III, it was changed to return
either 0 or -1.  Apparently Berkeley made the same change, and simply
neglected to change the declaration on the manual page to int.
				Kenneth Almquist

henry@utzoo.UUCP (Henry Spencer) (05/16/84)

Kenneth Almquist comments, in part:

   Brk() used to return the old break value if it succeeded and -1 if it
   failed, just like sbrk().  In system III, it was changed to return
   either 0 or -1.  Apparently Berkeley made the same change, and simply
   neglected to change the declaration on the manual page to int.

The change came long before System III; the V7 brk() returns 0 or -1.
The manual page does still (incorrectly) claim a "char *" returned
value type, however.
-- 
				Henry Spencer @ U of Toronto Zoology
				{allegra,ihnp4,linus,decvax}!utzoo!henry

rogers@dadla.UUCP (Roger Southwick) (05/21/84)

	I think you would find that brk() really returns an
int and not a char * (I've looked at the code for 4.1 BSD,
2.8 BSD and Bell V7).  This is because of the way the entries
are defined in the sysent[] table (as pointers to functions 
which return int).  Therefore all system calls return int.

	If you read the DIAGNOSTICS portion, it gives a 0
when the break was granted, and a -1 when not granted.  This
is consistant with all other system calls.

	I believe that this is an error in the documentation
in the page for brk, sbrk, break.  I think it should read:

	brk(addr)
	char *addr;

	sbrk(incr)
	char *incr;


	I think you'll find that this is the way it should be, 
although I really didn't dig into how brk() and sbrk() work all
that much.  I am real positive as to the return values though.


		-Roger Southwick

		...!tektronix!dadla!rogers

guy@rlgvax.UUCP (05/30/84)

> 	I think you would find that brk() really returns an
> int and not a char * (I've looked at the code for 4.1 BSD,
> 2.8 BSD and Bell V7).  This is because of the way the entries
> are defined in the sysent[] table (as pointers to functions 
> which return int).  Therefore all system calls return int.

Look at the "time(2)" system call page.  Then tell me all system calls
return "int".  The declaration of the routines in the sysent[] table
is irrelevant; values are returned from a system call in the kernel to
user-mode code by filling in the return value in the U page; this value
is then stuffed into the appropriate register(s), so a system call can
return whatever it pleases, except for a structure.  Furthermore, the
user-mode routine that issues the system call need not have the same
behavior as the actual trap; check out the "signal" call for an example.

However, "brk" does, indeed, return an "int" and "sbrk" does, indeed, return
a "char *".  The S5 manual (which is the one sitting in front of me at this
instant) states it correctly, and probably other versions of the manual do
so as well.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy