From 3e9f5e829fe068069916eb2bfa01a6534bfa86a2 Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Wed, 17 May 2023 13:25:34 +0200 Subject: [PATCH] fix: replace write by printf --- Makefile | 3 --- print.c | 9 ++------ print2.c | 9 ++------ utils/putchar.c | 18 --------------- utils/putchar.o | Bin 0 -> 2256 bytes utils/putnum.c | 59 ------------------------------------------------ utils/putnum.o | Bin 0 -> 3568 bytes utils/putstr.c | 26 --------------------- utils/putstr.o | Bin 0 -> 2552 bytes 9 files changed, 4 insertions(+), 120 deletions(-) delete mode 100644 utils/putchar.c create mode 100644 utils/putchar.o delete mode 100644 utils/putnum.c create mode 100644 utils/putnum.o delete mode 100644 utils/putstr.c create mode 100644 utils/putstr.o diff --git a/Makefile b/Makefile index 29a7523..bb789be 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,5 @@ SRCS = parsing.c \ utils/ft_isnum.c \ - utils/putchar.c \ - utils/putnum.c \ - utils/putstr.c \ utils/ft_atoi.c \ main.c \ time.c \ diff --git a/print.c b/print.c index 5cee2ab..7eb190a 100644 --- a/print.c +++ b/print.c @@ -6,7 +6,7 @@ /* By: cchauvet print_mutex); } diff --git a/print2.c b/print2.c index 7691378..f597e66 100644 --- a/print2.c +++ b/print2.c @@ -6,7 +6,7 @@ /* By: cchauvet data; time = get_time(); pthread_mutex_lock(&data->print_mutex); - ft_putnum(time, 7); - ft_putchar(' '); - ft_putnum(philo->id + 1, 3); - ft_putchar(' '); - ft_putstr("died"); - ft_putchar('\n'); + printf("%7zu %3zu %s\n", time, philo->id, "died"); pthread_mutex_unlock(&data->print_mutex); } diff --git a/utils/putchar.c b/utils/putchar.c deleted file mode 100644 index 0c0fdb6..0000000 --- a/utils/putchar.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putchar.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cchauvet - -void ft_putchar(char c) -{ - write(1, &c, 1); -} diff --git a/utils/putchar.o b/utils/putchar.o new file mode 100644 index 0000000000000000000000000000000000000000..6dc697cf7a92236f9edf30249e3b75ff869a9b65 GIT binary patch literal 2256 zcmb_d&1(};5TCc3q_Jt!v=wcwN<^iC^rfv8{JbH4q7LJQB__Inbx$gi;RIdkU|8)PTb z!*Mm8IXIRcWJ3u6g(EnW$d9P$3#p5#@zKkp0BRf*0bCyjh@Aj6J)26UaHAz$ei2Ep zz&_f27mXvLNR$+Ii!?T%DlgZ4X_1(>Qv&NRxu)Z0%Z6rFvn}1S>rFE|HO(jaGE#QiI7RK1`bUz@Y zw&7ylYXEfK!|Uh1owlh1EUxr^jk9DZSzrTCrkj4LvZk9Md^k3AlZ~LHs|_E8HhI2XfnE zVhG+!K=AP8p!-UgoGa;`7lNEqiHB!(01d%;lYU#`uto$xegx57Cz3ej4%b9>dH!-< z2qOyn&PHJ5_l_P&-q+L@y=OR{<}|8)+0<=pPl;zily;@|>xE z^evF_61NeHD)pNH7tkK0u&;^6sQgI*$~=^xzLDYl^j%UH+D&ASaP3f5#LIjXPb76; X!#<%9?j6}q3GgE+NEAnRES&!@_A0hb literal 0 HcmV?d00001 diff --git a/utils/putnum.c b/utils/putnum.c deleted file mode 100644 index e63b5be..0000000 --- a/utils/putnum.c +++ /dev/null @@ -1,59 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putnum.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cchauvet -#include -#include -#include "utils.h" - -static size_t get_size(size_t num) -{ - size_t nb_digit; - size_t rest; - - nb_digit = 0; - if (num == 0) - nb_digit++; - rest = num; - while (rest != 0) - { - nb_digit++; - rest = rest / 10; - } - return (nb_digit); -} - -static void ft_putdigit(size_t num) -{ - if (num > 9) - { - ft_putdigit(num / 10); - ft_putchar(num % 10 + 48); - } - else - ft_putchar(num + 48); -} - -void ft_putnum(size_t num, size_t padding) -{ - size_t size; - size_t i; - - i = 0; - size = get_size(num); - while (i < padding - size) - { - ft_putchar('0'); - i++; - } - ft_putdigit(num); -} diff --git a/utils/putnum.o b/utils/putnum.o new file mode 100644 index 0000000000000000000000000000000000000000..fc7a7af519a21d6140334045eb46d22b931cc623 GIT binary patch literal 3568 zcmb_eU5Fc16h1SPo6RO|lJ54`iVd_yq3k5PR;0Dml^Q!;TScL=71wNjCdptjS(3@p z7Pc1CR+sgmeGq)Hf(kwf)fX#8Emmm3ms0Un@={2#V2Yp%it9Nu_a@W3DI$2n%(>?~ zzjN-LGkG(8_&HTkK#&6ap)Uy(pgY`OPrA!Vh@<6EWAV1px|=W-7nY61X4kl$Zj;(r zT3GJ9NQ=dE$5=|Yjin=9W7m<6vFAptwG|cLrtsFm3vE%|x~iaQ`_9dkl@-_dEz-2U zPt05^>alHS$PkL>-F%emdb&%9(OOuB*x5C-TuOI&m@cld9L(HW=s@hu_SNdnS78Ll zZyA5wBf~ql+`Q?oKV58_c)qy%e3)xEcJ4_p*s?#s_0Er;zaMRVmwM-B?3-oxA@9Vw z8-TCKx3eC;Ls>Q zVE26@lU>LrD1!h)8{yEX7ZxD21GMP=NF;*A{fburFGSrFKs{Ye&!SEhZ~+&}DqXo^5@5?b z@>R6G=fAy8%AsF86KrnCl|yhe*R-8xB45ecrNq2hZ&)=uF+QQE^wiknO;>c)GgTaNxg{46vR*vvTrf zP>#oyt!sut=Wz=kMw~7p>KQx}jh|BwtPQFewD5HM2uGrQ>FZzb>0cupX^?*ca|D1a z6h-+nx|SH7D!df8k&tXQ>dA_gOI9lL)v@sjckS*((%XTgW#=o+f(g*;IeIsoLcuKR zW$zFU_l}~bD=ZNHosG2EaBzwZO(T1rt;OYrDHfSx>OQ6g%PjCAQ@>=<8K$B}2_9ph zO@|UJ5Oy4}zQSS%g)Sm;kcGVf5bUrpYRE5!(MQoj zyMcbk*a$8+U1U)NbaZL4=<KQQDRo#D-As9z>s_A^`VRWIatX6@P86aC?vIQyh0+ z5nQ`_#%;9z3(FCYY5aA+4@5zOAsKRI4OWkYy{MtdCKC;X5noQR=OX@DF8?IqBJXVpr}Is8*JB{!RJferoaTXlUnV77^kG)Q+g!Fd z7xi-yw2%sV!OS&FnQSgsH|IgGo0Y8Yn8zK^^R;T##EI^WeQ#WI>xNV3Fn%QJ+{+7O z*+u`CLbq#3thq}+JH#A`2WMJl8*Z5C;A={=6^RyKS?(v`g`FgdA7t*>EB;rJI4bW z93VS73+|U5`DTt&cqxUeIm1EmesJ?uwo?!Ak5DqC-#pg4%em618C3seUVog&q55gA z$@M1@qnIhY{PZ{X`@#?6TI3g;=Gq|tOMFxHfAOF7#q^v0Jm^piu%)?$`R91Ky%25g z@BW4Cq5bC<(EGR;)V~|NQU3j>86o%YUBpB$L`>q-Jm?NdDTzSmV^ID$KmX#K(f-l5 tNX}35M?1VyLv|Xk9zDkWMH|VVNX~y5F}ZhScbX0hQrBayALW+w{{uV5zJLG# literal 0 HcmV?d00001 diff --git a/utils/putstr.c b/utils/putstr.c deleted file mode 100644 index ffc9796..0000000 --- a/utils/putstr.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* putstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cchauvet - -void ft_putstr(char *str) -{ - size_t i; - - i = 0; - while (str[i] != 0) - { - ft_putchar(str[i]); - i++; - } -} diff --git a/utils/putstr.o b/utils/putstr.o new file mode 100644 index 0000000000000000000000000000000000000000..262d5fb19b680099a733f3be543b74a530c0f8e4 GIT binary patch literal 2552 zcmb_e-D@O85U-xuncdu8HgkJ&<~)(b5AHxRlf)>ehBI14_4H0FUD8F2YvJp@JTsP@cb`)5fpsLJsDBhtD33KPTExwEa1V=x#jNtj%I5FdmQH(RbFhZ^bF`NaeJlSFC%_RZfYj382{s zR?W3}z4BD~>GJur&zuF&4bT|4avGqpa?CX5fKc;c&?}e91I`1&RVn z>DQi2=jzW(2xt-{LtG_GSh}{qo6TNBRnYdgQ>)q|Wi;>y!^R&`j7Xzsc8U~Bu+>b$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