#include <stdlib.h>
#include <assert.h>
#include <time.h>
+#include <errno.h>
-#include "vlc_access.h"
-#include "vlc_block.h"
-#include "charset.h"
+#include <vlc_access.h>
+
+#include <vlc_charset.h>
#include "vlc_keys.h"
#define DEFAULT_MARGIN 32 // megabytes
{
FILE *stream;
int64_t tmp_max;
+ int64_t dumpsize;
};
/**
access_sys_t *p_sys = access->p_sys;
FILE *stream = p_sys->stream;
- if ((stream == NULL) || (len == 0))
+ if ((stream == NULL) /* not dumping */
+ || (access->info.i_pos < p_sys->dumpsize) /* already known data */)
return;
+ size_t needed = access->info.i_pos - p_sys->dumpsize;
+ if (len < needed)
+ return; /* gap between data and dump offset (seek too far ahead?) */
+
+ buffer += len - needed;
+ len = needed;
+
+ if (len == 0)
+ return; /* no useful data */
+
if ((p_sys->tmp_max != -1) && (access->info.i_pos > p_sys->tmp_max))
{
msg_Dbg (access, "too much data - dump will not work");
goto error;
}
+ assert (len > 0);
if (fwrite (buffer, len, 1, stream) != 1)
{
msg_Err (access, "cannot write to file: %s", strerror (errno));
goto error;
}
+ p_sys->dumpsize += len;
return;
error:
access->info = src->info;
Dump (access, buffer, len);
- //Trigger (access);
return len;
}
}
if (p_sys->stream != NULL)
- {
- msg_Dbg (access, "seeking - dump will not work");
- fclose (p_sys->stream);
- p_sys->stream = NULL;
- }
+ msg_Dbg (access, "seeking - dump might not work");
src->info.i_update = access->info.i_update;
int ret = src->pf_seek (src, offset);
}
+#ifndef HAVE_LOCALTIME_R
+static inline struct tm *localtime_r (const time_t *now, struct tm *res)
+{
+ struct tm *unsafe = localtime (now);
+ /*
+ * This is not thread-safe. Blame your C library.
+ * On Win32 there SHOULD be _localtime_s instead, but of course
+ * Cygwin and Mingw32 don't know about it. You're on your own if you
+ * this platform.
+ */
+ if (unsafe == NULL)
+ return NULL;
+
+ memcpy (res, unsafe, sizeof (*res));
+ return res;
+}
+#endif
+
+
static void Trigger (access_t *access)
{
access_sys_t *p_sys = access->p_sys;
msg_Info (access, "dumping media to \"%s\"...", filename);
- FILE *newstream = fopen (filename, "wb");
+ FILE *newstream = utf8_fopen (filename, "wb");
if (newstream == NULL)
{
msg_Err (access, "cannot create dump file \"%s\": %s", filename,