aboutsummaryrefslogtreecommitdiff
path: root/src/lib9/fmt
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-08-22 15:39:56 +0000
committerrsc <devnull@localhost>2004-08-22 15:39:56 +0000
commit984e353160593b20d1e2944e1f2e9ce2117c8490 (patch)
treed7347f9d2ffa06d1033fb41712257a2001fd4d57 /src/lib9/fmt
parentc8c0df440f1a22effd43023368c801e1351e31ed (diff)
downloadplan9port-984e353160593b20d1e2944e1f2e9ce2117c8490.tar.gz
plan9port-984e353160593b20d1e2944e1f2e9ce2117c8490.tar.bz2
plan9port-984e353160593b20d1e2944e1f2e9ce2117c8490.zip
PowerPC Linux support from ericvh.
Mainly adding va_copy/va_end. Also fix bug in sprint wrapping around top of memory.
Diffstat (limited to 'src/lib9/fmt')
-rw-r--r--src/lib9/fmt/fmtprint.c5
-rw-r--r--src/lib9/fmt/fmtvprint.c8
-rw-r--r--src/lib9/fmt/nan64.c2
-rw-r--r--src/lib9/fmt/runevseprint.c3
-rw-r--r--src/lib9/fmt/runevsmprint.c3
-rw-r--r--src/lib9/fmt/runevsnprint.c3
-rw-r--r--src/lib9/fmt/sprint.c11
-rw-r--r--src/lib9/fmt/vfprint.c3
-rw-r--r--src/lib9/fmt/vseprint.c3
-rw-r--r--src/lib9/fmt/vsmprint.c3
-rw-r--r--src/lib9/fmt/vsnprint.c4
11 files changed, 34 insertions, 14 deletions
diff --git a/src/lib9/fmt/fmtprint.c b/src/lib9/fmt/fmtprint.c
index fe2ad3cc..c682f49f 100644
--- a/src/lib9/fmt/fmtprint.c
+++ b/src/lib9/fmt/fmtprint.c
@@ -32,14 +32,15 @@ fmtprint(Fmt *f, char *fmt, ...)
f->flags = 0;
f->width = 0;
f->prec = 0;
- va = f->args;
+ va_copy(va, f->args);
va_start(f->args, fmt);
n = dofmt(f, fmt);
va_end(f->args);
f->flags = 0;
f->width = 0;
f->prec = 0;
- f->args = va;
+ va_copy(f->args,va);
+ va_end(va);
if(n >= 0)
return 0;
return n;
diff --git a/src/lib9/fmt/fmtvprint.c b/src/lib9/fmt/fmtvprint.c
index 6aed013d..60974a0b 100644
--- a/src/lib9/fmt/fmtvprint.c
+++ b/src/lib9/fmt/fmtvprint.c
@@ -32,13 +32,15 @@ fmtvprint(Fmt *f, char *fmt, va_list args)
f->flags = 0;
f->width = 0;
f->prec = 0;
- va = f->args;
- f->args = args;
+ va_copy(va,f->args);
+ va_copy(f->args,args);
n = dofmt(f, fmt);
f->flags = 0;
f->width = 0;
f->prec = 0;
- f->args = va;
+ va_end(f->args);
+ va_copy(f->args,va);
+ va_end(va);
if(n >= 0)
return 0;
return n;
diff --git a/src/lib9/fmt/nan64.c b/src/lib9/fmt/nan64.c
index a02a3adb..4df496cc 100644
--- a/src/lib9/fmt/nan64.c
+++ b/src/lib9/fmt/nan64.c
@@ -7,7 +7,7 @@
#include "nan.h"
-#ifdef __APPLE__
+#if defined (__APPLE__) || (__powerpc__)
#define _NEEDLL
#endif
diff --git a/src/lib9/fmt/runevseprint.c b/src/lib9/fmt/runevseprint.c
index e4cc1ea8..a9ef99b9 100644
--- a/src/lib9/fmt/runevseprint.c
+++ b/src/lib9/fmt/runevseprint.c
@@ -31,8 +31,9 @@ runevseprint(Rune *buf, Rune *e, char *fmt, va_list args)
f.flush = nil;
f.farg = nil;
f.nfmt = 0;
- f.args = args;
+ va_copy(f.args,args);
dofmt(&f, fmt);
+ va_end(f.args);
*(Rune*)f.to = '\0';
return (Rune*)f.to;
}
diff --git a/src/lib9/fmt/runevsmprint.c b/src/lib9/fmt/runevsmprint.c
index 71c23d84..3326da81 100644
--- a/src/lib9/fmt/runevsmprint.c
+++ b/src/lib9/fmt/runevsmprint.c
@@ -28,8 +28,9 @@ runevsmprint(char *fmt, va_list args)
if(runefmtstrinit(&f) < 0)
return nil;
- f.args = args;
+ va_copy(f.args,args);
n = dofmt(&f, fmt);
+ va_end(f.args);
if(n < 0)
return nil;
*(Rune*)f.to = '\0';
diff --git a/src/lib9/fmt/runevsnprint.c b/src/lib9/fmt/runevsnprint.c
index 933a04ca..71557e5b 100644
--- a/src/lib9/fmt/runevsnprint.c
+++ b/src/lib9/fmt/runevsnprint.c
@@ -31,8 +31,9 @@ runevsnprint(Rune *buf, int len, char *fmt, va_list args)
f.flush = nil;
f.farg = nil;
f.nfmt = 0;
- f.args = args;
+ va_copy(f.args,args);
dofmt(&f, fmt);
+ va_end(f.args);
*(Rune*)f.to = '\0';
return (Rune*)f.to - buf;
}
diff --git a/src/lib9/fmt/sprint.c b/src/lib9/fmt/sprint.c
index 57150c36..ac68851b 100644
--- a/src/lib9/fmt/sprint.c
+++ b/src/lib9/fmt/sprint.c
@@ -18,10 +18,19 @@ int
sprint(char *buf, char *fmt, ...)
{
int n;
+ uint len;
va_list args;
+ len = 1<<30; /* big number, but sprint is deprecated anyway */
+ /*
+ * on PowerPC, the stack is near the top of memory, so
+ * we must be sure not to overflow a 32-bit pointer.
+ */
+ if(buf+len < buf)
+ len = -(uint)buf-1;
+
va_start(args, fmt);
- n = vsnprint(buf, 65536, fmt, args); /* big number, but sprint is deprecated anyway */
+ n = vsnprint(buf, len, fmt, args);
va_end(args);
return n;
}
diff --git a/src/lib9/fmt/vfprint.c b/src/lib9/fmt/vfprint.c
index e4ab82ac..711b6588 100644
--- a/src/lib9/fmt/vfprint.c
+++ b/src/lib9/fmt/vfprint.c
@@ -23,8 +23,9 @@ vfprint(int fd, char *fmt, va_list args)
int n;
fmtfdinit(&f, fd, buf, sizeof(buf));
- f.args = args;
+ va_copy(f.args,args);
n = dofmt(&f, fmt);
+ va_end(f.args);
if(n > 0 && __fmtFdFlush(&f) == 0)
return -1;
return n;
diff --git a/src/lib9/fmt/vseprint.c b/src/lib9/fmt/vseprint.c
index 85ed810b..a1be5e40 100644
--- a/src/lib9/fmt/vseprint.c
+++ b/src/lib9/fmt/vseprint.c
@@ -29,8 +29,9 @@ vseprint(char *buf, char *e, char *fmt, va_list args)
f.flush = 0;
f.farg = nil;
f.nfmt = 0;
- f.args = args;
+ va_copy(f.args,args);
dofmt(&f, fmt);
+ va_end(f.args);
*(char*)f.to = '\0';
return (char*)f.to;
}
diff --git a/src/lib9/fmt/vsmprint.c b/src/lib9/fmt/vsmprint.c
index 34a1b36f..4f55c41c 100644
--- a/src/lib9/fmt/vsmprint.c
+++ b/src/lib9/fmt/vsmprint.c
@@ -27,8 +27,9 @@ vsmprint(char *fmt, va_list args)
if(fmtstrinit(&f) < 0)
return nil;
- f.args = args;
+ va_copy(f.args,args);
n = dofmt(&f, fmt);
+ va_end(f.args);
if(n < 0)
return nil;
return fmtstrflush(&f);
diff --git a/src/lib9/fmt/vsnprint.c b/src/lib9/fmt/vsnprint.c
index 21662e6d..ad64203a 100644
--- a/src/lib9/fmt/vsnprint.c
+++ b/src/lib9/fmt/vsnprint.c
@@ -20,6 +20,7 @@ int
vsnprint(char *buf, int len, char *fmt, va_list args)
{
Fmt f;
+ int x = 0;
if(len <= 0)
return -1;
@@ -30,8 +31,9 @@ vsnprint(char *buf, int len, char *fmt, va_list args)
f.flush = 0;
f.farg = nil;
f.nfmt = 0;
- f.args = args;
+ va_copy(f.args,args);
dofmt(&f, fmt);
+ va_end(f.args);
*(char*)f.to = '\0';
return (char*)f.to - buf;
}