13 October 2018, 11:23 | #1 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
vasm Get Current Work Directory (Windows expert needed)
The last days I have implemented DWARF support in the portable vasm assembler, which theoretically allows you to do source level debugging with an appropriate debugger.
DWARF needs to specify the current work directory in the .debug_info Compilation Unit, to find all paths relative to it. Unfortunately there is no portable way to determine this path and I have to write such a function for different operation systems. I do easily manage that for Unix, AmigaOS, Atari, etc., but I have absolutely no experience with Windows! Does anybody know what is the best equivalent to getcwd() on Windows. I g**gled a lot and am about to try the following: Code:
char *get_workdir(void) { static char buf[MAX_PATH]; char *fileExt; GetFullPathName("",MAX_PATH,buf,&fileExt); return buf; } Anybody here with some Windows knowledge who could help? At least it would be nice when it still compiles (I know there are a lot of people using vasm under Windows). |
13 October 2018, 13:19 | #2 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Both getcwd and Microsoft's recommended alternative _getcwd are available to VC. Not sure about MingW.
GetCurrentDirectoryA() returns a char* to the absolute path, gives the absolute path with drive-letter, and if the path can't be converted to Windows 1252 (or whatever it uses) I guess it returns zero, but it would be a good idea to make vbcc, vasm, and vlink unicode compatible |
13 October 2018, 16:53 | #3 |
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
Happy to help. You targeting any particular C/C++ toolchain?
|
13 October 2018, 21:16 | #4 |
This cat is no more
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,160
|
https://msdn.microsoft.com/en-us/library/sf98bd4y.aspx
there's a wgetcwd() which takes wide chars as input. |
14 October 2018, 01:43 | #5 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
I guess most people will use some MSVC++ version to compile vasm and a few others maybe Cygwin? I have no statistics.
But it would be nice, of course, when I could just call an OS function, which always works, and doesn't depend on a specific linker-library/toolchain. So GetCurrentDirectoryA() sounds great, when it always returns a normal ASCII string as full path including drive-letter. Can somebody write an example function with it, like I did in my first post, and test if it works? Does it need "#include <windows.h>" or more? In my opinion Unicode support in vasm isn't worth the hassle. It would introduce some new dependencies to charset-conversion libraries, which is something I don't like at all. vasm, as the whole vbcc toolchain, should stay simple, portable ANSI-C, without dependencies. |
14 October 2018, 01:46 | #6 | |
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
Quote:
EDIT: the gotcha here is that if you accidentally define a local method as GetCurrentDirectory() you'll get an error that the linker cant find GetCurrentDirectoryA() ... which is pretty infuriating IMHO. |
|
14 October 2018, 02:12 | #7 |
Registered User
Join Date: Mar 2016
Location: Australia
Posts: 881
|
Don’t forget Windows paths don’t always have a drive letter.
|
14 October 2018, 11:11 | #8 | |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Quote:
Code:
#define WIN32_LEAN_AND_MEAN #include <windows.h> char* get_workdir(void) { static char dir[MAX_PATH]; GetCurrentDirectoryA(MAX_PATH, dir); return dir; } |
|
14 October 2018, 11:25 | #9 |
Banned
Join Date: Sep 2016
Location: UK
Posts: 2,917
|
I'll happily beta test this stuff. I use vbcc and vasm as part of my toolchain for the TF cards. @phx you should have my email address in your inbox from my bug reports in the past.
|
14 October 2018, 11:28 | #10 |
Registered User
Join Date: Sep 2008
Location: Gainesville U.S.A.
Posts: 771
|
I know first hand anything needing windows.h will cause these conflicts when building VASM. Swept under the rug since only a couple of functions were needed.
Code:
#include <windows.h> #undef LITTLEENDIAN #undef BIGENDIAN #undef LOBYTE #undef HIBYTE #undef NEAR #undef ABSOLUTE #undef ERROR Code:
#include <stdio.h> #include <unistd.h> /* getcwd */ #include <sys/param.h> /* MAXPATHLEN */ #define MAX_PATH MAXPATHLEN int main(void) { static char buf[MAX_PATH]; getcwd(buf, MAX_PATH); printf("I'm here in the middle - %s",buf); } ---------------------------------------------------- C:\MinGW>gcc phx.c C:\MinGW>a.exe I'm here in the middle - C:\MinGW C:\MinGW> c:\vasm>\mingw\a.exe I'm here in the middle - c:\vasm c:\vasm> |
14 October 2018, 14:09 | #11 | |||||||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Quote:
Quote:
Quote:
Quote:
@Leffmann: Can you confirm those conflicts? Or doesn't MSVC warn about it (which wouldn't surprise me)? Or maybe those are different windows.h, depending on the compiler used? Quote:
Quote:
Quote:
|
|||||||
14 October 2018, 15:33 | #12 | |
Registered User
Join Date: Sep 2008
Location: Gainesville U.S.A.
Posts: 771
|
Quote:
No Warns No Errors and Nobody left on base. No surprise here. Paste Leffmann's code near top of vasm.c Some of the warnings I used to get are gone. It's been a long time since a stock build was made. Still produces exe. Code:
In file included from vasm.h:24:0, from vasm.c:15: symbol.h:34:0: warning: "NEAR" redefined #define NEAR (1<<15) /* may refer symbol with near addressing modes */ ^ In file included from c:/mingw/include/windows.h:48:0, from vasm.c:4: c:/mingw/include/windef.h:36:0: note: this is the location of the previous definition #define NEAR ^ In file included from vasm.h:31:0, from vasm.c:15: error.h:21:0: warning: "ERROR" redefined #define ERROR 1 ^ In file included from c:/mingw/include/windows.h:52:0, from vasm.c:4: c:/mingw/include/wingdi.h:313:0: note: this is the location of the previous definition #define ERROR 0 ^ In file included from vasm.c:15:0: vasm.h:120:0: warning: "ABSOLUTE" redefined #define ABSOLUTE 16 ^ In file included from c:/mingw/include/windows.h:52:0, from vasm.c:4: c:/mingw/include/wingdi.h:821:0: note: this is the location of the previous definition #define ABSOLUTE 1 ^ |
|
14 October 2018, 16:57 | #13 | |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Quote:
Also thinking about what alpine9000 said, and on a network you may have paths that are much longer than those in the local file system (MAX_PATH, 260 characters), better replace that with 1000 or something. Last edited by Leffmann; 14 October 2018 at 17:07. |
|
15 October 2018, 20:57 | #14 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
Thanks all!
Yes, I should include as few as possible of the vasm headers into my new osdep.c. Usually I take vasm's MAXPATHLEN, which is 1024. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Building VASM on Windows | guy lateur | Coders. Asm / Hardware | 21 | 29 April 2022 16:56 |
Reading files from current directory in assembly | hukka | Coders. System | 40 | 21 May 2021 12:14 |
Will WinUAE work in Windows 10? | DisposableHero | support.WinUAE | 8 | 25 July 2015 21:16 |
Compress all adf's in a directory (Windows) | Leandro Jardim | Amiga scene | 6 | 05 January 2012 03:08 |
Directory Opus (Windows) update | Galaxy | News | 4 | 25 May 2004 20:55 |
|
|