More traces to help us make sense of the output.
[wine] / win32 / init.c
1 /*
2  * Win32 kernel functions
3  *
4  * Copyright 1995 Martin von Loewis and Cameron Heide
5  * 1999 Peter Ganten
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23
24 #include <string.h>
25 #ifdef HAVE_UNISTD_H
26 # include <unistd.h>
27 #endif
28 #include <stdlib.h>
29 #include <errno.h>
30
31 #include "winnls.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "wine/exception.h"
35 #include "msvcrt/excpt.h"
36 #include "wine/debug.h"
37
38 WINE_DEFAULT_DEBUG_CHANNEL(win32);
39
40 /* filter for page-fault exceptions */
41 static WINE_EXCEPTION_FILTER(page_fault)
42 {
43     if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
44         return EXCEPTION_EXECUTE_HANDLER;
45     return EXCEPTION_CONTINUE_SEARCH;
46 }
47
48 /***********************************************************************
49  *              GetComputerNameA         (KERNEL32.@)
50  */
51 BOOL WINAPI GetComputerNameA(LPSTR name,LPDWORD size)
52 {
53     /* At least Win95OSR2 survives if size is not a pointer (NT crashes though) */
54     BOOL ret;
55     __TRY
56     {
57         char host_name[256];
58         TRACE("*size = %ld\n", *size);
59         ret = (gethostname(host_name, sizeof(host_name)) != -1);
60         if (ret)
61         {
62             lstrcpynA(name, host_name, *size);
63             *size = strlen(name);
64         }
65         else
66             WARN("gethostname: %s\n", strerror(errno));
67     }
68     __EXCEPT(page_fault)
69     {
70       SetLastError( ERROR_INVALID_PARAMETER );
71       return FALSE;
72     }
73     __ENDTRY
74
75     TRACE("returning (%ld) %s\n", *size, debugstr_a(name));
76     return ret;
77 }
78
79 /***********************************************************************
80  *              GetComputerNameW         (KERNEL32.@)
81  */
82 BOOL WINAPI GetComputerNameW(LPWSTR name,LPDWORD size)
83 {
84     LPSTR nameA = (LPSTR)HeapAlloc( GetProcessHeap(), 0, *size);
85     BOOL ret = GetComputerNameA(nameA,size);
86     /* FIXME: should set *size in Unicode chars */
87     if (ret) MultiByteToWideChar( CP_ACP, 0, nameA, -1, name, *size+1 );
88     HeapFree( GetProcessHeap(), 0, nameA );
89     return ret;
90 }
91
92 /***********************************************************************
93  *              GetComputerNameExA         (KERNEL32.@)
94  */
95 BOOL WINAPI GetComputerNameExA(COMPUTER_NAME_FORMAT type, LPSTR name, LPDWORD size)
96 {
97     FIXME("(%d, %p, %p) semi-stub!\n", type, name, size);
98     return GetComputerNameA(name, size);
99 }
100
101 /***********************************************************************
102  *              GetComputerNameExW         (KERNEL32.@)
103  */
104 BOOL WINAPI GetComputerNameExW(COMPUTER_NAME_FORMAT type, LPWSTR name, LPDWORD size)
105 {
106     FIXME("(%d, %p, %p) semi-stub!\n", type, name, size);
107     return GetComputerNameW(name, size);
108 }