[ovs-dev] [PATCH 1/3] socket-util: Move get_mtime() here from stream-ssl.
Ben Pfaff
blp at nicira.com
Wed Apr 21 18:37:34 UTC 2010
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.
---
lib/socket-util.c | 28 ++++++++++++++++++++++++++++
lib/socket-util.h | 1 +
lib/stream-ssl.c | 21 ---------------------
3 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/lib/socket-util.c b/lib/socket-util.c
index 912c47e..966dcfa 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -588,3 +588,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;
+ }
+}
+
diff --git a/lib/socket-util.h b/lib/socket-util.h
index e489926..0ba4a4d 100644
--- a/lib/socket-util.h
+++ b/lib/socket-util.h
@@ -43,5 +43,6 @@ int read_fully(int fd, void *, size_t, size_t *bytes_read);
int write_fully(int fd, const void *, size_t, size_t *bytes_written);
int fsync_parent_dir(const char *file_name);
+int get_mtime(const char *file_name, struct timespec *mtime);
#endif /* socket-util.h */
diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c
index aeca21e..27c9d4c 100644
--- a/lib/stream-ssl.c
+++ b/lib/stream-ssl.c
@@ -37,7 +37,6 @@
#include "packets.h"
#include "poll-loop.h"
#include "socket-util.h"
-#include "socket-util.h"
#include "util.h"
#include "stream-provider.h"
#include "stream.h"
@@ -915,26 +914,6 @@ stream_ssl_is_configured(void)
return private_key.file_name || certificate.file_name || ca_cert.file_name;
}
-static void
-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
- } else {
- mtime->tv_sec = mtime->tv_nsec = 0;
- }
-}
-
static bool
update_ssl_config(struct ssl_config_file *config, const char *file_name)
{
--
1.6.6.1
More information about the dev
mailing list