diff --git a/modules/src/system/open.c b/modules/src/system/open.c
index cb6e7537e..85fa71e7a 100644
--- a/modules/src/system/open.c
+++ b/modules/src/system/open.c
@@ -45,7 +45,7 @@ sys_open(path, flag, filep)
 		}
 		/* Fall through */
 	case OP_WRITE:
-		if ((fd = open(path, O_CREAT|O_WRONLY|O_BINARY, 0666)) < 0)
+		if ((fd = open(path, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666)) < 0)
 			return 0;
 		break;
 	default:
diff --git a/util/ack/run.c b/util/ack/run.c
index e8265aee9..2ed761bbc 100644
--- a/util/ack/run.c
+++ b/util/ack/run.c
@@ -119,7 +119,7 @@ static int run_exec(trf* phase)
 
 		oldstdout = dup(1);
 		close(1);
-		if (open(out.p_path, O_CREAT|O_WRONLY|O_BINARY, 0666) != 1)
+		if (open(out.p_path, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666) != 1)
 		{
 			close(1);
 			dup(2);
@@ -139,7 +139,7 @@ static int run_exec(trf* phase)
 
 	if (oldstdout != -1)
 	{
-		int i = close(1);
+		close(1);
 		dup2(oldstdout, 1);
 		close(oldstdout);
 	}
diff --git a/util/opt/main.c b/util/opt/main.c
index 2856ffd33..7b75fb5c0 100644
--- a/util/opt/main.c
+++ b/util/opt/main.c
@@ -60,6 +60,7 @@ void fileinit(void)
 	else
 	{
 		outfile = stdout;
+		freopen(NULL, "wb", stdout);
 		outshort(sp_magic);
 	}
 }
@@ -84,8 +85,11 @@ int main(int argc, char* argv[])
 		exit(EXIT_FAILURE);
 	}
 	if (argc)
-		if (freopen(*argv, "r", stdin) == NULL)
+		if (freopen(*argv, "rb", stdin) == NULL)
 			error("Cannot open %s", *argv);
+	else
+		freopen(NULL, "rb", stdin);
+
 	fileinit();
 #ifdef USEMALLOC
 	coreinit();