75,056 matches across 25 files for func main lang:Go
snippet_mode: grep · sorted by relevance
16// external zip tool is used or the ordering of file names in a directory
17// or the current time.
18▶package main
19
20import (
· · ·
31)
32
33▶func usage() {
34 fmt.Fprintf(os.Stderr, "usage: go run mkzip.go zoneinfo.zip\n")
35 os.Exit(2)
· · ·
36}
37
38▶func main() {
39 log.SetPrefix("mkzip: ")
40 log.SetFlags(0)
· · ·
49 zw := zip.NewWriter(&zb)
50 seen := make(map[string]bool)
51▶ err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
52 if d.IsDir() {
53 return nil
10// and foreign code on multiple pthreads.
11
12▶package main
13
14import (
· · ·
17)
18
19▶func fibber(c chan *big.Int, out chan string, n int64) {
20 // Keep the fibbers in dedicated operating system
21 // threads, so that this program tests coordination
· · ·
35}
36
37▶func main() {
38 c := make(chan *big.Int)
39 out := make(chan string)
5//go:build ignore
6
7▶package main
8
9import (
· · ·
22)
23
24▶func extractDigit() int64 {
25 if big.CmpInt(numer, accum) > 0 {
26 return -1
· · ·
35}
36
37▶func nextTerm(k int64) {
38 y2 := k*2 + 1
39 accum.Add(accum, tmp1.Lsh(numer, 1))
· · ·
43}
44
45▶func eliminateDigit(d int64) {
46 accum.Sub(accum, tmp1.Mul(denom, tmp1.SetInt64(d)))
47 accum.Mul(accum, ten)
· · ·
49}
50
51▶func main() {
52 i := 0
53 k := int64(0)
5//go:build !(windows || js || wasip1)
6
7▶package main
8
9import (
· · ·
13)
14
15▶func TestExitCodeFilter(t *testing.T) {
16 // Write text to the filter one character at a time.
17 var out strings.Builder
· · ·
46}
47
48▶func TestExitCodeMissing(t *testing.T) {
49 var wantErr *regexp.Regexp
50 check := func(text string) {
· · ·
50▶ check := func(text string) {
51 t.Helper()
52 var out strings.Builder
11// This program can be used as go_android_GOARCH_exec by the Go tool.
12// It executes binaries on an android device using adb.
13▶package main
14
15import (
· · ·
32)
33
34▶func adbRun(args string) (int, error) {
35 // The exit code of adb is often wrong. In theory it was fixed in 2016
36 // (https://code.google.com/p/android/issues/detail?id=3254), but it's
· · ·
63}
64
65▶func adb(args ...string) error {
66 if out, err := adbCmd(args...).CombinedOutput(); err != nil {
67 fmt.Fprintf(os.Stderr, "adb %s\n%s", strings.Join(args, " "), out)
· · ·
71}
72
73▶func adbCmd(args ...string) *exec.Cmd {
74 if flags := os.Getenv("GOANDROID_ADB_FLAGS"); flags != "" {
75 args = append(strings.Split(flags, " "), args...)
· · ·
83)
84
85▶func main() {
86 log.SetFlags(0)
87 log.SetPrefix("go_android_exec: ")
+ 13 more matches in this file
11// be obtained by following the instructions at
12// https://github.com/libimobiledevice/libimobiledevice.
13▶package main
14
15import (
· · ·
22)
23
24▶func main() {
25 udids := getLines(exec.Command("idevice_id", "-l"))
26 if len(udids) == 0 {
· · ·
64}
65
66▶func detectMobileProvisionFiles(udids [][]byte) []string {
67 cmd := exec.Command("mdfind", "-name", ".mobileprovision")
68 lines := getLines(cmd)
· · ·
89}
90
91▶func parseMobileProvision(fname string) *exec.Cmd {
92 return exec.Command("security", "cms", "-D", "-i", string(fname))
93}
· · ·
94
95▶func plistExtract(fname string, path string) ([]byte, error) {
96 out, err := exec.Command("/usr/libexec/PlistBuddy", "-c", "Print "+path, fname).CombinedOutput()
97 if err != nil {
+ 4 more matches in this file
5// This program can be used as go_ios_$GOARCH_exec by the Go tool. It executes
6// binaries on the iOS Simulator using the XCode toolchain.
7▶package main
8
9import (
· · ·
36var lock *os.File
37
38▶func main() {
39 log.SetFlags(0)
40 log.SetPrefix("go_ios_exec: ")
· · ·
49 bundleID = "golang.gotest"
50
51▶ exitCode, err := runMain()
52 if err != nil {
53 log.Fatalf("%v\n", err)
· · ·
56}
57
58▶func runMain() (int, error) {
59 var err error
60 tmpdir, err = os.MkdirTemp("", "go_ios_exec_")
· · ·
95}
96
97▶func runOnSimulator(appdir string) error {
98 if err := installSimulator(appdir); err != nil {
99 return err
+ 9 more matches in this file
45type headerError []string
46
47▶func (he headerError) Error() string {
48 const prefix = "archive/tar: cannot encode header"
49 var ss []string
· · ·
214type sparseEntry struct{ Offset, Length int64 }
215
216▶func (s sparseEntry) endOffset() int64 { return s.Offset + s.Length }
217
218// A sparse file can be represented as either a sparseDatas or a sparseHoles.
· · ·
255// validateSparseEntries reports whether sp is a valid sparse map.
256// It does not matter whether sp represents data fragments or hole fragments.
257▶func validateSparseEntries(sp []sparseEntry, size int64) bool {
258 // Validate all sparse entries. These are the same checks as performed by
259 // the BSD tar utility.
· · ·
285// with arbitrary offsets and lengths, the GNU tar utility can only handle
286// offsets and lengths that are multiples of blockSize.
287▶func alignSparseEntries(src []sparseEntry, size int64) []sparseEntry {
288 dst := src[:0]
289 for _, s := range src {
· · ·
304// The input must have been already validated.
305//
306▶// This function mutates src and returns a normalized map where:
307// - adjacent fragments are coalesced together
308// - only the last fragment may be empty
+ 22 more matches in this file
37
38// NewReader creates a new [Reader] reading from r.
39▶func NewReader(r io.Reader) *Reader {
40 return &Reader{r: r, curr: ®FileReader{r, 0}}
41}
· · ·
43// Next advances to the next entry in the tar archive.
44// The Header.Size determines how many bytes can be read for the next file.
45▶// Any remaining data in the current file is automatically discarded.
46// At the end of the archive, Next returns the error io.EOF.
47//
· · ·
53// Programs that want to accept non-local names can ignore
54// the [ErrInsecurePath] error and use the returned header.
55▶func (tr *Reader) Next() (*Header, error) {
56 if tr.err != nil {
57 return nil, tr.err
· · ·
68}
69
70▶func (tr *Reader) next() (*Header, error) {
71 var paxHdrs map[string]string
72 var gnuLongName, gnuLongLink string
· · ·
79 format := FormatUSTAR | FormatPAX | FormatGNU
80 for {
81▶ // Discard the remainder of the file and any padding.
82 if err := discard(tr.r, tr.curr.physicalRemaining()); err != nil {
83 return nil, err
+ 46 more matches in this file
25)
26
27▶func TestReader(t *testing.T) {
28 vectors := []struct {
29 file string // Test input file
· · ·
633
634 for _, v := range vectors {
635▶ t.Run(strings.TrimSuffix(path.Base(v.file), ".base64"), func(t *testing.T) {
636 path := v.file
637 if v.obscured {
· · ·
712}
713
714▶func TestPartialRead(t *testing.T) {
715 type testCase struct {
716 cnt int // Number of bytes to read
· · ·
738
739 for _, v := range vectors {
740▶ t.Run(path.Base(v.file), func(t *testing.T) {
741 f, err := os.Open(v.file)
742 if err != nil {
· · ·
767}
768
769▶func TestUninitializedRead(t *testing.T) {
770 f, err := os.Open("testdata/gnu.tar")
771 if err != nil {
+ 56 more matches in this file
14
15// hasNUL reports whether the NUL character exists within s.
16▶func hasNUL(s string) bool {
17 return strings.Contains(s, "\x00")
18}
· · ·
19
20// isASCII reports whether the input is an ASCII C-style string.
21▶func isASCII(s string) bool {
22 for _, c := range s {
23 if c >= 0x80 || c == 0x00 {
· · ·
30// toASCII converts the input to an ASCII C-style string.
31// This is a best effort conversion, so invalid characters are dropped.
32▶func toASCII(s string) string {
33 if isASCII(s) {
34 return s
· · ·
53// parseString parses bytes as a NUL-terminated C-style string.
54// If a NUL byte is not found then the whole slice is returned as a string.
55▶func (*parser) parseString(b []byte) string {
56 if i := bytes.IndexByte(b, 0); i >= 0 {
57 return string(b[:i])
· · ·
61
62// formatString copies s into b, NUL-terminating if possible.
63▶func (f *formatter) formatString(b []byte, s string) {
64 if len(s) > len(b) {
65 f.err = ErrFieldTooLong
+ 14 more matches in this file
34
35// NewWriter creates a new Writer writing to w.
36▶func NewWriter(w io.Writer) *Writer {
37 return &Writer{w: w, curr: ®FileWriter{w, 0}}
38}
· · ·
50// This is unnecessary as the next call to [Writer.WriteHeader] or [Writer.Close]
51// will implicitly flush out the file's padding.
52▶func (tw *Writer) Flush() error {
53 if tw.err != nil {
54 return tw.err
· · ·
55 }
56▶ if nb := tw.curr.logicalRemaining(); nb > 0 {
57 return fmt.Errorf("archive/tar: missed writing %d bytes", nb)
58 }
· · ·
68// If the current file is not fully written, then this returns an error.
69// This implicitly flushes any padding necessary before writing the header.
70▶func (tw *Writer) WriteHeader(hdr *Header) error {
71 if err := tw.Flush(); err != nil {
72 return err
· · ·
111}
112
113▶func (tw *Writer) writeUSTARHeader(hdr *Header) error {
114 // Check if we can use USTAR prefix/suffix splitting.
115 var namePrefix string
+ 42 more matches in this file
24)
25
26▶func bytediff(a, b []byte) string {
27 const (
28 uniqueA = "- "
· · ·
53}
54
55▶func TestWriter(t *testing.T) {
56 type (
57 testHeader struct { // WriteHeader(hdr) == wantErr
· · ·
480 }}
481
482▶ equalError := func(x, y error) bool {
483 _, ok1 := x.(headerError)
484 _, ok2 := y.(headerError)
· · ·
489 }
490 for _, v := range vectors {
491▶ t.Run(strings.TrimSuffix(path.Base(v.file), ".base64"), func(t *testing.T) {
492 const maxSize = 10 << 10 // 10KiB
493 buf := new(bytes.Buffer)
· · ·
550}
551
552▶func TestPax(t *testing.T) {
553 // Create an archive with a large name
554 fileinfo, err := os.Stat("testdata/small.txt")
+ 71 more matches in this file
26type ZipTest struct {
27 Name string
28▶ Source func() (r io.ReaderAt, size int64) // if non-nil, used instead of testdata/<Name> file
29 Comment string
30 File []ZipTestFile
· · ·
583}
584
585▶func TestReader(t *testing.T) {
586 for _, zt := range tests {
587 t.Run(zt.Name, func(t *testing.T) {
· · ·
587▶ t.Run(zt.Name, func(t *testing.T) {
588 readTestZip(t, zt)
589 })
· · ·
591}
592
593▶func readTestZip(t *testing.T, zt ZipTest) {
594 var z *Reader
595 var err error
· · ·
663 for i := 0; i < 5; i++ {
664 for j, ft := range zt.File {
665▶ go func(j int, ft ZipTestFile) {
666 readTestFile(t, zt, ft, z.File[j], raw)
667 done <- true
+ 47 more matches in this file
33 // testHookCloseSizeOffset if non-nil is called with the size
34 // of offset of the central directory at Close.
35▶ testHookCloseSizeOffset func(size, offset uint64)
36}
37
· · ·
47// compatibility promise. Callers, including tests, should not depend on the
48// exact written bytes.
49▶func NewWriter(w io.Writer) *Writer {
50 return &Writer{cw: &countWriter{w: bufio.NewWriter(w)}}
51}
· · ·
55// existing file, such as a binary executable.
56// It must be called before any data is written.
57▶func (w *Writer) SetOffset(n int64) {
58 if w.cw.count != 0 {
59 panic("zip: SetOffset called after data was written")
· · ·
64// Flush flushes any buffered data to the underlying writer.
65// Calling Flush is not normally necessary; calling Close is sufficient.
66▶func (w *Writer) Flush() error {
67 return w.cw.w.(*bufio.Writer).Flush()
68}
· · ·
70// SetComment sets the end-of-central-directory comment field.
71// It can only be called before [Writer.Close].
72▶func (w *Writer) SetComment(comment string) error {
73 if len(comment) > uint16max {
74 return errors.New("zip: Writer.Comment too long")
+ 23 more matches in this file
22)
23
24▶func TestOver65kFiles(t *testing.T) {
25 if testing.Short() && testenv.Builder() == "" {
26 t.Skip("skipping in short mode")
· · ·
57}
58
59▶func TestModTime(t *testing.T) {
60 var testTime = time.Date(2009, time.November, 10, 23, 45, 58, 0, time.UTC)
61 fh := new(FileHeader)
· · ·
67}
68
69▶func testHeaderRoundTrip(fh *FileHeader, wantUncompressedSize uint32, wantUncompressedSize64 uint64, t *testing.T) {
70 fi := fh.FileInfo()
71 fh2, err := FileInfoHeader(fi)
· · ·
94}
95
96▶func TestFileHeaderRoundTrip(t *testing.T) {
97 fh := &FileHeader{
98 Name: "foo.txt",
· · ·
104}
105
106▶func TestFileHeaderRoundTrip64(t *testing.T) {
107 fh := &FileHeader{
108 Name: "foo.txt",
+ 55 more matches in this file
48// size. If the argument io.Reader is already a [Reader] with large enough
49// size, it returns the underlying [Reader].
50▶func NewReaderSize(rd io.Reader, size int) *Reader {
51 // Is it already a Reader?
52 b, ok := rd.(*Reader)
· · ·
60
61// NewReader returns a new [Reader] whose buffer has the default size.
62▶func NewReader(rd io.Reader) *Reader {
63 return NewReaderSize(rd, defaultBufSize)
64}
· · ·
65
66// Size returns the size of the underlying buffer in bytes.
67▶func (b *Reader) Size() int { return len(b.buf) }
68
69// Reset discards any buffered data, resets all state, and switches
· · ·
72// to the default size.
73// Calling b.Reset(b) (that is, resetting a [Reader] to itself) does nothing.
74▶func (b *Reader) Reset(r io.Reader) {
75 // If a Reader r is passed to NewReader, NewReader will return r.
76 // Different layers of code may do that, and then later pass r
· · ·
85}
86
87▶func (b *Reader) reset(buf []byte, r io.Reader) {
88 *b = Reader{
89 buf: buf,
+ 38 more matches in this file
26}
27
28▶func newRot13Reader(r io.Reader) *rot13Reader {
29 r13 := new(rot13Reader)
30 r13.r = r
· · ·
32}
33
34▶func (r13 *rot13Reader) Read(p []byte) (int, error) {
35 n, err := r13.r.Read(p)
36 for i := 0; i < n; i++ {
· · ·
46
47// Call ReadByte to accumulate the text of a file
48▶func readBytes(buf *Reader) string {
49 var b [1000]byte
50 nb := 0
· · ·
64}
65
66▶func TestReaderSimple(t *testing.T) {
67 data := "hello world"
68 b := NewReader(strings.NewReader(data))
· · ·
79type readMaker struct {
80 name string
81▶ fn func(io.Reader) io.Reader
82}
83
+ 129 more matches in this file
16// the [Scanner.Scan] method will step through the 'tokens' of a file, skipping
17// the bytes between the tokens. The specification of a token is
18▶// defined by a split function of type [SplitFunc]; the default split
19// function breaks the input into lines with line termination stripped. [Scanner.Split]
20// functions are defined in this package for scanning a file into
· · ·
19▶// function breaks the input into lines with line termination stripped. [Scanner.Split]
20// functions are defined in this package for scanning a file into
21// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
· · ·
20▶// functions are defined in this package for scanning a file into
21// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
22// client may instead provide a custom split function.
· · ·
22▶// client may instead provide a custom split function.
23//
24// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
· · ·
29type Scanner struct {
30 r io.Reader // The reader provided by the client.
31▶ split SplitFunc // The function to split the tokens.
32 maxTokenSize int // Maximum size of a token; modified by tests.
33 token []byte // Last token returned by split.
+ 35 more matches in this file
22type negativeReader struct{}
23
24▶func (r *negativeReader) Read([]byte) (int, error) { return -1, nil }
25
26func init() {
· · ·
26▶func init() {
27 testBytes = make([]byte, N)
28 for i := 0; i < N; i++ {
· · ·
33
34// Verify that contents of buf match the string s.
35▶func check(t *testing.T, testname string, buf *Buffer, s string) {
36 bytes := buf.Bytes()
37 str := buf.String()
· · ·
56// The initial contents of buf corresponds to the string s;
57// the result is the final contents of buf returned as a string.
58▶func fillString(t *testing.T, testname string, buf *Buffer, s string, n int, fus string) string {
59 check(t, testname+" (fill 1)", buf, s)
60 for ; n > 0; n-- {
· · ·
75// The initial contents of buf corresponds to the string s;
76// the result is the final contents of buf returned as a string.
77▶func fillBytes(t *testing.T, testname string, buf *Buffer, s string, n int, fub []byte) string {
78 check(t, testname+" (fill 1)", buf, s)
79 for ; n > 0; n-- {
+ 46 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶// Package bytes implements functions for the manipulation of byte slices.
6// It is analogous to the facilities of the [strings] package.
7package bytes
· · ·
19// are the same length and contain the same bytes.
20// A nil argument is equivalent to an empty slice.
21▶func Equal(a, b []byte) bool {
22 // Neither cmd/compile nor gccgo allocates for these string conversions.
23 return string(a) == string(b)
· · ·
27// The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
28// A nil argument is equivalent to an empty slice.
29▶func Compare(a, b []byte) int {
30 return bytealg.Compare(a, b)
31}
· · ·
33// explode splits s into a slice of UTF-8 sequences, one per Unicode code point (still slices of bytes),
34// up to a maximum of n byte slices. Invalid UTF-8 sequences are chopped into individual bytes.
35▶func explode(s []byte, n int) [][]byte {
36 if n <= 0 || n > len(s) {
37 n = len(s)
· · ·
56// Count counts the number of non-overlapping instances of sep in s.
57// If sep is an empty slice, Count returns 1 + the number of UTF-8-encoded code points in s.
58▶func Count(s, sep []byte) int {
59 // special case
60 if len(sep) == 0 {
+ 91 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶package main
6
7import (
· · ·
16)
17
18▶// TestMain executes the test binary as the addr2line command if
19// GO_ADDR2LINETEST_IS_ADDR2LINE is set, and runs the tests otherwise.
20func TestMain(m *testing.M) {
· · ·
20▶func TestMain(m *testing.M) {
21 if os.Getenv("GO_ADDR2LINETEST_IS_ADDR2LINE") != "" {
22 main()
· · ·
22▶ main()
23 os.Exit(0)
24 }
· · ·
28}
29
30▶func loadSyms(t *testing.T, dbgExePath string) map[string]string {
31 cmd := testenv.Command(t, testenv.GoToolPath(t), "tool", "nm", dbgExePath)
32 out, err := cmd.CombinedOutput()
+ 8 more matches in this file
12// Addr2line reads hexadecimal addresses, one per line and with optional 0x prefix,
13// from standard input. For each input address, addr2line prints two output lines,
14▶// first the name of the function containing the address and second the file:line
15// of the source code corresponding to that address.
16//
· · ·
17// This tool is intended for use only by pprof; its interface may change or
18// it may be deleted entirely in future releases.
19▶package main
20
21import (
· · ·
32)
33
34▶func printUsage(w *os.File) {
35 fmt.Fprintf(w, "usage: addr2line binary\n")
36 fmt.Fprintf(w, "reads addresses from standard input and writes two lines for each:\n")
· · ·
37▶ fmt.Fprintf(w, "\tfunction name\n")
38 fmt.Fprintf(w, "\tfile:line\n")
39}
· · ·
40
41▶func usage() {
42 printUsage(os.Stderr)
43 os.Exit(2)
+ 1 more matches in this file
3// license that can be found in the LICENSE file.
4
5▶package main
6
7import (
· · ·
20var flagCheck = flag.Bool("check", false, "run API checks")
21
22▶func TestMain(m *testing.M) {
23 flag.Parse()
24 for _, c := range contexts {
· · ·
34)
35
36▶func TestGolden(t *testing.T) {
37 if *flagCheck {
38 // slow, not worth repeating in -check
· · ·
99}
100
101▶func TestCompareAPI(t *testing.T) {
102 if *flagCheck {
103 // not worth repeating in -check
· · ·
185}
186
187▶func TestSkipInternal(t *testing.T) {
188 if *flagCheck {
189 // not worth repeating in -check
+ 9 more matches in this file