| 1 |
// Copyright 2009 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package base |
| 6 |
|
| 7 |
import ( |
| 8 |
"os" |
| 9 |
) |
| 10 |
|
| 11 |
var atExitFuncs []func() |
| 12 |
|
| 13 |
func AtExit(f func()) { |
| 14 |
atExitFuncs = append(atExitFuncs, f) |
| 15 |
} |
| 16 |
|
| 17 |
func Exit(code int) { |
| 18 |
for i := len(atExitFuncs) - 1; i >= 0; i-- { |
| 19 |
f := atExitFuncs[i] |
| 20 |
atExitFuncs = atExitFuncs[:i] |
| 21 |
f() |
| 22 |
} |
| 23 |
os.Exit(code) |
| 24 |
} |
| 25 |
|
| 26 |
// To enable tracing support (-t flag), set EnableTrace to true. |
| 27 |
const EnableTrace = false |