9front - general discussion about 9front
 help / color / mirror / Atom feed
* Re: [9front] Enable and fix warnings in ape/lib/ap
@ 2019-06-21  2:16 ori
  0 siblings, 0 replies; 2+ messages in thread
From: ori @ 2019-06-21  2:16 UTC (permalink / raw)
  To: cinap_lenrek, 9front

> looking fine, except two small issues:
> 
> --- a/sys/src/ape/lib/ap/plan9/_buf.c	Thu Jun 20 00:36:51 2019 +0200
> +++ b/sys/src/ape/lib/ap/plan9/_buf.c	Wed Jun 19 22:55:29 2019 -0700
> @@ -57,7 +58,7 @@
>  	if(mux == 0){
>  		_RFORK(RFREND);
>  		mux = (Muxseg*)_SEGATTACH(0, "shared", 0, sizeof(Muxseg));
> -		if((long)mux == -1){
> +		if((uintptr_t)mux == -1){
>  			_syserrno();
>  			return -1;
>  		}
> 
> might be better comparing mux == (void*)-1, which is also the
> definition of the error code in the manpge.

Agreed. Changed it.

> diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/rename.c
> --- a/sys/src/ape/lib/ap/plan9/rename.c	Thu Jun 20 00:36:51 2019 +0200
> +++ b/sys/src/ape/lib/ap/plan9/rename.c	Wed Jun 19 22:55:29 2019 -0700
> 
> -		if((ffd = _OPEN(from, OREAD)) < 0 ||
> -		   (tfd = _CREATE(to, OWRITE, d->mode)) < 0){
> -			_CLOSE(ffd);
> +		tfd = _CREATE(to, OWRITE, d->mode);
> +		ffd = _OPEN(from, OREAD);
> +		if(ffd == -1 || tfd == -1){
> 
> this changes the order which means we would leave marooned
> destination file arround.
> 
> i think it would be easier to just have the two blocks nested. and not
> trying to handle it in one block.

Decided I didn't like the way this function was written overall, and did
heavier refactoring.

Updated patch below.

diff -r aedb4c585577 sys/src/ape/config
--- a/sys/src/ape/config	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/config	Thu Jun 20 19:14:05 2019 -0700
@@ -5,7 +5,7 @@
 APELIB=/rc/bin/ape		# where helper programs go
 CC=pcc				# compiler (must be ansi)
 LD=pcc				# loader
-CFLAGS=				# global defaults
+CFLAGS=-Fw			# global defaults
 FAMILY=plan9
 AR=ar				# manipulating libraries
 RANLIB=echo			# for updating libraries
diff -r aedb4c585577 sys/src/ape/lib/ap/amd64/mkfile
--- a/sys/src/ape/lib/ap/amd64/mkfile	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/amd64/mkfile	Thu Jun 20 19:14:05 2019 -0700
@@ -16,5 +16,5 @@
 
 </sys/src/cmd/mksyslib
 
-CFLAGS=-c -D_POSIX_SOURCE -D_PLAN9_SOURCE
+CFLAGS=$CFLAGS -c -D_POSIX_SOURCE -D_PLAN9_SOURCE
 
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/getenv.c
--- a/sys/src/ape/lib/ap/gen/getenv.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/getenv.c	Thu Jun 20 19:14:05 2019 -0700
@@ -6,7 +6,7 @@
 getenv(const char *name)
 {
 	char **p = environ;
-	char *v, *s1, *s2;
+	char *s1, *s2;
 
 	while (*p != NULL){
 		for(s1 = (char *)name, s2 = *p++; *s1 == *s2; s1++, s2++)
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/memchr.c
--- a/sys/src/ape/lib/ap/gen/memchr.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/memchr.c	Thu Jun 20 19:14:05 2019 -0700
@@ -5,7 +5,7 @@
 {
 	unsigned char *sp;
 
-	sp = ap;
+	sp = (unsigned char*)ap;
 	c &= 0xFF;
 	while(n > 0) {
 		if(*sp++ == c)
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/memcmp.c
--- a/sys/src/ape/lib/ap/gen/memcmp.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/memcmp.c	Thu Jun 20 19:14:05 2019 -0700
@@ -6,8 +6,8 @@
 	char *s1, *s2;
 	unsigned c1, c2;
 
-	s1 = a1;
-	s2 = a2;
+	s1 = (char*)a1;
+	s2 = (char*)a2;
 	while(n > 0) {
 		c1 = *s1++;
 		c2 = *s2++;
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/memmove.c
--- a/sys/src/ape/lib/ap/gen/memmove.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/memmove.c	Thu Jun 20 19:14:05 2019 -0700
@@ -11,7 +11,7 @@
 	if(a1 > a2)
 		goto back;
 	s1 = a1;
-	s2 = a2;
+	s2 = (char*)a2;
 	while(n > 0) {
 		*s1++ = *s2++;
 		n--;
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/mkfile
--- a/sys/src/ape/lib/ap/gen/mkfile	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/mkfile	Thu Jun 20 19:14:05 2019 -0700
@@ -63,4 +63,4 @@
 
 </sys/src/cmd/mksyslib
 
-CFLAGS=-c -D_POSIX_SOURCE
+CFLAGS=$CFLAGS -c -D_POSIX_SOURCE
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/putenv.c
--- a/sys/src/ape/lib/ap/gen/putenv.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/putenv.c	Thu Jun 20 19:14:05 2019 -0700
@@ -9,16 +9,16 @@
 	int n;
 
 	for(n = 0; s2 = environ[n]; n++)
-		for(s1 = str; *s1 == *s2; s1++, s2++)
+		for(s1 = (char *)str; *s1 == *s2; s1++, s2++)
 			if(*s1 == '\0' || *s1 == '='){
-				environ[n] = str;
+				environ[n] = (char*)str;
 				return 0;
 			}
 	e = realloc(environ, (n+1) * sizeof(char*));
 	if(e == 0)
 		return -1;
 	environ = e;
-	e[n++] = str;
+	e[n++] = (char*)str;
 	e[n] = 0;
 	return 0;
 }
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/rand.c
--- a/sys/src/ape/lib/ap/gen/rand.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/rand.c	Thu Jun 20 19:14:05 2019 -0700
@@ -27,8 +27,6 @@
 	rng_tap = rng_vec;
 	rng_feed = rng_vec+LEN-TAP;
 	seed = seed%M;
-	if(seed < 0)
-		seed += M;
 	if(seed == 0)
 		seed = 89482311;
 	x = seed;
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/strcspn.c
--- a/sys/src/ape/lib/ap/gen/strcspn.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/strcspn.c	Thu Jun 20 19:14:05 2019 -0700
@@ -13,7 +13,7 @@
 		if(*b++ == 0)
 			break;
 	}
-	os = s;
+	os = (char*)s;
 	while(map[*(unsigned char*)s++] == 0)
 		;
 	return s - os - 1;
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/strpbrk.c
--- a/sys/src/ape/lib/ap/gen/strpbrk.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/strpbrk.c	Thu Jun 20 19:14:05 2019 -0700
@@ -15,6 +15,6 @@
 	while(map[*s++] == 0)
 		;
 	if(*--s)
-		return s;
+		return (char*)s;
 	return 0;
 }
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/strrchr.c
--- a/sys/src/ape/lib/ap/gen/strrchr.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/strrchr.c	Thu Jun 20 19:14:05 2019 -0700
@@ -9,6 +9,6 @@
 		return strchr(s, 0);
 	r = 0;
 	while(s = strchr(s, c))
-		r = s++;
+		r = (char*)s++;
 	return r;
 }
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/strspn.c
--- a/sys/src/ape/lib/ap/gen/strspn.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/strspn.c	Thu Jun 20 19:14:05 2019 -0700
@@ -10,7 +10,7 @@
 	memset(map, 0, N);
 	while(*b)
 		map[*(unsigned char *)b++] = 1;
-	os = s;
+	os = (char*)s;
 	while(map[*(unsigned char *)s++])
 		;
 	return s - os - 1;
diff -r aedb4c585577 sys/src/ape/lib/ap/gen/strstr.c
--- a/sys/src/ape/lib/ap/gen/strstr.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/gen/strstr.c	Thu Jun 20 19:14:05 2019 -0700
@@ -2,19 +2,19 @@
 
 /* Return pointer to first occurrence of s2 in s1, NULL if none */
 
-char
-*strstr(const char *s1, const char *s2)
+char*
+strstr(const char *s1, const char *s2)
 {
 	char *p, *pa, *pb;
 	int c0, c;
 
 	c0 = *s2;
 	if(c0 == 0)
-		return s1;
+		return (char *)s1;
 	s2++;
 	for(p=strchr(s1, c0); p; p=strchr(p+1, c0)) {
 		pa = p;
-		for(pb=s2;; pb++) {
+		for(pb=(char*)s2;; pb++) {
 			c = *pb;
 			if(c == 0)
 				return p;
diff -r aedb4c585577 sys/src/ape/lib/ap/math/mkfile
--- a/sys/src/ape/lib/ap/math/mkfile	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/math/mkfile	Thu Jun 20 19:14:05 2019 -0700
@@ -25,4 +25,4 @@
 
 </sys/src/cmd/mksyslib
 
-CFLAGS=-c -D_POSIX_SOURCE
+CFLAGS=$CFLAGS -c -D_POSIX_SOURCE
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/_buf.c
--- a/sys/src/ape/lib/ap/plan9/_buf.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/_buf.c	Thu Jun 20 19:14:05 2019 -0700
@@ -2,6 +2,7 @@
 #define _LOCK_EXTENSION
 #include "lib.h"
 #include <stdlib.h>
+#include <stdint.h>
 #include <errno.h>
 #include <unistd.h>
 #include <signal.h>
@@ -57,7 +58,7 @@
 	if(mux == 0){
 		_RFORK(RFREND);
 		mux = (Muxseg*)_SEGATTACH(0, "shared", 0, sizeof(Muxseg));
-		if((long)mux == -1){
+		if(mux == (void*)-1){
 			_syserrno();
 			return -1;
 		}
@@ -124,7 +125,7 @@
 
 	while((v = _RENDEZVOUS(&b->copypid, 0)) == (void*)~0)
 		;
-	_muxsid = (int)v;
+	_muxsid = (uintptr_t)v;
 
 	/* leave fd open in parent so system doesn't reuse it */
 	return 0;
@@ -182,6 +183,7 @@
 		 * happened, or it might mean eof; try several times to
 		 * disambiguate (posix read() discards 0-length messages)
 		 */
+		n = 0;
 		nzeros = 0;
 		do {
 			if(b->fd != fd)
@@ -395,7 +397,7 @@
 	}
 	mux->selwait = 1;
 	unlock(&mux->lock);
-	fd = (int)_RENDEZVOUS(&mux->selwait, 0);
+	fd = (int)(uintptr_t)_RENDEZVOUS(&mux->selwait, 0);
 	if(fd >= 0 && fd < nfds) {
 		b = _fdinfo[fd].buf;
 		if(b == 0 || b->fd != fd) {
@@ -504,7 +506,7 @@
 }
 
 static int
-copynotehandler(void *u, char *msg)
+copynotehandler(void *, char *)
 {
 	if(_finishing)
 		_finish(0, 0);
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/_envsetup.c
--- a/sys/src/ape/lib/ap/plan9/_envsetup.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/_envsetup.c	Thu Jun 20 19:14:05 2019 -0700
@@ -40,6 +40,8 @@
 	char **pp;
 	Dir *d9, *d9a;
 
+	ps = 0;
+	psize = 0;
 	nohandle = 0;
 	fdinited = 0;
 	cnt = 0;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/_getpw.c
--- a/sys/src/ape/lib/ap/plan9/_getpw.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/_getpw.c	Thu Jun 20 19:14:05 2019 -0700
@@ -59,6 +59,7 @@
 			return 0;
 		au[n] = 0;
 	}
+	mem = nil;
 	matchnum = (*pname == NULL);
 	matched = 0;
 	/* try using memo */
@@ -68,9 +69,8 @@
 			matched = (mem->num == *pnum);
 		else
 			matched = (strcmp(mem->name, *pname) == 0);
-		if(matched) {
+		if(matched)
 			break;
-		}
 	}
 	if(!matched)
 		for(f1 = au, eline = au; !matched && *eline; f1 = eline+1){
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/brk.c
--- a/sys/src/ape/lib/ap/plan9/brk.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/brk.c	Thu Jun 20 19:14:05 2019 -0700
@@ -1,5 +1,6 @@
 #include "lib.h"
 #include <errno.h>
+#include <stdint.h>
 #include "sys9.h"
 
 char	end[];
@@ -11,7 +12,7 @@
 {
 	unsigned long n;
 
-	n = (unsigned long)p;
+	n = (uintptr_t)p;
 	n += 3;
 	n &= ~3;
 	if(_BRK_((void*)n) < 0){
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/cfgetospeed.c
--- a/sys/src/ape/lib/ap/plan9/cfgetospeed.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/cfgetospeed.c	Thu Jun 20 19:14:05 2019 -0700
@@ -1,25 +1,25 @@
 #include <termios.h>
 
 speed_t
-cfgetospeed(const struct termios *p)
+cfgetospeed(const struct termios *)
 {
 	return B0;
 }
 
 int
-cfsetospeed(struct termios *p, speed_t s)
+cfsetospeed(struct termios *, speed_t)
 {
 	return 0;
 }
 
 speed_t
-cfgetispeed(const struct termios *p)
+cfgetispeed(const struct termios *)
 {
 	return B0;
 }
 
 int
-cfsetispeed(struct termios *p, speed_t s)
+cfsetispeed(struct termios *, speed_t)
 {
 	return 0;
 }
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/execle.c
--- a/sys/src/ape/lib/ap/plan9/execle.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/execle.c	Thu Jun 20 19:14:05 2019 -0700
@@ -1,7 +1,7 @@
 #include <unistd.h>
 
 int
-execle(const char *name, const char *arg0, const char *aore, ...)
+execle(const char *name, const char *arg0, const char *, ...)
 {
 	char *p;
 
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/execve.c
--- a/sys/src/ape/lib/ap/plan9/execve.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/execve.c	Thu Jun 20 19:14:05 2019 -0700
@@ -85,7 +85,7 @@
 		_CLOSE(f);
 	}
 	if(envp){
-		for(e = envp; (ss = *e); e++) {
+		for(e = (char**)envp; (ss = *e); e++) {
 			se = strchr(ss, '=');
 			if(!se || ss==se)
 				continue;	/* what is name? value? */
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/fsync.c
--- a/sys/src/ape/lib/ap/plan9/fsync.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/fsync.c	Thu Jun 20 19:14:05 2019 -0700
@@ -3,7 +3,7 @@
 #include <errno.h>
 
 int
-fsync(int fd)
+fsync(int)
 {
 	errno = EINVAL;
 	return -1;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/getgrnam.c
--- a/sys/src/ape/lib/ap/plan9/getgrnam.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/getgrnam.c	Thu Jun 20 19:14:05 2019 -0700
@@ -13,7 +13,7 @@
 	char *nam, *mem;
 
 	num = 0;
-	nam = name;
+	nam = (char *)name;
 	mem = 0;
 	if(_getpw(&num, &nam, &mem)){
 		holdgroup.gr_name = nam;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/getgroups.c
--- a/sys/src/ape/lib/ap/plan9/getgroups.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/getgroups.c	Thu Jun 20 19:14:05 2019 -0700
@@ -3,7 +3,7 @@
 #include <errno.h>
 
 int
-getgroups(int gidsize, gid_t grouplist[])
+getgroups(int, gid_t*)
 {
 	errno = EINVAL;
 	return -1;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/getpwnam.c
--- a/sys/src/ape/lib/ap/plan9/getpwnam.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/getpwnam.c	Thu Jun 20 19:14:05 2019 -0700
@@ -14,7 +14,7 @@
 	char *nam, *mem;
 
 	num = 0;
-	nam = name;
+	nam = (char*)name;
 	mem = 0;
 	if(_getpw(&num, &nam, &mem)){
 		holdpw.pw_name = nam;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/link.c
--- a/sys/src/ape/lib/ap/plan9/link.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/link.c	Thu Jun 20 19:14:05 2019 -0700
@@ -5,7 +5,7 @@
  * BUG: LINK_MAX==1 isn't really allowed
  */
 int
-link(const char *name1, const char *name2)
+link(const char *, const char *)
 {
 	errno = EMLINK;
 	return -1;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/mkfile
--- a/sys/src/ape/lib/ap/plan9/mkfile	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/mkfile	Thu Jun 20 19:14:05 2019 -0700
@@ -107,6 +107,6 @@
 
 </sys/src/cmd/mksyslib
 
-CFLAGS=-c -D_POSIX_SOURCE -D_PLAN9_SOURCE -D_BSD_EXTENSION
+CFLAGS=$CFLAGS -c -D_POSIX_SOURCE -D_PLAN9_SOURCE -D_BSD_EXTENSION
 
 $OFILES: lib.h
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/opendir.c
--- a/sys/src/ape/lib/ap/plan9/opendir.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/opendir.c	Thu Jun 20 19:14:05 2019 -0700
@@ -26,7 +26,7 @@
 		s[n++] = '/';
 		s[n] = 0;
 	} else
-		s = filename;
+		s = (char*)filename;
 	f = open(s, O_RDONLY);
 	if(s != filename)
 		free(s);
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/pause.c
--- a/sys/src/ape/lib/ap/plan9/pause.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/pause.c	Thu Jun 20 19:14:05 2019 -0700
@@ -7,5 +7,5 @@
 {
 	for(;;)
 		if(_SLEEP(1000*1000) < 0)
-			return;
+			return -1;
 }
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/read.c
--- a/sys/src/ape/lib/ap/plan9/read.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/read.c	Thu Jun 20 19:14:05 2019 -0700
@@ -12,7 +12,7 @@
 	int n, noblock, isbuf;
 	Fdinfo *f;
 
-	if(d<0 || d>=OPEN_MAX || !((f = &_fdinfo[d])->flags&FD_ISOPEN)){
+	if(d<0 || d>=OPEN_MAX || !(_fdinfo[d].flags & FD_ISOPEN)){
 		errno = EBADF;
 		return -1;
 	}
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/rename.c
--- a/sys/src/ape/lib/ap/plan9/rename.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/rename.c	Thu Jun 20 19:14:05 2019 -0700
@@ -10,7 +10,7 @@
 int
 rename(const char *from, const char *to)
 {
-	int n, i;
+	int n, ffd, tfd;
 	char *f, *t;
 	Dir *d, nd;
 
@@ -31,45 +31,45 @@
 	}
 	f = strrchr(from, '/');
 	t = strrchr(to, '/');
-	f = f? f+1 : from;
-	t = t? t+1 : to;
-	n = 0;
+	f = f? f+1 : (char*)from;
+	t = t? t+1 : (char*)to;
 	if(f-from==t-to && strncmp(from, to, f-from)==0){
 		/* from and to are in same directory (we miss some cases) */
-		i = strlen(t);
 		_nulldir(&nd);
 		nd.name = t;
 		if(_dirwstat(from, &nd) < 0){
 			_syserrno();
-			n = -1;
+			return -1;
 		}
 	}else{
 		/* different directories: have to copy */
-		int ffd, tfd;
 		char buf[8192];
 
-		if((ffd = _OPEN(from, OREAD)) < 0 ||
-		   (tfd = _CREATE(to, OWRITE, d->mode)) < 0){
-			_CLOSE(ffd);
-			_syserrno();
-			n = -1;
+
+		if((ffd = _OPEN(from, OREAD)) == -1)
+			goto err1;
+		if((tfd = _CREATE(to, OWRITE, d->mode)) == -1)
+			goto err2;
+		n = 0;
+		while(n>=0){
+			if((n = _READ(ffd, buf, sizeof(buf))) == -1)
+				goto err2;
+			if(_WRITE(tfd, buf, n) != n)
+				goto err2;
 		}
-		while(n>=0 && (n = _READ(ffd, buf, sizeof(buf))) > 0)
-			if(_WRITE(tfd, buf, n) != n){
-				_syserrno();
-				n = -1;
-			}
 		_CLOSE(ffd);
 		_CLOSE(tfd);
-		if(n>0)
-			n = 0;
-		if(n == 0) {
-			if(_REMOVE(from) < 0){
-				_syserrno();
-				return -1;
-			}
-		}
+		if(_REMOVE(from) < 0)
+			goto err2;
 	}
 	free(d);
-	return n;
+	return 0;
+
+err2:
+	_CLOSE(tfd);
+err1:
+	_CLOSE(ffd);
+	_syserrno();
+	free(d);
+	return -1;
 }
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/setgid.c
--- a/sys/src/ape/lib/ap/plan9/setgid.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/setgid.c	Thu Jun 20 19:14:05 2019 -0700
@@ -7,7 +7,7 @@
  */
 
 int
-setgid(gid_t gid)
+setgid(gid_t)
 {
 	errno = EPERM;
 	return -1;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/setuid.c
--- a/sys/src/ape/lib/ap/plan9/setuid.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/setuid.c	Thu Jun 20 19:14:05 2019 -0700
@@ -7,7 +7,7 @@
  */
 
 int
-setuid(uid_t uid)
+setuid(uid_t)
 {
 	errno = EPERM;
 	return -1;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/signal.c
--- a/sys/src/ape/lib/ap/plan9/signal.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/signal.c	Thu Jun 20 19:14:05 2019 -0700
@@ -107,7 +107,7 @@
 				/* notetramp is machine-dependent; doesn't return to here */
 			}
 			_NOTED(0); /* NCONT */
-			return;
+			return 0;
 		}
 	}
 	_doatexits();
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/sigsuspend.c
--- a/sys/src/ape/lib/ap/plan9/sigsuspend.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/sigsuspend.c	Thu Jun 20 19:14:05 2019 -0700
@@ -6,7 +6,7 @@
  */
 
 int
-sigsuspend(sigset_t *set)
+sigsuspend(sigset_t *)
 {
 	errno = EINVAL;
 	return -1;
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/tcgetattr.c
--- a/sys/src/ape/lib/ap/plan9/tcgetattr.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/tcgetattr.c	Thu Jun 20 19:14:05 2019 -0700
@@ -87,7 +87,7 @@
 /* BUG: ignores optional actions */
 
 int
-tcsetattr(int fd, int optactions, const struct termios *t)
+tcsetattr(int fd, int, const struct termios *t)
 {
 	int n, i;
 	char buf[100];
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/umask.c
--- a/sys/src/ape/lib/ap/plan9/umask.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/umask.c	Thu Jun 20 19:14:05 2019 -0700
@@ -7,7 +7,7 @@
  */
 
 mode_t
-umask(mode_t numask)
+umask(mode_t)
 {
 	return 0;
 }
diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/unlink.c
--- a/sys/src/ape/lib/ap/plan9/unlink.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/unlink.c	Thu Jun 20 19:14:05 2019 -0700
@@ -26,6 +26,7 @@
 		_syserrno();
 		return -1;
 	}
+	n = -1;
 	fd = -1;
 	for(i=0, f = _fdinfo;i < OPEN_MAX; i++, f++) {
 		if((f->flags&FD_ISOPEN) && (db2=_dirfstat(i)) != nil) {
diff -r aedb4c585577 sys/src/ape/lib/ap/posix/getpwent.c
--- a/sys/src/ape/lib/ap/posix/getpwent.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/posix/getpwent.c	Thu Jun 20 19:14:05 2019 -0700
@@ -49,7 +49,7 @@
 	passwd.pw_dir = p;
 	p = pwskip(p);
 	passwd.pw_shell = p;
-	p = pwskip(p);
+	pwskip(p);
 	return(&passwd);
 }
 
diff -r aedb4c585577 sys/src/ape/lib/ap/posix/mkfifo.c
--- a/sys/src/ape/lib/ap/posix/mkfifo.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/posix/mkfifo.c	Thu Jun 20 19:14:05 2019 -0700
@@ -3,7 +3,7 @@
 #include	<errno.h>
 
 int
-mkfifo(char *path, mode_t mode)
+mkfifo(char *, mode_t)
 {
 #pragma ref path
 #pragma ref mode
diff -r aedb4c585577 sys/src/ape/lib/ap/posix/mkfile
--- a/sys/src/ape/lib/ap/posix/mkfile	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/posix/mkfile	Thu Jun 20 19:14:05 2019 -0700
@@ -14,4 +14,4 @@
 
 </sys/src/cmd/mksyslib
 
-CFLAGS=-c -D_POSIX_SOURCE
+CFLAGS=$CFLAGS -c -D_POSIX_SOURCE
diff -r aedb4c585577 sys/src/ape/lib/ap/posix/pathconf.c
--- a/sys/src/ape/lib/ap/posix/pathconf.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/posix/pathconf.c	Thu Jun 20 19:14:05 2019 -0700
@@ -4,7 +4,7 @@
 #include	<sys/limits.h>
 
 long
-pathconf(const char *path, int name)
+pathconf(const char *, int name)
 {
 #pragma ref path
 
@@ -46,10 +46,8 @@
 }
 
 long
-fpathconf(int fd, int name)
+fpathconf(int, int name)
 {
-#pragma ref fd
-
 	return pathconf(0, name);
 }
 
diff -r aedb4c585577 sys/src/ape/lib/ap/posix/tzset.c
--- a/sys/src/ape/lib/ap/posix/tzset.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/posix/tzset.c	Thu Jun 20 19:14:05 2019 -0700
@@ -20,6 +20,7 @@
 {
 	char *env, *p, *q;
 	
+	env = NULL;
 	if((p = getenv("timezone")) == 0)
 		goto error;
 	if((env = malloc(strlen(p) + 1)) == 0)
diff -r aedb4c585577 sys/src/ape/lib/ap/stdio/_fconv.c
--- a/sys/src/ape/lib/ap/stdio/_fconv.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/stdio/_fconv.c	Thu Jun 20 19:14:05 2019 -0700
@@ -509,7 +509,7 @@
 			}
 		else
 			x[0] = y;
-		i = b->wds = (x[1] = z) ? 2 : 1;
+		b->wds = (x[1] = z) ? 2 : 1;
 		}
 	else {
 #ifdef DEBUG
@@ -518,7 +518,7 @@
 #endif
 		k = lo0bits(&z);
 		x[0] = z;
-		i = b->wds = 1;
+		b->wds = 1;
 		k += 32;
 		}
 #else
diff -r aedb4c585577 sys/src/ape/lib/ap/stdio/ftoa.c
--- a/sys/src/ape/lib/ap/stdio/ftoa.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/stdio/ftoa.c	Thu Jun 20 19:14:05 2019 -0700
@@ -27,7 +27,7 @@
 		e1=e/2;
 		e2=e-e1;
 		p=f*pow10(e2);
-		while((g=p*pow10(e1))<1.) e1++;
+		while((p*pow10(e1))<1.) e1++;
 		while((g=p*pow10(e1))>=10.) --e1;
 		e=e1+e2;
 		f=g;
diff -r aedb4c585577 sys/src/ape/lib/ap/stdio/mkfile
--- a/sys/src/ape/lib/ap/stdio/mkfile	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/stdio/mkfile	Thu Jun 20 19:14:05 2019 -0700
@@ -66,4 +66,4 @@
 
 </sys/src/cmd/mksyslib
 
-CFLAGS=-c -D_POSIX_SOURCE
+CFLAGS=$CFLAGS -c -D_POSIX_SOURCE
diff -r aedb4c585577 sys/src/ape/lib/ap/stdio/vfprintf.c
--- a/sys/src/ape/lib/ap/stdio/vfprintf.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/stdio/vfprintf.c	Thu Jun 20 19:14:05 2019 -0700
@@ -3,6 +3,7 @@
  */
 #include "iolib.h"
 #include <stdarg.h>
+#include <stdint.h>
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
@@ -218,9 +219,8 @@
 }
 
 static int
-ocvt_c(FILE *f, va_list *args, int flags, int width, int precision)
+ocvt_c(FILE *f, va_list *args, int flags, int width, int)
 {
-#pragma ref precision
 	int i;
 
 	if(!(flags&LEFT)) for(i=1; i<width; i++) putc(' ', f);
@@ -269,11 +269,8 @@
 }
 
 static int
-ocvt_n(FILE *f, va_list *args, int flags, int width, int precision)
+ocvt_n(FILE *, va_list *args, int flags, int, int)
 {
-#pragma ref f
-#pragma ref width
-#pragma ref precision
 	if(flags&SHORT)
 		*va_arg(*args, short *) = nprint;
 	else if(flags&LONG)
@@ -307,7 +304,7 @@
 	int nout, npad, nlzero;
 
 	if(sgned){
-		if(flags&PTR) snum = (long)va_arg(*args, void *);
+		if(flags&PTR) snum = (uintptr_t)va_arg(*args, void *);
 		else if(flags&SHORT) snum = va_arg(*args, short);
 		else if(flags&LONG) snum = va_arg(*args, long);
 		else if(flags&VLONG) snum = va_arg(*args, long long);
@@ -323,7 +320,7 @@
 		}
 	} else {
 		sign = "";
-		if(flags&PTR) num = (long)va_arg(*args, void *);
+		if(flags&PTR) num = (uintptr_t)va_arg(*args, void *);
 		else if(flags&SHORT) num = va_arg(*args, unsigned short);
 		else if(flags&LONG) num = va_arg(*args, unsigned long);
 		else if(flags&VLONG) num = va_arg(*args, unsigned long long);
diff -r aedb4c585577 sys/src/ape/lib/ap/stdio/vfscanf.c
--- a/sys/src/ape/lib/ap/stdio/vfscanf.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/stdio/vfscanf.c	Thu Jun 20 19:14:05 2019 -0700
@@ -60,7 +60,8 @@
 static int nread, ncvt;
 static const char *fmtp;
 
-int vfscanf(FILE *f, const char *s, va_list args){
+int vfscanf(FILE *f, const char *s, va_list args)
+{
 	int c, width, type, store;
 	nread=0;
 	ncvt=0;
@@ -105,9 +106,10 @@
 	}
 	return ncvt;	
 }
-static int icvt_n(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref f
-#pragma ref width
+
+static int
+icvt_n(FILE *, va_list *args, int store, int, int type)
+{
 	if(store){
 		--ncvt;	/* this assignment doesn't count! */
 		switch(type){
@@ -119,6 +121,7 @@
 	}
 	return 1;
 }
+
 #define	SIGNED		1
 #define	UNSIGNED	2
 #define	POINTER		3
@@ -132,7 +135,8 @@
  *	unsgned is SIGNED, UNSIGNED or POINTER, giving part of the type to store in;
  *	base is the number base -- if 0, C number syntax is used.
  */
-static int icvt_fixed(FILE *f, va_list *args,
+static int
+icvt_fixed(FILE *f, va_list *args,
 				int store, int width, int type, int unsgned, int base){
 	unsigned long int num=0;
 	int sign=1, ndig=0, dig;
@@ -211,26 +215,46 @@
 	}
 	return 1;
 }
-static int icvt_d(FILE *f, va_list *args, int store, int width, int type){
+
+static int
+icvt_d(FILE *f, va_list *args, int store, int width, int type)
+{
 	return icvt_fixed(f, args, store, width, type, SIGNED, 10);
 }
-static int icvt_x(FILE *f, va_list *args, int store, int width, int type){
+
+static int
+icvt_x(FILE *f, va_list *args, int store, int width, int type)
+{
 	return icvt_fixed(f, args, store, width, type, UNSIGNED, 16);
 }
-static int icvt_o(FILE *f, va_list *args, int store, int width, int type){
+
+static int
+icvt_o(FILE *f, va_list *args, int store, int width, int type)
+{
 	return icvt_fixed(f, args, store, width, type, UNSIGNED, 8);
 }
-static int icvt_i(FILE *f, va_list *args, int store, int width, int type){
+
+static int
+icvt_i(FILE *f, va_list *args, int store, int width, int type)
+{
 	return icvt_fixed(f, args, store, width, type, SIGNED, 0);
 }
-static int icvt_u(FILE *f, va_list *args, int store, int width, int type){
+
+static int
+icvt_u(FILE *f, va_list *args, int store, int width, int type)
+{
 	return icvt_fixed(f, args, store, width, type, UNSIGNED, 10);
 }
-static int icvt_p(FILE *f, va_list *args, int store, int width, int type){
+
+static int
+icvt_p(FILE *f, va_list *args, int store, int width, int type)
+{
 	return icvt_fixed(f, args, store, width, type, POINTER, 16);
 }
 #define	NBUF	509
-static int icvt_f(FILE *f, va_list *args, int store, int width, int type){
+static int
+icvt_f(FILE *f, va_list *args, int store, int width, int type)
+{
 	char buf[NBUF+1];
 	char *s=buf;
 	int c, ndig=0, ndpt=0, nexp=1;
@@ -278,11 +302,16 @@
 	}
 	return 1;
 }
-static int icvt_s(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
+
+static int
+icvt_s(FILE *f, va_list *args, int store, int width, int)
+{
 	int c, nn;
-	register char *s;
-	if(store) s=va_arg(*args, char *);
+	char *s;
+
+	s = 0;
+	if(store)
+		s=va_arg(*args, char *);
 	do
 		c=ngetc(f);
 	while(isspace(c));
@@ -298,7 +327,8 @@
 			else goto Done;
 		}
 		nn++;
-		if(store) *s++=c;
+		if(store)
+			*s++=c;
 		wgetc(c, f, Done);
 	}
 	nungetc(c, f);
@@ -306,21 +336,27 @@
 	if(store) *s='\0';
 	return 1;
 }
-static int icvt_c(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
+static int
+icvt_c(FILE *f, va_list *args, int store, int width, int)
+{
 	int c;
-	register char *s;
-	if(store) s=va_arg(*args, char *);
+	char *s;
+
+	s = 0;
+	if(store)
+		s=va_arg(*args, char *);
 	if(width<0) width=1;
 	for(;;){
 		wgetc(c, f, Done);
 		if(c==EOF) return 0;
-		if(store) *s++=c;
+		if(store)
+			*s++=c;
 	}
 Done:
 	return 1;
 }
-static int match(int c, const char *pat){
+static int match(int c, const char *pat)
+{
 	int ok=1;
 	if(*pat=='^'){
 		ok=!ok;
@@ -338,16 +374,20 @@
 	}
 	return !ok;
 }
-static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
+static int
+icvt_sq(FILE *f, va_list *args, int store, int width, int)
+{
 	int c, nn;
-	register char *s;
-	register const char *pat;
-	pat=++fmtp;
+	char *s;
+	char *pat;
+
+	s = 0;
+	pat=(char*)++fmtp;
 	if(*fmtp=='^') fmtp++;
 	if(*fmtp!='\0') fmtp++;
 	while(*fmtp!='\0' && *fmtp!=']') fmtp++;
-	if(store) s=va_arg(*args, char *);
+	if(store)
+		s=va_arg(*args, char *);
 	nn=0;
 	for(;;){
 		wgetc(c, f, Done);
@@ -356,8 +396,10 @@
 			if(nn==0) return 0;
 			else goto Done;
 		}
-		if(!match(c, pat)) break;
-		if(store) *s++=c;
+		if(!match(c, pat))
+			break;
+		if(store)
+			*s++=c;
 		nn++;
 	}
 	nungetc(c, f);



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [9front] Enable and fix warnings in ape/lib/ap
@ 2019-06-20 10:30 cinap_lenrek
  0 siblings, 0 replies; 2+ messages in thread
From: cinap_lenrek @ 2019-06-20 10:30 UTC (permalink / raw)
  To: 9front

looking fine, except two small issues:

--- a/sys/src/ape/lib/ap/plan9/_buf.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/_buf.c	Wed Jun 19 22:55:29 2019 -0700
@@ -57,7 +58,7 @@
 	if(mux == 0){
 		_RFORK(RFREND);
 		mux = (Muxseg*)_SEGATTACH(0, "shared", 0, sizeof(Muxseg));
-		if((long)mux == -1){
+		if((uintptr_t)mux == -1){
 			_syserrno();
 			return -1;
 		}

might be better comparing mux == (void*)-1, which is also the
definition of the error code in the manpge.

      DIAGNOSTICS
          These functions set errstr. Segattach returns (void*)-1 on
          error.

---

diff -r aedb4c585577 sys/src/ape/lib/ap/plan9/rename.c
--- a/sys/src/ape/lib/ap/plan9/rename.c	Thu Jun 20 00:36:51 2019 +0200
+++ b/sys/src/ape/lib/ap/plan9/rename.c	Wed Jun 19 22:55:29 2019 -0700

-		if((ffd = _OPEN(from, OREAD)) < 0 ||
-		   (tfd = _CREATE(to, OWRITE, d->mode)) < 0){
-			_CLOSE(ffd);
+		tfd = _CREATE(to, OWRITE, d->mode);
+		ffd = _OPEN(from, OREAD);
+		if(ffd == -1 || tfd == -1){

this changes the order which means we would leave marooned
destination file arround.

i think it would be easier to just have the two blocks nested. and not
trying to handle it in one block.

--
cinap


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-06-21  2:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-21  2:16 [9front] Enable and fix warnings in ape/lib/ap ori
  -- strict thread matches above, loose matches on Subject: below --
2019-06-20 10:30 cinap_lenrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).