From 359c64bb674ea0606e64b91fd8252297310a9862 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Sun, 6 Sep 2009 18:47:54 -0400 Subject: [PATCH] Windows: Use secure ctime and strncpy in afs_ctime Microsoft compilers version 1500 and above provide secure versions of ctime and strncpy. Use them in afs_ctime. Reviewed-on: http://gerrit.openafs.org/408 Reviewed-by: Derrick Brashear Tested-by: Asanka Herath Reviewed-by: Asanka Herath Tested-by: Derrick Brashear Reviewed-by: Jeffrey Altman --- src/util/afsutil.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util/afsutil.h b/src/util/afsutil.h index dc587a65e..177a3f2b6 100644 --- a/src/util/afsutil.h +++ b/src/util/afsutil.h @@ -91,8 +91,15 @@ extern char *vctime(const time_t * atime); #else /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */ static_inline char * afs_ctime(const time_t *C, char *B, size_t S) { +#if !defined(AFS_NT40_ENV) || (_MSC_VER < 1500) strncpy(B, ctime(C), (S-1)); B[S-1] = '\0'; +#else + char buf[32]; + if (ctime_s(buf, sizeof(buf), C) || + strncpy_s(B, S, buf, _TRUNCATE) + B[0] = '\0'; +#endif return B; } #endif /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */ -- 2.39.5