- for (i = 0; i < 4; i++) {
- const char* arg = i < argc ? argv[i] : "";
- if (write(fd, arg, strlen(arg) + 1) <= 0) {
+ for (i = 0; i < argc && p < limit; i++) {
+ if (i >= cmd_args) p[-1] = ' ';
+ p = stpncpy(p, argv[i], limit - p) + 1;
+ }
+ for (i = cmd_args; i < 4 && p < limit; i++) {
+ *p++ = 0;
+ }
+
+ const char* q = p < limit ? p : limit;
+ for (p = buf; p < q; ) {
+ ssize_t bytes = write(fd, p, q - p);
+ if (bytes <= 0) {