From 2dba000784ff99e4eb651743fda6a2c1934cd334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 13 Sep 2014 20:44:05 +0200 Subject: [PATCH] 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). --- src/system/libroot/posix/unistd/hostname.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/posix/unistd/hostname.cpp b/src/system/libroot/posix/unistd/hostname.cpp index 3a819733ee..10f1201e98 100644 --- a/src/system/libroot/posix/unistd/hostname.cpp +++ b/src/system/libroot/posix/unistd/hostname.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Copyright 2002-2014, Axel Dörfler, axeld@pinc-software.de. * 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) {