I hope the question explained my problem. I would also be grateful if the workaround that "works" is explained.
The traditional way of reading a file (that i know of)
int fd;
char buffer[MAX];
while(read(fd,buffer,MAX)>0)
{
buffer[MAX]='\0';
write(sockfd,buffer,MAX);
memset(buffer,NULL,MAX);
}
was causing an overflow. The workaround that somehow unexpectedly worked was
while((read(fd,buffer,MAX)!=0)||(read(fd,buffer,MAX)!= -1))
{
buffer[MAX]='\0';
write(sockfd,buffer,MAX);
memset(buffer,NULL,MAX);
}
^^ This code printed out the entire file, no skips as far as observable.
Things like
do
{
int temp;
temp=read(fd,buffer,MAX);
if((temp == 0) || (temp == -1))
{
break;
}
buffer[MAX]='\0';
write(sockfd,buffer,MAX);
memset(buffer,NULL,MAX);
}while(1);
also caused a stack overflow. Am i missing something really important here?
Thanks