MythTV  0.26-pre
dir_mythiowrapper.c
Go to the documentation of this file.
00001 #if HAVE_CONFIG_H
00002 #include "config.h"
00003 #endif
00004 
00005 #include "file.h"
00006 #include "util/macro.h"
00007 #include "util/logging.h"
00008 
00009 #include "mythiowrapper.h"
00010 #include "file_mythiowrapper.h"  // to pass GCC -Werror=missing-prototypes
00011 
00012 static void dir_close_mythiowrapper(BD_DIR_H *dir)
00013 {
00014     if (dir) {
00015         mythdir_closedir((int)dir->internal);
00016 
00017         BD_DEBUG(DBG_DIR, "Closed mythdir dir (%p)\n", dir);
00018 
00019         X_FREE(dir);
00020     }
00021 }
00022 
00023 static int dir_read_mythiowrapper(BD_DIR_H *dir, BD_DIRENT *entry)
00024 {
00025     char *filename = mythdir_readdir((int)dir->internal);
00026     if (filename)
00027     {
00028         strncpy(entry->d_name, filename, 256);
00029         free(filename);
00030         return 0;
00031     }
00032 
00033     return 1;
00034 }
00035 
00036 BD_DIR_H *dir_open_mythiowrapper(const char* dirname)
00037 {
00038     BD_DIR_H *dir = malloc(sizeof(BD_DIR_H));
00039 
00040     BD_DEBUG(DBG_DIR, "Opening mythdir dir %s... (%p)\n", dirname, dir);
00041     dir->close = dir_close_mythiowrapper;
00042     dir->read = dir_read_mythiowrapper;
00043 
00044     int dirID = 0;
00045     if ((dirID = mythdir_opendir(dirname))) {
00046         dir->internal = (void *)dirID;
00047 
00048         return dir;
00049     }
00050 
00051     BD_DEBUG(DBG_DIR, "Error opening dir! (%p)\n", dir);
00052 
00053     X_FREE(dir);
00054 
00055     return NULL;
00056 }
00057 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends