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:
Axel Dörfler
2014-09-14 14:11:00 +02:00
parent 6762f5f678
commit 2dba000784
+2 -1
View File
@@ -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) {