home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / ixnet / misc.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  3KB  |  154 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.  
  35. int getpgrp(void)
  36. {
  37.     int err;
  38.     struct ixnet *p = (struct ixnet *)u.u_ixnet;
  39.  
  40.     switch (p->u_networkprotocol) {
  41.  
  42.     case IX_NETWORK_AMITCP:
  43.         err = UG_getpgrp();
  44.  
  45.         if (err == -1) {
  46.         errno = ug_GetErr();
  47.         }
  48.     break;
  49.  
  50.     default:
  51.         return (int) FindTask(0);
  52.     }
  53.     return err;
  54. }
  55.  
  56.  
  57. #include <pwd.h>
  58.  
  59. extern char *getenv(const char *);
  60.  
  61. int gethostname (char *name, int namelen)
  62. {
  63.     char *host;
  64.     struct ixnet *p = (struct ixnet *)u.u_ixnet;
  65.  
  66.     switch (p->u_networkprotocol) {
  67.     case IX_NETWORK_AMITCP:
  68.         return TCP_GetHostName(name,namelen);
  69.  
  70.     default: /* case IX_NETWORK_AS225: */
  71.         host = getenv("HOSTNAME");
  72.         if (host || (host = getenv("hostname")))
  73.         {
  74.                 char domain[257];
  75.  
  76.             if (!strchr(host, '.'))
  77.             {
  78.                 int len;
  79.               
  80.                 strcpy(domain, host);
  81.                 len = strlen(domain);
  82.                 domain[len] = '.';
  83.                 if (!getdomainname(domain + len + 1, sizeof(domain) - 1 - len))
  84.                     host = domain;
  85.             }
  86.         strncpy (name, host, namelen);
  87.         }
  88.         else
  89.         strncpy (name, "localhost", namelen);
  90.         return 0;
  91.     }
  92. }
  93.  
  94. static char hostname[MAXHOSTNAMELEN] = "localhost";
  95.  
  96. int sethostname (const char *name, int namelen)
  97. {
  98.   struct ixnet *p = (struct ixnet *)u.u_ixnet;
  99.  
  100.   if (p->u_networkprotocol != IX_NETWORK_AMITCP) {
  101.     int len = namelen < sizeof (hostname) - 1 ? namelen : sizeof (hostname) - 1;
  102.  
  103.     strncpy (hostname, name, len);
  104.     hostname[len] = 0;
  105.   }
  106.   return 0;
  107. }
  108.  
  109. char *crypt (const char *key, const char *setting)
  110. {
  111.   struct ixnet *p = (struct ixnet *)u.u_ixnet;
  112.  
  113.   if (p->u_networkprotocol == IX_NETWORK_AMITCP)
  114.     return UG_crypt(key,setting);
  115.   return NULL;
  116. }
  117.  
  118. mode_t
  119. umask (mode_t mode)
  120. {
  121.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  122.  
  123.     if (p->u_networkprotocol == IX_NETWORK_AMITCP) {
  124.         return UG_umask(mode);
  125.     }
  126.     else {
  127.         int md = (int)mode;
  128.         mode_t res;
  129.         if (md < 0 || (int)md > 0777) {
  130.         errno = EINVAL;
  131.         KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  132.         return -1;
  133.     }
  134.  
  135.     /* one day I'll use this field ;-)) */
  136.     mode &= ((1<<9)-1);
  137.     res = u.u_cmask;
  138.     u.u_cmask = mode;
  139.     return res;
  140.     }
  141. }
  142.  
  143. pid_t
  144. setsid(void)
  145. {
  146.     register struct ixnet *p = (struct ixnet *)u.u_ixnet;
  147.  
  148.     if (p->u_networkprotocol == IX_NETWORK_AMITCP)
  149.       return UG_setsid();
  150.     errno = EPERM;
  151.     return -1;
  152. }
  153.  
  154.