[hackers] [9base] Sync lib9 with plan9port. Fix build with bsdmake. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Mon, 19 Jul 2010 15:50:33 +0000 (UTC)

changeset: 78:84e25376f0a4
tag: tip
user: Kris Maglione <maglione.k_AT_gmail.com>
date: Mon Jul 19 11:50:26 2010 -0400
files: diff/Makefile lib9/Makefile lib9/_p9dir.c lib9/bio/bgetrune.c lib9/bio/bputrune.c lib9/convM2S.c lib9/convS2M.c lib9/dial.c lib9/dirread.c lib9/fcall.h lib9/fmt.h lib9/fmt/dofmt.c lib9/libc.h lib9/u.h lib9/utf.h lib9/utf/rune.c
description:
Sync lib9 with plan9port. Fix build with bsdmake.

diff -r 351055ae4ff5 -r 84e25376f0a4 diff/Makefile
--- a/diff/Makefile Mon Jul 19 07:49:13 2010 +0100
+++ b/diff/Makefile Mon Jul 19 11:50:26 2010 -0400
@@ -32,4 +32,4 @@
 
 ${TARG}: ${OFILES}
         @echo LD ${TARG}
- @${CC} ${LDFLAGS} -o ${TARG} ${OFILES} -lm -L${PREFIX}/lib -L../lib9 -l9
+ ${CC} ${LDFLAGS} -o ${TARG} ${OFILES} -lm -L../lib9 -L${PREFIX}/lib -l9
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/Makefile
--- a/lib9/Makefile Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/Makefile Mon Jul 19 11:50:26 2010 -0400
@@ -221,8 +221,8 @@
         @${AR} ${LIB} ${OFILES}
 
 .c.o:
- @echo CC $*.c
- @${CC} -o $*.o ${CFLAGS} -Isec -I${PREFIX}/include $*.c
+ @echo CC $<
+ @${CC} -o $@ ${CFLAGS} -Isec -I${PREFIX}/include $<
 
 clean:
         rm -f ${OFILES} ${LIB}
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/_p9dir.c
--- a/lib9/_p9dir.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/_p9dir.c Mon Jul 19 11:50:26 2010 -0400
@@ -44,7 +44,6 @@
 #define _HAVESTGEN
 #include <sys/disklabel.h>
 #include <sys/ioctl.h>
