home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / gcc / ixemulsrc.lha / ixemul / ixnet / misc.c < prev    next >
C/C++ Source or Header  |  1996-12-11  |  3KB  |  119 lines

  1. /*
  2.  *  This file is part of ixnet.library for the Amiga.
  3.  *  Copyright (C) 1996 Jeff Shepherd
  4.  *
  5.  *  This library is free software; you can redistribute it and/or
  6.  *  modify it under the terms of the GNU Library General Public
  7.  *  License as published by the Free Software Foundation; either
  8.  *  version 2 of the License, or (at your option) any later version.
  9.  *
  10.  *  This library is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  *  Library General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU Library General Public
  16.  *  License along with this library; if not, write to the Free
  17.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  $Id: $
  20.  *
  21.  *  $Log:$
  22.  *
  23.  */
  24.  
  25.  
  26. /* stubs for group-file access functions */
  27.  
  28. #define _KERNEL
  29. #include "ixnet.h"
  30. #include "kprintf.h"
  31. #include <string.h>
  32. #include <unistd.h>
  33. #include <stdlib.h>
  34. #include <pwd.h>
  35.  
  36. extern char *getenv(const char *);
  37.  
  38. int gethostname (char *name, int namelen)
  39. {
  40.     char *host;
  41.     struct ixnet *p = (struct ixnet *)u.u_ixnet;
  42.  
  43.     switch (p->u_networkprotocol) {
  44.     case IX_NETWORK_AMITCP:
  45.         return TCP_GetHostName(name,namelen);
  46.  
  47.     default: /* case IX_NETWORK_AS225: */
  48.         host = getenv("HOSTNAME");
  49.         if (host || (host = getenv("hostname")))
  50.         {
  51.                 char domain[257];
  52.  
  53.             if (!strchr(host, '.'))
  54.             {
  55.                 int len;
  56.               
  57.                 strcpy(domain, host);
  58.                 len = strlen(domain);
  59.                 domain[len] = '.';
  60.                 if (!getdomainname(domain + len + 1, sizeof(domain) - 1 - len))
  61.                     host = domain;
  62.             }
  63.         strncpy (name, host, namelen);
  64.         }
  65.         else
  66.         strncpy (name, "localhost", namelen);
  67.         return 0;
  68.     }
  69. }
  70.  
  71. static char hostname[MAXHOSTNAMELEN] = "localhost";
  72.  
  73. int sethostname (const char *name, int namelen)
  74. {
  75.   struct ixnet *p = (struct ixnet *)u.u_ixnet;
  76.  
  77.   if (p->u_networkprotocol != IX_NETWORK_AMITCP) {
  78.     int len = namelen < sizeof (hostname) - 1 ? namelen : sizeof (hostname) - 1;
  79.  
  80.     strncpy (hostname, name, len);
  81.     hostname[len] = 0;
  82.   }
  83.   return 0;
  84. }
  85.  
  86. char *crypt (const char *key, const char *setting)
  87. {
  88.   struct ixnet *p = (struct ixnet *)u.u_ixnet;
  89.  
  90.   if (p->u_networkprotocol == IX_NETWORK_AMITCP)
  91.     return UG_crypt(key,setting);
  92.   return NULL;
  93. }
  94.  
  95. mode_t
  96. umask (mode_t mode)
  97. {
  98.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  99.  
  100.     if (p->u_networkprotocol == IX_NETWORK_AMITCP) {
  101.         return UG_umask(mode);
  102.     }
  103.     else {
  104.         int md = (int)mode;
  105.         mode_t res;
  106.         if (md < 0 || (int)md > 0777) {
  107.         errno = EINVAL;
  108.         KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  109.         return -1;
  110.     }
  111.  
  112.     /* one day I'll use this field ;-)) */
  113.     mode &= ((1<<9)-1);
  114.     res = u.u_cmask;
  115.     u.u_cmask = mode;
  116.     return res;
  117.     }
  118. }
  119.