Skip to content

Commit 0ec6cfa

Browse files
committed
record: skip whitespaces after shebang for scripts
Python tracing won't work when the shebang line has a space like below: " #! /usr/bin/env python3 " This patch makes uftrace to understand the above shebang as well. Fixed: namhyung#1690 Signed-off-by: Gabriel Kim <[email protected]>
1 parent 534a366 commit 0ec6cfa

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

utils/utils.c

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -598,30 +598,43 @@ char *strjoin(char *left, char *right, const char *delim)
598598
* str_trim - to trim all spaces
599599
* @str: input string
600600
*
601-
* This function make @str to right trimmed @str
601+
* This function make @str to all trimmed @str
602602
*/
603603
char *str_trim(char *str)
604604
{
605-
int i = 0;
606-
int j = 0;
607-
bool spaceFound = false;
605+
str = str_ltrim(str);
606+
str = str_rtrim(str);
607+
return str;
608+
}
608609

610+
/**
611+
* str_ltrim - to trim left spaces
612+
* @str: input string
613+
*
614+
* This function make @str to left trimmed @str
615+
*/
616+
char *str_ltrim(char *str)
617+
{
609618
if (!str)
610619
return NULL;
611-
612-
while (str[j]) {
613-
if (str[j] != ' ' || !spaceFound) {
614-
str[i] = str[j];
615-
i++;
616-
spaceFound = (str[j] == ' ');
617-
}
618-
j++;
620+
while (isspace((unsigned char)*str)) {
621+
str++;
619622
}
623+
return str;
624+
}
620625

621-
if (i > 0 && str[i - 1] == ' ')
622-
i--;
623-
624-
str[i] = '\0';
626+
/**
627+
* str_rtrim - to trim right spaces
628+
* @str: input string
629+
*
630+
* This function make @str to right trimmed @str
631+
*/
632+
char *str_rtrim(char *str)
633+
{
634+
char *p = strchr(str, '\0');
635+
while (--p >= str && isspace(*p))
636+
;
637+
*(p + 1) = '\0';
625638
return str;
626639
}
627640

utils/utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ void strv_replace(struct strv *strv, int idx, const char *str);
390390
char *strv_join(struct strv *strv, const char *delim);
391391
void strv_free(struct strv *strv);
392392
char *str_trim(char *str);
393+
char *str_ltrim(char *str);
394+
char *str_rtrim(char *str);
393395

394396
char **parse_cmdline(char *cmd, int *argc);
395397
void free_parsed_cmdline(char **argv);

0 commit comments

Comments
 (0)