diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-12-13 09:22:15 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-12-13 09:22:15 +0000 |
commit | 23bbdf1b43cc34d3d52f6b342a6122198bb3d938 (patch) | |
tree | 3da19d11935aa83a5051a2a6c3b4d7dc7782b2d0 /src/util/w32cat.c | |
parent | afae5a70d61a1aef2ba6e330bf8090ca47906818 (diff) | |
download | gnunet-23bbdf1b43cc34d3d52f6b342a6122198bb3d938.tar.gz gnunet-23bbdf1b43cc34d3d52f6b342a6122198bb3d938.zip |
-dos2unix
Diffstat (limited to 'src/util/w32cat.c')
-rw-r--r-- | src/util/w32cat.c | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/src/util/w32cat.c b/src/util/w32cat.c index 4c60c4906..292bd6d48 100644 --- a/src/util/w32cat.c +++ b/src/util/w32cat.c | |||
@@ -17,92 +17,92 @@ | |||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <stdio.h> | 21 | #include <stdio.h> |
22 | #include <windows.h> | 22 | #include <windows.h> |
23 | 23 | ||
24 | int | 24 | int |
25 | main (int argc, char **argv) | 25 | main (int argc, char **argv) |
26 | { | 26 | { |
27 | HANDLE stdi, stdo; | 27 | HANDLE stdi, stdo; |
28 | BOOL b; | 28 | BOOL b; |
29 | wchar_t *commandlinew, **argvw; | 29 | wchar_t *commandlinew, **argvw; |
30 | int argcw; | 30 | int argcw; |
31 | int i; | 31 | int i; |
32 | 32 | ||
33 | stdo = GetStdHandle (STD_OUTPUT_HANDLE); | 33 | stdo = GetStdHandle (STD_OUTPUT_HANDLE); |
34 | if (stdo == INVALID_HANDLE_VALUE || stdo == NULL) | 34 | if (stdo == INVALID_HANDLE_VALUE || stdo == NULL) |
35 | return 1; | 35 | return 1; |
36 | 36 | ||
37 | commandlinew = GetCommandLineW (); | 37 | commandlinew = GetCommandLineW (); |
38 | argvw = CommandLineToArgvW (commandlinew, &argcw); | 38 | argvw = CommandLineToArgvW (commandlinew, &argcw); |
39 | if (argvw == NULL) | 39 | if (argvw == NULL) |
40 | return 1; | 40 | return 1; |
41 | 41 | ||
42 | for (i = 1; i < argcw || argcw == 1; i++) | 42 | for (i = 1; i < argcw || argcw == 1; i++) |
43 | { | 43 | { |
44 | DWORD r, w; | 44 | DWORD r, w; |
45 | int is_dash = wcscmp (argvw[i], L"-") == 0; | 45 | int is_dash = wcscmp (argvw[i], L"-") == 0; |
46 | if (argcw == 1 || is_dash) | 46 | if (argcw == 1 || is_dash) |
47 | { | 47 | { |
48 | stdi = GetStdHandle (STD_INPUT_HANDLE); | 48 | stdi = GetStdHandle (STD_INPUT_HANDLE); |
49 | if (stdi == INVALID_HANDLE_VALUE) | 49 | if (stdi == INVALID_HANDLE_VALUE) |
50 | { | 50 | { |
51 | fprintf (stderr, "cat: Failed to obtain stdin handle.\n"); | 51 | fprintf (stderr, "cat: Failed to obtain stdin handle.\n"); |
52 | return 4; | 52 | return 4; |
53 | } | 53 | } |
54 | if (stdi == NULL) | 54 | if (stdi == NULL) |
55 | { | 55 | { |
56 | fprintf (stderr, "cat: Have no stdin.\n"); | 56 | fprintf (stderr, "cat: Have no stdin.\n"); |
57 | return 5; | 57 | return 5; |
58 | } | 58 | } |
59 | } | 59 | } |
60 | else | 60 | else |
61 | { | 61 | { |
62 | stdi = CreateFileW (argvw[i], GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); | 62 | stdi = CreateFileW (argvw[i], GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL); |
63 | if (stdi == INVALID_HANDLE_VALUE) | 63 | if (stdi == INVALID_HANDLE_VALUE) |
64 | { | 64 | { |
65 | wchar_t *msgbuf; | 65 | wchar_t *msgbuf; |
66 | DWORD le = GetLastError (); | 66 | DWORD le = GetLastError (); |
67 | if (0 < FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, le, 0, (wchar_t *) &msgbuf, 0, NULL)) | 67 | if (0 < FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, le, 0, (wchar_t *) &msgbuf, 0, NULL)) |
68 | { | 68 | { |
69 | fprintf (stderr, "cat: Failed to open file `%S'. Error %lu.\n", argvw[i], le); | 69 | fprintf (stderr, "cat: Failed to open file `%S'. Error %lu.\n", argvw[i], le); |
70 | return 3; | 70 | return 3; |
71 | } | 71 | } |
72 | fprintf (stderr, "cat: Failed to open file `%S'. Error %lu: %S\n", argvw[i], le, msgbuf); | 72 | fprintf (stderr, "cat: Failed to open file `%S'. Error %lu: %S\n", argvw[i], le, msgbuf); |
73 | if (msgbuf != NULL) | 73 | if (msgbuf != NULL) |
74 | LocalFree (msgbuf); | 74 | LocalFree (msgbuf); |
75 | return 2; | 75 | return 2; |
76 | } | 76 | } |
77 | } | 77 | } |
78 | do | 78 | do |
79 | { | 79 | { |
80 | unsigned char c; | 80 | unsigned char c; |
81 | b = ReadFile (stdi, &c, 1, &r, NULL); | 81 | b = ReadFile (stdi, &c, 1, &r, NULL); |
82 | if (b && r > 0) | 82 | if (b && r > 0) |
83 | { | 83 | { |
84 | b = WriteFile (stdo, &c, 1, &w, NULL); | 84 | b = WriteFile (stdo, &c, 1, &w, NULL); |
85 | if (b == 0) | 85 | if (b == 0) |
86 | { | 86 | { |
87 | wchar_t *msgbuf; | 87 | wchar_t *msgbuf; |
88 | DWORD le = GetLastError (); | 88 | DWORD le = GetLastError (); |
89 | if (0 < FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, le, 0, (wchar_t *) &msgbuf, 0, NULL)) | 89 | if (0 < FormatMessageW (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, le, 0, (wchar_t *) &msgbuf, 0, NULL)) |
90 | { | 90 | { |
91 | fprintf (stderr, "cat: Failed to write into stdout. Error %lu.\n", le); | 91 | fprintf (stderr, "cat: Failed to write into stdout. Error %lu.\n", le); |
92 | return 3; | 92 | return 3; |
93 | } | 93 | } |
94 | fprintf (stderr, "cat: Failed to write into stdout. Error %lu: %S\n", le, msgbuf); | 94 | fprintf (stderr, "cat: Failed to write into stdout. Error %lu: %S\n", le, msgbuf); |
95 | if (msgbuf != NULL) | 95 | if (msgbuf != NULL) |
96 | LocalFree (msgbuf); | 96 | LocalFree (msgbuf); |
97 | return 6; | 97 | return 6; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | } while (b && r > 0); | 100 | } while (b && r > 0); |
101 | if (argcw == 1) | 101 | if (argcw == 1) |
102 | break; | 102 | break; |
103 | if (!is_dash) | 103 | if (!is_dash) |
104 | CloseHandle (stdi); | 104 | CloseHandle (stdi); |
105 | } | 105 | } |
106 | LocalFree (argvw); | 106 | LocalFree (argvw); |
107 | return 0; | 107 | return 0; |
108 | } | 108 | } |