+# 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
+ *
+ * This function converts a mtime date into a string.
+ * psz_buffer should be a buffer long enough to store the formatted
+ * date.
+ * \param date to be converted
+ * \param psz_buffer should be a buffer at least MSTRTIME_MAX_SIZE characters
+ * \return psz_buffer is returned so this can be used as printf parameter.
+ */
+char *mstrtime( char *psz_buffer, mtime_t date )
+{
+ static mtime_t ll1000 = 1000, ll60 = 60, ll24 = 24;
+
+ snprintf( psz_buffer, MSTRTIME_MAX_SIZE, "%02d:%02d:%02d-%03d.%03d",
+ (int) (date / (ll1000 * ll1000 * ll60 * ll60) % ll24),
+ (int) (date / (ll1000 * ll1000 * ll60) % ll60),
+ (int) (date / (ll1000 * ll1000) % ll60),
+ (int) (date / ll1000 % ll1000),
+ (int) (date % ll1000) );
+ return( psz_buffer );
+}
+
+/**
+ * Convert seconds to a time in the format h:mm:ss.
+ *
+ * This function is provided for any interface function which need to print a
+ * time string in the format h:mm:ss
+ * date.
+ * \param secs the date to be converted
+ * \param psz_buffer should be a buffer at least MSTRTIME_MAX_SIZE characters
+ * \return psz_buffer is returned so this can be used as printf parameter.
+ */
+char *secstotimestr( char *psz_buffer, int i_seconds )
+{
+ 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) );