/* Must be loaded before the following headers. */
#include "ldpreload.h"
+/* Disable assert()s if not compiled with --enable-debug. */
+#ifndef DEBUG
+# define NDEBUG
+#endif
+
+#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
* additional call. */
static int isatty_noinline(int fd) noinline;
static int isatty_noinline(int fd) {
+ assert(fd >= 0);
+
int saved_errno = errno;
int result = isatty(fd);
errno = saved_errno;
debug("%3d -> %3d\t\t\t[%d]\n", oldfd, newfd, getpid());
#endif
+ assert(oldfd >= 0 && newfd >= 0);
+
if (unlikely(!initialized)) {
init_from_environment();
}
debug("%3d -> .\t\t\t[%d]\n", fd, getpid());
#endif
+ assert(fd >= 0);
+
if (unlikely(!initialized)) {
init_from_environment();
}
/* Count arguments. */ \
size_t count = 1; /* arg */ \
va_start(ap, arg); \
- while (va_arg(ap, char const *)) { \
+ while (va_arg(ap, char *)) { \
count++; \
} \
va_end(ap); \
\
/* Copy varargs. */ \
char *args[count + 1 /* terminating NULL */]; \
- args[0] = (char *)arg; \
+ args[0] = (char *)arg; /* there's no other way around the cast */ \
\
size_t i = 1; \
va_start(ap, arg); \
int execl(char const *path, char const *arg, ...) {
EXECL_COPY_VARARGS(args);
- update_environment();
+ /* execv() updates the environment. */
return execv(path, args);
}
-
int execlp(char const *file, char const *arg, ...) {
EXECL_COPY_VARARGS(args);
- update_environment();
+ /* execvp() updates the environment. */
return execvp(file, args);
}
-
int execle(char const *path, char const *arg, ... /*, char * const envp[] */) {
+ char * const *envp;
+
EXECL_COPY_VARARGS_START(args);
/* Get envp[] located after arguments. */
- char * const *envp = va_arg(ap, char * const *);
+ envp = va_arg(ap, char * const *);
EXECL_COPY_VARARGS_END(args);
+ /* execve() updates the environment. */
return execve(path, args, envp);
}
/* Fake the environment so we can reuse execvp(). */
environ = (char **)envp;
+ /* execvp() updates the environment. */
return execvp(file, argv);
}
#endif