1 /* $Id: uname.c,v 1.4 2002/10/29 04:45:46 rex Exp $
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: lib/psxdll/sys/utsname/uname.c
7 * PURPOSE: Get name of current system
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
13 #include <ddk/ntddk.h>
14 #include <ntdll/rtl.h>
16 #include <sys/utsname.h>
17 #include <psx/stdlib.h>
18 #include <psx/debug.h>
19 #include <psx/errno.h>
21 int uname(struct utsname
*name
)
24 OBJECT_ATTRIBUTES oaKeyAttribs
;
25 UNICODE_STRING wstrKeyPath
;
26 UNICODE_STRING wstrValueName
;
27 UNICODE_STRING wstrValueData
;
28 ANSI_STRING strValueData
;
29 PKEY_VALUE_PARTIAL_INFORMATION pkvpiKeyValue
;
33 /* system name and version info are fixed strings, at the moment */ /* FIXME? */
34 strncpy(name
->sysname
, "ReactOS" , 255);
35 strncpy(name
->release
, "0.0" , 255);
36 strncpy(name
->version
, "pre-alpha", 255);
38 /* hardware identifier */
39 /* FIXME: this should definitely be determined programmatically */
40 strncpy(name
->machine
, "i386" , 255);
42 /* we use the active computer's name as the node name */
43 /* TODO: POSIX-style registry functions */
45 /* initialize the registry key path */
48 L
"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName"
51 /* initialize object attributes */
52 oaKeyAttribs
.Length
= sizeof(OBJECT_ATTRIBUTES
);
53 oaKeyAttribs
.RootDirectory
= NULL
;
54 oaKeyAttribs
.ObjectName
= &wstrKeyPath
;
55 oaKeyAttribs
.Attributes
= OBJ_CASE_INSENSITIVE
/* | OBJ_OPENLINK | OBJ_OPENIF */ /* FIXME? */;
56 oaKeyAttribs
.SecurityDescriptor
= NULL
;
57 oaKeyAttribs
.SecurityQualityOfService
= NULL
;
59 /* open the key object */
68 if(!NT_SUCCESS(nErrCode
))
71 ERR("NtOpenKey() failed with status 0x%08X", nErrCode
);
72 errno
= __status_to_errno(nErrCode
);
76 /* initialize the registry value name */
77 RtlInitUnicodeString(&wstrValueName
, L
"ComputerName");
79 /* fake query - null buffer and zero length to pre-fetch the appropriate buffer size */
80 nErrCode
= NtQueryValueKey
84 KeyValuePartialInformation
,
91 if(nErrCode
== (NTSTATUS
)STATUS_BUFFER_TOO_SMALL
)
94 /* allocate the appropriate buffer size */
95 if(nKeyValueSize
< sizeof(KEY_VALUE_PARTIAL_INFORMATION
)) /* just to be sure */
96 nKeyValueSize
= sizeof(KEY_VALUE_PARTIAL_INFORMATION
);
98 pkvpiKeyValue
= __malloc(nKeyValueSize
);
105 ERR("NtQueryValueKey() failed with status 0x%08X", nErrCode
);
107 errno
= __status_to_errno(nErrCode
);
111 /* query the value */
112 nErrCode
= NtQueryValueKey
116 KeyValuePartialInformation
,
122 /* close the key handle (not needed anymore) */
126 if(!NT_SUCCESS(nErrCode
))
128 ERR("NtQueryValueKey() failed with status 0x%08X", nErrCode
);
129 __free(pkvpiKeyValue
);
130 errno
= __status_to_errno(nErrCode
);
134 /* make wstrValueData refer to the Data field of the key value information */
135 wstrValueData
.Length
= pkvpiKeyValue
->DataLength
;
136 wstrValueData
.MaximumLength
= wstrValueData
.Length
;
137 wstrValueData
.Buffer
= (PWCHAR
)&(pkvpiKeyValue
->Data
[0]);
139 /* make strValueData refer to the nodename buffer */
140 strValueData
.Length
= 0;
141 strValueData
.MaximumLength
= 254;
142 strValueData
.Buffer
= name
->nodename
;
144 RtlUnicodeStringToAnsiString
151 /* free the key value buffer */
152 __free(pkvpiKeyValue
);
154 /* null-terminate the returned string */
155 name
->nodename
[strValueData
.Length
] = '0';
160 name->sysname = \"%s\"\n\
161 tname->nodename = \"%s\"\n\
162 tname->release = \"%s\"\n\
163 tname->version = \"%s\"\n\
164 tname->machine = \"%s\"",