Work towards zipos / open(argv[0]) on metal (#667)

This commit is contained in:
tkchia 2022-11-06 15:29:47 +08:00 committed by GitHub
parent 543c93f623
commit cb9a0466f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 257 additions and 46 deletions

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/metalfile.internal.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
@ -76,6 +77,11 @@ static inline void GetProgramExecutableNameImpl(char *p, char *e) {
return;
}
if (IsMetal()) {
if (!memccpy(p, APE_COM_NAME, 0, e - p - 1)) e[-1] = 0;
return;
}
// if argv[0] exists then turn it into an absolute path. we also try
// adding a .com suffix since the ape auto-appends it when resolving
if (__argc && (((q = __argv[0]) && !sys_faccessat(AT_FDCWD, q, F_OK, 0)) ||