libroot: sethostname() now uses ftruncate().
* Before, it would just overwrite the previous name, leaving extra bytes from the previous name (they wouldn't become part of the host name, but it just didn't look that nice).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2007, Axel Dörfler, [email protected]. All rights reserved.
|
||||
* Copyright 2002-2014, Axel Dörfler, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
@@ -46,6 +46,7 @@ sethostname(const char *hostName, size_t nameSize)
|
||||
return -1;
|
||||
|
||||
nameSize = min_c(nameSize, MAXHOSTNAMELEN);
|
||||
ftruncate(file, nameSize + 1);
|
||||
|
||||
if (write(file, hostName, nameSize) != (ssize_t)nameSize
|
||||
|| write(file, "\n", 1) != 1) {
|
||||
|
||||
Reference in New Issue
Block a user