]> git.sesse.net Git - vlc/blobdiff - src/misc/mtime.c
remove memory leak
[vlc] / src / misc / mtime.c
index 094556289404b7b831b0ba793e36f8339bb6671b..91c7187f91eb842e661ae06ef396cac8b74000fa 100644 (file)
@@ -67,6 +67,24 @@ struct timespec
 int nanosleep(struct timespec *, struct timespec *);
 #endif
 
+#if !defined (_POSIX_CLOCK_SELECTION)
+#  define _POSIX_CLOCK_SELECTION (-1)
+#endif
+
+# if (_POSIX_CLOCK_SELECTION < 0)
+/*
+ * We cannot use the monotonic clock is clock selection is not available,
+ * as it would screw vlc_cond_timedwait() completely. Instead, we have to
+ * stick to the realtime clock. Nevermind it screws everything when ntpdate
+ * warps the wall clock.
+ */
+#  undef CLOCK_MONOTONIC
+#  define CLOCK_MONOTONIC CLOCK_REALTIME
+#elif !defined (HAVE_CLOCK_NANOSLEEP)
+/* Clock selection without clock in the first place, I don't think so. */
+#  error We have quite a situation here! Fix me if it ever happens.
+#endif
+
 /**
  * Return a date in a readable format
  *
@@ -102,10 +120,22 @@ char *mstrtime( char *psz_buffer, mtime_t date )
  */
 char *secstotimestr( char *psz_buffer, int i_seconds )
 {
-    snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%d:%2.2d:%2.2d",
-              (int) (i_seconds / (60 *60)),
-              (int) ((i_seconds / 60) % 60),
-              (int) (i_seconds % 60) );
+    int i_hours, i_mins;
+    i_mins = i_seconds / 60;
+    i_hours = i_mins / 60 ;
+    if( i_hours )
+    {
+        snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%d:%2.2d:%2.2d",
+                 (int) i_hours,
+                 (int) (i_mins % 60),
+                 (int) (i_seconds % 60) );
+    }
+    else
+    {
+         snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%2.2d:%2.2d",
+                   (int) i_mins ,
+                   (int) (i_seconds % 60) );
+    }
     return( psz_buffer );
 }
 
@@ -127,11 +157,6 @@ static inline unsigned mprec( void )
 
 static unsigned prec = 0;
 static volatile mtime_t cached_time = 0;
-#if defined( HAVE_CLOCK_NANOSLEEP )
-#  if (_POSIX_MONOTONIC_CLOCK - 0 < 0)
-#    define CLOCK_MONOTONIC CLOCK_REALTIME
-#  endif
-#endif
 
 /**
  * Return high precision date