Actually. qsort is fine since most versions fal back to a cheaper

sort when the number of elements to sort is small (like in our case).
This commit is contained in:
Todd C. Miller
2009-09-03 13:21:43 +00:00
parent 2935e2a5ba
commit 568c99b099

View File

@@ -268,24 +268,21 @@ script_duplow(fd)
/* sort fds so we can dup them safely */ /* sort fds so we can dup them safely */
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
indices[i] = i; indices[i] = i;
/* XXX - qsort is overkill for this */
qsort(indices, 5, sizeof(int), fdcompar); qsort(indices, 5, sizeof(int), fdcompar);
/* Move pty master/slave and session fds to low numbered fds. */ /* Move pty master/slave and session fds to low numbered fds. */
if (def_script) { for (i = 0; i < 5; i++) {
for (i = 0; i < 5; i++) { j = indices[i];
j = indices[i]; if (script_fds[j] != fd) {
if (script_fds[j] != fd) {
#ifdef HAVE_DUP2 #ifdef HAVE_DUP2
dup2(script_fds[j], fd); dup2(script_fds[j], fd);
#else #else
close(fd); close(fd);
dup(script_fds[j]); dup(script_fds[j]);
close(script_fds[j]); close(script_fds[j]);
#endif #endif
}
script_fds[j] = fd++;
} }
script_fds[j] = fd++;
} }
return(fd); return(fd);
} }