[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Removing mint-dependencies in mintlib
Hi there!
Here is a patch for the mintlib (based on pl44) for some of the files
(opendir/readdir/closedir/rewinddir/stat/kill/killpg/chown/chmod/fork/
getuid/getgid/getpid/getppid/sync)
to get rid of the MiNT-dependencies. Now only the existence of the
system call is tested, not the __mint variable.
This stuff is already tested a bit under Mag!C, so it should work.
diff -uw old/chmod.c ./chmod.c
--- old/chmod.c Fri Jan 27 22:51:00 1995
+++ ./chmod.c Fri Jan 27 23:24:22 1995
@@ -10,7 +10,6 @@
#include <unistd.h>
#include "lib.h"
-extern int __mint;
int
chmod(_path, mode)
@@ -22,14 +21,14 @@
(void)_unx2dos(_path, path);
- if (__mint >= 9) { /* use MiNT Fchmod function */
r = (int)Fchmod(path, mode);
- if (r) {
+ if (r && (r != -EINVAL)) {
errno = -r;
return -1;
}
+ else if (r != -EINVAL) /* call was successful */
return 0;
- }
+
/* The following lines ensure that the archive bit isn't cleared */
r = Fattrib(path, 0, 0);
diff -uw old/chown.c ./chown.c
--- old/chown.c Tue Mar 1 17:54:40 1994
+++ ./chown.c Fri Jan 27 22:50:14 1995
@@ -11,7 +11,6 @@
#include <unistd.h>
#include "lib.h"
-extern int __mint;
int
chown(_name, uid, gid)
@@ -21,14 +20,11 @@
int r;
char name[PATH_MAX];
- if (__mint >= 9) {
(void)_unx2dos(_name, name);
r = (int)Fchown(name, uid, gid);
if (r && (r != -EINVAL)) {
errno = -r;
return -1;
}
- return 0;
- }
return 0;
}
diff -uw old/closedir.c ./closedir.c
--- old/closedir.c Mon Jan 2 22:10:44 1995
+++ ./closedir.c Fri Jan 27 22:45:00 1995
@@ -16,18 +16,26 @@
#include <mintbind.h>
#include "lib.h"
-extern int __mint;
+
+/* Important note: the same comment for the status variable of
+ * opendir/readdir under Metados applies also here.
+ */
+
extern ino_t __inode; /* in stat.c */
+
int
closedir(dirp)
DIR *dirp;
{
- int r;
+ long r;
- if (__mint > 8) {
- r = (int)Dclosedir(dirp->handle);
- } else {
+ if (dirp->handle != 0xff000000L)
+ r = Dclosedir(dirp->handle);
+ else
+ r = 0;
+ if (r == -EINVAL) {
+ /* hmm, something went wrong, just ignore it. */
r = 0;
}
free(dirp);
diff -uw old/do_stat.c ./do_stat.c
--- old/do_stat.c Thu Jan 12 19:01:48 1995
+++ ./do_stat.c Sun Jan 15 22:46:18 1995
@@ -53,7 +53,9 @@
short magic;
_DTA d;
int isdot = 0;
+ static short have_fxattr = 1; /* for the first call, assume we have it */
+
if (!_path) {
errno = EFAULT;
return -1;
@@ -64,16 +66,22 @@
*/
nval = _unx2dos(_path, path);
-/* for MiNT 0.9 and up, we use the built in stat() call */
- if (__mint >= 9) {
+ /* try to use the build in stat() call, but if the system does not
+ * have it, record that and never try again
+ */
+ if (have_fxattr) {
r = Fxattr(lflag, path, st);
- if (r) {
+ if (r == -EINVAL) {
+ have_fxattr = 0;
+ }
+ else if (r) {
if ((r == -EPATH) && _enoent(path)) {
r = -ENOENT;
}
errno = (int) -r;
return -1;
}
+ else {
__UNIXTIME(st->st_mtime);
__UNIXTIME(st->st_atime);
__UNIXTIME(st->st_ctime);
@@ -95,6 +103,7 @@
}
return 0;
}
+ }
/* otherwise, check to see if we have a name like CON: or AUX: */
if (nval == 1) {
diff -uw old/fork.c ./fork.c
--- old/fork.c Wed Jan 4 20:48:08 1995
+++ ./fork.c Wed Jan 4 20:51:04 1995
@@ -8,13 +8,8 @@
fork()
{
int r;
- extern int __mint;
- if (__mint == 0)
- r = -EINVAL;
- else
r = (int)Pfork();
-
if (r < 0) {
errno = -r;
return -1;
diff -uw old/getgid.c ./getgid.c
--- old/getgid.c Fri Jan 27 23:00:38 1995
+++ ./getgid.c Fri Jan 27 23:09:02 1995
@@ -1,12 +1,22 @@
#include <types.h>
#include <unistd.h>
#include <mintbind.h>
+#include <errno.h>
-extern int __mint;
extern gid_t __gid;
gid_t
getgid()
{
- return __mint ? Pgetgid() : __gid;
+ long r;
+ static short have_getgid = 1;
+
+ if (have_getgid) {
+ r = Pgetgid();
+ if (r == -EINVAL)
+ have_getgid = 0;
+ else
+ return (gid_t)r;
+ }
+ return __gid;
}
diff -uw old/getpid.c ./getpid.c
--- old/getpid.c Fri Jan 27 23:00:38 1995
+++ ./getpid.c Fri Jan 27 23:07:48 1995
@@ -2,6 +2,7 @@
#include <unistd.h>
#include <basepage.h>
#include <mintbind.h>
+#include <errno.h>
int
diff -uw old/getppid.c ./getppid.c
--- old/getppid.c Fri Jan 27 23:00:38 1995
+++ ./getppid.c Fri Jan 27 23:08:04 1995
@@ -2,11 +2,21 @@
#include <unistd.h>
#include <basepage.h>
#include <mintbind.h>
+#include <errno.h>
-extern int __mint;
int
getppid()
{
- return __mint ? Pgetppid() : (int) (((long)(_base->p_parent)) >> 8);
+ long r;
+ static short have_getppid = 1;
+
+ if (have_getppid) {
+ r = Pgetppid();
+ if (r == -EINVAL)
+ have_getppid = 0;
+ else
+ return (int)r;
+ }
+ return (int)(((long)(_base->p_parent)) >> 8);
}
diff -uw old/getuid.c ./getuid.c
--- old/getuid.c Fri Jan 27 23:00:38 1995
+++ ./getuid.c Fri Jan 27 23:08:14 1995
@@ -2,12 +2,22 @@
#include <unistd.h>
#include <osbind.h>
#include <mintbind.h>
+#include <errno.h>
-extern int __mint;
extern uid_t __uid;
uid_t
getuid()
{
- return __mint ? Pgetuid() : __uid;
+ long r;
+ static short have_getuid = 1;
+
+ if (have_getuid) {
+ r = Pgetuid();
+ if (r == -EINVAL)
+ have_getuid = 0;
+ else
+ return (uid_t)r;
+ }
+ return __uid;
}
diff -uw old/kill.c ./kill.c
--- old/kill.c Wed Jan 4 21:27:28 1995
+++ ./kill.c Wed Jan 4 21:36:02 1995
@@ -7,7 +7,6 @@
#include <unistd.h>
#include <mintbind.h>
-extern int __mint;
/* vector of signal handlers (for TOS) */
extern __Sigfunc _sig_handler[]; /* in signal.c */
@@ -18,6 +17,8 @@
/* which signals are pending? */
extern long _sigpending;
+short have_pkill = 1;
+
int
kill(pid, sig)
int pid, sig;
@@ -25,13 +26,19 @@
long r;
__Sigfunc hndle;
- if (__mint) {
+ if (have_pkill) {
r = Pkill(pid, sig);
- if (r < 0) {
+ if (r == -EINVAL)
+ have_pkill = 0;
+ else if (r < 0) {
errno = (int) -r;
return -1;
}
- } else {
+ else
+ return 0;
+ }
+ /* fall through to TOS emulation */
+
if (sig < 0 || sig >= NSIG || (pid && pid != getpid())) {
errno = ERANGE;
return -1;
@@ -56,6 +63,6 @@
(*hndle)(sig);
}
}
- }
+
return 0;
}
diff -uw old/killpg.c ./killpg.c
--- old/killpg.c Wed Jan 4 21:27:28 1995
+++ ./killpg.c Wed Jan 4 21:37:48 1995
@@ -18,18 +18,22 @@
/* which signals are pending? */
extern long _sigpending;
+extern short _have_pkill;
+
int
killpg(pgrp, sig)
int pgrp, sig;
{
long r;
+#if 0
if (__mint == 0) {
if (pgrp == 0 || pgrp == getpgrp())
return kill(getpid(), sig);
errno = EINVAL;
return -1;
}
+#endif
if (pgrp < 0) {
errno = ERANGE;
return -1;
@@ -38,6 +42,12 @@
if (__mint < 7) { /* compensate for a bug in MiNT 0.6 */
(void)Syield();
}
+ if (r == -EINVAL)
+ {
+ _have_pkill = 0;
+ if (pgrp == 0 || pgrp == getpgrp())
+ return kill(getpid(), sig);
+ }
if (r < 0) {
errno = (int) -r;
return -1;
diff -uw old/opendir.c ./opendir.c
--- old/opendir.c Mon Jan 2 22:10:44 1995
+++ ./opendir.c Fri Jan 27 22:43:32 1995
@@ -16,9 +16,20 @@
#include <mintbind.h>
#include "lib.h"
-extern int __mint;
+
+/* Important note: Metados can have opendir for some device and do not
+ * have it for others, so there is no point in having a status variable
+ * saying there is an opendir call. Check this every time.
+ */
+
extern ino_t __inode; /* in stat.c */
+/* a new value for DIR->status, to indicate that the file system is not
+ * case sensitive.
+ */
+#define _NO_CASE 8
+
+
DIR *
opendir(uname)
const char *uname;
@@ -38,17 +49,27 @@
_unx2dos(uname, name);
- if (__mint > 8) {
r = Dopendir(name, 0);
+ if (r != -EINVAL) {
if ( (r & 0xff000000L) == 0xff000000L ) {
errno = (int) -r;
free(d);
return 0;
}
+ else {
d->handle = r;
d->buf.d_off = 0;
+
+ /* test if the file system is case sensitive */
+ r = Dpathconf(name, 6);
+ if (r > 0)
+ d->status = _NO_CASE;
+ else
+ d->status = 0;
return d;
}
+ }
+ d->handle = 0xff000000L; /* indicate that the handle is invalid */
/* TOS emulation routines */
diff -uw old/readdir.c ./readdir.c
--- old/readdir.c Mon Jan 2 22:10:44 1995
+++ ./readdir.c Fri Jan 27 22:45:06 1995
@@ -16,9 +16,20 @@
#include <mintbind.h>
#include "lib.h"
-extern int __mint;
+
+/* Important note: under Metados, some file systems can have opendir/readdir/
+ * closdir, so we must not have a status variable for these ones.
+ * Instead, check the directory struct if there was an opendir call.
+ */
+
extern ino_t __inode; /* in stat.c */
+/* a new value for DIR->status, to indicate that the file system is not
+ * case sensitive.
+ */
+#define _NO_CASE 8
+
+
struct dirent *
readdir(d)
DIR *d;
@@ -31,7 +42,10 @@
_DTA *olddta;
struct dirent *dd = &d->buf;
- if (__mint > 8) {
+ if (d->handle != 0xff000000L) {
+ /* The directory descriptor was optained by calling Dopendir(), as
+ * there is a valid handle.
+ */
r = (int)Dreaddir((int)(NAME_MAX+1+sizeof(long)), d->handle, (char *) &dbuf);
if (r == -ENMFIL)
return 0;
@@ -39,12 +53,19 @@
errno = (int) -r;
return 0;
}
+ else {
dd->d_ino = dbuf.ino;
dd->d_off++;
dd->d_reclen = (short)strlen(dbuf.name);
strcpy(dd->d_name, dbuf.name);
+
+ /* if file system is case insensitive, transform name to lowercase */
+ if (d->status == _NO_CASE)
+ strlwr(dd->d_name);
+
return dd;
}
+ }
/* ordinary TOS search, using Fsnext. Note that the first time through,
* Fsfirst has already provided valid data for us; for subsequent
* searches, we need Fsnext.
diff -uw old/rewinddi.c ./rewinddi.c
--- old/rewinddi.c Fri Jan 27 22:32:54 1995
+++ ./rewinddi.c Fri Jan 27 22:45:36 1995
@@ -16,7 +16,9 @@
#include <mintbind.h>
#include "lib.h"
-extern int __mint;
+/* See the comment in opendir.c/readdir.c for the use (or better non-use)
+ * of a status variable for the system call being implemented.
+ */
extern ino_t __inode; /* in stat.c */
void
@@ -26,7 +28,7 @@
long r;
_DTA *olddta;
- if (__mint >= 9) {
+ if (dirp->handle != 0xff000000L) {
(void)Drewinddir(dirp->handle);
dirp->buf.d_off = 0;
return;
diff -uw old/sync.c ./sync.c
--- old/sync.c Tue Mar 1 17:55:00 1994
+++ ./sync.c Sat Jan 7 11:31:48 1995
@@ -2,73 +2,38 @@
* FILE
* sync.c
*
- *
* DESCRIPTION
- * syncing filesystems, makes only sense with mint and
- * minixfs for now
+ * syncing filesystems, makes only sense with mint
*
* BUGS
- * minixfs V 060 PL 5 always syncs all drives, so there will
- * be too much syncing, since we call Dcntl for all known drives.
- *
+ * fsync does the same as sync()
*/
#include <mintbind.h>
-#include <stat.h>
-#include <errno.h>
#include <support.h>
-#include <string.h>
-
-extern int __mint;
-/* from minixfs.h by S N Henson*/
-#define MFS_BASE 0x100
-#define MFS_VERIFY (MFS_BASE) /* Return minixfs magic number */
-#define MFS_SYNC (MFS_BASE|0x01) /* Sync the filesystem */
-#define MFS_MAGIC 0x18970431 /* Magic number from MFS_VERIFY */
+extern int errno;
/*
* FUNCTION
* int sync(void)
*
* DESCRIPTION
- * query all known drives for a valid MinixFs
- * if we find one, sync it.
+ * call MiNT's sync system call
*/
int
sync()
{
- long magic;
- unsigned long drives;
- int i, rv;
- char path[4];
-
- if (!__mint)
- return 0;
-
- strcpy(path, "A:\\");
+ long res;
- drives = Dsetdrv(Dgetdrv());
-
- drives &= ~0x3; /* don't sync the floppys */
-
- for (i = 2; drives ; i++) {
- if (drives & (1L << i)) {
- drives &= ~(1L << i);
- path[0] = 'A' + i;
- magic = 0L;
- if (!Dcntl(MFS_VERIFY, path, &magic) && magic == MFS_MAGIC) {
- if ((rv = (int)Dcntl(MFS_SYNC, path, 0L)) < 0) {
- errno = -rv;
+ res = Sync();
+ if (res < 0)
+ {
+ errno = -res;
return -1;
}
- }
- }
- }
-
return 0;
-} /* sync() */
-
+}
/*
@@ -77,40 +42,14 @@
*
* DESCRIPTION
* sync all buffers related to file descriptor fd
- * since MFS 605 always syncs all the buffers, we don't bother
- * to get the full path.
+ * for now, just call the sync() function.
*/
int
fsync(fd)
int fd;
{
- int rv;
- long magic = 0L;
- char path[4];
- struct stat statbuf;
-
- if (!__mint)
- return 0;
-
- strcpy(path, "A:\\");
- if (fstat(fd, &statbuf))
- return -1; /* errno set from fstat */
-
- if (statbuf.st_dev >= 32)
- /* If mounted via FS_MOUNT, st_dev will be > 0x100.
- Pretend that it worked. */
- return 0;
-
- path[0] = 'A'+ statbuf.st_dev;
- if (!Dcntl(MFS_VERIFY, path, &magic) && magic == MFS_MAGIC) {
- if ((rv = (int)Dcntl(MFS_SYNC, path, 0L)) < 0) {
- errno = -rv;
- return -1;
+ return sync();
}
- }
-
- return 0;
-} /* fsync() */
#ifdef TEST
Regards,
Ulrich
--
+---------------+----------------------------+-----------------------+
| Ulrich Kuehn | Internet: | Life is uncertain -- |
| Cand.Math.Inf | kuehn@math.uni-muenster.de | eat the dessert first |
+---------------+----------------------------+-----------------------+