LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-28-2006, 12:51 PM   #1
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Rep: Reputation: 30
Porting To Win32!!!!


I'm trying to port my program over to windows using visual c++ express as my compiler. Why I really don't know, I guess to allow my friends (who won't try Linux for nothing) to test and use it. I want it to be capable of being built on either system. I've ran into a couple of problems and was seeking some help.

1.) Windows doesn't use file permission, well at least to my knowledge and I have all these errors.
"error C2065: 'F_OK' : undeclared identifier"
"error C2065: 'mode_t' : undeclared identifier"
etc... I know that I will have to find a way to 'by pass' these permission sections in my code, but how. I know that windows compilers define a preprocessor directive WIN32, so I could use something similar to this to test if it is being built on windows.
#ifdef WIN32
....
#endif
I know that I could include different files this way (that don't include these permissions, but that would be a LOT of work. Is there any shortcuts to this?

2.) I also have a couple functions that test if a path points to a file or a directory. Here's a sample:
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>

using namespace std;

bool isdirectory(string path)
{
    bool test = false;
    struct stat stats;
    if (!stat(path.c_str(), &stats)) {
        if (S_ISDIR(stats.st_mode)) {
            test = true;
        }
    }
    return test;
}

bool isfile(string path)
{
    bool test = false;
    struct stat stats;
    if (!stat(path.c_str(), &stats)) {
        if (S_ISREG(stats.st_mode)) {
            test = true;
        }
    }
    return test;
}
But this results in these errors:
"error C3861: 'S_ISDIR': identifier not found"
"error C3861: 'S_ISREG': identifier not found"
Is there a different way to preform these test under win32?

THANKS in advance!!!
Bendeco

Last edited by bendeco13; 03-28-2006 at 12:52 PM.
 
Old 03-28-2006, 01:48 PM   #2
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Hey, Windows Is Not Unix (or POSIX as they say).
Try compiling with Cygwin, Mingw32, or use ANSI C and #ifdef's to use pure Win32 code.
 
Old 03-28-2006, 02:02 PM   #3
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
ok....?
I tried using cygwin, but I couldn't get it to find all of my include files, such as gtk, glib, id3, etc...
In visual c++ you can specify all of the directories to search. (really snappy)

So I have somewhat of a solution to 1.), but what about 2.)?

Last edited by bendeco13; 03-28-2006 at 03:32 PM.
 
Old 03-28-2006, 08:36 PM   #4
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
OK...
I've fixed all of my problems (the long way), except for question 2. How would I go about testing if a path points to a file or a directory in win? I've googled for about an hour and can't seem to find a solution.

Thanks...
 
Old 03-28-2006, 09:09 PM   #5
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Try with these defines:

Code:
#ifndef S_ISDIR
#define S_ISDIR(mode)  (((mode) & S_IFMT) == S_IFDIR)
#endif

#ifndef S_ISREG
#define S_ISREG(mode)  (((mode) & S_IFMT) == S_IFREG)
#endif
if your compiler gives errors to these, then the whole stat() stuff can't be done the Unix way.
 
Old 03-28-2006, 09:31 PM   #6
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
THANKS....
I think that did the trick...
 
Old 03-28-2006, 10:10 PM   #7
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Quote:
Originally Posted by bendeco13
THANKS....
I think that did the trick...
Seriously ?

Huh, I thought that no system with S_ISDIR() had S_IFDIR though some packages redefine these when the configure script detected them to be broken with the "STAT_MACROS_BROKEN" macro.
 
Old 03-28-2006, 10:12 PM   #8
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Can you post <sys/stat.h> here ? (with copyright notices included )
 
Old 04-04-2006, 02:01 AM   #9
bendeco13
Member
 
Registered: Oct 2004
Distribution: Fedora 7
Posts: 232

Original Poster
Rep: Reputation: 30
Thanks for all of the replies, I did get it to 'compile' on visual c++, but I can't seem to build a solution to the project. I'm not really familier with this software and I don't understand what the differerence is in compiling and building a solution, but I get a whole bunch of link errors when attempting to build. I googled around and tried a few different things, but I was unsuccessful at finding a solution to the problem. I'm really busy with school at this time, so I'm just gonna put this off for a while and continue it when I have more time to learn how to use the visual c++ software.

Thanks Again,
Bendeco
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Win32/MFC porting toolkit? Artik Programming 3 08-09-2005 01:03 PM
porting Win32 API calls to Linux integer Programming 3 03-30-2005 10:41 PM
Porting Win32 API && PIC programing bobbens Programming 2 02-11-2005 07:14 AM
Help Porting i386_get_ioperm azrail1222 Programming 4 12-05-2004 02:11 AM
Porting win32 application into Linux sergeyy Linux - Software 1 06-23-2003 08:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration