Windows: Use secure ctime and strncpy in afs_ctime
[openafs.git] / src / util / afsutil.h
index e4dfead..5b73ad4 100644 (file)
@@ -89,8 +89,19 @@ extern char *vctime(const time_t * atime);
 #define afs_ctime(C, B, L) (char*)ctime_r(C, B)
 #endif /* AFS_SUN5_ENV */
 #else /* AFS_PTHREAD_ENV && !AFS_NT40_ENV */
-#define afs_ctime(C, B, S) \
-       ((void)strncpy(B, ctime(C), (S-1)), (B)[S-1] = '\0', (B))
+static_inline char *
+afs_ctime(const time_t *C, char *B, size_t S) {
+#if !defined(AFS_NT40_ENV) || (_MSC_VER < 1400)
+    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 */
 
 
@@ -121,14 +132,15 @@ extern char *vctime(const time_t * atime);
 /* Unbuffer output when Un*x would do line buffering. */
 #define setlinebuf(S) setvbuf(S, NULL, _IONBF, 0)
 
-/* regular expression parser for NT */
-     extern char *re_comp(char *sp);
-     extern int rc_exec(char *p);
-
 /* Abort on error, possibly trapping to debugger or dumping a trace. */
      void afs_NTAbort(void);
 #endif /* AFS_NT40_ENV */
 
+#ifndef HAVE_POSIX_REGEX
+extern char *re_comp(const char *sp);
+extern int re_exec(const char *p1);
+#endif
+
      typedef char b32_string_t[8];
 /* b64_string_t is 8 bytes, in stds.h */
      typedef char lb64_string_t[12];