Patching the fucking pwd

This commit is contained in:
Raphaël 2024-08-12 18:15:29 +02:00
parent c5a06ce9df
commit 45bacdd3c0
3 changed files with 11 additions and 5 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/07 14:22:50 by rparodi #+# #+# */
/* Updated: 2024/08/11 12:49:51 by maiboyer ### ########.fr */
/* Updated: 2024/08/12 14:16:45 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/07 13:58:37 by rparodi #+# #+# */
/* Updated: 2024/08/11 11:26:12 by maiboyer ### ########.fr */
/* Updated: 2024/08/12 18:14:08 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,6 +14,7 @@
#include "me/mem/mem.h"
#include "me/string/string.h"
#include "me/types.h"
#include <errno.h>
t_error builtin_pwd___(t_state *state, t_builtin_spawn_info info, t_i32 *exit_code)
{
@ -21,7 +22,12 @@ t_error builtin_pwd___(t_state *state, t_builtin_spawn_info info, t_i32 *exit_co
s = string_new(1024);
while (getcwd(s.buf, s.capacity - 1) == NULL)
string_reserve(&s, s.capacity * 2);
{
if (errno == ERANGE)
string_reserve(&s, s.capacity * 3);
else
return (string_free(s), ERROR);
}
printf("%s\n", s.buf);
string_free(s);
return (*exit_code = 0, NO_ERROR);