From bdfd67f9cc728ee91e59308a0c977367727fd636 Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Tue, 27 Jun 2000 22:57:02 +0000 Subject: [PATCH] installed into CVS --- src/ca/localHostName.cpp | 29 +++++++++++++++++++++++++++ src/ca/localHostName.h | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/ca/localHostName.cpp create mode 100644 src/ca/localHostName.h diff --git a/src/ca/localHostName.cpp b/src/ca/localHostName.cpp new file mode 100644 index 000000000..5c4e95d56 --- /dev/null +++ b/src/ca/localHostName.cpp @@ -0,0 +1,29 @@ + +/* $Id$ + * + * L O S A L A M O S + * Los Alamos National Laboratory + * Los Alamos, New Mexico 87545 + * + * Copyright, 1986, The Regents of the University of California. + * + * Author: Jeff Hill + */ + +#include + +#include "osiSock.h" + +#include "localHostName.h" + +localHostName localHostNameAtLoadTime; + +localHostName::localHostName () +{ + int status = gethostname ( this->cache, sizeof ( this->cache ) ); + if ( status ) { + strncpy ( this->cache, "", sizeof ( this->cache ) ); + localHostName::cache [ sizeof ( this->cache ) - 1u ] = '\0'; + } + this->length = strlen ( this->cache ); +} diff --git a/src/ca/localHostName.h b/src/ca/localHostName.h new file mode 100644 index 000000000..53e76d91a --- /dev/null +++ b/src/ca/localHostName.h @@ -0,0 +1,43 @@ + +/* $Id$ + * + * L O S A L A M O S + * Los Alamos National Laboratory + * Los Alamos, New Mexico 87545 + * + * Copyright, 1986, The Regents of the University of California. + * + * Author: Jeff Hill + */ + +class localHostName { +public: + localHostName (); + const char * pointer () const; + void copy ( char *pBuf, unsigned bufLength ) const; + unsigned stringLength () const; +private: + unsigned length; + char cache [128]; +}; + +extern localHostName localHostNameAtLoadTime; + +inline unsigned localHostName::stringLength () const +{ + return this->length; +} + +inline void localHostName::copy ( char *pBuf, unsigned bufLength ) const +{ + if ( bufLength ) { + strncpy ( pBuf, this->cache, bufLength ); + pBuf [ bufLength - 1 ] = '\0'; + } +} + +inline const char * localHostName::pointer () const +{ + return this->cache; +} +