Skip to content

Commit 9719db2

Browse files
committed
Add script launching based on argv[0]
1 parent 66baebd commit 9719db2

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

patchlevel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ hunk.
158158
static const char * const local_patches[] = {
159159
NULL
160160
,"G4Vi:cosmo/73ecc6c - https://github.com/G4Vi/perl5/commit/73ecc6c6640c61baa00ee91949d502f0fe991db5 various changes to support building with the Cosmopolitan Libc"
161+
,"G4Vi:cosmo-apperl/SHORT_HASH - https://github.com/G4Vi/perl5/commit/FULL_HASH add argv[0] /zip/bin script launching"
161162
#ifdef PERL_GIT_UNCOMMITTED_CHANGES
162163
,"uncommitted-changes"
163164
#endif

perl.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,29 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)
20752075

20762076
init_main_stash();
20772077

2078+
const char *programname = argv[0];
2079+
const char *slash = strrchr(programname, '/');
2080+
if(slash != NULL)
2081+
{
2082+
programname = slash + 1;
2083+
}
2084+
if(programname[0])
2085+
{
2086+
unsigned namelen = strlen(programname);
2087+
const char *dot = strrchr(programname, '.');
2088+
if(dot != NULL)
2089+
{
2090+
namelen = dot - programname;
2091+
}
2092+
static char name[256];
2093+
snprintf(name, sizeof(name), "/zip/bin/%.*s", namelen, programname);
2094+
struct stat st;
2095+
if((stat(name, &st) == 0) && S_ISREG(st.st_mode))
2096+
{
2097+
scriptname = name;
2098+
}
2099+
}
2100+
if(scriptname == NULL)
20782101
{
20792102
const char *s;
20802103
for (argc--,argv++; argc > 0; argc--,argv++) {

0 commit comments

Comments
 (0)