Hello,

I'm checkng whether a file has been modified or not in order to refresh the content...
However, i need a couple improvements :
- How do I test the return value of stat to tell if it failed ?
- The returned errno numbers may change between glibc versions, right ? in this case it is useless to do errno==... How do I fix that ?

Please help, thank you !

int is_refreshing_needed (char * path)
{
	int refresh_content;
	struct stat file;
	stat(path, &file);
//File does not exist or Permission Denied or the file has not been modified
	if( errno == 2 || errno == 13 || file.st_atime > file.st_mtime ) {  
		refresh_content=0;
	}
	else { 
		refresh_content=1;	
	}
	return refresh_content; 
}

> How do I fix that ?
You use the error enumerations in errno.h (like EPERM) rather than magic numbers like 2 and 13

> How do I test the return value of stat to tell if it failed ?

int result = stat(path, &file);
// RTFM to see what value(s) result can take, and act accordingly.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.