-#include <sys/dkio.h>
 static vlong
 disksize(int fd, struct stat *st)
 {
@@ -190,7 +189,14 @@
                 d->type = 'M';
 
                 d->muid = "";
- d->qid.path = ((uvlong)st->st_dev<<32) | st->st_ino;
+ d->qid.path = st->st_ino;
+ /*
+ * do not include st->st_dev in path, because
+ * automounters give the same file system different
+ * st_dev values for successive mounts, causing
+ * spurious write warnings in acme and sam.
+ d->qid.path |= (uvlong)st->st_dev<<32;
+ */
 #ifdef _HAVESTGEN
                 d->qid.vers = st->st_gen;
 #endif
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/bio/bgetrune.c
--- a/lib9/bio/bgetrune.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/bio/bgetrune.c Mon Jul 19 11:50:26 2010 -0400
@@ -7,7 +7,7 @@
 {
         int c, i;
         Rune rune;
- char str[4];
+ char str[UTFmax];
 
         c = Bgetc(bp);
         if(c < Runeself) { /* one char */
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/bio/bputrune.c
--- a/lib9/bio/bputrune.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/bio/bputrune.c Mon Jul 19 11:50:26 2010 -0400
@@ -6,7 +6,7 @@
 Bputrune(Biobuf *bp, long c)
 {
         Rune rune;
- char str[4];
+ char str[UTFmax];
         int n;
 
         rune = c;
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/convM2S.c
--- a/lib9/convM2S.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/convM2S.c Mon Jul 19 11:50:26 2010 -0400
@@ -100,6 +100,13 @@
                 p = gstring(p, ep, &f->aname);
                 if(p == nil)
                         break;
+ f->uidnum = NOUID;
+ if(dotu){
+ if(p+BIT32SZ > ep)
+ return 0;
+ f->uidnum = GBIT32(p);
+ p += BIT32SZ;
+ }
                 break;
 
         case Tattach:
@@ -117,6 +124,13 @@
                 p = gstring(p, ep, &f->aname);
                 if(p == nil)
                         break;
+ f->uidnum = NOUID;
+ if(dotu){
+ if(p+BIT32SZ > ep)
+ return 0;
+ f->uidnum = GBIT32(p);
+ p += BIT32SZ;
+ }
                 break;
 
         case Twalk:
@@ -233,10 +247,10 @@
                 p = gstring(p, ep, &f->ename);
                 f->errornum = 0;
                 if(dotu){
- if(p+BIT16SZ > ep)
+ if(p+BIT32SZ > ep)
                                 return 0;
- f->errornum = GBIT16(p);
- p += BIT16SZ;
+ f->errornum = GBIT32(p);
+ p += BIT32SZ;
                 }
                 break;
 
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/convS2M.c
--- a/lib9/convS2M.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/convS2M.c Mon Jul 19 11:50:26 2010 -0400
@@ -74,6 +74,8 @@
                 n += BIT32SZ;
                 n += stringsz(f->uname);
                 n += stringsz(f->aname);
+ if(dotu)
+ n += BIT32SZ;
                 break;
 
         case Tattach:
@@ -81,6 +83,8 @@
                 n += BIT32SZ;
                 n += stringsz(f->uname);
                 n += stringsz(f->aname);
+ if(dotu)
+ n += BIT32SZ;
                 break;
 
         case Twalk:
@@ -144,7 +148,7 @@
         case Rerror:
                 n += stringsz(f->ename);
                 if(dotu)
- n += BIT16SZ;
+ n += BIT32SZ;
                 break;
 
         case Rflush:
@@ -249,6 +253,11 @@
                 p += BIT32SZ;
                 p = pstring(p, f->uname);
                 p = pstring(p, f->aname);
+ if(dotu){
+ f->uidnum = NOUID;
+ PBIT32(p, f->uidnum);
+ p += BIT32SZ;
+ }
                 break;
 
         case Tattach:
@@ -258,6 +267,11 @@
                 p += BIT32SZ;
                 p = pstring(p, f->uname);
                 p = pstring(p, f->aname);
+ if(dotu){
+ f->uidnum = NOUID;
+ PBIT32(p, f->uidnum);
+ p += BIT32SZ;
+ }
                 break;
 
         case Twalk:
@@ -344,8 +358,8 @@
         case Rerror:
                 p = pstring(p, f->ename);
                 if(dotu){
- PBIT16(p, f->errornum);
- p += BIT16SZ;
+ PBIT32(p, f->errornum);
+ p += BIT32SZ;
                 }
                 break;
 
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/dial.c
--- a/lib9/dial.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/dial.c Mon Jul 19 11:50:26 2010 -0400
@@ -46,6 +46,11 @@
                 free(buf);
                 return -1;
         }
+ if(strcmp(net, "unix") != 0 && host == 0){
+ werrstr("invalid dial address 0.0.0.0 (aka *)");
+ free(buf);
+ return -1;
+ }
 
         if(strcmp(net, "tcp") == 0)
                 proto = SOCK_STREAM;
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/dirread.c
--- a/lib9/dirread.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/dirread.c Mon Jul 19 11:50:26 2010 -0400
@@ -6,7 +6,7 @@
 
 extern int _p9dir(struct stat*, struct stat*, char*, Dir*, char**, char*);
 
-#if defined(__linux__) || defined(__FreeBSD_kernel__)
+#if defined(__linux__)
 static int
 mygetdents(int fd, struct dirent *buf, int n)
 {
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/fcall.h
--- a/lib9/fcall.h Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/fcall.h Mon Jul 19 11:50:26 2010 -0400
@@ -34,20 +34,25 @@
         ushort nwname; /* Twalk */
         char *wname[MAXWELEM]; /* Twalk */
         ushort nwqid; /* Rwalk */
- Qid wqid[MAXWELEM]; /* Rwalk */
+ Qid wqid[MAXWELEM]; /* Rwalk */
         vlong offset; /* Tread, Twrite */
         u32int count; /* Tread, Twrite, Rread */
         char *data; /* Twrite, Rread */
         ushort nstat; /* Twstat, Rstat */
         uchar *stat; /* Twstat, Rstat */
         int unixfd; /* Ropenfd */
+
+ /* 9P2000.u extensions */
+ int errornum; /* Rerror */
+ int uidnum; /* Tattach, Tauth */
+ char *extension; /* Tcreate */
 } Fcall;
 
 
 #define GBIT8(p) ((p)[0])
 #define GBIT16(p) ((p)[0]|((p)[1]<<8))
-#define GBIT32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
-#define GBIT64(p) ((vlong)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
+#define GBIT32(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)))
+#define GBIT64(p) ((u32int)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
                                 ((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
 
 #define PBIT8(p,v) (p)[0]=(v)
@@ -65,9 +70,11 @@
 /* STATFIXLEN includes leading 16-bit count */
 /* The count, however, excludes itself; total size is BIT16SZ+count */
 #define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */
+#define STATFIXLENU (STATFIXLEN+BIT16SZ+3*BIT32SZ) /* for 9P2000.u */
 
 #define NOTAG (ushort)~0U /* Dummy tag */
 #define NOFID (u32int)~0U /* Dummy fid */
+#define NOUID (-1) /* Dummy uid */
 #define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */
 
 enum
@@ -103,7 +110,7 @@
         Tmax,
 
         Topenfd = 98,
- Ropenfd,
+ Ropenfd
 };
 
 uint convM2S(uchar*, uint, Fcall*);
@@ -115,6 +122,15 @@
 uint convD2M(Dir*, uchar*, uint);
 uint sizeD2M(Dir*);
 
+uint convM2Su(uchar*, uint, Fcall*, int);
+uint convS2Mu(Fcall*, uchar*, uint, int);
+uint sizeS2Mu(Fcall*, int);
+
+int statchecku(uchar *abuf, uint nbuf, int);
+uint convM2Du(uchar*, uint, Dir*, char*, int);
+uint convD2Mu(Dir*, uchar*, uint, int);
+uint sizeD2Mu(Dir*, int);
+
 int fcallfmt(Fmt*);
 int dirfmt(Fmt*);
 int dirmodefmt(Fmt*);
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/fmt.h
--- a/lib9/fmt.h Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/fmt.h Mon Jul 19 11:50:26 2010 -0400
@@ -30,7 +30,7 @@
         void *farg; /* to make flush a closure */
         int nfmt; /* num chars formatted so far */
         va_list args; /* args passed to dofmt */
- int r; /* % format Rune */
+ Rune r; /* % format Rune */
         int width;
         int prec;
         unsigned long flags;
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/fmt/dofmt.c
--- a/lib9/fmt/dofmt.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/fmt/dofmt.c Mon Jul 19 11:50:26 2010 -0400
@@ -605,12 +605,13 @@
 int
 __badfmt(Fmt *f)
 {
- char x[3];
+ char x[2+UTFmax];
+ int n;
 
         x[0] = '%';
- x[1] = f->r;
- x[2] = '%';
- f->prec = 3;
- __fmtcpy(f, (const void*)x, 3, 3);
+ n = 1 + runetochar(x+1, &f->r);
+ x[n++] = '%';
+ f->prec = n;
+ __fmtcpy(f, (const void*)x, n, n);
         return 0;
 }
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/libc.h
--- a/lib9/libc.h Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/libc.h Mon Jul 19 11:50:26 2010 -0400
@@ -66,10 +66,11 @@
 /*
 enum
 {
- UTFmax = 3,
+ UTFmax = 4,
         Runesync = 0x80,
         Runeself = 0x80,
- Runeerror = 0x80,
+ Runeerror = 0xFFFD,
+ Runemax = 0x10FFFF,
 };
 */
 
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/u.h
--- a/lib9/u.h Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/u.h Mon Jul 19 11:50:26 2010 -0400
@@ -32,6 +32,9 @@
 #if defined(__AIX__)
 # define _XOPEN_SOURCE 1
 #endif
+#if defined(__APPLE__)
+# define _DARWIN_NO_64_BIT_INODE /* Snow Leopard */
+#endif
 #define _LARGEFILE64_SOURCE 1
 #define _FILE_OFFSET_BITS 64
 
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/utf.h
--- a/lib9/utf.h Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/utf.h Mon Jul 19 11:50:26 2010 -0400
@@ -4,14 +4,14 @@
 extern "C" {
 #endif
 
-typedef unsigned short Rune; /* 16 bits */
+typedef unsigned int Rune; /* 32 bits */
 
 enum
 {
- UTFmax = 3, /* maximum bytes per rune */
+ UTFmax = 4, /* maximum bytes per rune */
         Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */
         Runeself = 0x80, /* rune and UTF sequences are the same (<) */
- Runeerror = 0xFFFD, /* decoding error in UTF */
+ Runeerror = 0xFFFD, /* decoding error in UTF */
         Runemax = 0x10FFFF /* maximum rune value */
 };
 
diff -r 351055ae4ff5 -r 84e25376f0a4 lib9/utf/rune.c
--- a/lib9/utf/rune.c Mon Jul 19 07:49:13 2010 +0100
+++ b/lib9/utf/rune.c Mon Jul 19 11:50:26 2010 -0400
@@ -23,16 +23,19 @@
         Bit2 = 5,
         Bit3 = 4,
         Bit4 = 3,
+ Bit5 = 2,
 
         T1 = ((1<<(Bit1+1))-1) ^ 0xFF, /* 0000 0000 */
         Tx = ((1<<(Bitx+1))-1) ^ 0xFF, /* 1000 0000 */
         T2 = ((1<<(Bit2+1))-1) ^ 0xFF, /* 1100 0000 */
         T3 = ((1<<(Bit3+1))-1) ^ 0xFF, /* 1110 0000 */
         T4 = ((1<<(Bit4+1))-1) ^ 0xFF, /* 1111 0000 */
+ T5 = ((1<<(Bit5+1))-1) ^ 0xFF, /* 1111 1000 */
 
- Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0111 1111 */
- Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0111 1111 1111 */
- Rune3 = (1<<(Bit3+2*Bitx))-1, /* 1111 1111 1111 1111 */
+ Rune1 = (1<<(Bit1+0*Bitx))-1, /* 0000 0000 0000 0000 0111 1111 */
+ Rune2 = (1<<(Bit2+1*Bitx))-1, /* 0000 0000 0000 0111 1111 1111 */
+ Rune3 = (1<<(Bit3+2*Bitx))-1, /* 0000 0000 1111 1111 1111 1111 */
+ Rune4 = (1<<(Bit4+3*Bitx))-1, /* 0011 1111 1111 1111 1111 1111 */
 
         Maskx = (1<<Bitx)-1, /* 0011 1111 */
         Testx = Maskx ^ 0xFF, /* 1100 0000 */
@@ -43,7 +46,7 @@
 int
 chartorune(Rune *rune, char *str)
 {
- int c, c1, c2;
+ int c, c1, c2, c3;
         long l;
 
         /*
@@ -89,6 +92,25 @@
         }
 
         /*
+ * four character sequence
+ * 10000-10FFFF => T4 Tx Tx Tx
+ */
+ if(UTFmax >= 4) {
+ c3 = *(uchar*)(str+3) ^ Tx;
+ if(c3 & Testx)
+ goto bad;
+ if(c < T5) {
+ l = ((((((c << Bitx) | c1) << Bitx) | c2) << Bitx) | c3) & Rune4;
+ if(l <= Rune3)
+ goto bad;
+ if(l > Runemax)
+ goto bad;
+ *rune = l;
+ return 4;
+ }
+ }
+
+ /*
          * bad decoding
          */
 bad:
@@ -113,7 +135,7 @@
 
         /*
          * two character sequence
- * 0080-07FF => T2 Tx
+ * 00080-007FF => T2 Tx
          */
         if(c <= Rune2) {
                 str[0] = T2 | (c >> 1*Bitx);
@@ -123,12 +145,26 @@
 
         /*
          * three character sequence
- * 0800-FFFF => T3 Tx Tx
+ * 00800-0FFFF => T3 Tx Tx
          */
- str[0] = T3 | (c >> 2*Bitx);
- str[1] = Tx | ((c >> 1*Bitx) & Maskx);
- str[2] = Tx | (c & Maskx);
- return 3;
+ if(c > Runemax)
+ c = Runeerror;
+ if(c <= Rune3) {
+ str[0] = T3 | (c >> 2*Bitx);
+ str[1] = Tx | ((c >> 1*Bitx) & Maskx);
+ str[2] = Tx | (c & Maskx);
+ return 3;
+ }
+
+ /*
+ * four character sequence
+ * 010000-1FFFFF => T4 Tx Tx Tx
+ */
+ str[0] = T4 | (c >> 3*Bitx);
+ str[1] = Tx | ((c >> 2*Bitx) & Maskx);
+ str[2] = Tx | ((c >> 1*Bitx) & Maskx);
+ str[3] = Tx | (c & Maskx);
+ return 4;
 }
 
 int
@@ -155,7 +191,10 @@
                 if(c <= Rune2)
                         nb += 2;
                 else
+ if(c <= Rune3 || c > Runemax)
                         nb += 3;
+ else
+ nb += 4;
         }
         return nb;
 }
@@ -165,13 +204,14 @@
 {
         int c;
 
- if(n > 0) {
- c = *(uchar*)str;
- if(c < Tx)
- return 1;
- if(n > 1)
- if(c < T3 || n > 2)
- return 1;
- }
- return 0;
+ if(n <= 0)
+ return 0;
+ c = *(uchar*)str;
+ if(c < Tx)
+ return 1;
+ if(c < T3)
+ return n >= 2;
+ if(UTFmax == 3 || c < T4)
+ return n >= 3;
+ return n >= 4;
 }
Received on Mon Jul 19 2010 - 17:50:33 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 19 2010 - 18:00:08 CEST