LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-18-2009, 07:00 AM   #1
Unni2003
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: Disabled
Emulate DOS/Windows Drive Letters like C: D: etc. in Linux


I'm recompiling my Windows based software to Linux, and the drive letters are becoming a great hurdle.

Many files are accessed with their Drive letters in the program. For example, O:REPORT.TXT, F:\DATA\CUSTLIST.CSV etc.,

I'm able to recompile it perfectly in Linux. But I need to change everywhere the program is explicitly specifiying the path. If I change the path, then it will cease to work with Windows, unless it is controlled by an IF.

I'm not using Wine - my code has been natively compiled into Linux. So, other than changing my code, is there any way to 'emulate' drive letters in Linux?

Thanks.
 
Old 04-18-2009, 08:42 AM   #2
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
Well since the letters are pretty much a shortcut for /path/to why not switch the letters for the path to the file?
 
Old 04-18-2009, 09:07 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Another thing you could do is save settings in a configuration file and then read that file when the program runs, using its' contents to set the relevant variables.
 
Old 04-18-2009, 09:27 AM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
We luv symlinks. Lets you make drive letters whenever you need 'em.

Of course, that won't let you escape the linux path syntax vs the windows path syntax.

The way I handle code that gets compiled on multiple platforms (notably Windows and Linux) is like this:

First line of my C (or C++) file:

#include "target_platform.h"

If the target platform is Linux, target_platform.h contains this:
Code:
#ifndef LINUX_TARGET
#define LINUX_TARGET
#endif
If Windows, this:
Code:
#ifndef MS_WINDOWS_TARGET
#define MS_WINDOWS_TARGET
#include "windows.h"
#endif
Then, where it is relevant in my code, there are statements like this:
Code:
#ifdef MS_WINDOWS_TARGET
xsize=GetSystemMetrics(SM_CXSCREEN);
#endif
#ifdef LINUX_TARGET
xsize=gdk_screen_get_width(screen);
#endif

This way, you wind up with code that will compile on both platforms without difficulty.
 
Old 04-19-2009, 08:43 AM   #5
Unni2003
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: Disabled
The codebase is pretty large, old and unstructured. (10+ years).. File names and paths are given as hard literals throughout the program (A few million lines+). I've been trying to locate a solution wherein the code would run without any change whatsoever.

But I guess I'll have to follow jiml8's advice. Thank you everyone.
 
Old 04-19-2009, 09:11 AM   #6
janhe
Member
 
Registered: Jul 2007
Location: Belgium
Distribution: slackware64 14.2, slackware 13.1
Posts: 371

Rep: Reputation: 54
I am not a developer, but not posting certainly won't help you:

I know you said you're not using wine, but wine is not only an emulator.
Winelib (http://winehq.org/docs/winelib-guide/index) is meant to help porting windows applications to linux.
You can find the guide in other formats here: http://winehq.org/documentation
 
Old 04-19-2009, 04:31 PM   #7
maresmasb
Member
 
Registered: Apr 2009
Posts: 108

Rep: Reputation: 24
Do this:
$ mkdir C:
$ mkdir C:\\

and you will get this
$ ls
C: C:\

Not a perfect solution actually, especially "C:\" and the backslash will become a pain in the a..

Conditional compilation makes more sense, like in jiml8's posting. You can pass define values to the code from the makefile by adding
-DMS_WINDOWS_TARGET
where MS_WINDOWS_TARGET is the definition

Last edited by Tinkster; 10-30-2010 at 03:18 PM.
 
  


Reply



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
Linux tool for assigning drive letters to Windows XP partitions? moxieman99 Linux - General 3 10-23-2008 03:56 PM
LXer: How to flash motherboard BIOS from Linux (no DOS/Windows, no floppy drive)? LXer Syndicated Linux News 1 03-11-2007 07:24 AM
Emulate Windows inside Linux? Mikesoft Linux - Newbie 10 11-30-2006 01:21 PM
Emulate Windows XP on Linux Garibaldi3489 Linux - Software 20 08-20-2005 11:31 PM
Swapping Drive Letters in Windows while multibooting with LILO akfnphx2 Linux - General 2 05-27-2001 07:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:04 PM.

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