diff --git a/libc/calls/getprogramexecutablename.greg.c b/libc/calls/getprogramexecutablename.greg.c index 78cb0f30b..1bc5a1494 100644 --- a/libc/calls/getprogramexecutablename.greg.c +++ b/libc/calls/getprogramexecutablename.greg.c @@ -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,10 +77,14 @@ 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)) || - IsMetal() || ((q = StrCat(u.path, __argv[0], ".com")) && !sys_faccessat(AT_FDCWD, q, F_OK, 0)))) { if (*q != '/') { diff --git a/libc/calls/metalfile.internal.h b/libc/calls/metalfile.internal.h index 17563585b..a7586c85d 100644 --- a/libc/calls/metalfile.internal.h +++ b/libc/calls/metalfile.internal.h @@ -15,8 +15,6 @@ extern size_t __ape_com_size; COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#define APE_COM_NAME "/ape.com" -#define APE_COM_ALT_NAME "/proc/self/exe" -#define APE_COM_URI "file:/proc/self/exe" +#define APE_COM_NAME "/proc/self/exe" #endif /* COSMOPOLITAN_LIBC_CALLS_METALFILE_INTERNAL_H_ */ diff --git a/libc/calls/metalfile_init.S b/libc/calls/metalfile_init.S index aa6a41b1b..2793b27a2 100644 --- a/libc/calls/metalfile_init.S +++ b/libc/calls/metalfile_init.S @@ -34,5 +34,5 @@ pop %rsi pop %rdi .init.end 101,_init_metalfile -APE_COM_URI: - .endobj APE_COM_URI,globl,hidden +APE_COM_NAME: + .endobj APE_COM_NAME,globl,hidden diff --git a/libc/calls/openat-metal.c b/libc/calls/openat-metal.c index c49dab405..3eef25ff0 100644 --- a/libc/calls/openat-metal.c +++ b/libc/calls/openat-metal.c @@ -38,8 +38,7 @@ int sys_openat_metal(int dirfd, const char *file, int flags, unsigned mode) { int fd; struct MetalFile *state; - if (dirfd != AT_FDCWD || (strcmp(file, APE_COM_NAME) && - strcmp(file, APE_COM_ALT_NAME))) return enoent(); + if (dirfd != AT_FDCWD || strcmp(file, APE_COM_NAME)) return enoent(); if (flags != O_RDONLY) return eacces(); if (!_weaken(__ape_com_base) || !_weaken(__ape_com_size)) return eopnotsupp(); diff --git a/libc/zipos/get.c b/libc/zipos/get.c index 76ffbc5e9..47b4bc26d 100644 --- a/libc/zipos/get.c +++ b/libc/zipos/get.c @@ -30,7 +30,7 @@ #include "libc/zip.h" #include "libc/zipos/zipos.internal.h" -STATIC_YOINK(APE_COM_URI); +STATIC_YOINK(APE_COM_NAME); static uint64_t __zipos_get_min_offset(const uint8_t *base, const uint8_t *cdir) {