1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: gethostname.cl
6 ;;;; Purpose: UFFI Example file to get hostname of system
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: gethostname.cl,v 1.10 2002/04/02 21:29:45 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
22 ;;; This example is inspired by the example on the CL-Cookbook web site
24 (uffi:def-function ("gethostname" c-gethostname)
25 ((name (* :unsigned-char))
30 "Returns the hostname"
31 (let* ((name (uffi:allocate-foreign-string 256))
32 (result (c-gethostname name 256)))
35 (uffi:convert-from-foreign-string name)
36 (error "gethostname() failed."))
37 (uffi:free-foreign-object name))))
39 (defun gethostname2 ()
40 "Returns the hostname"
41 (uffi:with-foreign-object (name '(:array :unsigned-char 256))
42 (if (zerop (c-gethostname (uffi:char-array-to-pointer name) 256))
43 (uffi:convert-from-foreign-string name)
44 (error "gethostname() failed."))))
47 (format t "~&Hostname (technique 1): ~A" (gethostname))
48 (format t "~&Hostname (technique 2): ~A" (gethostname2))