aboutsummaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl
diff options
context:
space:
mode:
authorJoerg Wunsch <joerg@FreeBSD.org>1996-03-18 21:42:31 +0000
committerJoerg Wunsch <joerg@FreeBSD.org>1996-03-18 21:42:31 +0000
commit8aa07454ea5dcaa1fb68015e922ab967b812e413 (patch)
tree5cfbeda7197942ec0163e950106b34467dddaf10 /gnu/usr.bin/perl
parent4c2aa33eb864dd615454a32679b7cf0d337cb095 (diff)
downloadsrc-8aa07454ea5dcaa1fb68015e922ab967b812e413.tar.gz
src-8aa07454ea5dcaa1fb68015e922ab967b812e413.zip
Several changes to the gethostname module:
. rename the function to main'gethostname, so it can be called unqualified, . strip the trailing \0 character, closes PR # bin/1084, . a better way to express an insane long string. Submitted by: Giles Lean <giles@topaz.nemeton.com.au> (except the 1st)
Notes
Notes: svn path=/head/; revision=14677
Diffstat (limited to 'gnu/usr.bin/perl')
-rw-r--r--gnu/usr.bin/perl/lib/gethostname.pl11
1 files changed, 5 insertions, 6 deletions
diff --git a/gnu/usr.bin/perl/lib/gethostname.pl b/gnu/usr.bin/perl/lib/gethostname.pl
index 626d49d3fa48..2342bad7d7b9 100644
--- a/gnu/usr.bin/perl/lib/gethostname.pl
+++ b/gnu/usr.bin/perl/lib/gethostname.pl
@@ -4,7 +4,7 @@
# Written 13-Feb-96 by Jörg Wunsch, interface business GmbH Dresden.
# Placed in the public domain.
#
-# $Id$
+# $Id: gethostname.pl,v 1.1 1996/02/13 13:17:49 joerg Exp $
#
package gethostname;
@@ -16,22 +16,21 @@ require "sys/sysctl.ph";
# usage:
#
# require "gethostname.pl";
-# printf "This machine is named \"%s\".\n", &gethostname'gethostname;
+# printf "This machine is named \"%s\".\n", &gethostname;
#
-sub gethostname {
+sub main'gethostname {
# get hostname via sysctl(2)
local($name, $oldval, $oldlen, $len);
$name = pack("LL", &CTL_KERN, &KERN_HOSTNAME);
# 64-byte string to get the hostname
- $oldval =
- " ";
+ $oldval = " " x 64;
$oldlen = pack("L", length($oldval));
syscall(&SYS___sysctl, $name, 2, $oldval, $oldlen, 0, 0) != -1 ||
die "Cannot get hostname via sysctl(2), errno = $!\n";
($len) = unpack("L", $oldlen);
- return substr($oldval, 0, $len);
+ return substr($oldval, 0, $len - 1);
}
1;