When I study c programming on linux,I see the linux API.
The file function: int open( const char * pathname,int flags, mode_t mode);
and it said,if success return file descriptor,else -1.
if it means we can't decide when it return -1 and when success?
Suppose that,if it means we can't ensure the validity of a program.But how can we realize a system like oracle DBA.
And most demos in books often use many "if statement' to judge the result and then do the next step.
For example:
int f;
f=open("outfile",O_RDWR|O_CREAT,0664);
if(f!=-1){
if(write(f,"12345",i)!=i)
perror("write error");
}
else
perror("open failed");
Since we don't know how it return -1,why we judge it?Even if we judge it,we can get nothing.Why not ingore it,and then at the end of the program,we just give a output and tell it successes.If we have not get the output,means we failed.And according to my solution,we leave many "if statement" out,our program's speed will improve.
my code:
int f;
open("outfile",O_RDWR|O_CREAT,0664);
write(f,"12345",i);
printf("success\n");
why not we did this?Can you help me,and I will appreciate it.