i was playing with pcc+musl and compiled various
libs including 9base with them

i found that there are two versions of the fmt lib
in 9base/plan9port: plan9 style and ansi style
(former is used when PLAN9PORT is defined)

the problem is that all the commands seem to
expect the plan9 style fmt

eg unsigned decimal and unsigned hexadecimal
formating is different:
plan9: %ud %ux
ansi: %u %x

this can cause all sort of issues eg ls -l or du
prints file sizes with a 'd' suffix

so essentially the tools are unusable if
PLAN9PORT is not defined (ansi style fmt,
the default in 9base)

imho this should be fixed in p9p by using ifdef
PLAN9PORT in all the tools where necessary
(as it is done in some places under lib9/)

in 9base we either define PLAN9PORT (it has some
other effects beyond the formatting style..)
or manually fix the formats in the source to use
the ansi style


i also attached a patch i used to be able to compile
with musl
diff -r 3314f6c2b58a lib9/_p9dir.c
--- a/lib9/_p9dir.c	Sun May 08 08:26:38 2011 +0000
+++ b/lib9/_p9dir.c	Sat May 21 21:51:37 2011 +0200
@@ -1,3 +1,4 @@
+#define _FILE_OFFSET_BITS 64
 #include <u.h>
 #define NOPLAN9DEFINES
 #include <libc.h>
@@ -61,38 +62,17 @@
 	return (vlong)lab.d_partitions[n].p_size * lab.d_secsize;
 }
 
-#elif defined(__linux__)
-#include <linux/hdreg.h>
-#include <linux/fs.h>
-#include <sys/ioctl.h>
-#undef major
-#define major(dev) ((int)(((dev) >> 8) & 0xff))
+#else
+#include <unistd.h>
 static vlong
 disksize(int fd, struct stat *st)
 {
-	u64int u64;
-	long l;
-	struct hd_geometry geo;
+	off_t n;
 
-	memset(&geo, 0, sizeof geo);
-	l = 0;
-	u64 = 0;
-#ifdef BLKGETSIZE64
-	if(ioctl(fd, BLKGETSIZE64, &u64) >= 0)
-		return u64;
-#endif
-	if(ioctl(fd, BLKGETSIZE, &l) >= 0)
-		return l*512;
-	if(ioctl(fd, HDIO_GETGEO, &geo) >= 0)
-		return (vlong)geo.heads*geo.sectors*geo.cylinders*512;
-	return 0;
-}
-
-#else
-static vlong
-disksize(int fd, struct stat *st)
-{
-	return 0;
+	n = lseek(fd, 0, SEEK_END);
+	if (n == -1)
+		return 0;
+	return n;
 }
 #endif
 
diff -r 3314f6c2b58a lib9/dirfwstat.c
--- a/lib9/dirfwstat.c	Sun May 08 08:26:38 2011 +0000
+++ b/lib9/dirfwstat.c	Sat May 21 21:51:37 2011 +0200
@@ -4,9 +4,19 @@
 #include <sys/time.h>
 #include <sys/stat.h>
 
-#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__linux__)
+#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
 /* do nothing -- futimes exists and is fine */
 
+#elif defined(__linux__)
+static int
+futimes(int fd, struct timeval *tv)
+{
+	char name[32];
+
+	sprint(name, "/dev/fd/%d", fd);
+	return utimes(name, tv);
+}
+
 #elif defined(__SunOS5_9__)
 /* use futimesat */
 static int
diff -r 3314f6c2b58a lib9/dirread.c
--- a/lib9/dirread.c	Sun May 08 08:26:38 2011 +0000
+++ b/lib9/dirread.c	Sat May 21 21:51:37 2011 +0200
@@ -7,16 +7,11 @@
 extern int _p9dir(struct stat*, struct stat*, char*, Dir*, char**, char*);
 
 #if defined(__linux__)
+#include <sys/syscall.h>
 static int
 mygetdents(int fd, struct dirent *buf, int n)
 {
-	off_t off;
-	int nn;
-
-	/* This doesn't match the man page, but it works in Debian with a 2.2 kernel */
-	off = p9seek(fd, 0, 1);
-	nn = getdirentries(fd, (void*)buf, n, &off);
-	return nn;
+	return syscall(SYS_getdents, fd, (void*)buf, n);
 }
 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__)
 static int
diff -r 3314f6c2b58a lib9/libc.h
--- a/lib9/libc.h	Sun May 08 08:26:38 2011 +0000
+++ b/lib9/libc.h	Sat May 21 21:51:37 2011 +0200
@@ -7,7 +7,7 @@
 #define _LIBC_H_ 1
 #if defined(__cplusplus)
 extern "C" {
-#endif                                                                
+#endif
 
 #include <utf.h>
 #include <fmt.h>
diff -r 3314f6c2b58a lib9/readcons.c
--- a/lib9/readcons.c	Sun May 08 08:26:38 2011 +0000
+++ b/lib9/readcons.c	Sat May 21 21:51:37 2011 +0200
@@ -2,7 +2,7 @@
 #define NOPLAN9DEFINES
 #include <libc.h>
 #include <termios.h>
-#include <sys/termios.h>
+//#include <sys/termios.h>
 
 static int
 rawx(int fd, int echoing)
diff -r 3314f6c2b58a lib9/utf/utfecpy.c
--- a/lib9/utf/utfecpy.c	Sun May 08 08:26:38 2011 +0000
+++ b/lib9/utf/utfecpy.c	Sat May 21 21:51:37 2011 +0200
@@ -11,7 +11,7 @@
  * ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
  * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  */
-#define _BSD_SOURCE 1	/* memccpy */
+#define _XOPEN_SOURCE 1000	/* memccpy */
 #include <stdarg.h>
 #include <string.h>
 #include "plan9.h"

Reply via email to