installed into CVS
This commit is contained in:
29
src/ca/localHostName.cpp
Normal file
29
src/ca/localHostName.cpp
Normal file
@@ -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 <string.h>
|
||||
|
||||
#include "osiSock.h"
|
||||
|
||||
#include "localHostName.h"
|
||||
|
||||
localHostName localHostNameAtLoadTime;
|
||||
|
||||
localHostName::localHostName ()
|
||||
{
|
||||
int status = gethostname ( this->cache, sizeof ( this->cache ) );
|
||||
if ( status ) {
|
||||
strncpy ( this->cache, "<unknown host>", sizeof ( this->cache ) );
|
||||
localHostName::cache [ sizeof ( this->cache ) - 1u ] = '\0';
|
||||
}
|
||||
this->length = strlen ( this->cache );
|
||||
}
|
||||
43
src/ca/localHostName.h
Normal file
43
src/ca/localHostName.h
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user