home *** CD-ROM | disk | FTP | other *** search
- /*
- * gethostname - get current name of machine
- *
- */
- #include "lib.h"
- #include <sys/file.h>
- #include <sys/param.h>
- #include <errno.h>
-
- #ifndef MAXHOSTNAMELEN
- # define MAXHOSTNAMELEN 64 /* just like BSD */
- #endif
-
- extern int errno;
- static char namebuf[ MAXHOSTNAMELEN ];
-
- int gethostname( name, namelen )
- char *name;
- int namelen;
- {
- int fd;
- char *sp;
-
- if ((fd = open( HOSTNAME, O_RDONLY )) < 0) {
- errno = EIO; /* cannot open */
- return( -1 );
- }
- if ((read( fd, namebuf, MAXHOSTNAMELEN )) < 0) {
- errno = EIO; /* cannot read */
- return( -1 );
- } else {
- sp = namebuf;
- while (( *sp ) && (--namelen))
- if (*sp == '\n') {
- *sp = '\0';
- break;
- } else
- *name++ = *sp++;
- }
- close( fd );
- return( 0 );
- }
-