2 * Copyright 2016 Austin English
3 * Copyright 2016 Michael Müller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/debug.h"
23 #include "resources.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(fsutil
);
27 static void output_write(const WCHAR
*str
, DWORD wlen
)
31 ret
= WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE
), str
, wlen
, &count
, NULL
);
37 /* On Windows WriteConsoleW() fails if the output is redirected. So fall
38 * back to WriteFile(), assuming the console encoding is still the right
41 len
= WideCharToMultiByte(CP_ACP
, 0, str
, wlen
, NULL
, 0, NULL
, NULL
);
42 msgA
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(char));
45 WideCharToMultiByte(CP_ACP
, 0, str
, wlen
, msgA
, len
, NULL
, NULL
);
46 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE
), msgA
, len
, &count
, FALSE
);
47 HeapFree(GetProcessHeap(), 0, msgA
);
51 static int WINAPIV
output_string(int msg
, ...)
54 __ms_va_list arguments
;
57 __ms_va_start(arguments
, msg
);
58 len
= FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE
, NULL
, msg
, 0, out
, ARRAY_SIZE(out
), &arguments
);
59 __ms_va_end(arguments
);
61 if (len
== 0 && GetLastError() != NO_ERROR
)
62 WINE_FIXME("Could not format string: le=%u, msg=%d\n", GetLastError(), msg
);
64 output_write(out
, len
);
69 static BOOL
output_error_string(DWORD error
)
72 if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
|
73 FORMAT_MESSAGE_IGNORE_INSERTS
| FORMAT_MESSAGE_ALLOCATE_BUFFER
,
74 NULL
, error
, 0, (LPWSTR
)&pBuffer
, 0, NULL
))
76 output_write(pBuffer
, lstrlenW(pBuffer
));
83 static int create_hardlink(int argc
, WCHAR
*argv
[])
87 output_string(STRING_HARDLINK_CREATE_USAGE
);
91 if (CreateHardLinkW(argv
[3], argv
[4], NULL
))
94 output_error_string(GetLastError());
98 static int hardlink(int argc
, WCHAR
*argv
[])
104 if (!wcsicmp(argv
[2], L
"create"))
105 return create_hardlink(argc
, argv
);
108 FIXME("unsupported parameter %s\n", debugstr_w(argv
[2]));
113 output_string(STRING_HARDLINK_USAGE
);
117 int __cdecl
wmain(int argc
, WCHAR
*argv
[])
121 TRACE("Command line:");
122 for (i
= 0; i
< argc
; i
++)
123 TRACE(" %s", debugstr_w(argv
[i
]));
128 if (!wcsicmp(argv
[1], L
"hardlink"))
129 return hardlink(argc
, argv
);
132 FIXME("unsupported command %s\n", debugstr_w(argv
[1]));
137 output_string(STRING_USAGE
);