[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MiNT library PL46 patches



Hi all, it's me again.

Here are some bugs fixes for the MiNT libs PL 46 which where floating
around on my harddisk for some days already :-).

In mincl I added the initgroups.o and getloadavg.o to the list of
targets; somehow they didn't manage into the distribution.

The access function wasn't using the supplementary groups for checking
access rights. (May be it would be worth to include a Faccess routine
in the kernel so access can definitely report the kernel's opinion on
access rights instead of the library implementor's opinion.)

Truncate always returned -1 when the call to Dcntl did not return
EINVAL, even if the call succeeded.

In the getpass routine now uses a longer buffer, so there is room for
some line editing (remember that MiNT's tty driver does no line buffering).

In the open function I fixed the check that a file cannot be truncated when
opened read-only; the old check was just a no-op. Now open should really
return an access denied error (as the comment already suggested).

Finally the fopen_i function does not need to fseek to the end-of-file
when a file is opened in append mode, as this is already done by open.
Also if someone reenables the code again (for any reason I can't think of),
I made sure that the _cnt field of the file is cleared before the call to
fseek. This missing initialization could result in garbage at thebeginning
of a file if the file had been written to, then closed and then opened
again. (This was the reason for a hard to find bug in my port of cvs :-)

Cheers
Wolfgang

----
Wolfgang Lux                            #include <Standard Disclaimer>
WZH Heidelberg, IBM Germany             Internet: lux@heidelbg.ibm.com
+49-6221-59-4546                        VNET:     LUX at HEIDELBG
+49-6221-59-3200 (fax)	                EARN:     LUX at DHDIBMIP


diff -u -xChangeLog -xMakefile /usr/src/libsrc/access.c ./access.c
--- /usr/src/libsrc/access.c	Sat Feb 13 13:17:54 1993
+++ ./access.c	Tue Jan  3 17:47:42 1995
@@ -1,6 +1,7 @@
 /* access() emulation; relies heavily on stat() */
 
 #include <types.h>
+#include <limits.h>
 #include <stat.h>
 #include <fcntl.h>
 #include <errno.h>
@@ -14,6 +15,8 @@
 	int mode;
 {
 	struct stat sb;
+	gid_t groups[NGROUPS_MAX];
+	int i, n;
 
 	if (stat(path, &sb) < 0)
 		return -1;	/* errno was set by stat() */
@@ -38,6 +41,18 @@
 		else
 			goto accdn;
 	}
+
+	if ( __mint >= 0x10b ) {
+		n = getgroups(NGROUPS_MAX, groups);
+		for ( i = 0; i < n; i++ ) {
+			if ( groups[i] == sb.st_gid ) {
+				if ( ((sb.st_mode >> 3) & mode) == mode )
+					return 0;
+				else
+					goto accdn;
+			}
+		}
+	}
 
 	if ( (sb.st_mode & mode) == mode)
 		return 0;
diff -u -xChangeLog -xMakefile /usr/src/libsrc/fopen_i.c ./fopen_i.c
--- /usr/src/libsrc/fopen_i.c	Tue Mar  1 22:54:42 1994
+++ ./fopen_i.c	Fri Apr 14 14:40:42 1995
@@ -71,8 +71,13 @@
 		f |= _IOFBF;
 	fp->_file = h;			/* file handle */
 	fp->_flag = f;			/* file status flags */
+#if 0
 	if (iomode & O_APPEND)
+	{
+		fp->_cnt = 0;		/* required for fseek */
 		(void) fseek(fp, 0L, SEEK_END);
+	}
+#endif
 
 	return (fp);
 	}
diff -u -xChangeLog -xMakefile /usr/src/libsrc/getpass.c ./getpass.c
--- /usr/src/libsrc/getpass.c	Tue Mar 14 21:01:08 1995
+++ ./getpass.c	Thu Apr 13 22:52:16 1995
@@ -4,17 +4,19 @@
 #include <string.h>
 #include <limits.h>
 
+#define LINE_MAX 80
+
 extern int __mint;
 
 char *
 getpass(prompt)
 	const char *prompt;
 {
-	static char buf[PASS_MAX + 1];
+	static char buf[LINE_MAX + 1];
         char *ret;
 	struct sgttyb oldsb, newsb;
 	FILE *tty;
-	int ttyfd;
+	int l, ttyfd;
 
 	fflush(stdin);
 	tty = stdin;
@@ -30,19 +32,18 @@
 	stty(ttyfd, &newsb);
 	fputs(prompt, stderr);
 	fflush(stderr);
-	if ((ret = fgets(buf, PASS_MAX + 1, tty)) != 0)
+	if ((ret = fgets(buf, LINE_MAX, tty)) != 0)
 	{
 	  /* zap the newline */
-	  if (buf[strlen(buf) - 1] == '\n')
-          {
-	    buf[strlen(buf) - 1] = 0;
-          }
-          else
-          {
-            buf[PASS_MAX] = 0;
-            while (fgetc(tty) != '\n')
-              /* wait for a newline */ ;
-          }
+	  l = strlen(buf);
+	  if (buf[l-1] != '\n') {
+	    while (fgetc(tty) != '\n')
+	      /* wait for a newline */ ;
+	  }
+	  if (l > PASS_MAX)
+	    buf[PASS_MAX] = '\0';
+	  else if (buf[l-1] == '\n')
+	    buf[l-1] = '\0';
 	}
 	stty(ttyfd, &oldsb);
 	if (__mint)
diff -u -xChangeLog -xMakefile /usr/src/libsrc/mincl ./mincl
--- /usr/src/libsrc/mincl	Tue Mar 14 21:03:58 1995
+++ ./mincl	Fri Apr 14 12:46:24 1995
@@ -76,9 +76,9 @@
 	execl.o execle.o execp.o execv.o execve.o \
 	fcntl.o flock.o fork.o fstat.o \
 	getcwd.o getdtabl.o getegid.o geteuid.o getgid.o getgroup.o \
-	getitimer.o getpid.o getppid.o \
+	getitimer.o getloadavg.o getpid.o getppid.o \
 	getuid.o getrusag.o getwd.o \
-	inode.o ioctl.o isatty.o isctty.o \
+	initgroups.o inode.o ioctl.o isatty.o isctty.o \
 	kill.o killpg.o link.o lockf.o lseek.o lstat.o \
 	mkfifo.o mkdir.o mknod.o \
 	nice.o open.o opendir.o \
diff -u -xChangeLog -xMakefile /usr/src/libsrc/open.c ./open.c
--- /usr/src/libsrc/open.c	Tue Mar 14 21:04:02 1995
+++ ./open.c	Thu Apr 13 23:13:08 1995
@@ -118,7 +118,7 @@
 		}
 		if ((iomode & ~modemask & O_TRUNC) && (rv >= 0)) {
 			/* Give up if the mode flags conflict */
-			if (iomode & O_RDONLY) {
+			if (iomode & O_ACCMODE == O_RDONLY) {
 				(void)Fclose(rv);
 				errno = EACCES;
 				return __SMALLEST_VALID_HANDLE - 1;
diff -u -xChangeLog -xMakefile /usr/src/libsrc/truncate.c ./truncate.c
--- /usr/src/libsrc/truncate.c	Tue Mar 14 21:04:12 1995
+++ ./truncate.c	Fri Dec 30 17:02:58 1994
@@ -41,10 +41,14 @@
       res = Dcntl(FTRUNCATE, (long) filename, (long) &length);
       if (res != -EINVAL)
         {
-	  if ((res == -EPATH) && (_enoent(filename)))
+	  if (res < 0)
+	    {
+	      if ((res == -EPATH) && (_enoent(filename)))
 		res = -ENOENT;
-          errno = (int) -res;
-          return -1;
+	      errno = (int) -res;
+	      return -1;
+	    }
+	  return 0;
 	}
     }
   fh = (int)Fopen (filename, 2);