I'm trying to get my old filemanager program that I coded years ago with ncurses as a school project to run (the code is not great, might be a good exercise for some refactoring). I created it on Ubuntu, doesn't work on my Macbook. Can't figure out the difference that makes it work on one system, but not the other.
Works fine on Linux: https://imageshack.com/a/img922/8487/1Atzsx.jpg
But OSX does not display the file names correctly: https://imageshack.com/a/img923/3640/CeRzCm.png
Neither do the type descriptions which are hardcoded based on the d_type from readdir.
At first I thought that there might be an issue with wide character support from ncurses. This should be supported by default on OSX, but to be sure I installed the lastest ncurses from Homebrew. Didn't help.
The file names are obtained in this way and saved into objects:
struct dirent *ent;
DIR *dir;
if((dir = opendir(path.c_str())) != NULL) {
for(auto it = m_files.begin(); it != m_files.end(); ++it) {
delete *it;
}
m_files.clear();
while((ent = readdir (dir)) != NULL) {
if(ent->d_type==DT_DIR) {
if(!root) {
m_files.push_back( new CDirectory(ent->d_name, path+"/"+ent->d_name) );
}else{
m_files.push_back( new CDirectory(ent->d_name, path+ent->d_name) );
}
}
These objects are then accessed to create items for the ncurses menu. Valgrind detects memory leaks here (not happening with the same code on Ubuntu).
void CSelection::CreateItems () {
size_t number_of_choices = m_files.size();
size_t i;
m_items = (ITEM **)calloc(number_of_choices+1, sizeof(ITEM *));
for(i = 0; i < number_of_choices; i++) {
m_items[i] = new_item(m_files[i]->GetName().c_str(), m_files[i]->GetType().c_str());
}
m_items[i] = NULL;
}
After some research I think that I have the same problem as here: https://github.com/rust-lang/libc/issues/414 , but I'm stuck on implementing the fix.
I tried including this code (found here: https://forums.coronalabs.com/topic/53249-link-errors-with-openssl-plugin-when-building-universal-32-64-bit-binaries-for-ios/),
#include <dirent.h>
#include <fnmatch.h>
extern "C" DIR * opendir$INODE64( char * dirName );
DIR * opendir$INODE64( char * dirName )
{
return opendir( dirName );
}
extern "C" struct dirent * readdir$INODE64( DIR * dir );
struct dirent * readdir$INODE64( DIR * dir )
{
return readdir( dir );
}
but I get a segmentation fault on those returns.
Any advice? Thanks in advance.