Skip to content

Commit

Permalink
Add script launching based on argv[0]
Browse files Browse the repository at this point in the history
  • Loading branch information
G4Vi committed Oct 12, 2022
1 parent 66baebd commit 9719db2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions patchlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ hunk.
static const char * const local_patches[] = {
NULL
,"G4Vi:cosmo/73ecc6c - https://github.com/G4Vi/perl5/commit/73ecc6c6640c61baa00ee91949d502f0fe991db5 various changes to support building with the Cosmopolitan Libc"
,"G4Vi:cosmo-apperl/SHORT_HASH - https://github.com/G4Vi/perl5/commit/FULL_HASH add argv[0] /zip/bin script launching"
#ifdef PERL_GIT_UNCOMMITTED_CHANGES
,"uncommitted-changes"
#endif
Expand Down
23 changes: 23 additions & 0 deletions perl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,29 @@ S_parse_body(pTHX_ char **env, XSINIT_t xsinit)

init_main_stash();

const char *programname = argv[0];
const char *slash = strrchr(programname, '/');
if(slash != NULL)
{
programname = slash + 1;
}
if(programname[0])
{
unsigned namelen = strlen(programname);
const char *dot = strrchr(programname, '.');
if(dot != NULL)
{
namelen = dot - programname;
}
static char name[256];
snprintf(name, sizeof(name), "/zip/bin/%.*s", namelen, programname);
struct stat st;
if((stat(name, &st) == 0) && S_ISREG(st.st_mode))
{
scriptname = name;
}
}
if(scriptname == NULL)
{
const char *s;
for (argc--,argv++; argc > 0; argc--,argv++) {
Expand Down

0 comments on commit 9719db2

Please sign in to comment.