FreeBASIC  0.91.0
time_time.c
Go to the documentation of this file.
1 /* time$ function */
2 
3 #include "fb.h"
4 #include <time.h>
5 
6 /*:::::*/
8 {
9  FBSTRING *dst;
10  time_t rawtime;
11  struct tm *ptm;
12 
13  /* guard by global lock because time/localtime might not be thread-safe */
14  FB_LOCK();
15 
16  rawtime = time( NULL );
17 
18  /* Note: localtime() may return NULL, as documented on MSDN and Linux man pages,
19  and it has been observed to do that on at least one FB user's Windows system,
20  because of a negative time_t value from time(). */
21  if( ((ptm = localtime( &rawtime )) != NULL) &&
22  ((dst = fb_hStrAllocTemp( NULL, 2+1+2+1+2 )) != NULL) /* done last so it's not leaked */ ) {
23  sprintf( dst->data, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec );
24  } else {
25  dst = &__fb_ctx.null_desc;
26  }
27 
28  FB_UNLOCK();
29 
30  return dst;
31 }