On Wed, 7 Oct 1998, Jean-Marie Sulmont wrote:
> /*
> Bonjour,
>
> read(0,0,1) returns 1 as soon as 1 char has been keyed in.
> I'm using 2.1.124 SMP. Included is a little program illustrating it.
> The ext2 read operation is OK. Which operation is invoked when reading
> from 0 and 0 hasn't been redirected? Could not find it, so could not fix it.
> Let me know!
>
> jean-marie
> */
>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <errno.h>
> #include <stdio.h>
> #include <assert.h>
>
> main (int argc , char** argv)
> {
> char *x = 0;
> int fd, rc;
>
> #ifndef BUG
> fd = open(argv[0], O_RDONLY), assert( fd != -1 );
> #endif
> printf("before: errno=%d\n", errno);
> #ifdef BUG
> fd = 0;
> #endif
> rc = read (fd, 0, 1);
what are you using for a buffer here? IE how are you going to read
passing read() a null pointer to a buffer??? I use read from descriptor
0 all the time in several programs, but I always use a valid buffer
address. Note that "rc" does *not* get the character read. It returns
the number of characters read (in your case 1)...
> printf("after : errno=%d\n", errno);
> if (rc == -1) perror ("read");
> else printf ("rc = %d\n", rc);
> exit(0);
> }
>