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

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  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.  *  posixconf.c,v 1.1.1.1 1994/04/04 04:30:59 amiga Exp
  20.  *
  21.  *  posixconf.c,v
  22.  * Revision 1.1.1.1  1994/04/04  04:30:59  amiga
  23.  * Initial CVS check in.
  24.  *
  25.  *  Revision 1.2  1992/07/04  22:08:39  mwild
  26.  *  machlimits is now limits...
  27.  *
  28.  *  Revision 1.1  1992/05/22  01:50:03  mwild
  29.  *  Initial revision
  30.  *
  31.  */
  32.  
  33. #define _KERNEL
  34. #include "ixemul.h"
  35. #include "kprintf.h"
  36. #include <unistd.h>
  37. #include <time.h>
  38. #include <sys/syslimits.h>
  39. #include <machine/limits.h>
  40.  
  41. long
  42. sysconf (int name)
  43. {
  44.   switch (name)
  45.     {
  46.     case _SC_ARG_MAX:
  47.       return ARG_MAX;
  48.       
  49.     case _SC_CHILD_MAX:
  50.       return CHILD_MAX;
  51.       
  52.     case _SC_CLK_TCK:
  53.       return CLK_TCK;
  54.       
  55.     case _SC_NGROUPS_MAX:
  56.       return NGROUPS_MAX;
  57.       
  58.     case _SC_OPEN_MAX:
  59.       return FD_SETSIZE; /* Was OPEN_MAX. See comments before getdtablesize()
  60.                 why this was changed. */
  61.  
  62.     case _SC_JOB_CONTROL:
  63.       return _POSIX_JOB_CONTROL;
  64.     
  65.     case _SC_SAVED_IDS:
  66.       return _POSIX_SAVED_IDS;
  67.  
  68.     case _SC_VERSION:
  69.       return _POSIX_VERSION;
  70.       
  71.     default:
  72.       errno = EINVAL;
  73.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  74.       return -1;
  75.     }
  76. }
  77.  
  78.  
  79. long
  80. fpathconf (int fd, int name)
  81. {
  82.   struct file *f = u.u_ofile[fd];
  83.  
  84.   if ((unsigned)fd >= NOFILE || !f)
  85.     {
  86.       errno = EBADF;
  87.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  88.       return -1;
  89.     }
  90.  
  91.   switch (name)
  92.     {
  93.     case _PC_LINK_MAX:
  94.       return LINK_MAX;
  95.       
  96.     case _PC_MAX_CANON:
  97.       return MAX_CANON;
  98.       
  99.     case _PC_MAX_INPUT:
  100.       return MAX_INPUT;
  101.       
  102.     case _PC_NAME_MAX:
  103.       return NAME_MAX;    /* or 32 on AmigaOS? What about NFS ? */
  104.       
  105.     case _PC_PATH_MAX:
  106.       return PATH_MAX;
  107.       
  108.     case _PC_PIPE_BUF:
  109.       return PIPE_BUF;
  110.       
  111.     case _PC_CHOWN_RESTRICTED:
  112.       return _POSIX_CHOWN_RESTRICTED;
  113.       
  114.     case _PC_NO_TRUNC:
  115.       return _POSIX_NO_TRUNC;
  116.     
  117.     case _PC_VDISABLE:
  118.       return _POSIX_VDISABLE;
  119.  
  120.     default:
  121.       errno = EINVAL;
  122.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  123.       return -1;
  124.     }
  125. }
  126.  
  127.  
  128. long
  129. pathconf (const char *file, int name)
  130. {
  131.   int fd = syscall(SYS_open, file, 0);
  132.   
  133.   if (fd >= 0)
  134.     {
  135.       int err, res;
  136.       res = fpathconf (fd, name);
  137.       err = errno;
  138.       close (fd);
  139.       errno = err;
  140.       KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
  141.       return res;
  142.     }
  143.  
  144.   return -1;
  145. }
  146.