]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blobdiff - src/coloredstderr.c
Also hook un-macroed putc when it's a macro.
[coloredstderr/coloredstderr.git] / src / coloredstderr.c
index 586b0240d3df19b3a70a3f4a1d0692e81a36345f..66467b402e14d0a95b630dea38e1e3d59a77a7d7 100644 (file)
@@ -238,6 +238,14 @@ HOOK_FILE2(int, fputc, stream,
            int, c, FILE *, stream)
 HOOK_FILE2(int, putc, stream,
            int, c, FILE *, stream)
+/* The glibc uses a macro for putc() which expands to _IO_putc(). However
+ * sometimes the raw putc() is used as well, not sure why. Make sure to hook
+ * it too. */
+#ifdef putc
+# undef putc
+HOOK_FILE2(int, putc, stream,
+           int, c, FILE *, stream)
+#endif
 HOOK_FILE1(int, putchar, stdout,
            int, c)
 HOOK_FILE1(int, puts, stdout,
@@ -406,7 +414,7 @@ HOOK_FUNC_DEF1(int, dup, int, oldfd) {
     DLSYM_FUNCTION(real_dup, "dup");
 
     newfd = real_dup(oldfd);
-    if (newfd != -1) {
+    if (newfd > -1) {
         dup_fd(oldfd, newfd);
     }
 
@@ -417,7 +425,7 @@ HOOK_FUNC_DEF2(int, dup2, int, oldfd, int, newfd) {
     DLSYM_FUNCTION(real_dup2, "dup2");
 
     newfd = real_dup2(oldfd, newfd);
-    if (newfd != -1) {
+    if (newfd > -1) {
         dup_fd(oldfd, newfd);
     }
 
@@ -428,7 +436,7 @@ HOOK_FUNC_DEF3(int, dup3, int, oldfd, int, newfd, int, flags) {
     DLSYM_FUNCTION(real_dup3, "dup3");
 
     newfd = real_dup3(oldfd, newfd, flags);
-    if (newfd != -1) {
+    if (newfd > -1) {
         dup_fd(oldfd, newfd);
     }
 
@@ -460,7 +468,7 @@ HOOK_FUNC_VAR_DEF2(int, fcntl, int, fd, int, cmd /*, ... */) {
     va_end(ap);
 
     /* We only care about duping fds. */
-    if (cmd == F_DUPFD && result != -1) {
+    if (cmd == F_DUPFD && result > -1) {
         dup_fd(fd, result);
     }
 
@@ -646,10 +654,16 @@ HOOK_FUNC_DEF2(int, execvp, char const *, file, char * const *, argv) {
 #ifdef HAVE_EXECVPE
 extern char **environ;
 int execvpe(char const *file, char * const argv[], char * const envp[]) {
+    int result;
+    char **old_environ = environ;
+
     /* Fake the environment so we can reuse execvp(). */
     environ = (char **)envp;
 
     /* execvp() updates the environment. */
-    return execvp(file, argv);
+    result = execvp(file, argv);
+
+    environ = old_environ;
+    return result;
 }
 #endif