summaryrefslogtreecommitdiff
path: root/src/tee/tee.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-01-03 16:56:10 +0100
committerBram Moolenaar <Bram@vim.org>2016-01-03 16:56:10 +0100
commit24db72958fc91bd067c7d60a4990d09a6f295b48 (patch)
tree161dfae4fd7303c807d3fd67e48bee62e255c949 /src/tee/tee.c
parentd798af8c77cf47dba74b6b69ae4eba904023981c (diff)
downloadvim-24db72958fc91bd067c7d60a4990d09a6f295b48.zip
patch 7.4.1040
Problem: The tee command is not available on MS-Windows. Solution: Adjust tee.c for MSVC and add a makefile. (Yasuhiro Matsumoto)
Diffstat (limited to 'src/tee/tee.c')
-rw-r--r--src/tee/tee.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/tee/tee.c b/src/tee/tee.c
index 6c85766bb..c668d2d1e 100644
--- a/src/tee/tee.c
+++ b/src/tee/tee.c
@@ -4,6 +4,7 @@
*
* Author: Paul Slootman
* (paul@wurtel.hobby.nl, paul@murphy.nl, paulS@toecompst.nl)
+ * Modifications for MSVC: Yasuhiro Matsumoto
*
* This source code is released into the public domain. It is provided on an
* as-is basis and no responsibility is accepted for its failure to perform
@@ -26,9 +27,16 @@
* precompiled for OS/2. That one probably works better.
*/
-#include <unistd.h>
+#ifndef _MSC_VER
+# include <unistd.h>
+#endif
#include <malloc.h>
#include <stdio.h>
+#include <fcntl.h>
+
+#ifdef _WIN32
+# define sysconf(x) -1
+#endif
void usage(void)
{
@@ -79,17 +87,17 @@ main(int argc, char *argv[])
int i;
char buf[BUFSIZ];
int n;
- extern int optind;
+ int optind = 1;
- while ((opt = getopt(argc, argv, "a")) != EOF)
+ for (i = 1; i < argc; i++)
{
- switch (opt)
- {
- case 'a': append++;
- break;
- default: usage();
- exit(2);
- }
+ if (argv[i][0] != '-')
+ break;
+ if (!strcmp(argv[i], "-a"))
+ append++;
+ else
+ usage();
+ optind++;
}
numfiles = argc - optind;
@@ -124,9 +132,9 @@ main(int argc, char *argv[])
exit(1);
}
}
- _fsetmode(stdin, "b");
+ setmode(fileno(stdin), O_BINARY);
fflush(stdout); /* needed for _fsetmode(stdout) */
- _fsetmode(stdout, "b");
+ setmode(fileno(stdout), O_BINARY);
while ((n = myfread(buf, sizeof(char), sizeof(buf), stdin)) > 0)
{