All pastes #1923805 Raw Edit

Unnamed

public cpp v1 · immutable
#1923805 ·published 2010-08-24 00:00 UTC
rendered paste body
Index: file/file_mythiowrapper.h===================================================================--- file/file_mythiowrapper.h	(revision 0)+++ file/file_mythiowrapper.h	(revision 0)@@ -0,0 +1,10 @@+#ifndef __FILE_MYTHIOWRAPPER__+#define __FILE_MYTHIOWRAPPER__++#include "file.h"++BD_FILE_H *file_open_mythiowrapper(const char* filename, const char *mode);+BD_DIR_H  *dir_open_mythiowrapper(const char* dirname);++#endif+Index: file/dir_posix.c===================================================================--- file/dir_posix.c	(revision 25801)+++ file/dir_posix.c	(working copy)@@ -22,6 +22,7 @@ #endif  #include "file.h"+#include "file_mythiowrapper.h" #include "util/macro.h" #include "util/logging.h" @@ -68,6 +69,9 @@  static BD_DIR_H *dir_open_posix(const char* dirname) {+    if (strncmp(dirname, "myth://", 7) == 0)+        return dir_open_mythiowrapper(dirname);+     DIR *dp = NULL;     BD_DIR_H *dir = malloc(sizeof(BD_DIR_H)); Index: file/file_posix.c===================================================================--- file/file_posix.c	(revision 25801)+++ file/file_posix.c	(working copy)@@ -23,6 +23,7 @@ #endif  #include "file.h"+#include "file_mythiowrapper.h" #include "util/macro.h" #include "util/logging.h" @@ -67,6 +68,9 @@  static BD_FILE_H *file_open_linux(const char* filename, const char *mode) {+    if (strncmp(filename, "myth://", 7) == 0)+        return file_open_mythiowrapper(filename, mode);+     FILE *fp = NULL;     BD_FILE_H *file = malloc(sizeof(BD_FILE_H)); Index: file/dir_mythiowrapper.c===================================================================--- file/dir_mythiowrapper.c	(revision 0)+++ file/dir_mythiowrapper.c	(revision 0)@@ -0,0 +1,56 @@+#if HAVE_CONFIG_H+#include "config.h"+#endif++#include "file.h"+#include "util/macro.h"+#include "util/logging.h"++#include "mythiowrapper.h"++static void dir_close_mythiowrapper(BD_DIR_H *dir)+{+    if (dir) {+        mythdir_closedir((int)dir->internal);++        DEBUG(DBG_DIR, "Closed mythdir dir (%p)\n", dir);++        X_FREE(dir);+    }+}++static int dir_read_mythiowrapper(BD_DIR_H *dir, BD_DIRENT *entry)+{+	char *filename = mythdir_readdir((int)dir->internal);+	if (filename)+	{+        strncpy(entry->d_name, filename, 256);+		free(filename);+		return 0;+	}++	return 1;+}++BD_DIR_H *dir_open_mythiowrapper(const char* dirname)+{+    BD_DIR_H *dir = malloc(sizeof(BD_DIR_H));++    DEBUG(DBG_DIR, "Opening mythdir dir %s... (%p)\n", dirname, dir);+    dir->close = dir_close_mythiowrapper;+    dir->read = dir_read_mythiowrapper;++    int dirID = 0;+    if ((dirID = mythdir_opendir(dirname))) {+        dir->internal = (void *)dirID;++        return dir;+    }++    DEBUG(DBG_DIR, "Error opening dir! (%p)\n", dir);++    X_FREE(dir);++    return NULL;+}+Index: file/file_mythiowrapper.c===================================================================--- file/file_mythiowrapper.c	(revision 0)+++ file/file_mythiowrapper.c	(revision 0)@@ -0,0 +1,83 @@+#if HAVE_CONFIG_H+#include "config.h"+#endif++#include <fcntl.h>++#include "file.h"+#include "util/macro.h"+#include "util/logging.h"++#include "mythiowrapper.h"++static void file_close_mythiowrapper(BD_FILE_H *file)+{+    if (file) {+        mythfile_close((int)file->internal);++        DEBUG(DBG_FILE, "Closed mythfile file (%p)\n", file);++        X_FREE(file);+    }+}++static int64_t file_seek_mythiowrapper(BD_FILE_H *file, int64_t offset, int32_t origin)+{+    return mythfile_seek((int)file->internal, offset, origin);+}++static int64_t file_tell_mythiowrapper(BD_FILE_H *file)+{+    return mythfile_tell((int)file->internal);+}++static int file_eof_mythiowrapper(BD_FILE_H *file)+{+    // FIXME+    // return mythfile_eof((FILE *)file->internal);++    fprintf(stderr, "file_eof_mythiowrapper() ERROR UNIMPLEMENTED\n");+    return 0;+}++static int64_t file_read_mythiowrapper(BD_FILE_H *file, uint8_t *buf, int64_t size)+{+    return mythfile_read((int)file->internal, buf, size);+}++static int64_t file_write_mythiowrapper(BD_FILE_H *file, const uint8_t *buf, int64_t size)+{+    return mythfile_write((int)file->internal, buf, size);+}++BD_FILE_H *file_open_mythiowrapper(const char* filename, const char *mode)+{+    FILE *fp = NULL;+    BD_FILE_H *file = malloc(sizeof(BD_FILE_H));++    DEBUG(DBG_FILE, "Opening mythfile file %s... (%p)\n", filename, file);+    file->close = file_close_mythiowrapper;+    file->seek = file_seek_mythiowrapper;+    file->read = file_read_mythiowrapper;+    file->write = file_write_mythiowrapper;+    file->tell = file_tell_mythiowrapper;+    file->eof = file_eof_mythiowrapper;++    int fd;+	int intMode = O_RDONLY;+	if (!strcasecmp(mode, "wb"))+	    intMode = O_WRONLY;++    if ((fd = mythfile_open(filename, intMode)) >= 0) {+        file->internal = (void *)fd;++        return file;+    }++    DEBUG(DBG_FILE, "Error opening file! (%p)\n", file);++    X_FREE(file);++    return NULL;+}+Index: libmythbluray.pro===================================================================--- libmythbluray.pro	(revision 25801)+++ libmythbluray.pro	(working copy)@@ -9,6 +9,7 @@ INCLUDEPATH += . ../../ INCLUDEPATH += ./bdnav INCLUDEPATH += ../libmythdb+INCLUDEPATH += ../libmythtv  DEFINES += HAVE_CONFIG_H DLOPEN_CRYPTO_LIBS