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

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *  Portions Copyright (C) 1996 Jeff Shepherd
  6.  *
  7.  *  This library is free software; you can redistribute it and/or
  8.  *  modify it under the terms of the GNU Library General Public
  9.  *  License as published by the Free Software Foundation; either
  10.  *  version 2 of the License, or (at your option) any later version.
  11.  *
  12.  *  This library is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  *  Library General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU Library General Public
  18.  *  License along with this library; if not, write to the Free
  19.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  */
  21.  
  22. /* Miscellaneous functions */
  23.  
  24. #define _KERNEL
  25. #include "ixemul.h"
  26. #include "kprintf.h"
  27. #include <stdlib.h>
  28.  
  29. int
  30. getpid(void)
  31. {
  32.   return (int)FindTask (0);
  33. }
  34.  
  35. int
  36. getppid(void)
  37. {
  38.   /* all processes have been started by init :-)) */
  39.   return 1;
  40. }
  41.  
  42. int
  43. setpgid(int pid, int pgrp)
  44. {
  45.   if (pid)
  46.       getuser(pid)->p_pgrp = pgrp;
  47.   else
  48.       u.p_pgrp = pgrp;
  49.   return 0;
  50. }
  51.  
  52. int
  53. setpgrp(int pid, int pgrp)
  54. {
  55.   return setpgid(pid, pgrp);
  56. }
  57.  
  58. pid_t
  59. getpgrp(void)
  60. {
  61.   return u.p_pgrp;
  62. }
  63.  
  64. pid_t
  65. setsid(void)
  66. {
  67.   struct session *s;
  68.  
  69.   if (u.u_session && u.u_session->s_count <= 1)
  70.     {
  71.       errno = EPERM;
  72.       return (pid_t)-1;
  73.     }
  74.  
  75.   s = kmalloc(sizeof(struct session));
  76.   if (s == NULL)
  77.     {
  78.       errno = ENOMEM;
  79.       return (pid_t)-1;
  80.     }
  81.   if (u.u_session)
  82.     u.u_session->s_count--;
  83.   u.u_session = s;
  84.   s->s_count = 1;
  85.   s->pgrp = u.p_pgrp = getpid();
  86.  
  87.   return u.p_pgrp;
  88. }
  89.  
  90. int
  91. getrusage(int who, struct rusage *rusage)
  92. {
  93.   if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
  94.     {
  95.       errno = EINVAL;
  96.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  97.       return -1;
  98.     }
  99.  
  100.   *rusage = (who == RUSAGE_SELF) ? u.u_ru : u.u_cru;
  101.   return 0;
  102. }
  103.  
  104. char hostname[64] = "localhost";
  105.  
  106. int
  107. gethostname(char *name, int namelen)
  108. {
  109.   if (u.u_ixnetbase)
  110.     return netcall(NET_gethostname, name, namelen);
  111.   strncpy (name, hostname, namelen);
  112.   return 0;
  113. }
  114.  
  115. int
  116. sethostname(char *name, int namelen)
  117. {
  118.   int len;
  119.  
  120.   if (u.u_ixnetbase)
  121.     return netcall(NET_sethostname, name, namelen);
  122.  
  123.   len = namelen < sizeof (hostname) - 1 ? namelen : sizeof (hostname) - 1;
  124.   strncpy (hostname, name, len);
  125.   hostname[len] = 0;
  126.   return 0;
  127. }
  128.  
  129. /* not really useful.. but it's there ;-)) */
  130. int
  131. getpagesize(void)
  132. {
  133.   return 2048;
  134. }
  135.  
  136. extern char _ctype_[];
  137. extern int sys_nerr;
  138.  
  139. void
  140. ix_get_vars(char **ctype, int *_sys_nerr)
  141. {
  142.   if (ctype)
  143.     *ctype = _ctype_;
  144.   if (_sys_nerr)
  145.     *_sys_nerr = sys_nerr;
  146. }
  147.  
  148. void sync (void)
  149. {
  150.   /* could probably walk the entire file table and fsync each, but
  151.      this is too much of a nuisance ;-)) */
  152.   errno = ENOSYS;
  153.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  154. }
  155.  
  156. int
  157. fork (void)
  158. {
  159.   errno = ENOSYS;
  160.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  161.   return -1;
  162. }
  163.  
  164. int
  165. mkfifo (const char *path, mode_t mode)
  166. {
  167.   errno = ENOSYS;
  168.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  169.   return -1;
  170. }
  171.  
  172. int
  173. mknod (const char *path, mode_t mode, dev_t dev)
  174. {
  175.   errno = ENOSYS;
  176.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  177.   return -1;
  178. }
  179.