Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmds/record.c
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ static void check_binary(struct uftrace_opts *opts)
if (!opts->force && !opts->patch)
pr_err_ns(SCRIPT_MSG, opts->exename);

script = str_ltrim(script);
script = str_trim(script);

/* ignore options */
p = strchr(script, ' ');
Expand Down Expand Up @@ -2188,7 +2188,7 @@ int do_child_exec(int ready, struct uftrace_opts *opts, int argc, char *argv[])
if (strstr(shebang, "python"))
is_python = true;
#endif
s = str_ltrim(shebang);
s = str_trim(shebang);

p = strchr(s, ' ');
if (p != NULL)
Expand Down
49 changes: 49 additions & 0 deletions utils/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,22 @@ char *strjoin(char *left, char *right, const char *delim)
return new;
}

/**
* str_trim - to trim all spaces
* @str: input string
*
* This function make @str to all trimmed @str
*/
char *str_trim(char *str)
{
if (!str)
return NULL;
str = str_ltrim(str);
str = str_rtrim(str);
str = str_mtrim(str);
return str;
}

/**
* str_ltrim - to trim left spaces
* @str: input string
Expand Down Expand Up @@ -625,6 +641,39 @@ char *str_rtrim(char *str)
return str;
}

/**
* str_mtrim - to trim middle spaces
* @str: input string
*
* This function make @str to middle trimmed @str
*/
char *str_mtrim(char *str)
{
char *read_ptr = str;
char *write_ptr = str;
int space_flag = 0;

if (!str)
return NULL;

while (*read_ptr != '\0') {
if (isspace((unsigned char)*read_ptr)) {
if (!space_flag) {
*write_ptr++ = ' ';
space_flag = 1;
}
}
else {
*write_ptr++ = *read_ptr;
space_flag = 0;
}
read_ptr++;
}

*write_ptr = '\0';
return str;
}

/**
* strv_split - split given string and construct a string vector
* @strv: string vector
Expand Down
2 changes: 2 additions & 0 deletions utils/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,10 @@ void strv_append(struct strv *strv, const char *str);
void strv_replace(struct strv *strv, int idx, const char *str);
char *strv_join(struct strv *strv, const char *delim);
void strv_free(struct strv *strv);
char *str_trim(char *str);
char *str_ltrim(char *str);
char *str_rtrim(char *str);
char *str_mtrim(char *str);

char **parse_cmdline(char *cmd, int *argc);
void free_parsed_cmdline(char **argv);
Expand Down