#include <sys/wait.h>
#include <arpa/inet.h>
#include <netinet/in.h>
+#include <errno.h>
#ifdef HAVE_PRINTF_H
# include <printf.h>
return 0;
}
-int
+size_t
count_strings (char *const *argv)
{
- int argc;
+ size_t argc;
for (argc = 0; argv[argc] != NULL; ++argc)
;
return argc;
}
+/* http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 */
+int
+is_power_of_2 (unsigned long v)
+{
+ return v && ((v & (v - 1)) == 0);
+}
+
static int
compare (const void *vp1, const void *vp2)
{
*/
if (pipe (so_fd) == -1 || pipe (se_fd) == -1) {
- perror ("pipe");
+ error (0, errno, "pipe");
abort ();
}
if (flag_copy_stdin) {
if (pipe (stdin_fd) == -1) {
- perror ("pipe");
+ error (0, errno, "pipe");
abort ();
}
}
pid = fork ();
if (pid == -1) {
- perror ("fork");
+ error (0, errno, "fork");
abort ();
}
dup2 (stdin_fd[0], 0);
close (stdin_fd[0]);
close (stdin_fd[1]);
- } else
+ } else {
/* Set stdin to /dev/null (ignore failure) */
open ("/dev/null", O_RDONLY);
+ }
close (so_fd[0]);
close (se_fd[0]);
if (!(flags & COMMAND_FLAG_FOLD_STDOUT_ON_STDERR))
stdin_pid = fork ();
if (stdin_pid == -1) {
- perror ("fork");
+ error (0, errno, "fork");
abort ();
}