R
rtillmore
Hi,
I have a program that writes data to a file. I need to check for out
of disk space and other disk related errors. My code looks like:
if ((optr = fopen(filename,"w")) == NULL) {
printf("could not open %s\n", filename);
return -1;
}
else {
fprintf(optr,"%s\n",output);
while ((doneyet(output,next)==0) && (status==0)) {
nextone(output,next);
status=fprintf(optr,"%s\n",output); //out of disk space
}
if (fclose(optr) != 0) {
printf("fclose error number = %d\n",errno);
return -1;
}
if (status !=0) {
printf("fprintf error = %d\n",status);
return -1;
}
}
So far I have run out of disk space during the while loop and my
program just keeps running. I want it to say out of disk space and
exit gracefully. With the code above I just get fprint error = -1.
feof only returns 0 or 1 so that won't work. What is the best way to
check for the out of disk space error condition?
Thanks,
I have a program that writes data to a file. I need to check for out
of disk space and other disk related errors. My code looks like:
if ((optr = fopen(filename,"w")) == NULL) {
printf("could not open %s\n", filename);
return -1;
}
else {
fprintf(optr,"%s\n",output);
while ((doneyet(output,next)==0) && (status==0)) {
nextone(output,next);
status=fprintf(optr,"%s\n",output); //out of disk space
}
if (fclose(optr) != 0) {
printf("fclose error number = %d\n",errno);
return -1;
}
if (status !=0) {
printf("fprintf error = %d\n",status);
return -1;
}
}
So far I have run out of disk space during the while loop and my
program just keeps running. I want it to say out of disk space and
exit gracefully. With the code above I just get fprint error = -1.
feof only returns 0 or 1 so that won't work. What is the best way to
check for the out of disk space error condition?
Thanks,