[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
MiNTlib: new functions
Here are interfaces for the new functions that MiNT 1.11 provides
(getloadavg, set/getitimer, initgroups) and some changes to existing
functions to use the new features, as well as some bug fixes.
In <limits.h> i have changed _POSIX_NGROUPS_MAX to 8 since this is the
value MiNT provides.
------------------------- include file changes -------------------------
--- orig/limits.h Thu Oct 28 02:00:20 1993
+++ limits.h Wed Aug 24 19:01:20 1994
@@ -75,7 +75,7 @@
#define _POSIX_MAX_CANON 64 /* <- NON-CONFORMING */
#define _POSIX_MAX_INPUT 64 /* <- NON-CONFORMING */
#define _POSIX_NAME_MAX 31 /* <- arbitrary */
-#define _POSIX_NGROUPS_MAX 512 /* <- arbitrary */
+#define _POSIX_NGROUPS_MAX 8 /* <- arbitrary */
#define _POSIX_OPEN_MAX 32
#define _POSIX_PATH_MAX 128 /* <- NON-CONFORMING */
#define _POSIX_PIPE_BUF 512
--- orig/mintbind.h Wed Mar 2 18:56:00 1994
+++ mintbind.h Sat Aug 27 17:46:52 1994
@@ -329,6 +329,68 @@
retvalue; \
})
+#if __GNUC__ > 1
+#define trap_1_wwllll(n, a, b, c, d, e) \
+__extension__ \
+({ \
+ register long retvalue __asm__("d0"); \
+ short _a = (short)(a); \
+ long _b = (long) (b); \
+ long _c = (long) (c); \
+ long _d = (long) (d); \
+ long _e = (long) (e); \
+ \
+ __asm__ volatile \
+ ("\
+ movl %6,sp@-; \
+ movl %5,sp@-; \
+ movl %4,sp@-; \
+ movl %3,sp@-; \
+ movw %2,sp@-; \
+ movw %1,sp@-; \
+ trap #1; \
+ lea sp@(20),sp " \
+ : "=r"(retvalue) /* outputs */ \
+ : "g"(n), "r"(_a), "r"(_b), "r"(_c), "r"(_d), "r"(_e) /* inputs */ \
+ : "d0", "d1", "d2", "a0", "a1", "a2" /* clobbered regs */ \
+ AND_MEMORY \
+ ); \
+ retvalue; \
+})
+#else
+#define trap_1_wwllll(n, a, b, c, d, e) \
+({ \
+ register long retvalue __asm__("d0"); \
+ short _a = (short)(a); \
+ long _b = (long) (b); \
+ long _c = (long) (c); \
+ long _d = (long) (d); \
+ long _e = (long) (e); \
+ \
+ __asm__ volatile \
+ ("\
+ movl %4,sp@-; \
+ movl %3,sp@-; \
+ movl %2,sp@-; \
+ movl %1,sp@-; \
+ movw %0,sp@- " \
+ : /* outputs */ \
+ : "r"(_a), "r"(_b), "r"(_c), "r"(_d), "r"(_e) /* inputs */ \
+ ); \
+ \
+ __asm__ volatile \
+ ("\
+ movw %1,sp@-; \
+ trap #1; \
+ lea sp@(20),sp " \
+ : "=r"(retvalue) /* outputs */ \
+ : "g"(n) /* inputs */ \
+ : "d0", "d1", "d2", "a0", "a1", "a2" /* clobbered regs */ \
+ ); \
+ retvalue; \
+})
+#endif
+
#else
#ifdef __GNUC__
@@ -355,6 +417,8 @@
# define trap_1_wwww(n,a,b,c) gemdos(n, a, b, c)
# define trap_1_wwl(n, a, b) gemdos(n, a, (long)(b))
# define trap_1_wwwl(n,a,b,c) gemdos(n, a, b, (long)(c))
+# define trap_1_wwllll(n, a, b, c, d, e) \
+ gemdos(n, a, (long)(b), (long)(c), (long)(d), (long)(e))
#endif /* __LONG_TRAPS__ */
#endif /* __GNUC_INLINE__ */
@@ -488,6 +552,24 @@
trap_1_www(0x13e, (short)(vec), (short)(sig))
#define Suptime(uptime, avenrun) \
trap_1_wll(0x13f, (long)(uptime), (long)(avenrun))
+#define Dxreaddir(len, handle, buf, xattr, xret) \
+ trap_1_wwllll(0x142, (short)(len), (long)(handle), \
+ (long)(buf), (long)(xattr), (long)(xret))
+#define Pseteuid(id) \
+ (int)trap_1_ww(0x143, (short)(id))
+#define Psetegid(id) \
+ (int)trap_1_ww(0x144, (short)(id))
+#define Psetauid(id) \
+ (int)trap_1_ww(0x145, (short)(id))
+#define Pgetauid() \
+ (int)trap_1_w(0x146)
+#define Pgetgroups(gidsetlen, gidset) \
+ trap_1_wwl(0x147, (short)(gidsetlen), (long)(gidset))
+#define Psetgroups(gidsetlen, gidset) \
+ trap_1_wwl(0x148, (short)(gidsetlen), (long)(gidset))
+#define Tsetitimer(which, interval, value, ointerval, ovalue) \
+ trap_1_wwllll(0x149, (short)(which), (long)(interval), \
+ (long)(value), (long)(ointerval), (long)(ovalue))
#endif /* __LATTICE__ */
--- orig/osbind.h Tue Jul 19 19:01:54 1994
+++ osbind.h Sat Aug 27 17:43:54 1994
@@ -925,7 +925,7 @@
__asm__ volatile \
("\
trap #1; \
- lea sp@(16),sp " \
+ lea sp@(14),sp " \
: "=r"(retvalue) /* outputs */ \
: /* inputs */ \
: "d0", "d1", "d2", "a0", "a1", "a2" /* clobbered regs */ \
--- orig/param.h Sat May 16 04:00:16 1992
+++ param.h Thu Feb 24 23:40:16 1994
@@ -12,4 +12,6 @@
# define NCARGS 126 /* max. no. of characters in argv */
#endif
+#define FSCALE 2048
+
#endif /* _PARAM_H */
--- orig/time.h Thu Oct 28 02:00:22 1993
+++ time.h Wed Aug 10 20:35:00 1994
@@ -57,6 +57,15 @@
int tz_minuteswest; /* minues west of GMT */
int tz_dsttime; /* daylight savings time correction */
};
+
+#define ITIMER_REAL 0
+#define ITIMER_VIRTUAL 1
+#define ITIMER_PROF 2
+
+struct itimerval {
+ struct timeval it_interval; /* timer interval */
+ struct timeval it_value; /* current value */
+};
#endif
__EXTERN clock_t clock __PROTO((void));
@@ -77,6 +86,9 @@
__EXTERN clock_t _clock __PROTO((void));
__EXTERN int gettimeofday __PROTO((struct timeval *, struct timezone *));
__EXTERN int settimeofday __PROTO((struct timeval *, struct timezone *));
+__EXTERN int getitimer __PROTO ((int, struct itimerval *));
+__EXTERN int setitimer __PROTO ((int, const struct itimerval *,
+ struct itimerval *));
#ifndef _FD_SET_T
#define _FD_SET_T unsigned long
--- orig/unistd.h Wed Jan 19 21:23:38 1994
+++ unistd.h Sat Mar 26 21:36:50 1994
@@ -123,6 +123,8 @@
#ifndef _POSIX_SOURCE
__EXTERN int _bsd_getpgrp __PROTO((int));
__EXTERN int _bsd_setpgrp __PROTO((int, int));
+__EXTERN int getdtablesize __PROTO ((void));
+__EXTERN int getloadavg __PROTO((double *, int));
__EXTERN char * getwd __PROTO((char *));
__EXTERN int getopt __PROTO((int, char * const *, const char *));
__EXTERN int getpagesize __PROTO((void));
------------------------- lib source changes -------------------------
--- orig/getgroup.c Wed Mar 2 01:35:28 1994
+++ getgroup.c Wed Aug 24 22:13:42 1994
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <grp.h>
#include <pwd.h>
+#include <mintbind.h>
#ifdef TEST
#include <stdlib.h> /* for calloc() */
#endif
@@ -41,6 +42,19 @@
if (!__mint)
return 0;
+
+ if (__mint >= 0x10b)
+ {
+ long r;
+
+ r = Pgetgroups (gsetlen, grpset);
+ if (r < 0)
+ {
+ errno = -r;
+ return -1;
+ }
+ return r;
+ }
currgid = getgid();
if (gsetlen) {
--- orig/osbind.cpp Fri Sep 17 20:10:26 1993
+++ osbind.cpp Sat Aug 27 17:37:42 1994
@@ -210,10 +210,24 @@
movew sp@(18+10), sp@-
movew sp@(14+12), sp@-
trap #1
- addw #16, sp
+ lea sp@(14), sp
moveml sp@+, d2/a2
rts
+ .globl _trap_1_wwllll
+_trap_1_wwllll:
+ moveml d2/a2,sp@-
+ movel sp@(32),sp@-
+ movel sp@(28+4),sp@-
+ movel sp@(24+8),sp@-
+ movel sp@(20+12),sp@-
+ movew sp@(18+16),sp@-
+ movew sp@(14+18),sp@-
+ trap #1
+ lea sp@(20),sp
+ moveml sp@+,d2/a2
+ rts
+
.globl _trap_13_w
_trap_13_w:
moveml d2/a2, sp@-
@@ -413,9 +427,22 @@
movel sp@(16+8), sp@-
movew sp@(14+12), sp@-
trap #14
- addw #14, sp
+ lea sp@(14), sp
moveml sp@+, d2/a2
rts
+
+ .globl _trap_14_wllll
+_trap_14_wllll:
+ moveml d2/a2,sp@-
+ movel sp@(28),sp@-
+ movel sp@(24+4),sp@-
+ movel sp@(20+8),sp@-
+ movel sp@(16+12),sp@-
+ movew sp@(14+16),sp@-
+ trap #14
+ lea sp@(18),sp
+ moveml sp@+,d2/a2
+ rts
.globl _trap_14_wwwwww
_trap_14_wwwwww:
@@ -427,8 +454,23 @@
movew sp@(18+8), sp@-
movew sp@(14+10), sp@-
trap #14
- lea sp@(14), sp
+ lea sp@(12), sp
moveml sp@+, d2/a2
+ rts
+
+ .globl _trap_14_wllllll
+_trap_14_wllllll:
+ moveml d2/a2,sp@-
+ movel sp@(36),sp@-
+ movel sp@(32+4),sp@-
+ movel sp@(28+8),sp@-
+ movel sp@(24+12),sp@-
+ movel sp@(20+16),sp@-
+ movel sp@(16+20),sp@-
+ movew sp@(14+24),sp@-
+ trap #14
+ lea sp@(26),sp
+ moveml sp@+,d2/a2
rts
.globl _trap_14_wwwwwww
--- orig/setegid.c Wed Mar 2 19:08:00 1994
+++ setegid.c Sat Aug 27 19:24:58 1994
@@ -1,8 +1,11 @@
#include <unistd.h>
+#include <mintbind.h>
+
+extern int __mint;
int
setegid(x)
int x;
{
- return setgid(x);
+ return __mint >= 0x10b ? Psetegid(x) : setgid(x);
}
--- orig/seteuid.c Wed Mar 2 19:08:02 1994
+++ seteuid.c Sat Aug 27 19:25:14 1994
@@ -1,8 +1,11 @@
#include <unistd.h>
+#include <mintbind.h>
+
+extern int __mint;
int
seteuid(x)
int x;
{
- return setuid(x);
+ return __mint >= 0x10b ? Pseteuid(x) : setuid(x);
}
------------------------- getloadavg.c -------------------------
#include <compiler.h>
#include <sys/param.h>
#include <unistd.h>
#include <errno.h>
#include <mintbind.h>
extern int __mint;
int
getloadavg (loadavg, nelem)
double *loadavg;
int nelem;
{
long uptime, avenrun[3], r;
int i;
if (!__mint)
{
errno = EINVAL;
return -1;
}
r = Suptime (&uptime, avenrun);
if (r < 0)
{
errno = (int) -r;
return -1;
}
for (i = 0; i < nelem && i < 3; i++)
loadavg[i] = (double) avenrun[i] / FSCALE;
return i;
}
------------------------- initgroups.c -------------------------
#include <sys/types.h>
#include <grp.h>
#include <limits.h>
#include <string.h>
#include <errno.h>
#include <mintbind.h>
int
initgroups (user, group)
char *user;
gid_t group;
{
struct group *g;
gid_t groups[NGROUPS_MAX];
int n;
long r;
n = 0;
groups[n++] = group;
setgrent ();
while (n < NGROUPS_MAX && (g = getgrent ()) != NULL)
if (g->gr_gid != group)
{
char **m;
for (m = g->gr_mem; *m != NULL; ++m)
if (!strcmp (*m, user))
groups[n++] = g->gr_gid;
}
endgrent ();
r = Psetgroups (n, groups);
if (r < 0)
{
errno = -r;
return -1;
}
return 0;
}
------------------------- setitimer.c -------------------------
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include <mintbind.h>
/* in getrusage.c */
__EXTERN void _ms2tval __PROTO ((unsigned long, struct timeval *));
int
setitimer (which, new, old)
int which;
const struct itimerval *new;
struct itimerval *old;
{
long r;
long newint, newval, oldint = 0, oldval = 0;
if (new)
{
newint = (new->it_interval.tv_sec * 1000L
+ new->it_interval.tv_usec / 1000L);
newval = (new->it_value.tv_sec * 1000L
+ new->it_value.tv_usec / 1000L);
}
r = Tsetitimer (which, new ? &newint : 0, new ? &newval : 0,
old ? &oldint : 0, old ? &oldval : 0);
if (r < 0)
{
errno = -r;
return -1;
}
if (old)
{
_ms2tval (oldint, &old->it_interval);
_ms2tval (oldval, &old->it_value);
}
return 0;
}
------------------------- getitimer.c -------------------------
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#include <mintbind.h>
/* in getrusage.c */
__EXTERN void _ms2tval __PROTO ((unsigned long, struct timeval *));
int
getitimer (which, old)
int which;
struct itimerval *old;
{
long r;
long interval, value;
r = Tsetitimer (which, 0, 0, &interval, &value);
if (r < 0)
{
errno = -r;
return -1;
}
_ms2tval (interval, &old->it_interval);
_ms2tval (value, &old->it_value);
return 0;
}
------------------------- that's it! -------------------------
--
Andreas Schwab "And now for something
schwab@ls5.informatik.uni-dortmund.de completely different"