mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 22:05:19 +00:00
socket-util: Move get_mtime() here from stream-ssl.
An upcoming commit will add a new user for this function in another file, so export it and move it to a common library file.
This commit is contained in:
@@ -611,3 +611,31 @@ fsync_parent_dir(const char *file_name)
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Obtains the modification time of the file named 'file_name' to the greatest
|
||||
* supported precision. If successful, stores the mtime in '*mtime' and
|
||||
* returns 0. On error, returns a positive errno value and stores zeros in
|
||||
* '*mtime'. */
|
||||
int
|
||||
get_mtime(const char *file_name, struct timespec *mtime)
|
||||
{
|
||||
struct stat s;
|
||||
|
||||
if (!stat(file_name, &s)) {
|
||||
mtime->tv_sec = s.st_mtime;
|
||||
|
||||
#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
|
||||
mtime->tv_nsec = s.st_mtim.tv_nsec;
|
||||
#elif HAVE_STRUCT_STAT_ST_MTIMENSEC
|
||||
mtime->tv_nsec = s.st_mtimensec;
|
||||
#else
|
||||
mtime->tv_nsec = 0;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
mtime->tv_sec = mtime->tv_nsec = 0;
|
||||
return errno;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user