Made wildcard expansion more responsive to signals
authorLukas Jiriste <ljiriste@student.42prague.com>
Sun, 1 Sep 2024 09:24:02 +0000 (11:24 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sun, 1 Sep 2024 12:09:49 +0000 (14:09 +0200)
src/wildcards_helpers.c

index 7a71494ffd929b4efd924b2a35c78e90e3be2cc8..edf3a75b0c5768748f3dcc3b27217da56c0fbb28 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: lnikolov <lnikolov@student.42prague.com    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2024/08/31 15:57:29 by lnikolov          #+#    #+#             */
-/*   Updated: 2024/08/31 16:28:30 by lnikolov         ###   ########.fr       */
+/*   Updated: 2024/09/01 11:19:35 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -28,21 +28,21 @@ int replace_str_by_joint_split(char **str, char **expanded_split)
        len = 0;
        i = 0;
        while (expanded_split[i])
-               len += ft_strlen(expanded_split[i++]) + 1;
-       *str = malloc(len + 1 + 1);
-       if (!str)
-       {
-               *str = tmp;
+               len += ft_strlen(expanded_split[i++]) + 2 + 1;
+       tmp = malloc(len + 1 + 1);
+       if (!tmp)
                return (1);
-       }
+       free(*str);
+       *str = tmp;
        str[0][0] = '\0';
        i = 0;
        while (expanded_split[i])
        {
+               if (g_last_signal)
+                       return (1);
                ft_strlcat(*str, expanded_split[i++], len + 1 + 1);
                ft_strlcat(*str, " ", len + 1 + 1);
        }
-       free(tmp);
        return (0);
 }
 
@@ -65,6 +65,8 @@ int   replace_str_by_joint_quoted_split(char **str, char **expanded_split)
        i = 0;
        while (expanded_split[i])
        {
+               if (g_last_signal)
+                       return (1);
                ft_strlcat(*str, "'", len + 1 + 1);
                ft_strlcat(*str, expanded_split[i++], len + 1 + 1);
                ft_strlcat(*str, "'", len + 1 + 1);