0

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; 
}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Salem
1

> 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.

Edited by Salem: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.