Subject: Re: wrap up of pipe(2)
To: Greg A. Woods <>
From: Andrew Brown <>
List: tech-userlevel
Date: 10/16/2001 13:46:40
>> Or, let's take a different example, read(2) is defined as returning EINVAL
>> if "The total length of the I/O is more than can be expressed by the ssize_t
>> return value."   Which of NetBSD's current ports can ever actually return
>> that error (for that reason) ??   Maybe some can, but there are certainly
>> some of them where it will never happen.

all of them.  if you read the code for sys_read(), you'll see that it
calls dofileread(), and the first thing that function does is this:

	 * Reads return ssize_t because -1 is returned on error.  Therefore
	 * we must restrict the length to SSIZE_MAX to avoid garbage return
	 * values.
	if (auio.uio_resid > SSIZE_MAX) {
		error = EINVAL;
		goto out;

that's from current.  the code i see in 1.3.3 (which doesn't have a
routine called dofileread()) looks like this:

	if (auio.uio_resid < 0)
		return EINVAL;

which is effectively the same.

>Well, since ssize_t is a (signed) int, the possibility is there on at
>least some platforms....

it's not an int.  and int isn't always big enough to do the job.
ssize_t is defined like this:

sys/types.h:typedef	_BSD_SSIZE_T_		ssize_t;

and _BSD_SSIZE_T_ comes from here:

arch/alpha/include/ansi.h:#define	_BSD_SSIZE_T_		long
arch/arm/include/ansi.h:#define	_BSD_SSIZE_T_		long int
arch/arm/include/ansi.h:#define	_BSD_SSIZE_T_		int
arch/i386/include/ansi.h:#define	_BSD_SSIZE_T_		int
arch/m68k/include/ansi.h:#define	_BSD_SSIZE_T_		int
arch/mips/include/ansi.h:#define	_BSD_SSIZE_T_		int
arch/pc532/include/ansi.h:#define	_BSD_SSIZE_T_		int
arch/powerpc/include/ansi.h:#define	_BSD_SSIZE_T_		int
arch/sh3/include/ansi.h:#define	_BSD_SSIZE_T_		int
arch/sparc/include/ansi.h:#define	_BSD_SSIZE_T_		long
arch/sparc64/include/ansi.h:#define	_BSD_SSIZE_T_		long
arch/vax/include/ansi.h:#define	_BSD_SSIZE_T_		long int
arch/vax/include/ansi.h:#define	_BSD_SSIZE_T_		int
arch/x86_64/include/ansi.h:#define	_BSD_SSIZE_T_		long
arch/hpc/stand/include/machine/ansi.h:#define	_BSD_SSIZE_T_		int

people should really read code before spouting off.

|-----< "CODE WARRIOR" >-----|             * "ah!  i see you have the internet (Andrew Brown)                that goes *ping*!"       * "information is power -- share the wealth."