1 | /*
|
---|
2 | * Copyright (c) 1999, 2000
|
---|
3 | * Intel Corporation.
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
7 | * are permitted provided that the following conditions are met:
|
---|
8 | *
|
---|
9 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
10 | * this list of conditions and the following disclaimer.
|
---|
11 | *
|
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
13 | * this list of conditions and the following disclaimer in the documentation
|
---|
14 | * and/or other materials provided with the distribution.
|
---|
15 | *
|
---|
16 | * 3. All advertising materials mentioning features or use of this software must
|
---|
17 | * display the following acknowledgement:
|
---|
18 | *
|
---|
19 | * This product includes software developed by Intel Corporation and its
|
---|
20 | * contributors.
|
---|
21 | *
|
---|
22 | * 4. Neither the name of Intel Corporation or its contributors may be used to
|
---|
23 | * endorse or promote products derived from this software without specific
|
---|
24 | * prior written permission.
|
---|
25 | *
|
---|
26 | * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS'' AND
|
---|
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
---|
29 | * DISCLAIMED. IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR
|
---|
30 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
---|
31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
---|
32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
---|
33 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
36 | *
|
---|
37 | */
|
---|
38 |
|
---|
39 | #include <errno.h>
|
---|
40 | #include <stdlib.h>
|
---|
41 | #include <string.h>
|
---|
42 | #include <Uefi.h>
|
---|
43 | #include <unistd.h>
|
---|
44 | #include <wchar.h>
|
---|
45 |
|
---|
46 | /*++
|
---|
47 |
|
---|
48 | Module Name:
|
---|
49 |
|
---|
50 | sethostname.c
|
---|
51 |
|
---|
52 | Abstract:
|
---|
53 |
|
---|
54 | Map FreeBSD sethostname call to EFI Interface
|
---|
55 |
|
---|
56 |
|
---|
57 | Revision History
|
---|
58 |
|
---|
59 | --*/
|
---|
60 |
|
---|
61 | int
|
---|
62 | sethostname(
|
---|
63 | const char * name,
|
---|
64 | size_t namelen
|
---|
65 | )
|
---|
66 | /*++
|
---|
67 |
|
---|
68 | Routine Description:
|
---|
69 |
|
---|
70 | Set the hostname for this system.
|
---|
71 |
|
---|
72 | Arguments:
|
---|
73 |
|
---|
74 | name - Pointer to hostname.
|
---|
75 | namelen - Length of name
|
---|
76 |
|
---|
77 | Returns:
|
---|
78 |
|
---|
79 | 0 on success, -1 if not set
|
---|
80 |
|
---|
81 | --*/
|
---|
82 | {
|
---|
83 | int SetStatus;
|
---|
84 | char * pName;
|
---|
85 |
|
---|
86 | //
|
---|
87 | // Allocate a new buffer for name since the input value
|
---|
88 | // does not need to be zero terminated
|
---|
89 | //
|
---|
90 | pName = malloc ( namelen + 1 );
|
---|
91 | if ( NULL == pName ) {
|
---|
92 | errno = ENOMEM;
|
---|
93 | SetStatus = -1;
|
---|
94 | }
|
---|
95 | else {
|
---|
96 | //
|
---|
97 | // Create a zero terminated string for name
|
---|
98 | //
|
---|
99 | memcpy ( pName, name, namelen );
|
---|
100 | pName[ namelen ] = 0;
|
---|
101 |
|
---|
102 | //
|
---|
103 | // Set the environment variable
|
---|
104 | //
|
---|
105 | SetStatus = setenv ("HOSTNAME", pName, TRUE);
|
---|
106 |
|
---|
107 | //
|
---|
108 | // Free the temporary buffer
|
---|
109 | //
|
---|
110 | free ( pName );
|
---|
111 | }
|
---|
112 |
|
---|
113 | //
|
---|
114 | // Return the results
|
---|
115 | //
|
---|
116 | return SetStatus;
|
---|
117 | }
|
---|