Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-18-2009, 08:00 AM   #1
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?

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

Rep: Reputation: 472Reputation: 472Reputation: 472Reputation: 472Reputation: 472
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, 10:07 AM   #3
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, 10:27 AM   #4
Senior Member
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
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:
If Windows, this:
#include "windows.h"
Then, where it is relevant in my code, there are statements like this:

This way, you wind up with code that will compile on both platforms without difficulty.
Old 04-19-2009, 09:43 AM   #5
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, 10:11 AM   #6
Registered: Jul 2007
Location: Belgium
Distribution: slackware64 13.1, slackware 13.1
Posts: 369

Rep: Reputation: 49
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 ( is meant to help porting windows applications to linux.
You can find the guide in other formats here:
Old 04-19-2009, 05:31 PM   #7
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
where MS_WINDOWS_TARGET is the definition

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


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

All times are GMT -5. The time now is 12:44 AM.

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