views:

317

answers:

3

I'm looking for help porting this Windows tool to Unix (Mac/OSX);

http://www.oxyron.de/html/netdrive01src.zip

First off I'd like to know, if anyone could take a moment to have a quick look at the (small) source code, if it's a reasonably straight-forward task.

Secondly, any tips on porting the code would be much appreciated.

I've tried compiling it already (with Xcode/G++) but it throws 80+ errors, many of them seem to be with constants such as "_MAX_FNAME" which I'm presuming is a system constant to define the maximum filename length. I've tried to look through the standard C headers (on my Mac) but while I found similar constants in, say, SYSLIMITS.H (NAME_MAX) I still can't seem to make much progress.

+1  A: 

If the bulk of the errors are about preprocessor definitions, you may add these definitions on the compiler command line. For g++, for instance, this would be the -D _MAX_FNAME=NAME_MAX option (or whatever value is applicable).

xtofl
A: 

A short look at the code (grep "#include <") shows that all platform dependencies are in the nethost header. This header contains all needed #ifdef's to handle platform-independency:

#ifdef WIN32
    #define WIN32_LEAN_AND_MEAN 1
    #include <winsock2.h>
#else
    #ifdef __APPLE__
     #include <netinet/in.h>
    #endif

    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netdb.h>
    #include <unistd.h>
    #include <arpa/inet.h>
    #include <sys/select.h>
#endif

It looks good. At first sight.

xtofl
+2  A: 

There appear to be a few different classes of error:

main.cpp:8:19: error: conio.h: No such file or directory
main.cpp:61: error: ‘_kbhit’ was not declared in this scope

conio.h is Window's console io header. _kbhit is one of the functions in it.

main.cpp:17: warning: deprecated conversion from string constant to ‘char*’

A string constant is of type const char * in ANSI C++. There are also quite a few odd string functions in the code which wouldn't exist if you were using C++ std::string rather than C strings using new.

vbinary.cpp:5:16: error: io.h: No such file or directory

vdirectory.cpp:91: error: ‘_findfirst’ was not declared in this scope
vdirectory.cpp:99: error: ‘_findnext’ was not declared in this scope
vdirectory.cpp:101: error: ‘_findclose’ was not declared in this scope
vfile.cpp:19: error: ‘_MAX_DRIVE’ was not declared in this scope
vfile.cpp:20: error: ‘_MAX_DIR’ was not declared in this scope
vfile.cpp:21: error: ‘_MAX_FNAME’ was not declared in this scope
vfile.cpp:22: error: ‘_MAX_EXT’ was not declared in this scope

io.h is another Microsoft header, with the functions for navigating directories and the macros used with them. Use the functions in dirent.h instead. Functions such as VDirectory::CreatePath assume that there are separate drive letters; unix file systems don't, so it's probably better to have completely separate classes for the implementations rather than trying to put two separate bodies into each function using #ifdefs, and use one #ifdef to select the appropriate one in your main.

Constants such as _MAX_FNAME are in both io.h and Microsoft's stdlib.h. They aren't in the standard stdlib.h, nor are the functions whose input size they limit. The POSIX versions use NAME_MAX.

Pete Kirkham
Thanks for all the information. In your opinion, do you think it's been written too windows-centric to be an easy port to unix? I'm thinking mainly about the drive/folder/file handling stuff.
Neil Baldwin
It shouldn't take more than a couple of hours to write and test a set of classes with the same interface which call the POSIX file and directory handling. Though I'd also check that whatever it is doing hasn't already been implemented in an existing piece of software; there are various fuse ( file system in user space ) network drive mounting systems in Linux.
Pete Kirkham