L
Larry
I was testing the buffer size of system call, read(), and found a
strange error on Ubuntu 7.10 server. The code is attached.
If the BUFFSIZE is set to from 128 to 255, the code will produce an error as
read error: Success
If the if statement (and the perror) is removed, the error disappears.
I have tried the same program on Sun Solaris 5.10 and got the same results.
The program read from the standard input and write to standard output.
Use any large file as the input redirected to standard input and dump
the output to null.
How to test:
../a.out < AnySufficientLargeFile >/dev/null
----------------------------------------
#include <stdio.h>
#include <unistd.h>
#define BUFFSIZE 128
int main(void)
{
char n;
char buf[BUFFSIZE];
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
if (write(STDOUT_FILENO, buf, n) != n)
perror("write error");
if (n < 0)
perror("read error");
return 0;
}
-----------------------------------------
strange error on Ubuntu 7.10 server. The code is attached.
If the BUFFSIZE is set to from 128 to 255, the code will produce an error as
read error: Success
If the if statement (and the perror) is removed, the error disappears.
I have tried the same program on Sun Solaris 5.10 and got the same results.
The program read from the standard input and write to standard output.
Use any large file as the input redirected to standard input and dump
the output to null.
How to test:
../a.out < AnySufficientLargeFile >/dev/null
----------------------------------------
#include <stdio.h>
#include <unistd.h>
#define BUFFSIZE 128
int main(void)
{
char n;
char buf[BUFFSIZE];
while ((n = read(STDIN_FILENO, buf, BUFFSIZE)) > 0)
if (write(STDOUT_FILENO, buf, n) != n)
perror("write error");
if (n < 0)
perror("read error");
return 0;
}
-----------------------------------------