11#include <errno.h>
22#include <fcntl.h>
33#include <signal.h>
4- #include <stdarg.h>
54#include <stdint.h>
65#include <stdio.h>
76#include <stdlib.h>
@@ -85,21 +84,6 @@ static int dprintf_ellipsise_long_snip_line(int fd, const char *line) {
8584 }
8685}
8786
88- static int launcher_vdprintf (int fd , const char * fmt , va_list args ) {
89- if (vdprintf (fd , fmt , args ) < 0 ) {
90- return negative_errno ();
91- }
92- return 0 ;
93- }
94-
95- static int launcher_dprintf (int fd , const char * fmt , ...) {
96- va_list args ;
97- va_start (args , fmt );
98- int ret = launcher_vdprintf (fd , fmt , args );
99- va_end (args );
100- return ret ;
101- }
102-
10387static int launcher_write_all (int fd , const char * buf , size_t count ) {
10488 while (count > 0 ) {
10589 ssize_t written = write (fd , buf , count );
@@ -168,8 +152,10 @@ static int _nonnull_ interact_with_dmenu(struct config *cfg, int *input_pipe,
168152 continue ;
169153 }
170154
171- int write_ret =
172- launcher_dprintf (input_pipe [1 ], "[%*zu] " , pad , idx + 1 );
155+ char prefix [64 ];
156+ size_t prefix_len =
157+ snprintf_safe (prefix , sizeof (prefix ), "[%*zu] " , pad , idx + 1 );
158+ int write_ret = launcher_write_all (input_pipe [1 ], prefix , prefix_len );
173159 if (write_ret == - EPIPE ) {
174160 launcher_closed_stdin = true;
175161 continue ;
@@ -190,8 +176,12 @@ static int _nonnull_ interact_with_dmenu(struct config *cfg, int *input_pipe,
190176 }
191177
192178 if (snip -> nr_lines > 1 ) {
193- write_ret =
194- launcher_dprintf (input_pipe [1 ], " (%zu lines)" , snip -> nr_lines );
179+ char lines_suffix [64 ];
180+ size_t lines_suffix_len =
181+ snprintf_safe (lines_suffix , sizeof (lines_suffix ),
182+ " (%zu lines)" , snip -> nr_lines );
183+ write_ret = launcher_write_all (input_pipe [1 ], lines_suffix ,
184+ lines_suffix_len );
195185 if (write_ret == - EPIPE ) {
196186 launcher_closed_stdin = true;
197187 continue ;
0 commit comments