wineps.drv: Return default resolution if PPD doesn't provide the list of supported...
[wine.git] / programs / fsutil / main.c
blob8de7027ee0efae44ed62fe36e6d6b9a7271cee6f
1 /*
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
20 #include <windows.h>
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)
29 DWORD count;
31 if (!WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, wlen, &count, NULL))
33 DWORD len;
34 char *msgA;
36 /* On Windows WriteConsoleW() fails if the output is redirected. So fall
37 * back to WriteFile() with OEM code page.
39 len = WideCharToMultiByte(GetOEMCP(), 0, str, wlen, NULL, 0, NULL, NULL);
40 msgA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
41 if (!msgA) return;
43 WideCharToMultiByte(GetOEMCP(), 0, str, wlen, msgA, len, NULL, NULL);
44 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
45 HeapFree(GetProcessHeap(), 0, msgA);
49 static int WINAPIV output_string(int msg, ...)
51 WCHAR out[8192];
52 va_list arguments;
53 int len;
55 va_start(arguments, msg);
56 len = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE, NULL, msg, 0, out, ARRAY_SIZE(out), &arguments);
57 va_end(arguments);
59 if (len == 0 && GetLastError() != NO_ERROR)
60 WINE_FIXME("Could not format string: le=%lu, msg=%d\n", GetLastError(), msg);
61 else
62 output_write(out, len);
64 return 0;
67 static BOOL output_error_string(DWORD error)
69 LPWSTR pBuffer;
70 if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
71 FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
72 NULL, error, 0, (LPWSTR)&pBuffer, 0, NULL))
74 output_write(pBuffer, lstrlenW(pBuffer));
75 LocalFree(pBuffer);
76 return TRUE;
78 return FALSE;
81 static int create_hardlink(int argc, WCHAR *argv[])
83 if (argc != 5)
85 output_string(STRING_HARDLINK_CREATE_USAGE);
86 return 1;
89 if (CreateHardLinkW(argv[3], argv[4], NULL))
90 return 0;
92 output_error_string(GetLastError());
93 return 1;
96 static int hardlink(int argc, WCHAR *argv[])
98 int ret = 0;
100 if (argc > 2)
102 if (!wcsicmp(argv[2], L"create"))
103 return create_hardlink(argc, argv);
104 else
106 FIXME("unsupported parameter %s\n", debugstr_w(argv[2]));
107 ret = 1;
111 output_string(STRING_HARDLINK_USAGE);
112 return ret;
115 int __cdecl wmain(int argc, WCHAR *argv[])
117 int i, ret = 0;
119 TRACE("Command line:");
120 for (i = 0; i < argc; i++)
121 TRACE(" %s", debugstr_w(argv[i]));
122 TRACE("\n");
124 if (argc > 1)
126 if (!wcsicmp(argv[1], L"hardlink"))
127 return hardlink(argc, argv);
128 else
130 FIXME("unsupported command %s\n", debugstr_w(argv[1]));
131 ret = 1;
135 output_string(STRING_USAGE);
136 return ret;