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

[MiNT] umask fixes for MiNTlib



Attached is a patch against MiNTlib which deals with some int/uint
problems with umask.

mode_t is defined as a uint, but Pumask() is returning an int. So
there's some casting that has to be done.

This patch does just that.

Alan.
diff --git a/mintlib/getumask.c b/mintlib/getumask.c
index 6e8b267..f62d84c 100644
--- a/mintlib/getumask.c
+++ b/mintlib/getumask.c
@@ -16,13 +16,13 @@ mode_t
 __getumask (void)
 {
 	/* The only possible failure for Pumask is ENOSYS.  */
-	mode_t old_umask = Pumask (0);
+	int old_umask = Pumask (0);
 
 	if (old_umask >= 0)
 		(void) Pumask (old_umask);
 	else
 		old_umask = __current_umask;
 
-	return old_umask;
+	return (mode_t)old_umask;
 }
 weak_alias (__getumask, getumask)
diff --git a/misc/setmode.c b/misc/setmode.c
index 99dcb68..e2bcfdf 100644
--- a/misc/setmode.c
+++ b/misc/setmode.c
@@ -72,7 +72,7 @@ typedef struct bitcmd {
 #define	CMD2_OBITS	0x08
 #define	CMD2_UBITS	0x10
 
-static BITCMD	*addcmd __P((BITCMD *, int, int, int, u_int));
+static BITCMD	*addcmd __P((BITCMD *, int, u_int, int, u_int));
 static void	 compress_mode __P((BITCMD *));
 #ifdef SETMODE_DEBUG
 static void	 dumpmode __P((BITCMD *));
@@ -178,11 +178,12 @@ void *
 setmode(p)
 	const char *p;
 {
-	int perm, who;
+	int perm;
+	unsigned int who;
 	char op, *ep;
 	BITCMD *set, *saveset, *endset;
 	sigset_t sigset, sigoset;
-	mode_t mask;
+	int mask;
 	int equalopdone = 0;	/* pacify gcc */
 	int permXbits, setlen;
 
@@ -350,7 +351,8 @@ apply:		if (!*p)
 static BITCMD *
 addcmd(set, op, who, oparg, mask)
 	BITCMD *set;
-	int oparg, who;
+	int oparg;
+	u_int who;
 	int op;
 	u_int mask;
 {
diff --git a/unix/open.c b/unix/open.c
index f320124..c6df17f 100644
--- a/unix/open.c
+++ b/unix/open.c
@@ -26,7 +26,7 @@
  * but adjust the file masks here.
  */
 
-mode_t __current_umask = -1;
+mode_t __current_umask = 0;
 
 /* Try to open the file NAME with FLAGS.  If the OS returns EACCES check
    if we are the super-user and then try to temporarily change the 
@@ -84,11 +84,7 @@ __open_v (const char *_filename, int iomode, va_list argp)
 	    	pmode = va_arg (argp, unsigned int);
 
 	/* use the umask() setting to get the right permissions */
-	if (__current_umask == -1) {
-		__current_umask = Pumask (0);
-		if (__current_umask < 0)
-			 __current_umask = 0;
-	}
+	__current_umask = Pumask (0);
 	pmode &= ~__current_umask;
 
 	/* set the file access modes correctly */
diff --git a/unix/umask.c b/unix/umask.c
index dfb88aa..4075ac7 100644
--- a/unix/umask.c
+++ b/unix/umask.c
@@ -21,12 +21,10 @@ __umask (mode_t complmode)
 	int old_umask;
 	int retval;
 
-	if (__current_umask == -1) {
-		__current_umask = Pumask (0);
-		if (__current_umask < 0)
-			__current_umask = 0;
-	}
-	old_umask = __current_umask;
+	if (__current_umask == complmode)
+		return __current_umask;
+
+	old_umask = Pumask (0);
 	__current_umask = complmode;
 
 	retval = Pumask (complmode);