home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / library / misc.c < prev    next >
C/C++ Source or Header  |  1996-10-01  |  4KB  |  226 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. //  if (u.u_ixnetbase)
  62. //    return netcall(NET_getpgrp);
  63.   return u.p_pgrp;
  64. }
  65.  
  66. pid_t
  67. setsid(void)
  68. {
  69.   struct session *s;
  70.  
  71.   if (u.u_session && u.u_session->s_count <= 1)
  72.     {
  73.       errno = EPERM;
  74.       return (pid_t)-1;
  75.     }
  76.  
  77.   s = kmalloc(sizeof(struct session));
  78.   if (s == NULL)
  79.     {
  80.       errno = ENOMEM;
  81.       return (pid_t)-1;
  82.     }
  83.   if (u.u_session)
  84.     u.u_session->s_count--;
  85.   u.u_session = s;
  86.   s->s_count = 1;
  87.   s->pgrp = u.p_pgrp = getpid();
  88.   if (u.u_ixnetbase)
  89.     netcall(NET_setsid);
  90.   return u.p_pgrp;
  91. }
  92.  
  93. int
  94. getrusage(int who, struct rusage *rusage)
  95. {
  96.   if (who != RUSAGE_SELF && who != RUSAGE_CHILDREN)
  97.     {
  98.       errno = EINVAL;
  99.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  100.       return -1;
  101.     }
  102.  
  103.   *rusage = (who == RUSAGE_SELF) ? u.u_ru : u.u_cru;
  104.   return 0;
  105. }
  106.  
  107. char hostname[64] = "localhost";
  108.  
  109. int
  110. gethostname(char *name, int namelen)
  111. {
  112.   if (u.u_ixnetbase)
  113.     return netcall(NET_gethostname, name, namelen);
  114.   strncpy (name, hostname, namelen);
  115.   return 0;
  116. }
  117.  
  118. int
  119. sethostname(char *name, int namelen)
  120. {
  121.   int len;
  122.  
  123.   if (u.u_ixnetbase)
  124.     return netcall(NET_sethostname, name, namelen);
  125.  
  126.   len = namelen < sizeof (hostname) - 1 ? namelen : sizeof (hostname) - 1;
  127.   strncpy (hostname, name, len);
  128.   hostname[len] = 0;
  129.   return 0;
  130. }
  131.  
  132. int
  133. __chown_func (struct StandardPacket *sp, struct MsgPort *handler,
  134.           BPTR parent_lock,
  135.           BSTR name,
  136.           int ugid, int *no_error)
  137. {
  138.   sp->sp_Pkt.dp_Type = ACTION_SET_OWNER;
  139.   sp->sp_Pkt.dp_Arg1 = 0;
  140.   sp->sp_Pkt.dp_Arg2 = parent_lock;
  141.   sp->sp_Pkt.dp_Arg3 = name;
  142.   sp->sp_Pkt.dp_Arg4 = ugid;
  143.  
  144.   PutPacket (handler, sp);
  145.   __wait_sync_packet (sp);
  146.  
  147.   *no_error = sp->sp_Pkt.dp_Res1 == -1;
  148.   return 1;
  149. }
  150.  
  151. int
  152. chown(const char *name, uid_t uid, gid_t gid)
  153. {
  154.   if (muBase)
  155.     {
  156.       int user = (uid << 16) | gid;
  157.       int result;
  158.       result = __plock(name,__chown_func, (void *)user);
  159.       if (result == 0)
  160.     {
  161.       errno = __ioerr_to_errno (IoErr ());
  162.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  163.     }
  164.  
  165.       return result == -1 ? 0 : -1;
  166.    }
  167.   return 0;
  168. }
  169.  
  170. int
  171. fchown(int fd, int uid, int mode)
  172. {
  173.   return 0;
  174. }
  175.  
  176. /* not really useful.. but it's there ;-)) */
  177. int
  178. getpagesize(void)
  179. {
  180.   return 2048;
  181. }
  182.  
  183. extern char _ctype_[];
  184. extern int sys_nerr;
  185.  
  186. void
  187. ix_get_vars(char **ctype, int *_sys_nerr)
  188. {
  189.   if (ctype)
  190.     *ctype = _ctype_;
  191.   if (_sys_nerr)
  192.     *_sys_nerr = sys_nerr;
  193. }
  194.  
  195. void sync (void)
  196. {
  197.   /* could probably walk the entire file table and fsync each, but
  198.      this is too much of a nuisance ;-)) */
  199.   errno = ENOSYS;
  200.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  201. }
  202.  
  203. int
  204. fork (void)
  205. {
  206.   errno = ENOSYS;
  207.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  208.   return -1;
  209. }
  210.  
  211. int
  212. mkfifo (const char *path, mode_t mode)
  213. {
  214.   errno = ENOSYS;
  215.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  216.   return -1;
  217. }
  218.  
  219. int
  220. mknod (const char *path, mode_t mode, dev_t dev)
  221. {
  222.   errno = ENOSYS;
  223.   KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  224.   return -1;
  225. }
  226.