r11087: add cygwin support
[uffi.git] / examples / gethostname.lisp
index 909811487b39e8ad6b1421a24c71e820c0a52fb6..fb6f6e8a278f088cc9caca7aed38247e2138883c 100644 (file)
@@ -7,13 +7,10 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: gethostname.lisp,v 1.1 2002/09/30 10:02:36 kevin Exp $
+;;;; $Id$
 ;;;;
-;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
+;;;; This file, part of UFFI, is Copyright (c) 2002-2005 by Kevin M. Rosenberg
 ;;;;
-;;;; UFFI users are granted the rights to distribute and use this software
-;;;; as governed by the terms of the Lisp Lesser GNU Public License
-;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
 (in-package :cl-user)
 (defun gethostname ()
   "Returns the hostname"
   (let* ((name (uffi:allocate-foreign-string 256))
-        (result (c-gethostname name 256)))
-    (unwind-protect
-       (if (zerop result)
-           (uffi:convert-from-foreign-string name)
-         (error "gethostname() failed."))
-      (uffi:free-foreign-object name))))
+        (result-code (c-gethostname name 256))
+        (hostname (when (zerop result-code)
+                    (uffi:convert-from-foreign-string name))))
+    (uffi:free-foreign-object name)
+    (unless (zerop result-code)
+      (error "gethostname() failed."))
+    hostname))
 
 (defun gethostname2 ()
   "Returns the hostname"