From: Jeffrey Altman Date: Sun, 6 Sep 2009 22:47:54 +0000 (-0400) Subject: Windows: Use secure ctime and strncpy in afs_ctime X-Git-Tag: openafs-devel-1_5_63~32 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=359c64bb674ea0606e64b91fd8252297310a9862;p=packages%2Fo%2Fopenafs.git 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 --- 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 */