source: trunk/src/kernel32/network.cpp@ 1081

Last change on this file since 1081 was 1081, checked in by sandervl, 26 years ago

GetComputerNameA bugfix

File size: 2.3 KB
Line 
1/*
2 * Win32 Network apis
3 *
4 * Copyright 1998 Peter Fitzsimmons
5 * 1999 Przemyslaw Dobrowolski
6 *
7 */
8#define INCL_DOSEXCEPTIONS
9#define INCL_DOSMEMMGR
10#include <os2wrap.h> //Odin32 OS/2 api wrappers
11#include <stdlib.h>
12#include <stdio.h>
13#include <string.h>
14#include "misc.h"
15#include "unicode.h"
16
17//******************************************************************************
18// GetComputerName
19//
20// Retrieve the NetBIOS name of the computer
21//******************************************************************************
22BOOL WIN32API GetComputerNameA(LPSTR lpBuffer, LPDWORD nSize)
23{
24 char szDefault[] = "NONAME";
25 char * szHostname = getenv("HOSTNAME"); // This is wrong;
26 // We should use NETBIOS computername
27
28 if (!szHostname) // Hostname not set; assume a default
29 szHostname = szDefault;
30
31 *nSize = min(strlen(szHostname) + 1, *nSize); // Truncate name as reqd.
32 // NB W95/98 would generate a
33 // BUFFER_OVERFLOW error here
34
35 if (lpBuffer)
36 {
37 strncpy(lpBuffer, szHostname, *nSize - 1); // Copy back name.
38 lpBuffer[*nSize - 1] = 0; // Ensure terminated.
39 }
40
41 dprintf(("KERNEL32: GetComputerNameA (Name: %.*s, nSize: %d)", *nSize, lpBuffer, *nSize));
42
43 return TRUE;
44}
45//******************************************************************************
46//******************************************************************************
47BOOL WIN32API GetComputerNameW(LPWSTR name, LPDWORD size)
48{
49 LPSTR nameA = NULL;
50 BOOL ret;
51
52 if (name) nameA=(LPSTR)malloc(2**size);
53
54 ret = GetComputerNameA(nameA,size);
55
56 if (ret) AsciiToUnicode(nameA,name);
57
58 free(nameA);
59
60 return ret;
61}
62//******************************************************************************
63//******************************************************************************
64BOOL WIN32API GetComputerName32W(LPWSTR name, LPDWORD size)
65{
66 LPSTR nameA = NULL;
67 BOOL ret;
68
69 if (name) nameA=(LPSTR)malloc(2**size);
70
71 ret = GetComputerNameA(nameA,size);
72
73 if (ret) AsciiToUnicode(nameA, name);
74
75 free(nameA);
76
77 return ret;
78}
79//******************************************************************************
80//******************************************************************************
Note: See TracBrowser for help on using the repository browser.