// OpenCore will open the core file and return a Process struct.
// If the DWARF information cannot be found in the binary, Delve will look
// for external debug files in the directories passed in.
501748
func OpenCore(corePath, exePath string, debugInfoDirs []string) (*Process, error) {
	var p *Process
	var err error
	for _, openFn := range openFns {
		p, err = openFn(corePath, exePath)
		if err != ErrUnrecognizedFormat {
			break
		}
	}
	if err != nil {
		return nil, err
	}

	if err := p.initialize(exePath, debugInfoDirs); err != nil {
		return nil, err
	}

	return p, nil
}
371960
func Open(path string, logfn func(fmt string, args ...interface{})) (*Minidump, error) {
	rawbuf, err := ioutil.ReadFile(path) //TODO(aarzilli): mmap?
	if err != nil {
		return nil, err
	}

	buf := &minidumpBuf{buf: rawbuf, kind: "file"}

	var mdmp Minidump

	readMinidumpHeader(&mdmp, buf)
	if buf.err != nil {
		return nil, buf.err
	}

	if logfn != nil {
		logfn("Minidump Header\n")
		logfn("Num Streams: %d\n", mdmp.streamNum)
		logfn("Streams offset: %#x\n", mdmp.streamOff)
		logfn("File flags: %s\n", fileFlagsToString(mdmp.Flags))
		logfn("Offset after header %#x\n", buf.off)
	}

	readDirectory(&mdmp, buf)
	if buf.err != nil {
		return nil, buf.err
	}

	for i := range mdmp.Streams {
		stream := &mdmp.Streams[i]
		if stream.Type != SystemInfoStream {
			continue
		}

		sb := streamBuf(stream, buf, "system info")
		if buf.err != nil {
			return nil, buf.err
		}

		arch := Arch(sb.u16())

		if logfn != nil {
			logfn("Found processor architecture %s\n", arch.String())
		}

		if arch != CpuArchitectureAMD64 {
			return nil, fmt.Errorf("unsupported architecture %s", arch.String())
		}
	}

	for i := range mdmp.Streams {
		stream := &mdmp.Streams[i]
		if logfn != nil {
			logfn("Stream %d: type:%s off:%#x size:%#x\n", i, stream.Type, stream.Offset, len(stream.RawData))
		}
		switch stream.Type {
		case ThreadListStream:
			readThreadList(&mdmp, streamBuf(stream, buf, "thread list"))
			if logfn != nil {
				for i := range mdmp.Threads {
					logfn("\tID:%#x TEB:%#x\n", mdmp.Threads[i].ID, mdmp.Threads[i].TEB)
				}
			}
		case ModuleListStream:
			readModuleList(&mdmp, streamBuf(stream, buf, "module list"))
			if logfn != nil {
				for i := range mdmp.Modules {
					logfn("\tName:%q BaseOfImage:%#x SizeOfImage:%#x\n", mdmp.Modules[i].Name, mdmp.Modules[i].BaseOfImage, mdmp.Modules[i].SizeOfImage)
				}
			}
		case ExceptionStream:
			//TODO(aarzilli): this stream contains the exception that made the
			//process stop and caused the minidump to be taken. If we ever start
			//caring about this we should parse this.
		case Memory64ListStream:
			readMemory64List(&mdmp, streamBuf(stream, buf, "memory64 list"), logfn)
		case MemoryInfoListStream:
			readMemoryInfoList(&mdmp, streamBuf(stream, buf, "memory info list"), logfn)
		case MiscInfoStream:
			readMiscInfo(&mdmp, streamBuf(stream, buf, "misc info"))
			if logfn != nil {
				logfn("\tPid: %#x\n", mdmp.Pid)
			}
		case CommentStreamW:
			if logfn != nil {
				logfn("\t%q\n", decodeUTF16(stream.RawData))
			}
		case CommentStreamA:
			if logfn != nil {
				logfn("\t%s\n", string(stream.RawData))
			}
		}
		if buf.err != nil {
			return nil, buf.err
		}
	}

	return &mdmp, nil
}
294323
func (p *parserMixin) OpenFileVar(target **os.File, flag int, perm os.FileMode) {
	p.SetValue(newFileValue(target, flag, perm))
}
46231
func (p *Pod) openFile(path string, flags int) (*os.File, error) {
	cdirfd, err := p.Fd()
	if err != nil {
		return nil, err
	}

	fd, err := syscall.Openat(cdirfd, path, flags, 0)
	if err != nil {
		return nil, err
	}

	return os.NewFile(uintptr(fd), path), nil
}
583933
func OpenBlock(logger log.Logger, dir string, pool chunkenc.Pool) (pb *Block, err error) {
	if logger == nil {
		logger = log.NewNopLogger()
	}
	var closers []io.Closer
	defer func() {
		if err != nil {
			var merr tsdb_errors.MultiError
			merr.Add(err)
			merr.Add(closeAll(closers))
			err = merr.Err()
		}
	}()
	meta, err := readMetaFile(dir)
	if err != nil {
		return nil, err
	}

	cr, err := chunks.NewDirReader(chunkDir(dir), pool)
	if err != nil {
		return nil, err
	}
	closers = append(closers, cr)

	ir, err := index.NewFileReader(filepath.Join(dir, indexFilename))
	if err != nil {
		return nil, err
	}
	closers = append(closers, ir)

	tr, tsr, err := readTombstones(dir)
	if err != nil {
		return nil, err
	}
	closers = append(closers, tr)

	// TODO refactor to set this at block creation time as
	// that would be the logical place for a block size to be calculated.
	bs := blockSize(cr, ir, tsr)
	meta.Stats.NumBytes = bs
	err = writeMetaFile(logger, dir, meta)
	if err != nil {
		level.Warn(logger).Log("msg", "couldn't write the meta file for the block size", "block", dir, "err", err)
	}

	pb = &Block{
		dir:             dir,
		meta:            *meta,
		chunkr:          cr,
		indexr:          ir,
		tombstones:      tr,
		symbolTableSize: ir.SymbolTableSize(),
		logger:          logger,
	}
	return pb, nil
}
472606
func Core(err error) error {
	const maxWrapLayer = 32
	c := 0
	for err != nil && c < maxWrapLayer {
		c++
		we, ok := err.(wrappedError)
		if !ok {
			break
		}
		err = we.Core()
	}
	return err
}
1141404
func (conf *Config) OpenPartition(colPath, lookupPath string) (part *Partition, err error) {
	part = conf.newPartition()
	part.CalculateConfigConstants()
	if part.col, err = conf.OpenCollection(colPath); err != nil {
		return
	} else if part.lookup, err = conf.OpenHashTable(lookupPath); err != nil {
		return
	}
	return
}
598368
func OpenFile(path string) (Sections, error) {
	f, err := os.Open(path)
	if err != nil {
		return Sections{}, awserr.New(ErrCodeUnableToReadFile, "unable to open file", err)
	}
	defer f.Close()

	return Parse(f)
}
742585
func OpenFile(filename string) (*File, error) {
	content, err := readFile(filename)
	if err != nil {
		return nil, err
	}

	f := CreateFile(filepath.Base(filename), content)

	return f, nil
}
423631
func openFile(url string) (io.ReadCloser, error) {
	usedUrl := url
	if strings.HasPrefix(url, "assets/") {
		usedUrl = usedUrl[7:]
	}

	return asset.Open(usedUrl)
}
702505
func (fs OsFS) OpenFile(name string, flag int, perm os.FileMode) (File, error) {
	return os.OpenFile(name, flag, perm)
}
485211
func open() (pty, tty *os.File, err error) {
	p, err := os.OpenFile("/dev/ptmx", os.O_RDWR, 0)
	if err != nil {
		return nil, nil, err
	}
	// In case of error after this point, make sure we close the ptmx fd.
	defer func() {
		if err != nil {
			_ = p.Close() // Best effort.
		}
	}()

	sname, err := ptsname(p)
	if err != nil {
		return nil, nil, err
	}

	if err := grantpt(p); err != nil {
		return nil, nil, err
	}

	if err := unlockpt(p); err != nil {
		return nil, nil, err
	}

	t, err := os.OpenFile(sname, os.O_RDWR, 0)
	if err != nil {
		return nil, nil, err
	}
	return p, t, nil
}
936189
func (w *Window) OpenDevTools() (err error) {
	if err = w.isActionable(); err != nil {
		return
	}
	return w.w.write(Event{Name: EventNameWindowCmdWebContentsOpenDevTools, TargetID: w.id})
}
1000399
func (st resourceState) OpenResource(applicationID, name string) (resource.Resource, io.ReadCloser, error) {
	id := newResourceID(applicationID, name)
	resourceInfo, storagePath, err := st.persist.GetResource(id)
	if err != nil {
		if err := st.raw.VerifyApplication(applicationID); err != nil {
			return resource.Resource{}, nil, errors.Trace(err)
		}
		return resource.Resource{}, nil, errors.Annotate(err, "while getting resource info")
	}
	if resourceInfo.IsPlaceholder() {
		logger.Tracef("placeholder resource %q treated as not found", name)
		return resource.Resource{}, nil, errors.NotFoundf("resource %q", name)
	}

	var resourceReader io.ReadCloser
	var resSize int64
	switch resourceInfo.Type {
	case charmresource.TypeContainerImage:
		resourceReader, resSize, err = st.dockerMetadataStorage.Get(resourceInfo.ID)
	case charmresource.TypeFile:
		resourceReader, resSize, err = st.storage.Get(storagePath)
	default:
		return resource.Resource{}, nil, errors.New("unknown resource type")
	}
	if err != nil {
		return resource.Resource{}, nil, errors.Annotate(err, "while retrieving resource data")
	}
	switch resourceInfo.Type {
	case charmresource.TypeContainerImage:
		// Resource size only found at this stage in time as it's a response from the charmstore, not a stored file.
		// Store it as it's used later for verification (in a separate call than this one)
		resourceInfo.Size = resSize
		if err := st.persist.SetResource(resourceInfo); err != nil {
			return resource.Resource{}, nil, errors.Annotate(err, "failed to update resource details with docker detail size")
		}
	case charmresource.TypeFile:
		if resSize != resourceInfo.Size {
			msg := "storage returned a size (%d) which doesn't match resource metadata (%d)"
			return resource.Resource{}, nil, errors.Errorf(msg, resSize, resourceInfo.Size)
		}
	}

	return resourceInfo, resourceReader, nil
}
337010
func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) {
	return trie.NewSecure(root, db.db)
}
979145
func OpenPin(number int, mode gpio.Mode) (gpio.Pin, error) {
	initOnce.Do(initRPi)
	p, err := gpio.OpenPin(number, mode)
	return &pin{Pin: p, pin: uint8(number)}, err
}
228757
func (computeSystem *System) OpenProcess(pid int) (_ *Process, err error) {
	computeSystem.handleLock.RLock()
	defer computeSystem.handleLock.RUnlock()

	// Add PID for the context of this operation
	computeSystem.logctx[logfields.ProcessID] = pid
	defer delete(computeSystem.logctx, logfields.ProcessID)

	operation := "hcsshim::ComputeSystem::OpenProcess"
	computeSystem.logOperationBegin(operation)
	defer func() { computeSystem.logOperationEnd(operation, err) }()

	var (
		processHandle hcsProcess
		resultp       *uint16
	)

	if computeSystem.handle == 0 {
		return nil, makeSystemError(computeSystem, "OpenProcess", "", ErrAlreadyClosed, nil)
	}

	syscallWatcher(computeSystem.logctx, func() {
		err = hcsOpenProcess(computeSystem.handle, uint32(pid), &processHandle, &resultp)
	})
	events := processHcsResult(resultp)
	if err != nil {
		return nil, makeSystemError(computeSystem, "OpenProcess", "", err, events)
	}

	process := newProcess(processHandle, pid, computeSystem)
	if err = process.registerCallback(); err != nil {
		return nil, makeSystemError(computeSystem, "OpenProcess", "", err, nil)
	}
	go process.waitBackground()

	return process, nil
}