QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: RhoSigma on September 29, 2021, 05:33:56 am
-
I'm currently fixing stuff, also taking the opportunity to improve things.
Need to know if the following code works on all QB64 supported platforms, but I've only Windows systems to test on, so this is a call on all Mac/Linux users.
The following code does expand a relative path into a fully qualified absolut path, it works on Windows 32- and 64-bit, but what about Mac/Linux?
PRINT "First test should work and print full path to qb64.exe" file$ = "qb64.exe"
succ%&
= ExpandPath%&
(buff$
, file$
+ CHR$(0), 1056)
PRINT "Second test should fail and print empty buffer and zero length" file$ = "qb64.exe"
succ%&
= ExpandPath%&
(buff$
, file$
+ CHR$(0), 3)
-
There's no _fullpath function in Unix, but there's the very similar realpath:
Declare Library
Function realpath%& (path$, buf$)
End Declare
Print expandpath$("untitled.bas")
Function expandpath$ (relpath$)
buf$ = String$(4096, Chr$(0)) 'PATH_MAX
r%& = realpath%&(relpath$ + Chr$(0), buf$)
If r%& = 0 Then
expandpath$ = ""
Else
expandpath$ = Left$(buf$, InStr(buf$, Chr$(0)) - 1)
End If
End Function
I've hardcoded the output buffer size as 4096 which is PATH_MAX on my current Linux, but that's pretty dodgy. A better way to do things would be to pass NULL for the second argument, then realpath returns a pointer to a malloc'd buffer that you can call free on.
I didn't do that because copying the data from the buffer into a QB64 string turns out to be rather annoying, so you get the hacky version for now.
-
In Ubuntu 20.04, and either compiling in v1.5 or the development build 2.0, I get an internal compiler error:
In file included from qbx.cpp:2173:
../temp/main.txt: In function ‘void QBMAIN(void*)’:
../temp/main.txt:29:30: error: ‘_fullpath’ was not declared in this scope
29 | *__OFFSET_SUCC=( ptrszint )_fullpath((char*)(__STRING_BUFF)->chr,(char*)(qbs_add(__STRING_FILE,func_chr( 0 )))->chr, 1056 );
| ^~~~~~~~~
../temp/main.txt:153:30: error: ‘_fullpath’ was not declared in this scope
153 | *__OFFSET_SUCC=( ptrszint )_fullpath((char*)(__STRING_BUFF)->chr,(char*)(qbs_add(__STRING_FILE,func_chr( 0 )))->chr, 3 );
| ^~~~~~~~~
-
Thank you @luke and @GeorgeMcGinn for your replies.
George, could you please check, if Luke's code is working for you?
-
Just a confirmation on my 32-bit windows for you. I get the results you got and expected.
- Dav
-
@RhoSigma - I just tried to compile it with the development build that is out there now, and I get the same internal compiler errors.
I'm running Linux Ubuntu 20.04 and 64-bit processing, it that means anything,
Thank you @luke and @GeorgeMcGinn for your replies.
George, could you please check, if Luke's code is working for you?
-
Thanks for testing @Dav and @George McGinn, the problem is already resolved now to my satisfaction.
-
Sorry, I missed Luke's code. It works fine now.
Thanks for testing @Dav and @George McGinn, the problem is already resolved now to my satisfaction.