Commit 2c5ec1eb authored by Russ Cox's avatar Russ Cox

apply gofmt to malloc math once os

R=gri
DELTA=566  (4 added, 14 deleted, 548 changed)
OCL=35410
CL=35419
parent 6faacd22
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"testing"; "testing";
) )
var vf = []float64 { var vf = []float64{
4.9790119248836735e+00, 4.9790119248836735e+00,
7.7388724745781045e+00, 7.7388724745781045e+00,
-2.7688005719200159e-01, -2.7688005719200159e-01,
...@@ -21,7 +21,7 @@ var vf = []float64 { ...@@ -21,7 +21,7 @@ var vf = []float64 {
1.8253080916808550e+00, 1.8253080916808550e+00,
-8.6859247685756013e+00, -8.6859247685756013e+00,
} }
var asin = []float64 { var asin = []float64{
5.2117697218417440e-01, 5.2117697218417440e-01,
8.8495619865825236e-01, 8.8495619865825236e-01,
-2.7691544662819413e-02, -2.7691544662819413e-02,
...@@ -33,7 +33,7 @@ var asin = []float64 { ...@@ -33,7 +33,7 @@ var asin = []float64 {
1.8355989225745148e-01, 1.8355989225745148e-01,
-1.0523547536021498e+00, -1.0523547536021498e+00,
} }
var atan = []float64 { var atan = []float64{
1.3725902621296217e+00, 1.3725902621296217e+00,
1.4422906096452980e+00, 1.4422906096452980e+00,
-2.7011324359471755e-01, -2.7011324359471755e-01,
...@@ -45,7 +45,7 @@ var atan = []float64 { ...@@ -45,7 +45,7 @@ var atan = []float64 {
1.0696031952318783e+00, 1.0696031952318783e+00,
-1.4561721938838085e+00, -1.4561721938838085e+00,
} }
var exp = []float64 { var exp = []float64{
1.4533071302642137e+02, 1.4533071302642137e+02,
2.2958822575694450e+03, 2.2958822575694450e+03,
7.5814542574851666e-01, 7.5814542574851666e-01,
...@@ -57,7 +57,7 @@ var exp = []float64 { ...@@ -57,7 +57,7 @@ var exp = []float64 {
6.2047063430646876e+00, 6.2047063430646876e+00,
1.6894712385826522e-04, 1.6894712385826522e-04,
} }
var floor = []float64 { var floor = []float64{
4.0000000000000000e+00, 4.0000000000000000e+00,
7.0000000000000000e+00, 7.0000000000000000e+00,
-1.0000000000000000e+00, -1.0000000000000000e+00,
...@@ -69,7 +69,7 @@ var floor = []float64 { ...@@ -69,7 +69,7 @@ var floor = []float64 {
1.0000000000000000e+00, 1.0000000000000000e+00,
-9.0000000000000000e+00, -9.0000000000000000e+00,
} }
var log = []float64 { var log = []float64{
1.6052314626930630e+00, 1.6052314626930630e+00,
2.0462560018708768e+00, 2.0462560018708768e+00,
-1.2841708730962657e+00, -1.2841708730962657e+00,
...@@ -81,7 +81,7 @@ var log = []float64 { ...@@ -81,7 +81,7 @@ var log = []float64 {
6.0174879014578053e-01, 6.0174879014578053e-01,
2.1617038728473527e+00, 2.1617038728473527e+00,
} }
var pow = []float64 { var pow = []float64{
9.5282232631648415e+04, 9.5282232631648415e+04,
5.4811599352999900e+07, 5.4811599352999900e+07,
5.2859121715894400e-01, 5.2859121715894400e-01,
...@@ -93,7 +93,7 @@ var pow = []float64 { ...@@ -93,7 +93,7 @@ var pow = []float64 {
6.6881821384514159e+01, 6.6881821384514159e+01,
2.0609869004248744e-09, 2.0609869004248744e-09,
} }
var sin = []float64 { var sin = []float64{
-9.6466616586009283e-01, -9.6466616586009283e-01,
9.9338225271646543e-01, 9.9338225271646543e-01,
-2.7335587039794395e-01, -2.7335587039794395e-01,
...@@ -105,7 +105,7 @@ var sin = []float64 { ...@@ -105,7 +105,7 @@ var sin = []float64 {
9.6778633541688000e-01, 9.6778633541688000e-01,
-6.7344058690503452e-01, -6.7344058690503452e-01,
} }
var sinh = []float64 { var sinh = []float64{
7.2661916084208533e+01, 7.2661916084208533e+01,
1.1479409110035194e+03, 1.1479409110035194e+03,
-2.8043136512812520e-01, -2.8043136512812520e-01,
...@@ -117,7 +117,7 @@ var sinh = []float64 { ...@@ -117,7 +117,7 @@ var sinh = []float64 {
3.0217691805496156e+00, 3.0217691805496156e+00,
-2.9595057572444951e+03, -2.9595057572444951e+03,
} }
var sqrt = []float64 { var sqrt = []float64{
2.2313699659365484e+00, 2.2313699659365484e+00,
2.7818829009464263e+00, 2.7818829009464263e+00,
5.2619393496314792e-01, 5.2619393496314792e-01,
...@@ -129,7 +129,7 @@ var sqrt = []float64 { ...@@ -129,7 +129,7 @@ var sqrt = []float64 {
1.3510396336454586e+00, 1.3510396336454586e+00,
2.9471892997524950e+00, 2.9471892997524950e+00,
} }
var tan = []float64 { var tan = []float64{
-3.6613165650402277e+00, -3.6613165650402277e+00,
8.6490023264859754e+00, 8.6490023264859754e+00,
-2.8417941955033615e-01, -2.8417941955033615e-01,
...@@ -141,7 +141,7 @@ var tan = []float64 { ...@@ -141,7 +141,7 @@ var tan = []float64 {
-3.8438855602011305e+00, -3.8438855602011305e+00,
9.1098879337768517e-01, 9.1098879337768517e-01,
} }
var tanh = []float64 { var tanh = []float64{
9.9990531206936328e-01, 9.9990531206936328e-01,
9.9999962057085307e-01, 9.9999962057085307e-01,
-2.7001505097318680e-01, -2.7001505097318680e-01,
...@@ -154,7 +154,7 @@ var tanh = []float64 { ...@@ -154,7 +154,7 @@ var tanh = []float64 {
-9.9999994291374019e-01, -9.9999994291374019e-01,
} }
func tolerance(a,b,e float64) bool { func tolerance(a, b, e float64) bool {
d := a-b; d := a-b;
if d < 0 { if d < 0 {
d = -d; d = -d;
...@@ -168,10 +168,10 @@ func tolerance(a,b,e float64) bool { ...@@ -168,10 +168,10 @@ func tolerance(a,b,e float64) bool {
} }
return d < e; return d < e;
} }
func close(a,b float64) bool { func close(a, b float64) bool {
return tolerance(a, b, 1e-14); return tolerance(a, b, 1e-14);
} }
func veryclose(a,b float64) bool { func veryclose(a, b float64) bool {
return tolerance(a, b, 4e-16); return tolerance(a, b, 4e-16);
} }
......
...@@ -19,8 +19,7 @@ package math ...@@ -19,8 +19,7 @@ package math
* range [-0.414...,+0.414...]. (tan(pi/8)) * range [-0.414...,+0.414...]. (tan(pi/8))
*/ */
func xatan(arg float64) float64 { func xatan(arg float64) float64 {
const const (
(
P4 = .161536412982230228262e2; P4 = .161536412982230228262e2;
P3 = .26842548195503973794141e3; P3 = .26842548195503973794141e3;
P2 = .11530293515404850115428136e4; P2 = .11530293515404850115428136e4;
...@@ -34,7 +33,7 @@ func xatan(arg float64) float64 { ...@@ -34,7 +33,7 @@ func xatan(arg float64) float64 {
) )
sq := arg*arg; sq := arg*arg;
value := ((((P4*sq + P3)*sq + P2)*sq + P1)*sq + P0); value := ((((P4*sq + P3)*sq + P2)*sq + P1)*sq + P0);
value = value/(((((sq + Q4)*sq + Q3)*sq + Q2)*sq + Q1)*sq + Q0); value = value/(((((sq+Q4)*sq + Q3)*sq + Q2)*sq + Q1)*sq + Q0);
return value*arg; return value*arg;
} }
...@@ -43,10 +42,10 @@ func xatan(arg float64) float64 { ...@@ -43,10 +42,10 @@ func xatan(arg float64) float64 {
* to the range [0,0.414...] and calls xatan. * to the range [0,0.414...] and calls xatan.
*/ */
func satan(arg float64) float64 { func satan(arg float64) float64 {
if arg < Sqrt2 - 1 { if arg < Sqrt2-1 {
return xatan(arg); return xatan(arg);
} }
if arg > Sqrt2 + 1 { if arg > Sqrt2+1 {
return Pi/2 - xatan(1/arg); return Pi/2 - xatan(1/arg);
} }
return Pi/4 + xatan((arg-1)/(arg+1)); return Pi/4 + xatan((arg-1)/(arg+1));
......
...@@ -14,14 +14,14 @@ func Atan2(x, y float64) float64 { ...@@ -14,14 +14,14 @@ func Atan2(x, y float64) float64 {
if x >= 0 { if x >= 0 {
return Pi/2; return Pi/2;
} }
return -Pi/2; return -Pi / 2;
} }
q := Atan(x/y); q := Atan(x/y);
if y < 0 { if y < 0 {
if q <= 0 { if q <= 0 {
return q + Pi; return q+Pi;
} }
return q - Pi; return q-Pi;
} }
return q; return q;
} }
...@@ -37,13 +37,13 @@ const ( ...@@ -37,13 +37,13 @@ const (
// Integer limit values. // Integer limit values.
const ( const (
MaxInt8 = 1<<7 - 1; MaxInt8 = 1<<7 - 1;
MinInt8 = -1<<7; MinInt8 = -1 << 7;
MaxInt16 = 1<<15 - 1; MaxInt16 = 1<<15 - 1;
MinInt16 = -1<<15; MinInt16 = -1 << 15;
MaxInt32 = 1<<31 - 1; MaxInt32 = 1<<31 - 1;
MinInt32 = -1<<31; MinInt32 = -1 << 31;
MaxInt64 = 1<<63 - 1; MaxInt64 = 1<<63 - 1;
MinInt64 = -1<<63; MinInt64 = -1 << 63;
MaxUint8 = 1<<8 - 1; MaxUint8 = 1<<8 - 1;
MaxUint16 = 1<<16 - 1; MaxUint16 = 1<<16 - 1;
MaxUint32 = 1<<32 - 1; MaxUint32 = 1<<32 - 1;
......
...@@ -93,7 +93,6 @@ func Exp(x float64) float64 { ...@@ -93,7 +93,6 @@ func Exp(x float64) float64 {
Ln2Hi = 6.93147180369123816490e-01; Ln2Hi = 6.93147180369123816490e-01;
Ln2Lo = 1.90821492927058770002e-10; Ln2Lo = 1.90821492927058770002e-10;
Log2e = 1.44269504088896338700e+00; Log2e = 1.44269504088896338700e+00;
P1 = 1.66666666666666019037e-01; /* 0x3FC55555; 0x5555553E */ P1 = 1.66666666666666019037e-01; /* 0x3FC55555; 0x5555553E */
P2 = -2.77777777770155933842e-03; /* 0xBF66C16C; 0x16BEBD93 */ P2 = -2.77777777770155933842e-03; /* 0xBF66C16C; 0x16BEBD93 */
P3 = 6.61375632143793436117e-05; /* 0x3F11566A; 0xAF25DE2C */ P3 = 6.61375632143793436117e-05; /* 0x3F11566A; 0xAF25DE2C */
...@@ -129,12 +128,12 @@ func Exp(x float64) float64 { ...@@ -129,12 +128,12 @@ func Exp(x float64) float64 {
} }
hi := x - float64(k)*Ln2Hi; hi := x - float64(k)*Ln2Hi;
lo := float64(k)*Ln2Lo; lo := float64(k)*Ln2Lo;
r := hi - lo; r := hi-lo;
// compute // compute
t := r * r; t := r*r;
c := r - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); c := r - t*(P1 + t*(P2 + t*(P3 + t*(P4 + t*P5))));
y := 1 - ((lo - (r*c)/(2-c)) - hi); y := 1-((lo - (r*c)/(2-c))-hi);
// TODO(rsc): make sure Ldexp can handle boundary k // TODO(rsc): make sure Ldexp can handle boundary k
return Ldexp(y, k); return Ldexp(y, k);
} }
...@@ -11,4 +11,3 @@ func Fabs(x float64) float64 { ...@@ -11,4 +11,3 @@ func Fabs(x float64) float64 {
} }
return x; return x;
} }
...@@ -29,7 +29,7 @@ func Fmod(x, y float64) float64 { ...@@ -29,7 +29,7 @@ func Fmod(x, y float64) float64 {
for r >= y { for r >= y {
rfr, rexp := Frexp(r); rfr, rexp := Frexp(r);
if rfr < yfr { if rfr < yfr {
rexp = rexp - 1; rexp = rexp-1;
} }
r = r - Ldexp(y, rexp-yexp); r = r - Ldexp(y, rexp-yexp);
} }
......
...@@ -45,5 +45,5 @@ func Hypot(p, q float64) float64 { ...@@ -45,5 +45,5 @@ func Hypot(p, q float64) float64 {
q = q*r; q = q*r;
r = q/p; r = q/p;
} }
panic("unreachable") panic("unreachable");
} }
...@@ -103,7 +103,7 @@ func Log(x float64) float64 { ...@@ -103,7 +103,7 @@ func Log(x float64) float64 {
f1 *= 2; f1 *= 2;
ki--; ki--;
} }
f := f1 - 1; f := f1-1;
k := float64(ki); k := float64(ki);
// compute // compute
...@@ -112,9 +112,9 @@ func Log(x float64) float64 { ...@@ -112,9 +112,9 @@ func Log(x float64) float64 {
s4 := s2*s2; s4 := s2*s2;
t1 := s2*(L1 + s4*(L3 + s4*(L5 + s4*L7))); t1 := s2*(L1 + s4*(L3 + s4*(L5 + s4*L7)));
t2 := s4*(L2 + s4*(L4 + s4*L6)); t2 := s4*(L2 + s4*(L4 + s4*L6));
R := t1 + t2; R := t1+t2;
hfsq := 0.5*f*f; hfsq := 0.5*f*f;
return k*Ln2Hi - ((hfsq-(s*(hfsq+R)+k*Ln2Lo)) - f); return k*Ln2Hi - ((hfsq-(s*(hfsq+R) + k*Ln2Lo))-f);
} }
// Log10 returns the decimal logarithm of x. // Log10 returns the decimal logarithm of x.
...@@ -123,6 +123,5 @@ func Log10(x float64) float64 { ...@@ -123,6 +123,5 @@ func Log10(x float64) float64 {
if x <= 0 { if x <= 0 {
return NaN(); return NaN();
} }
return Log(x) * (1/Ln10); return Log(x)*(1/Ln10);
} }
...@@ -20,7 +20,7 @@ func Pow(x, y float64) float64 { ...@@ -20,7 +20,7 @@ func Pow(x, y float64) float64 {
case y == 0.5: case y == 0.5:
return Sqrt(x); return Sqrt(x);
case y == -0.5: case y == -0.5:
return 1 / Sqrt(x); return 1/Sqrt(x);
} }
absy := y; absy := y;
...@@ -34,7 +34,7 @@ func Pow(x, y float64) float64 { ...@@ -34,7 +34,7 @@ func Pow(x, y float64) float64 {
return NaN(); return NaN();
} }
if yi >= 1<<63 { if yi >= 1<<63 {
return Exp(y * Log(x)); return Exp(y*Log(x));
} }
// ans = a1 * 2^ae (= 1 for now). // ans = a1 * 2^ae (= 1 for now).
...@@ -47,7 +47,7 @@ func Pow(x, y float64) float64 { ...@@ -47,7 +47,7 @@ func Pow(x, y float64) float64 {
yf--; yf--;
yi++; yi++;
} }
a1 = Exp(yf * Log(x)); a1 = Exp(yf*Log(x));
} }
// ans *= x^yi // ans *= x^yi
...@@ -72,7 +72,7 @@ func Pow(x, y float64) float64 { ...@@ -72,7 +72,7 @@ func Pow(x, y float64) float64 {
// if flip { ans = 1 / ans } // if flip { ans = 1 / ans }
// but in the opposite order // but in the opposite order
if flip { if flip {
a1 = 1 / a1; a1 = 1/a1;
ae = -ae; ae = -ae;
} }
return Ldexp(a1, ae); return Ldexp(a1, ae);
......
...@@ -13,12 +13,12 @@ package math ...@@ -13,12 +13,12 @@ package math
* than multipication of lower powers of 10. * than multipication of lower powers of 10.
*/ */
var pow10tab [70]float64; var pow10tab [70]float64
// Pow10 returns 10**x, the base-10 exponential of x. // Pow10 returns 10**x, the base-10 exponential of x.
func Pow10(e int) float64 { func Pow10(e int) float64 {
if e < 0 { if e < 0 {
return 1/Pow10(-e); return 1 / Pow10(-e);
} }
if e < len(pow10tab) { if e < len(pow10tab) {
return pow10tab[e]; return pow10tab[e];
...@@ -30,8 +30,8 @@ func Pow10(e int) float64 { ...@@ -30,8 +30,8 @@ func Pow10(e int) float64 {
func init() { func init() {
pow10tab[0] = 1.0e0; pow10tab[0] = 1.0e0;
pow10tab[1] = 1.0e1; pow10tab[1] = 1.0e1;
for i:=2; i<len(pow10tab); i++ { for i := 2; i < len(pow10tab); i++ {
m := i/2; m := i/2;
pow10tab[i] = pow10tab[m] * pow10tab[i-m]; pow10tab[i] = pow10tab[m]*pow10tab[i-m];
} }
} }
...@@ -7,8 +7,7 @@ package math ...@@ -7,8 +7,7 @@ package math
func sinus(x float64, quad int) float64 { func sinus(x float64, quad int) float64 {
// Coefficients are #3370 from Hart & Cheney (18.80D). // Coefficients are #3370 from Hart & Cheney (18.80D).
const const (
(
P0 = .1357884097877375669092680e8; P0 = .1357884097877375669092680e8;
P1 = -.4942908100902844161158627e7; P1 = -.4942908100902844161158627e7;
P2 = .4401030535375266501944918e6; P2 = .4401030535375266501944918e6;
...@@ -23,18 +22,18 @@ func sinus(x float64, quad int) float64 { ...@@ -23,18 +22,18 @@ func sinus(x float64, quad int) float64 {
x = -x; x = -x;
quad = quad+2; quad = quad+2;
} }
x = x * (2/Pi); /* underflow? */ x = x*(2/Pi); /* underflow? */
var y float64; var y float64;
if x > 32764 { if x > 32764 {
var e float64; var e float64;
e, y = Modf(x); e, y = Modf(x);
e = e + float64(quad); e = e+float64(quad);
_, f := Modf(0.25*e); _, f := Modf(0.25*e);
quad = int(e - 4*f); quad = int(e - 4*f);
} else { } else {
k := int32(x); k := int32(x);
y = x - float64(k); y = x-float64(k);
quad = (quad + int(k)) & 3; quad = (quad+int(k))&3;
} }
if quad&1 != 0 { if quad&1 != 0 {
...@@ -45,8 +44,8 @@ func sinus(x float64, quad int) float64 { ...@@ -45,8 +44,8 @@ func sinus(x float64, quad int) float64 {
} }
yy := y*y; yy := y*y;
temp1 := ((((P4*yy+P3)*yy+P2)*yy+P1)*yy+P0)*y; temp1 := ((((P4*yy + P3)*yy + P2)*yy + P1)*yy + P0)*y;
temp2 := ((((yy+Q3)*yy+Q2)*yy+Q1)*yy+Q0); temp2 := ((((yy+Q3)*yy + Q2)*yy + Q1)*yy + Q0);
return temp1/temp2; return temp1/temp2;
} }
......
...@@ -20,8 +20,7 @@ package math ...@@ -20,8 +20,7 @@ package math
// Sinh returns the hyperbolic sine of x. // Sinh returns the hyperbolic sine of x.
func Sinh(x float64) float64 { func Sinh(x float64) float64 {
// The coefficients are #2029 from Hart & Cheney. (20.36D) // The coefficients are #2029 from Hart & Cheney. (20.36D)
const const (
(
P0 = -0.6307673640497716991184787251e+6; P0 = -0.6307673640497716991184787251e+6;
P1 = -0.8991272022039509355398013511e+5; P1 = -0.8991272022039509355398013511e+5;
P2 = -0.2894211355989563807284660366e+4; P2 = -0.2894211355989563807284660366e+4;
...@@ -47,8 +46,8 @@ func Sinh(x float64) float64 { ...@@ -47,8 +46,8 @@ func Sinh(x float64) float64 {
default: default:
sq := x*x; sq := x*x;
temp = (((P3*sq+P2)*sq+P1)*sq+P0)*x; temp = (((P3*sq + P2)*sq + P1)*sq + P0)*x;
temp = temp/(((sq+Q2)*sq+Q1)*sq+Q0); temp = temp/(((sq+Q2)*sq + Q1)*sq + Q0);
} }
if sign { if sign {
...@@ -60,7 +59,7 @@ func Sinh(x float64) float64 { ...@@ -60,7 +59,7 @@ func Sinh(x float64) float64 {
// Cosh returns the hyperbolic cosine of x. // Cosh returns the hyperbolic cosine of x.
func Cosh(x float64) float64 { func Cosh(x float64) float64 {
if x < 0 { if x < 0 {
x = - x; x = -x;
} }
if x > 21 { if x > 21 {
return Exp(x)/2; return Exp(x)/2;
......
...@@ -40,25 +40,25 @@ func Sqrt(x float64) float64 { ...@@ -40,25 +40,25 @@ func Sqrt(x float64) float64 {
y = y*2; y = y*2;
exp = exp-1; exp = exp-1;
} }
temp := 0.5 * (1+y); temp := 0.5*(1+y);
for exp > 60 { for exp > 60 {
temp = temp * float64(1<<30); temp = temp * float64(1<<30);
exp = exp - 60; exp = exp-60;
} }
for exp < -60 { for exp < -60 {
temp = temp / float64(1<<30); temp = temp / float64(1<<30);
exp = exp + 60; exp = exp+60;
} }
if exp >= 0 { if exp >= 0 {
exp = 1 << uint(exp/2); exp = 1 << uint(exp/2);
temp = temp * float64(exp); temp = temp*float64(exp);
} else { } else {
exp = 1 << uint(-exp/2); exp = 1 << uint(-exp / 2);
temp = temp / float64(exp); temp = temp/float64(exp);
} }
for i:=0; i<=4; i++ { for i := 0; i <= 4; i++ {
temp = 0.5*(temp + x/temp); temp = 0.5*(temp + x/temp);
} }
return temp; return temp;
......
...@@ -5,4 +5,3 @@ ...@@ -5,4 +5,3 @@
package math package math
func Sqrt(x float64) float64 func Sqrt(x float64) float64
...@@ -12,8 +12,7 @@ package math ...@@ -12,8 +12,7 @@ package math
// Tan returns the tangent of x. // Tan returns the tangent of x.
func Tan(x float64) float64 { func Tan(x float64) float64 {
// Coefficients are #4285 from Hart & Cheney. (19.74D) // Coefficients are #4285 from Hart & Cheney. (19.74D)
const const (
(
P0 = -.1306820264754825668269611177e+5; P0 = -.1306820264754825668269611177e+5;
P1 = .1055970901714953193602353981e+4; P1 = .1055970901714953193602353981e+4;
P2 = -.1550685653483266376941705728e+2; P2 = -.1550685653483266376941705728e+2;
...@@ -30,14 +29,14 @@ func Tan(x float64) float64 { ...@@ -30,14 +29,14 @@ func Tan(x float64) float64 {
x = -x; x = -x;
sign = true; sign = true;
} }
x = x * (4/Pi); /* overflow? */ x = x*(4/Pi); /* overflow? */
var e float64; var e float64;
e, x = Modf(x); e, x = Modf(x);
i := int32(e); i := int32(e);
switch i & 3 { switch i&3 {
case 1: case 1:
x = 1 - x; x = 1-x;
flag = true; flag = true;
case 2: case 2:
...@@ -45,13 +44,13 @@ func Tan(x float64) float64 { ...@@ -45,13 +44,13 @@ func Tan(x float64) float64 {
flag = true; flag = true;
case 3: case 3:
x = 1 - x; x = 1-x;
sign = !sign; sign = !sign;
} }
xsq := x*x; xsq := x*x;
temp := ((((P4*xsq+P3)*xsq+P2)*xsq+P1)*xsq+P0)*x; temp := ((((P4*xsq + P3)*xsq + P2)*xsq + P1)*xsq + P0)*x;
temp = temp/(((xsq+Q2)*xsq+Q1)*xsq+Q0); temp = temp/(((xsq+Q2)*xsq + Q1)*xsq + Q0);
if flag { if flag {
if temp == 0 { if temp == 0 {
......
...@@ -20,7 +20,7 @@ func Tanh(x float64) float64 { ...@@ -20,7 +20,7 @@ func Tanh(x float64) float64 {
if x > 21 { if x > 21 {
return -1; return -1;
} }
return -Sinh(x)/Cosh(x); return -Sinh(x) / Cosh(x);
} }
if x > 21 { if x > 21 {
return 1; return 1;
......
...@@ -14,7 +14,7 @@ type job struct { ...@@ -14,7 +14,7 @@ type job struct {
} }
var jobs = make(map[func()]*job) var jobs = make(map[func()]*job)
var joblock sync.Mutex; var joblock sync.Mutex
// Do is the the only exported piece of the package. // Do is the the only exported piece of the package.
// For one-time initialization that is not done during init, // For one-time initialization that is not done during init,
......
...@@ -9,9 +9,10 @@ import ( ...@@ -9,9 +9,10 @@ import (
"testing"; "testing";
) )
var ncall int; var ncall int
func call() { func call() {
ncall++ ncall++;
} }
func TestDo(t *testing.T) { func TestDo(t *testing.T) {
......
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
) )
const ( const (
blockSize = 4096 // TODO(r): use statfs blockSize = 4096; // TODO(r): use statfs
) )
// Readdirnames reads the contents of the directory associated with file and // Readdirnames reads the contents of the directory associated with file and
...@@ -29,7 +29,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -29,7 +29,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
d := file.dirinfo; d := file.dirinfo;
size := count; size := count;
if size < 0 { if size < 0 {
size = 100 size = 100;
} }
names = make([]string, 0, size); // Empty with room to grow. names = make([]string, 0, size); // Empty with room to grow.
for count != 0 { for count != 0 {
...@@ -44,7 +44,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -44,7 +44,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
return names, NewSyscallError("getdirentries", errno); return names, NewSyscallError("getdirentries", errno);
} }
if d.nbuf <= 0 { if d.nbuf <= 0 {
break // EOF break; // EOF
} }
} }
// Drain the buffer // Drain the buffer
...@@ -52,28 +52,28 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -52,28 +52,28 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp])); dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp]));
if dirent.Reclen == 0 { if dirent.Reclen == 0 {
d.bufp = d.nbuf; d.bufp = d.nbuf;
break break;
} }
d.bufp += int(dirent.Reclen); d.bufp += int(dirent.Reclen);
if dirent.Ino == 0 { // File absent in directory. if dirent.Ino == 0 { // File absent in directory.
continue continue;
} }
bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0])); bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]));
var name = string(bytes[0:dirent.Namlen]); var name = string(bytes[0 : dirent.Namlen]);
if name == "." || name == ".." { // Useless names if name == "." || name == ".." { // Useless names
continue continue;
} }
count--; count--;
if len(names) == cap(names) { if len(names) == cap(names) {
nnames := make([]string, len(names), 2*len(names)); nnames := make([]string, len(names), 2*len(names));
for i := 0; i < len(names); i++ { for i := 0; i < len(names); i++ {
nnames[i] = names[i] nnames[i] = names[i];
} }
names = nnames; names = nnames;
} }
names = names[0:len(names)+1]; names = names[0 : len(names)+1];
names[len(names)-1] = name; names[len(names)-1] = name;
} }
} }
return names, nil return names, nil;
} }
...@@ -10,7 +10,7 @@ import ( ...@@ -10,7 +10,7 @@ import (
) )
const ( const (
blockSize = 4096 // TODO(r): use statfs blockSize = 4096; // TODO(r): use statfs
) )
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
...@@ -24,7 +24,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -24,7 +24,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
d := file.dirinfo; d := file.dirinfo;
size := count; size := count;
if size < 0 { if size < 0 {
size = 100 size = 100;
} }
names = make([]string, 0, size); // Empty with room to grow. names = make([]string, 0, size); // Empty with room to grow.
for count != 0 { for count != 0 {
...@@ -39,7 +39,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -39,7 +39,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
return names, NewSyscallError("getdirentries", errno); return names, NewSyscallError("getdirentries", errno);
} }
if d.nbuf <= 0 { if d.nbuf <= 0 {
break // EOF break; // EOF
} }
} }
// Drain the buffer // Drain the buffer
...@@ -47,28 +47,28 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -47,28 +47,28 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp])); dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp]));
if dirent.Reclen == 0 { if dirent.Reclen == 0 {
d.bufp = d.nbuf; d.bufp = d.nbuf;
break break;
} }
d.bufp += int(dirent.Reclen); d.bufp += int(dirent.Reclen);
if dirent.Ino == 0 { // File absent in directory. if dirent.Ino == 0 { // File absent in directory.
continue continue;
} }
bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0])); bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]));
var name = string(bytes[0:dirent.Namlen]); var name = string(bytes[0 : dirent.Namlen]);
if name == "." || name == ".." { // Useless names if name == "." || name == ".." { // Useless names
continue continue;
} }
count--; count--;
if len(names) == cap(names) { if len(names) == cap(names) {
nnames := make([]string, len(names), 2*len(names)); nnames := make([]string, len(names), 2*len(names));
for i := 0; i < len(names); i++ { for i := 0; i < len(names); i++ {
nnames[i] = names[i] nnames[i] = names[i];
} }
names = nnames; names = nnames;
} }
names = names[0:len(names)+1]; names = names[0 : len(names)+1];
names[len(names)-1] = name; names[len(names)-1] = name;
} }
} }
return names, nil return names, nil;
} }
...@@ -14,16 +14,16 @@ import ( ...@@ -14,16 +14,16 @@ import (
) )
const ( const (
blockSize = 4096 // TODO(r): use statfs blockSize = 4096; // TODO(r): use statfs
) )
func clen(n []byte) int { func clen(n []byte) int {
for i := 0; i < len(n); i++ { for i := 0; i < len(n); i++ {
if n[i] == 0 { if n[i] == 0 {
return i return i;
} }
} }
return len(n) return len(n);
} }
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
...@@ -37,7 +37,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -37,7 +37,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
d := file.dirinfo; d := file.dirinfo;
size := count; size := count;
if size < 0 { if size < 0 {
size = 100 size = 100;
} }
names = make([]string, 0, size); // Empty with room to grow. names = make([]string, 0, size); // Empty with room to grow.
for count != 0 { for count != 0 {
...@@ -46,10 +46,10 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -46,10 +46,10 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
var errno int; var errno int;
d.nbuf, errno = syscall.Getdents(file.fd, d.buf); d.nbuf, errno = syscall.Getdents(file.fd, d.buf);
if errno != 0 { if errno != 0 {
return names, NewSyscallError("getdents", errno) return names, NewSyscallError("getdents", errno);
} }
if d.nbuf <= 0 { if d.nbuf <= 0 {
break // EOF break; // EOF
} }
d.bufp = 0; d.bufp = 0;
} }
...@@ -58,22 +58,22 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -58,22 +58,22 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp])); dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp]));
d.bufp += int(dirent.Reclen); d.bufp += int(dirent.Reclen);
if dirent.Ino == 0 { // File absent in directory. if dirent.Ino == 0 { // File absent in directory.
continue continue;
} }
bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0])); bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]));
var name = string(bytes[0:clen(bytes)]); var name = string(bytes[0:clen(bytes)]);
if name == "." || name == ".." { // Useless names if name == "." || name == ".." { // Useless names
continue continue;
} }
count--; count--;
if len(names) == cap(names) { if len(names) == cap(names) {
nnames := make([]string, len(names), 2*len(names)); nnames := make([]string, len(names), 2*len(names));
for i := 0; i < len(names); i++ { for i := 0; i < len(names); i++ {
nnames[i] = names[i] nnames[i] = names[i];
} }
names = nnames; names = nnames;
} }
names = names[0:len(names)+1]; names = names[0 : len(names)+1];
names[len(names)-1] = name; names[len(names)-1] = name;
} }
} }
......
...@@ -10,16 +10,16 @@ import ( ...@@ -10,16 +10,16 @@ import (
) )
const ( const (
blockSize = 4096 // TODO(r): use statfs blockSize = 4096; // TODO(r): use statfs
) )
func clen(n []byte) int { func clen(n []byte) int {
for i := 0; i < len(n); i++ { for i := 0; i < len(n); i++ {
if n[i] == 0 { if n[i] == 0 {
return i return i;
} }
} }
return len(n) return len(n);
} }
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
...@@ -33,7 +33,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -33,7 +33,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
d := file.dirinfo; d := file.dirinfo;
size := count; size := count;
if size < 0 { if size < 0 {
size = 100 size = 100;
} }
names = make([]string, 0, size); // Empty with room to grow. names = make([]string, 0, size); // Empty with room to grow.
for count != 0 { for count != 0 {
...@@ -42,10 +42,10 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -42,10 +42,10 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
var errno int; var errno int;
d.nbuf, errno = syscall.Getdents(file.fd, d.buf); d.nbuf, errno = syscall.Getdents(file.fd, d.buf);
if errno != 0 { if errno != 0 {
return names, NewSyscallError("getdents", errno) return names, NewSyscallError("getdents", errno);
} }
if d.nbuf <= 0 { if d.nbuf <= 0 {
break // EOF break; // EOF
} }
d.bufp = 0; d.bufp = 0;
} }
...@@ -54,22 +54,22 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -54,22 +54,22 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp])); dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp]));
d.bufp += int(dirent.Reclen); d.bufp += int(dirent.Reclen);
if dirent.Ino == 0 { // File absent in directory. if dirent.Ino == 0 { // File absent in directory.
continue continue;
} }
bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0])); bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]));
var name = string(bytes[0:clen(bytes)]); var name = string(bytes[0:clen(bytes)]);
if name == "." || name == ".." { // Useless names if name == "." || name == ".." { // Useless names
continue continue;
} }
count--; count--;
if len(names) == cap(names) { if len(names) == cap(names) {
nnames := make([]string, len(names), 2*len(names)); nnames := make([]string, len(names), 2*len(names));
for i := 0; i < len(names); i++ { for i := 0; i < len(names); i++ {
nnames[i] = names[i] nnames[i] = names[i];
} }
names = nnames; names = nnames;
} }
names = names[0:len(names)+1]; names = names[0 : len(names)+1];
names[len(names)-1] = name; names[len(names)-1] = name;
} }
} }
......
...@@ -14,16 +14,16 @@ import ( ...@@ -14,16 +14,16 @@ import (
) )
const ( const (
blockSize = 4096 // TODO(r): use statfs blockSize = 4096; // TODO(r): use statfs
) )
func clen(n []byte) int { func clen(n []byte) int {
for i := 0; i < len(n); i++ { for i := 0; i < len(n); i++ {
if n[i] == 0 { if n[i] == 0 {
return i return i;
} }
} }
return len(n) return len(n);
} }
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
...@@ -37,7 +37,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -37,7 +37,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
d := file.dirinfo; d := file.dirinfo;
size := count; size := count;
if size < 0 { if size < 0 {
size = 100 size = 100;
} }
names = make([]string, 0, size); // Empty with room to grow. names = make([]string, 0, size); // Empty with room to grow.
for count != 0 { for count != 0 {
...@@ -46,10 +46,10 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -46,10 +46,10 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
var errno int; var errno int;
d.nbuf, errno = syscall.Getdents(file.fd, d.buf); d.nbuf, errno = syscall.Getdents(file.fd, d.buf);
if errno != 0 { if errno != 0 {
return names, NewSyscallError("getdents", errno) return names, NewSyscallError("getdents", errno);
} }
if d.nbuf <= 0 { if d.nbuf <= 0 {
break // EOF break; // EOF
} }
d.bufp = 0; d.bufp = 0;
} }
...@@ -58,22 +58,22 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -58,22 +58,22 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp])); dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp]));
d.bufp += int(dirent.Reclen); d.bufp += int(dirent.Reclen);
if dirent.Ino == 0 { // File absent in directory. if dirent.Ino == 0 { // File absent in directory.
continue continue;
} }
bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0])); bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]));
var name = string(bytes[0:clen(bytes)]); var name = string(bytes[0:clen(bytes)]);
if name == "." || name == ".." { // Useless names if name == "." || name == ".." { // Useless names
continue continue;
} }
count--; count--;
if len(names) == cap(names) { if len(names) == cap(names) {
nnames := make([]string, len(names), 2*len(names)); nnames := make([]string, len(names), 2*len(names));
for i := 0; i < len(names); i++ { for i := 0; i < len(names); i++ {
nnames[i] = names[i] nnames[i] = names[i];
} }
names = nnames; names = nnames;
} }
names = names[0:len(names)+1]; names = names[0 : len(names)+1];
names[len(names)-1] = name; names[len(names)-1] = name;
} }
} }
......
...@@ -14,16 +14,16 @@ import ( ...@@ -14,16 +14,16 @@ import (
) )
const ( const (
blockSize = 4096 // TODO(r): use statfs blockSize = 4096; // TODO(r): use statfs
) )
func clen(n []byte) int { func clen(n []byte) int {
for i := 0; i < len(n); i++ { for i := 0; i < len(n); i++ {
if n[i] == 0 { if n[i] == 0 {
return i return i;
} }
} }
return len(n) return len(n);
} }
func (file *File) Readdirnames(count int) (names []string, err Error) { func (file *File) Readdirnames(count int) (names []string, err Error) {
...@@ -37,7 +37,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -37,7 +37,7 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
d := file.dirinfo; d := file.dirinfo;
size := count; size := count;
if size < 0 { if size < 0 {
size = 100 size = 100;
} }
names = make([]string, 0, size); // Empty with room to grow. names = make([]string, 0, size); // Empty with room to grow.
for count != 0 { for count != 0 {
...@@ -46,10 +46,10 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -46,10 +46,10 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
var errno int; var errno int;
d.nbuf, errno = syscall.Getdents(file.fd, d.buf); d.nbuf, errno = syscall.Getdents(file.fd, d.buf);
if errno != 0 { if errno != 0 {
return names, NewSyscallError("getdents", errno) return names, NewSyscallError("getdents", errno);
} }
if d.nbuf <= 0 { if d.nbuf <= 0 {
break // EOF break; // EOF
} }
d.bufp = 0; d.bufp = 0;
} }
...@@ -58,22 +58,22 @@ func (file *File) Readdirnames(count int) (names []string, err Error) { ...@@ -58,22 +58,22 @@ func (file *File) Readdirnames(count int) (names []string, err Error) {
dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp])); dirent := (*syscall.Dirent)(unsafe.Pointer(&d.buf[d.bufp]));
d.bufp += int(dirent.Reclen); d.bufp += int(dirent.Reclen);
if dirent.Ino == 0 { // File absent in directory. if dirent.Ino == 0 { // File absent in directory.
continue continue;
} }
bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0])); bytes := (*[len(dirent.Name)]byte)(unsafe.Pointer(&dirent.Name[0]));
var name = string(bytes[0:clen(bytes)]); var name = string(bytes[0:clen(bytes)]);
if name == "." || name == ".." { // Useless names if name == "." || name == ".." { // Useless names
continue continue;
} }
count--; count--;
if len(names) == cap(names) { if len(names) == cap(names) {
nnames := make([]string, len(names), 2*len(names)); nnames := make([]string, len(names), 2*len(names));
for i := 0; i < len(names); i++ { for i := 0; i < len(names); i++ {
nnames[i] = names[i] nnames[i] = names[i];
} }
names = nnames; names = nnames;
} }
names = names[0:len(names)+1]; names = names[0 : len(names)+1];
names[len(names)-1] = name; names[len(names)-1] = name;
} }
} }
......
...@@ -11,17 +11,17 @@ import ( ...@@ -11,17 +11,17 @@ import (
) )
// ENOENV is the Error indicating that an environment variable does not exist. // ENOENV is the Error indicating that an environment variable does not exist.
var ENOENV = NewError("no such environment variable"); var ENOENV = NewError("no such environment variable")
var env map[string] string; var env map[string]string
func copyenv() { func copyenv() {
env = make(map[string] string); env = make(map[string]string);
for _, s := range Envs { for _, s := range Envs {
for j := 0; j < len(s); j++ { for j := 0; j < len(s); j++ {
if s[j] == '=' { if s[j] == '=' {
env[s[0:j]] = s[j+1:len(s)]; env[s[0:j]] = s[j+1 : len(s)];
break; break;
} }
} }
...@@ -65,7 +65,7 @@ func Setenv(key, value string) Error { ...@@ -65,7 +65,7 @@ func Setenv(key, value string) Error {
// Clearenv deletes all environment variables. // Clearenv deletes all environment variables.
func Clearenv() { func Clearenv() {
once.Do(copyenv); // prevent copyenv in Getenv/Setenv once.Do(copyenv); // prevent copyenv in Getenv/Setenv
env = make(map[string] string); env = make(map[string]string);
} }
// Environ returns an array of strings representing the environment, // Environ returns an array of strings representing the environment,
...@@ -78,7 +78,7 @@ func Environ() []string { ...@@ -78,7 +78,7 @@ func Environ() []string {
// check i < len(a) for safety, // check i < len(a) for safety,
// in case env is changing underfoot. // in case env is changing underfoot.
if i < len(a) { if i < len(a) {
a[i] = k + "=" + v; a[i] = k+"="+v;
i++; i++;
} }
} }
......
...@@ -8,26 +8,28 @@ import syscall "syscall" ...@@ -8,26 +8,28 @@ import syscall "syscall"
// An Error can represent any printable error condition. // An Error can represent any printable error condition.
type Error interface { type Error interface {
String() string String() string;
} }
// A helper type that can be embedded or wrapped to simplify satisfying // A helper type that can be embedded or wrapped to simplify satisfying
// Error. // Error.
type ErrorString string type ErrorString string
func (e ErrorString) String() string { func (e ErrorString) String() string {
return string(e) return string(e);
} }
// NewError converts s to an ErrorString, which satisfies the Error interface. // NewError converts s to an ErrorString, which satisfies the Error interface.
func NewError(s string) Error { func NewError(s string) Error {
return ErrorString(s) return ErrorString(s);
} }
// Errno is the Unix error number. Names such as EINVAL are simple // Errno is the Unix error number. Names such as EINVAL are simple
// wrappers to convert the error number into an Error. // wrappers to convert the error number into an Error.
type Errno int64 type Errno int64
func (e Errno) String() string { func (e Errno) String() string {
return syscall.Errstr(int(e)) return syscall.Errstr(int(e));
} }
// Commonly known Unix errors. // Commonly known Unix errors.
...@@ -98,5 +100,5 @@ func NewSyscallError(syscall string, errno int) Error { ...@@ -98,5 +100,5 @@ func NewSyscallError(syscall string, errno int) Error {
if errno == 0 { if errno == 0 {
return nil; return nil;
} }
return &SyscallError{syscall, Errno(errno)} return &SyscallError{syscall, Errno(errno)};
} }
...@@ -15,9 +15,7 @@ import ( ...@@ -15,9 +15,7 @@ import (
// descriptor 0 (standard input), fd[1] descriptor 1, and so on. A nil entry // descriptor 0 (standard input), fd[1] descriptor 1, and so on. A nil entry
// will cause the child to have no open file descriptor with that index. // will cause the child to have no open file descriptor with that index.
// If dir is not empty, the child chdirs into the directory before execing the program. // If dir is not empty, the child chdirs into the directory before execing the program.
func ForkExec(argv0 string, argv []string, envv []string, dir string, fd []*File) func ForkExec(argv0 string, argv []string, envv []string, dir string, fd []*File) (pid int, err Error) {
(pid int, err Error)
{
// Create array of integer (system) fds. // Create array of integer (system) fds.
intfd := make([]int, len(fd)); intfd := make([]int, len(fd));
for i, f := range fd { for i, f := range fd {
...@@ -82,7 +80,7 @@ const ( ...@@ -82,7 +80,7 @@ const (
func Wait(pid int, options int) (w *Waitmsg, err Error) { func Wait(pid int, options int) (w *Waitmsg, err Error) {
var status syscall.WaitStatus; var status syscall.WaitStatus;
var rusage *syscall.Rusage; var rusage *syscall.Rusage;
if options & WRUSAGE != 0 { if options&WRUSAGE != 0 {
rusage = new(syscall.Rusage); rusage = new(syscall.Rusage);
options ^= WRUSAGE; options ^= WRUSAGE;
} }
...@@ -100,7 +98,7 @@ func Wait(pid int, options int) (w *Waitmsg, err Error) { ...@@ -100,7 +98,7 @@ func Wait(pid int, options int) (w *Waitmsg, err Error) {
// Convert i to decimal string. // Convert i to decimal string.
func itod(i int) string { func itod(i int) string {
if i == 0 { if i == 0 {
return "0" return "0";
} }
u := uint64(i); u := uint64(i);
...@@ -113,15 +111,15 @@ func itod(i int) string { ...@@ -113,15 +111,15 @@ func itod(i int) string {
bp := len(b); bp := len(b);
for ; u > 0; u /= 10 { for ; u > 0; u /= 10 {
bp--; bp--;
b[bp] = byte(u%10) + '0' b[bp] = byte(u%10) + '0';
} }
if i < 0 { if i < 0 {
bp--; bp--;
b[bp] = '-' b[bp] = '-';
} }
return string(b[bp:len(b)]) return string(b[bp:len(b)]);
} }
func (w Waitmsg) String() string { func (w Waitmsg) String() string {
...@@ -141,7 +139,7 @@ func (w Waitmsg) String() string { ...@@ -141,7 +139,7 @@ func (w Waitmsg) String() string {
res = "continued"; res = "continued";
} }
if w.CoreDump() { if w.CoreDump() {
res += " (core dumped)" res += " (core dumped)";
} }
return res; return res;
} }
......
...@@ -27,20 +27,20 @@ type File struct { ...@@ -27,20 +27,20 @@ type File struct {
// Fd returns the integer Unix file descriptor referencing the open file. // Fd returns the integer Unix file descriptor referencing the open file.
func (file *File) Fd() int { func (file *File) Fd() int {
return file.fd return file.fd;
} }
// Name returns the name of the file as presented to Open. // Name returns the name of the file as presented to Open.
func (file *File) Name() string { func (file *File) Name() string {
return file.name return file.name;
} }
// NewFile returns a new File with the given file descriptor and name. // NewFile returns a new File with the given file descriptor and name.
func NewFile(fd int, name string) *File { func NewFile(fd int, name string) *File {
if fd < 0 { if fd < 0 {
return nil return nil;
} }
return &File{fd, name, nil, 0} return &File{fd, name, nil, 0};
} }
// Stdin, Stdout, and Stderr are open Files pointing to the standard input, // Stdin, Stdout, and Stderr are open Files pointing to the standard input,
...@@ -89,7 +89,7 @@ func Open(name string, flag int, perm int) (file *File, err Error) { ...@@ -89,7 +89,7 @@ func Open(name string, flag int, perm int) (file *File, err Error) {
// It returns an Error, if any. // It returns an Error, if any.
func (file *File) Close() Error { func (file *File) Close() Error {
if file == nil { if file == nil {
return EINVAL return EINVAL;
} }
var err Error; var err Error;
if e := syscall.Close(file.fd); e != 0 { if e := syscall.Close(file.fd); e != 0 {
...@@ -100,8 +100,9 @@ func (file *File) Close() Error { ...@@ -100,8 +100,9 @@ func (file *File) Close() Error {
} }
type eofError int type eofError int
func (eofError) String() string { func (eofError) String() string {
return "EOF" return "EOF";
} }
// EOF is the Error returned by Read when no more input is available. // EOF is the Error returned by Read when no more input is available.
...@@ -117,19 +118,19 @@ var EOF Error = eofError(0) ...@@ -117,19 +118,19 @@ var EOF Error = eofError(0)
// TODO(r): Add Pread, Pwrite (maybe ReadAt, WriteAt). // TODO(r): Add Pread, Pwrite (maybe ReadAt, WriteAt).
func (file *File) Read(b []byte) (n int, err Error) { func (file *File) Read(b []byte) (n int, err Error) {
if file == nil { if file == nil {
return 0, EINVAL return 0, EINVAL;
} }
n, e := syscall.Read(file.fd, b); n, e := syscall.Read(file.fd, b);
if n < 0 { if n < 0 {
n = 0; n = 0;
} }
if n == 0 && e == 0 { if n == 0 && e == 0 {
return 0, EOF return 0, EOF;
} }
if e != 0 { if e != 0 {
err = &PathError{"read", file.name, Errno(e)}; err = &PathError{"read", file.name, Errno(e)};
} }
return n, err return n, err;
} }
// ReadAt reads len(b) bytes from the File starting at byte offset off. // ReadAt reads len(b) bytes from the File starting at byte offset off.
...@@ -158,11 +159,11 @@ func (file *File) ReadAt(b []byte, off int64) (n int, err Error) { ...@@ -158,11 +159,11 @@ func (file *File) ReadAt(b []byte, off int64) (n int, err Error) {
// Write returns a non-nil Error when n != len(b). // Write returns a non-nil Error when n != len(b).
func (file *File) Write(b []byte) (n int, err Error) { func (file *File) Write(b []byte) (n int, err Error) {
if file == nil { if file == nil {
return 0, EINVAL return 0, EINVAL;
} }
n, e := syscall.Write(file.fd, b); n, e := syscall.Write(file.fd, b);
if n < 0 { if n < 0 {
n = 0 n = 0;
} }
if e == syscall.EPIPE { if e == syscall.EPIPE {
file.nepipe++; file.nepipe++;
...@@ -175,7 +176,7 @@ func (file *File) Write(b []byte) (n int, err Error) { ...@@ -175,7 +176,7 @@ func (file *File) Write(b []byte) (n int, err Error) {
if e != 0 { if e != 0 {
err = &PathError{"write", file.name, Errno(e)}; err = &PathError{"write", file.name, Errno(e)};
} }
return n, err return n, err;
} }
// WriteAt writes len(b) bytes to the File starting at byte offset off. // WriteAt writes len(b) bytes to the File starting at byte offset off.
...@@ -210,17 +211,17 @@ func (file *File) Seek(offset int64, whence int) (ret int64, err Error) { ...@@ -210,17 +211,17 @@ func (file *File) Seek(offset int64, whence int) (ret int64, err Error) {
if e != 0 { if e != 0 {
return 0, &PathError{"seek", file.name, Errno(e)}; return 0, &PathError{"seek", file.name, Errno(e)};
} }
return r, nil return r, nil;
} }
// WriteString is like Write, but writes the contents of string s rather than // WriteString is like Write, but writes the contents of string s rather than
// an array of bytes. // an array of bytes.
func (file *File) WriteString(s string) (ret int, err Error) { func (file *File) WriteString(s string) (ret int, err Error) {
if file == nil { if file == nil {
return 0, EINVAL return 0, EINVAL;
} }
b := syscall.StringByteSlice(s); b := syscall.StringByteSlice(s);
b = b[0:len(b)-1]; b = b[0 : len(b)-1];
return file.Write(b); return file.Write(b);
} }
...@@ -240,7 +241,7 @@ func Pipe() (r *File, w *File, err Error) { ...@@ -240,7 +241,7 @@ func Pipe() (r *File, w *File, err Error) {
syscall.CloseOnExec(p[1]); syscall.CloseOnExec(p[1]);
syscall.ForkLock.RUnlock(); syscall.ForkLock.RUnlock();
return NewFile(p[0], "|0"), NewFile(p[1], "|1"), nil return NewFile(p[0], "|0"), NewFile(p[1], "|1"), nil;
} }
// Mkdir creates a new directory with the specified name and permission bits. // Mkdir creates a new directory with the specified name and permission bits.
...@@ -271,7 +272,7 @@ func Stat(name string) (dir *Dir, err Error) { ...@@ -271,7 +272,7 @@ func Stat(name string) (dir *Dir, err Error) {
statp = &stat; statp = &stat;
} }
} }
return dirFromStat(name, new(Dir), &lstat, statp), nil return dirFromStat(name, new(Dir), &lstat, statp), nil;
} }
// Stat returns the Dir structure describing file. // Stat returns the Dir structure describing file.
...@@ -282,7 +283,7 @@ func (file *File) Stat() (dir *Dir, err Error) { ...@@ -282,7 +283,7 @@ func (file *File) Stat() (dir *Dir, err Error) {
if e != 0 { if e != 0 {
return nil, &PathError{"stat", file.name, Errno(e)}; return nil, &PathError{"stat", file.name, Errno(e)};
} }
return dirFromStat(file.name, new(Dir), &stat, &stat), nil return dirFromStat(file.name, new(Dir), &stat, &stat), nil;
} }
// Lstat returns the Dir structure describing the named file and an error, if any. // Lstat returns the Dir structure describing the named file and an error, if any.
...@@ -294,7 +295,7 @@ func Lstat(name string) (dir *Dir, err Error) { ...@@ -294,7 +295,7 @@ func Lstat(name string) (dir *Dir, err Error) {
if e != 0 { if e != 0 {
return nil, &PathError{"lstat", name, Errno(e)}; return nil, &PathError{"lstat", name, Errno(e)};
} }
return dirFromStat(name, new(Dir), &stat, &stat), nil return dirFromStat(name, new(Dir), &stat, &stat), nil;
} }
// Readdir reads the contents of the directory associated with file and // Readdir reads the contents of the directory associated with file and
...@@ -310,18 +311,18 @@ func (file *File) Readdir(count int) (dirs []Dir, err Error) { ...@@ -310,18 +311,18 @@ func (file *File) Readdir(count int) (dirs []Dir, err Error) {
dirname += "/"; dirname += "/";
names, err1 := file.Readdirnames(count); names, err1 := file.Readdirnames(count);
if err1 != nil { if err1 != nil {
return nil, err1 return nil, err1;
} }
dirs = make([]Dir, len(names)); dirs = make([]Dir, len(names));
for i, filename := range names { for i, filename := range names {
dirp, err := Stat(dirname + filename); dirp, err := Stat(dirname+filename);
if dirp == nil || err != nil { if dirp == nil || err != nil {
dirs[i].Name = filename // rest is already zeroed out dirs[i].Name = filename; // rest is already zeroed out
} else { } else {
dirs[i] = *dirp dirs[i] = *dirp;
} }
} }
return return;
} }
// Chdir changes the current working directory to the named directory. // Chdir changes the current working directory to the named directory.
...@@ -479,4 +480,3 @@ func (f *File) Truncate(size int64) Error { ...@@ -479,4 +480,3 @@ func (f *File) Truncate(size int64) Error {
} }
return nil; return nil;
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
package os package os
import ( import (
"syscall" "syscall";
) )
// Getwd returns a rooted path name corresponding to the // Getwd returns a rooted path name corresponding to the
...@@ -27,11 +27,11 @@ func Getwd() (string, Error) { ...@@ -27,11 +27,11 @@ func Getwd() (string, Error) {
// Clumsy but widespread kludge: // Clumsy but widespread kludge:
// if $PWD is set and matches ".", use it. // if $PWD is set and matches ".", use it.
pwd:= Getenv("PWD"); pwd := Getenv("PWD");
if len(pwd) > 0 && pwd[0] == '/' { if len(pwd) > 0 && pwd[0] == '/' {
d, err := Stat(pwd); d, err := Stat(pwd);
if err == nil && d.Dev == dot.Dev && d.Ino == dot.Ino { if err == nil && d.Dev == dot.Dev && d.Ino == dot.Ino {
return pwd, nil return pwd, nil;
} }
} }
...@@ -43,14 +43,14 @@ func Getwd() (string, Error) { ...@@ -43,14 +43,14 @@ func Getwd() (string, Error) {
return "", err; return "", err;
} }
if root.Dev == dot.Dev && root.Ino == dot.Ino { if root.Dev == dot.Dev && root.Ino == dot.Ino {
return "/", nil return "/", nil;
} }
// General algorithm: find name in parent // General algorithm: find name in parent
// and then find name of parent. Each iteration // and then find name of parent. Each iteration
// adds /name to the beginning of pwd. // adds /name to the beginning of pwd.
pwd = ""; pwd = "";
for parent := "..";; parent = "../" + parent { for parent := ".."; ; parent = "../"+parent {
if len(parent) >= 1024 { // Sanity check if len(parent) >= 1024 { // Sanity check
return "", ENAMETOOLONG; return "", ENAMETOOLONG;
} }
...@@ -66,9 +66,9 @@ func Getwd() (string, Error) { ...@@ -66,9 +66,9 @@ func Getwd() (string, Error) {
return "", err; return "", err;
} }
for _, name := range names { for _, name := range names {
d, _ := Lstat(parent + "/" + name); d, _ := Lstat(parent+"/"+name);
if d.Dev == dot.Dev && d.Ino == dot.Ino { if d.Dev == dot.Dev && d.Ino == dot.Ino {
pwd = "/" + name + pwd; pwd = "/"+name+pwd;
goto Found; goto Found;
} }
} }
...@@ -88,5 +88,5 @@ func Getwd() (string, Error) { ...@@ -88,5 +88,5 @@ func Getwd() (string, Error) {
// Set up for next round. // Set up for next round.
dot = pd; dot = pd;
} }
return pwd, nil return pwd, nil;
} }
...@@ -23,7 +23,7 @@ var dot = []string{ ...@@ -23,7 +23,7 @@ var dot = []string{
"time.go", "time.go",
"types.go", "types.go",
"stat_darwin_amd64.go", "stat_darwin_amd64.go",
"stat_linux_amd64.go" "stat_linux_amd64.go",
} }
var etc = []string{ var etc = []string{
...@@ -44,13 +44,13 @@ func size(name string, t *testing.T) uint64 { ...@@ -44,13 +44,13 @@ func size(name string, t *testing.T) uint64 {
n, e := file.Read(&buf); n, e := file.Read(&buf);
len += n; len += n;
if e == EOF { if e == EOF {
break break;
} }
if e != nil { if e != nil {
t.Fatal("read failed:", err); t.Fatal("read failed:", err);
} }
} }
return uint64(len) return uint64(len);
} }
func TestStat(t *testing.T) { func TestStat(t *testing.T) {
...@@ -120,7 +120,7 @@ func testReaddirnames(dir string, contents []string, t *testing.T) { ...@@ -120,7 +120,7 @@ func testReaddirnames(dir string, contents []string, t *testing.T) {
if found { if found {
t.Error("present twice:", m); t.Error("present twice:", m);
} }
found = true found = true;
} }
} }
if !found { if !found {
...@@ -146,7 +146,7 @@ func testReaddir(dir string, contents []string, t *testing.T) { ...@@ -146,7 +146,7 @@ func testReaddir(dir string, contents []string, t *testing.T) {
if found { if found {
t.Error("present twice:", m); t.Error("present twice:", m);
} }
found = true found = true;
} }
} }
if !found { if !found {
...@@ -175,12 +175,12 @@ func smallReaddirnames(file *File, length int, t *testing.T) []string { ...@@ -175,12 +175,12 @@ func smallReaddirnames(file *File, length int, t *testing.T) []string {
t.Fatalf("readdir %q failed: %v", file.Name(), err); t.Fatalf("readdir %q failed: %v", file.Name(), err);
} }
if len(d) == 0 { if len(d) == 0 {
break break;
} }
names[count] = d[0]; names[count] = d[0];
count++; count++;
} }
return names[0:count] return names[0:count];
} }
// Check that reading a directory one entry at a time gives the same result // Check that reading a directory one entry at a time gives the same result
...@@ -211,7 +211,7 @@ func TestReaddirnamesOneAtATime(t *testing.T) { ...@@ -211,7 +211,7 @@ func TestReaddirnamesOneAtATime(t *testing.T) {
func TestHardLink(t *testing.T) { func TestHardLink(t *testing.T) {
from, to := "hardlinktestfrom", "hardlinktestto"; from, to := "hardlinktestfrom", "hardlinktestto";
Remove(from); // Just in case. Remove(from); // Just in case.
file, err := Open(to, O_CREAT | O_WRONLY, 0666); file, err := Open(to, O_CREAT|O_WRONLY, 0666);
if err != nil { if err != nil {
t.Fatalf("open %q failed: %v", to, err); t.Fatalf("open %q failed: %v", to, err);
} }
...@@ -240,7 +240,7 @@ func TestHardLink(t *testing.T) { ...@@ -240,7 +240,7 @@ func TestHardLink(t *testing.T) {
func TestSymLink(t *testing.T) { func TestSymLink(t *testing.T) {
from, to := "symlinktestfrom", "symlinktestto"; from, to := "symlinktestfrom", "symlinktestto";
Remove(from); // Just in case. Remove(from); // Just in case.
file, err := Open(to, O_CREAT | O_WRONLY, 0666); file, err := Open(to, O_CREAT|O_WRONLY, 0666);
if err != nil { if err != nil {
t.Fatalf("open %q failed: %v", to, err); t.Fatalf("open %q failed: %v", to, err);
} }
...@@ -297,7 +297,7 @@ func TestSymLink(t *testing.T) { ...@@ -297,7 +297,7 @@ func TestSymLink(t *testing.T) {
func TestLongSymlink(t *testing.T) { func TestLongSymlink(t *testing.T) {
s := "0123456789abcdef"; s := "0123456789abcdef";
s = s + s + s + s + s + s + s + s + s + s + s + s + s + s + s + s + s; s = s+s+s+s+s+s+s+s+s+s+s+s+s+s+s+s+s;
from := "longsymlinktestfrom"; from := "longsymlinktestfrom";
err := Symlink(s, from); err := Symlink(s, from);
if err != nil { if err != nil {
...@@ -347,7 +347,7 @@ func checkMode(t *testing.T, path string, mode uint32) { ...@@ -347,7 +347,7 @@ func checkMode(t *testing.T, path string, mode uint32) {
func TestChmod(t *testing.T) { func TestChmod(t *testing.T) {
MkdirAll("_obj", 0777); MkdirAll("_obj", 0777);
const Path = "_obj/_TestChmod_"; const Path = "_obj/_TestChmod_";
fd, err := Open(Path, O_WRONLY | O_CREAT, 0666); fd, err := Open(Path, O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %s: %s", Path, err); t.Fatalf("create %s: %s", Path, err);
} }
...@@ -386,7 +386,7 @@ func TestChown(t *testing.T) { ...@@ -386,7 +386,7 @@ func TestChown(t *testing.T) {
// basically useless. // basically useless.
const Path = "/tmp/_TestChown_"; const Path = "/tmp/_TestChown_";
fd, err := Open(Path, O_WRONLY | O_CREAT, 0666); fd, err := Open(Path, O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %s: %s", Path, err); t.Fatalf("create %s: %s", Path, err);
} }
...@@ -439,7 +439,7 @@ func checkSize(t *testing.T, path string, size uint64) { ...@@ -439,7 +439,7 @@ func checkSize(t *testing.T, path string, size uint64) {
func TestTruncate(t *testing.T) { func TestTruncate(t *testing.T) {
MkdirAll("_obj", 0777); MkdirAll("_obj", 0777);
const Path = "_obj/_TestTruncate_"; const Path = "_obj/_TestTruncate_";
fd, err := Open(Path, O_WRONLY | O_CREAT, 0666); fd, err := Open(Path, O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %s: %s", Path, err); t.Fatalf("create %s: %s", Path, err);
} }
...@@ -454,7 +454,7 @@ func TestTruncate(t *testing.T) { ...@@ -454,7 +454,7 @@ func TestTruncate(t *testing.T) {
fd.Truncate(0); fd.Truncate(0);
checkSize(t, Path, 0); checkSize(t, Path, 0);
fd.Write(strings.Bytes("surprise!")); fd.Write(strings.Bytes("surprise!"));
checkSize(t, Path, 13 + 9); // wrote at offset past where hello, world was. checkSize(t, Path, 13+9); // wrote at offset past where hello, world was.
fd.Close(); fd.Close();
Remove(Path); Remove(Path);
} }
...@@ -466,7 +466,7 @@ func TestChdirAndGetwd(t *testing.T) { ...@@ -466,7 +466,7 @@ func TestChdirAndGetwd(t *testing.T) {
} }
// These are chosen carefully not to be symlinks on a Mac // These are chosen carefully not to be symlinks on a Mac
// (unlike, say, /var, /etc, and /tmp). // (unlike, say, /var, /etc, and /tmp).
dirs := []string{ "/bin", "/", "/usr/bin" }; dirs := []string{"/bin", "/", "/usr/bin"};
for mode := 0; mode < 2; mode++ { for mode := 0; mode < 2; mode++ {
for _, d := range dirs { for _, d := range dirs {
if mode == 0 { if mode == 0 {
...@@ -533,15 +533,15 @@ func TestSeek(t *testing.T) { ...@@ -533,15 +533,15 @@ func TestSeek(t *testing.T) {
whence int; whence int;
out int64; out int64;
} }
var tests = []test { var tests = []test{
test{ 0, 1, int64(len(data)) }, test{0, 1, int64(len(data))},
test{ 0, 0, 0 }, test{0, 0, 0},
test{ 5, 0, 5 }, test{5, 0, 5},
test{ 0, 2, int64(len(data)) }, test{0, 2, int64(len(data))},
test{ 0, 0, 0 }, test{0, 0, 0},
test{ -1, 2, int64(len(data)) - 1 }, test{-1, 2, int64(len(data))-1},
test{ 1<<40, 0, 1<<40 }, test{1<<40, 0, 1<<40},
test{ 1<<40, 2, 1<<40 + int64(len(data)) } test{1<<40, 2, 1<<40 + int64(len(data))},
}; };
for i, tt := range tests { for i, tt := range tests {
off, err := f.Seek(tt.in, tt.whence); off, err := f.Seek(tt.in, tt.whence);
...@@ -558,18 +558,18 @@ type openErrorTest struct { ...@@ -558,18 +558,18 @@ type openErrorTest struct {
error string; error string;
} }
var openErrorTests = []openErrorTest { var openErrorTests = []openErrorTest{
openErrorTest { openErrorTest{
"/etc/no-such-file", "/etc/no-such-file",
O_RDONLY, O_RDONLY,
"open /etc/no-such-file: no such file or directory", "open /etc/no-such-file: no such file or directory",
}, },
openErrorTest { openErrorTest{
"/etc", "/etc",
O_WRONLY, O_WRONLY,
"open /etc: is a directory", "open /etc: is a directory",
}, },
openErrorTest { openErrorTest{
"/etc/passwd/group", "/etc/passwd/group",
O_WRONLY, O_WRONLY,
"open /etc/passwd/group: not a directory", "open /etc/passwd/group: not a directory",
...@@ -607,7 +607,7 @@ func run(t *testing.T, cmd []string) string { ...@@ -607,7 +607,7 @@ func run(t *testing.T, cmd []string) string {
Wait(pid, 0); Wait(pid, 0);
output := b.String(); output := b.String();
if n := len(output); n > 0 && output[n-1] == '\n' { if n := len(output); n > 0 && output[n-1] == '\n' {
output = output[0:n-1]; output = output[0 : n-1];
} }
if output == "" { if output == "" {
t.Fatalf("%v produced no output", cmd); t.Fatalf("%v produced no output", cmd);
......
...@@ -35,7 +35,7 @@ func MkdirAll(path string, perm int) Error { ...@@ -35,7 +35,7 @@ func MkdirAll(path string, perm int) Error {
if j > 0 { if j > 0 {
// Create parent // Create parent
err = MkdirAll(path[0:j-1], perm); err = MkdirAll(path[0 : j-1], perm);
if err != nil { if err != nil {
return err; return err;
} }
...@@ -91,7 +91,7 @@ func RemoveAll(path string) Error { ...@@ -91,7 +91,7 @@ func RemoveAll(path string) Error {
for { for {
names, err1 := fd.Readdirnames(100); names, err1 := fd.Readdirnames(100);
for _, name := range names { for _, name := range names {
err1 := RemoveAll(path + "/" + name); err1 := RemoveAll(path+"/"+name);
if err == nil { if err == nil {
err = err1; err = err1;
} }
......
...@@ -26,7 +26,7 @@ func TestMkdirAll(t *testing.T) { ...@@ -26,7 +26,7 @@ func TestMkdirAll(t *testing.T) {
// Make file. // Make file.
fpath := path + "/file"; fpath := path + "/file";
_, err = Open(fpath, O_WRONLY | O_CREAT, 0666); _, err = Open(fpath, O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %q: %s", fpath, err); t.Fatalf("create %q: %s", fpath, err);
} }
...@@ -65,13 +65,13 @@ func TestRemoveAll(t *testing.T) { ...@@ -65,13 +65,13 @@ func TestRemoveAll(t *testing.T) {
// Work directory. // Work directory.
path := "_obj/_TestRemoveAll_"; path := "_obj/_TestRemoveAll_";
fpath := path + "/file"; fpath := path + "/file";
dpath := path + "/dir"; dpath := path+"/dir";
// Make directory with 1 file and remove. // Make directory with 1 file and remove.
if err := MkdirAll(path, 0777); err != nil { if err := MkdirAll(path, 0777); err != nil {
t.Fatalf("MkdirAll %q: %s", path, err); t.Fatalf("MkdirAll %q: %s", path, err);
} }
fd, err := Open(fpath, O_WRONLY | O_CREAT, 0666); fd, err := Open(fpath, O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %q: %s", fpath, err); t.Fatalf("create %q: %s", fpath, err);
} }
...@@ -87,12 +87,12 @@ func TestRemoveAll(t *testing.T) { ...@@ -87,12 +87,12 @@ func TestRemoveAll(t *testing.T) {
if err = MkdirAll(dpath, 0777); err != nil { if err = MkdirAll(dpath, 0777); err != nil {
t.Fatalf("MkdirAll %q: %s", dpath, err); t.Fatalf("MkdirAll %q: %s", dpath, err);
} }
fd, err = Open(fpath, O_WRONLY | O_CREAT, 0666); fd, err = Open(fpath, O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %q: %s", fpath, err); t.Fatalf("create %q: %s", fpath, err);
} }
fd.Close(); fd.Close();
fd, err = Open(dpath+"/file", O_WRONLY | O_CREAT, 0666); fd, err = Open(dpath + "/file", O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %q: %s", fpath, err); t.Fatalf("create %q: %s", fpath, err);
} }
...@@ -109,8 +109,8 @@ func TestRemoveAll(t *testing.T) { ...@@ -109,8 +109,8 @@ func TestRemoveAll(t *testing.T) {
t.Fatalf("MkdirAll %q: %s", dpath, err); t.Fatalf("MkdirAll %q: %s", dpath, err);
} }
for _, s := range []string{fpath, dpath+"/file1", path+"/zzz"} { for _, s := range []string{fpath, dpath + "/file1", path+"/zzz"} {
fd, err = Open(s, O_WRONLY | O_CREAT, 0666); fd, err = Open(s, O_WRONLY|O_CREAT, 0666);
if err != nil { if err != nil {
t.Fatalf("create %q: %s", s, err); t.Fatalf("create %q: %s", s, err);
} }
......
...@@ -8,8 +8,8 @@ package os ...@@ -8,8 +8,8 @@ package os
import "syscall" import "syscall"
var Args []string; // provided by runtime var Args []string // provided by runtime
var Envs []string; // provided by runtime var Envs []string // provided by runtime
// Getuid returns the numeric user id of the caller. // Getuid returns the numeric user id of the caller.
...@@ -43,4 +43,3 @@ func Getgroups() ([]int, Error) { ...@@ -43,4 +43,3 @@ func Getgroups() ([]int, Error) {
func Exit(code int) { func Exit(code int) {
syscall.Exit(code); syscall.Exit(code);
} }
...@@ -9,7 +9,7 @@ package os ...@@ -9,7 +9,7 @@ package os
import "syscall" import "syscall"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK;
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
...@@ -26,9 +26,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { ...@@ -26,9 +26,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atimespec)); dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atimespec));
dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtimespec)); dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtimespec));
dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctimespec)); dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctimespec));
for i := len(name) - 1; i >= 0; i-- { for i := len(name)-1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:len(name)]; name = name[i+1 : len(name)];
break; break;
} }
} }
......
...@@ -9,7 +9,7 @@ package os ...@@ -9,7 +9,7 @@ package os
import "syscall" import "syscall"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK;
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
...@@ -26,9 +26,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { ...@@ -26,9 +26,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atimespec)); dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atimespec));
dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtimespec)); dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtimespec));
dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctimespec)); dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctimespec));
for i := len(name) - 1; i >= 0; i-- { for i := len(name)-1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:len(name)]; name = name[i+1 : len(name)];
break; break;
} }
} }
......
...@@ -13,7 +13,7 @@ package os ...@@ -13,7 +13,7 @@ package os
import "syscall" import "syscall"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK;
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
...@@ -30,9 +30,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { ...@@ -30,9 +30,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim)); dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim));
dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim)); dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim));
dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim)); dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim));
for i := len(name) - 1; i >= 0; i-- { for i := len(name)-1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:len(name)]; name = name[i+1 : len(name)];
break; break;
} }
} }
......
...@@ -9,7 +9,7 @@ package os ...@@ -9,7 +9,7 @@ package os
import "syscall" import "syscall"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK;
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
...@@ -26,9 +26,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { ...@@ -26,9 +26,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim)); dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim));
dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim)); dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim));
dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim)); dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim));
for i := len(name) - 1; i >= 0; i-- { for i := len(name)-1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:len(name)]; name = name[i+1 : len(name)];
break; break;
} }
} }
......
...@@ -13,7 +13,7 @@ package os ...@@ -13,7 +13,7 @@ package os
import "syscall" import "syscall"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK;
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
...@@ -30,9 +30,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { ...@@ -30,9 +30,9 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim)); dir.Atime_ns = uint64(syscall.TimespecToNsec(stat.Atim));
dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim)); dir.Mtime_ns = uint64(syscall.TimespecToNsec(stat.Mtim));
dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim)); dir.Ctime_ns = uint64(syscall.TimespecToNsec(stat.Ctim));
for i := len(name) - 1; i >= 0; i-- { for i := len(name)-1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:len(name)]; name = name[i+1 : len(name)];
break; break;
} }
} }
......
...@@ -13,7 +13,7 @@ package os ...@@ -13,7 +13,7 @@ package os
import "syscall" import "syscall"
func isSymlink(stat *syscall.Stat_t) bool { func isSymlink(stat *syscall.Stat_t) bool {
return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK return stat.Mode & syscall.S_IFMT == syscall.S_IFLNK;
} }
func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
...@@ -27,12 +27,12 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir { ...@@ -27,12 +27,12 @@ func dirFromStat(name string, dir *Dir, lstat, stat *syscall.Stat_t) *Dir {
dir.Size = uint64(stat.Size); dir.Size = uint64(stat.Size);
dir.Blksize = uint64(stat.Blksize); dir.Blksize = uint64(stat.Blksize);
dir.Blocks = uint64(stat.Blocks); dir.Blocks = uint64(stat.Blocks);
dir.Atime_ns = uint64(stat.Atime)*1e9; dir.Atime_ns = uint64(stat.Atime) * 1e9;
dir.Mtime_ns = uint64(stat.Mtime)*1e9; dir.Mtime_ns = uint64(stat.Mtime) * 1e9;
dir.Ctime_ns = uint64(stat.Ctime)*1e9; dir.Ctime_ns = uint64(stat.Ctime) * 1e9;
for i := len(name) - 1; i >= 0; i-- { for i := len(name)-1; i >= 0; i-- {
if name[i] == '/' { if name[i] == '/' {
name = name[i+1:len(name)]; name = name[i+1 : len(name)];
break; break;
} }
} }
......
...@@ -16,6 +16,5 @@ func Time() (sec int64, nsec int64, err Error) { ...@@ -16,6 +16,5 @@ func Time() (sec int64, nsec int64, err Error) {
if errno := syscall.Gettimeofday(&tv); errno != 0 { if errno := syscall.Gettimeofday(&tv); errno != 0 {
return 0, 0, NewSyscallError("gettimeofday", errno); return 0, 0, NewSyscallError("gettimeofday", errno);
} }
return int64(tv.Sec), int64(tv.Usec)*1000, err; return int64(tv.Sec), int64(tv.Usec) * 1000, err;
} }
...@@ -10,8 +10,8 @@ import "syscall" ...@@ -10,8 +10,8 @@ import "syscall"
// OS-specific routines in this directory convert the OS-local versions to these. // OS-specific routines in this directory convert the OS-local versions to these.
// Getpagesize returns the underlying system's memory page size. // Getpagesize returns the underlying system's memory page size.
func Getpagesize() int{ func Getpagesize() int {
return syscall.Getpagesize() return syscall.Getpagesize();
} }
// A Dir describes a file and is returned by Stat, Fstat, and Lstat // A Dir describes a file and is returned by Stat, Fstat, and Lstat
...@@ -35,41 +35,40 @@ type Dir struct { ...@@ -35,41 +35,40 @@ type Dir struct {
// IsFifo reports whether the Dir describes a FIFO file. // IsFifo reports whether the Dir describes a FIFO file.
func (dir *Dir) IsFifo() bool { func (dir *Dir) IsFifo() bool {
return (dir.Mode & syscall.S_IFMT) == syscall.S_IFIFO return (dir.Mode & syscall.S_IFMT) == syscall.S_IFIFO;
} }
// IsChar reports whether the Dir describes a character special file. // IsChar reports whether the Dir describes a character special file.
func (dir *Dir) IsChar() bool { func (dir *Dir) IsChar() bool {
return (dir.Mode & syscall.S_IFMT) == syscall.S_IFCHR return (dir.Mode & syscall.S_IFMT) == syscall.S_IFCHR;
} }
// IsDirectory reports whether the Dir describes a directory. // IsDirectory reports whether the Dir describes a directory.
func (dir *Dir) IsDirectory() bool { func (dir *Dir) IsDirectory() bool {
return (dir.Mode & syscall.S_IFMT) == syscall.S_IFDIR return (dir.Mode & syscall.S_IFMT) == syscall.S_IFDIR;
} }
// IsBlock reports whether the Dir describes a block special file. // IsBlock reports whether the Dir describes a block special file.
func (dir *Dir) IsBlock() bool { func (dir *Dir) IsBlock() bool {
return (dir.Mode & syscall.S_IFMT) == syscall.S_IFBLK return (dir.Mode & syscall.S_IFMT) == syscall.S_IFBLK;
} }
// IsRegular reports whether the Dir describes a regular file. // IsRegular reports whether the Dir describes a regular file.
func (dir *Dir) IsRegular() bool { func (dir *Dir) IsRegular() bool {
return (dir.Mode & syscall.S_IFMT) == syscall.S_IFREG return (dir.Mode & syscall.S_IFMT) == syscall.S_IFREG;
} }
// IsSymlink reports whether the Dir describes a symbolic link. // IsSymlink reports whether the Dir describes a symbolic link.
func (dir *Dir) IsSymlink() bool { func (dir *Dir) IsSymlink() bool {
return (dir.Mode & syscall.S_IFMT) == syscall.S_IFLNK return (dir.Mode & syscall.S_IFMT) == syscall.S_IFLNK;
} }
// IsSocket reports whether the Dir describes a socket. // IsSocket reports whether the Dir describes a socket.
func (dir *Dir) IsSocket() bool { func (dir *Dir) IsSocket() bool {
return (dir.Mode & syscall.S_IFMT) == syscall.S_IFSOCK return (dir.Mode & syscall.S_IFMT) == syscall.S_IFSOCK;
} }
// Permission returns the file permission bits. // Permission returns the file permission bits.
func (dir *Dir) Permission() int { func (dir *Dir) Permission() int {
return int(dir.Mode & 0777) return int(dir.Mode & 0777);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment