Add FLV file output code

This doesn't add FLV file output to the user interface yet, but we'll
get around to that eventually.  This just adds an FLV output type.

Also, removed ftello/fseeko because off_t is a really annoying data
type, and I'd rather have a firm int64_t for large sizes, so I named it
to os_fseeki64 and os_ftelli64 instead, and changed the file size
function to return an int64_t.
This commit is contained in:
jp9000
2014-05-16 00:18:23 -07:00
parent 7efecf648b
commit 1d2e5d50a4
10 changed files with 294 additions and 52 deletions

View File

@@ -14,6 +14,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define _FILE_OFFSET_BITS 64
#include <errno.h>
#include <stdlib.h>
#include "c99defs.h"
@@ -56,38 +58,56 @@ FILE *os_fopen(const char *path, const char *mode)
#endif
}
off_t os_fgetsize(FILE *file)
int64_t os_fgetsize(FILE *file)
{
off_t cur_offset = ftello(file);
off_t size;
int64_t cur_offset = os_ftelli64(file);
int64_t size;
int errval = 0;
if (fseeko(file, 0, SEEK_END) == -1)
if (fseek(file, 0, SEEK_END) == -1)
return -1;
size = ftello(file);
size = os_ftelli64(file);
if (size == -1)
errval = errno;
if (fseeko(file, cur_offset, SEEK_SET) != 0 && errval != 0)
if (os_fseeki64(file, cur_offset, SEEK_SET) != 0 && errval != 0)
errno = errval;
return size;
}
int os_fseeki64(FILE *file, int64_t offset, int origin)
{
#ifdef _MSC_VER
return _fseeki64(file, offset, origin);
#else
return fseeko(file, offset, origin);
#endif
}
int64_t os_ftelli64(FILE *file)
{
#ifdef _MSC_VER
return _ftelli64(file);
#else
return ftello(file);
#endif
}
size_t os_fread_mbs(FILE *file, char **pstr)
{
size_t size = 0;
size_t len = 0;
fseeko(file, 0, SEEK_END);
size = (size_t)ftello(file);
fseek(file, 0, SEEK_END);
size = (size_t)os_ftelli64(file);
*pstr = NULL;
if (size > 0) {
char *mbstr = bmalloc(size+1);
fseeko(file, 0, SEEK_SET);
fseek(file, 0, SEEK_SET);
size = fread(mbstr, 1, size, file);
if (size == 0) {
bfree(mbstr);
@@ -110,8 +130,8 @@ size_t os_fread_utf8(FILE *file, char **pstr)
*pstr = NULL;
fseeko(file, 0, SEEK_END);
size = (size_t)ftello(file);
fseek(file, 0, SEEK_END);
size = (size_t)os_ftelli64(file);
if (size > 0) {
char bom[3];
@@ -119,7 +139,7 @@ size_t os_fread_utf8(FILE *file, char **pstr)
off_t offset;
/* remove the ghastly BOM if present */
fseeko(file, 0, SEEK_SET);
fseek(file, 0, SEEK_SET);
size_read = fread(bom, 1, 3, file);
if (size_read != 3)
return 0;
@@ -131,7 +151,7 @@ size_t os_fread_utf8(FILE *file, char **pstr)
return 0;
utf8str = bmalloc(size+1);
fseeko(file, offset, SEEK_SET);
fseek(file, offset, SEEK_SET);
size = fread(utf8str, 1, size, file);
if (size == 0) {
@@ -314,23 +334,3 @@ size_t os_mbs_to_utf8_ptr(const char *str, size_t len, char **pstr)
return out_len;
}
#ifdef _MSC_VER
int fseeko(FILE *stream, off_t offset, int whence)
{
#if _FILE_OFFSET_BITS == 64
return _fseeki64(stream, offset, whence);
#else
return fseek(stream, offset, whence);
#endif /* _FILE_OFFSET_BITS == 64 */
}
off_t ftello(FILE *stream)
{
#if _FILE_OFFSET_BITS == 64
return _ftelli64(stream);
#else
return ftell(stream);
#endif /* _FILE_OFFSET_BITS == 64 */
}
#endif /* _MSC_VER */

View File

@@ -32,7 +32,10 @@ extern "C" {
EXPORT FILE *os_wfopen(const wchar_t *path, const char *mode);
EXPORT FILE *os_fopen(const char *path, const char *mode);
EXPORT off_t os_fgetsize(FILE *file);
EXPORT int64_t os_fgetsize(FILE *file);
EXPORT int os_fseeki64(FILE *file, int64_t offset, int origin);
EXPORT int64_t os_ftelli64(FILE *file);
EXPORT size_t os_fread_mbs(FILE *file, char **pstr);
EXPORT size_t os_fread_utf8(FILE *file, char **pstr);
@@ -97,8 +100,6 @@ EXPORT int os_unlink(const char *path);
EXPORT int os_mkdir(const char *path);
#ifdef _MSC_VER
EXPORT int fseeko(FILE *stream, off_t offset, int whence);
EXPORT off_t ftello(FILE *stream);
#define strtoll _strtoi64
#endif