// ReadLink returns the symbolic link content of f.
762205
func (f *File) ReadLink() (string, error) {
	if f.ino.Mode&ifmt != iflnk {
		return "", fmt.Errorf("not a symbolic link")
	}

	size := f.ino.Size

	if f.ino.Nblock != 0 {
		if size > uint32(f.fs.BlockSize) {
			return "", fmt.Errorf("invalid symlink size")
		}
		// Symlink fits in one block.
		b, err := f.dblock(0)
		if err != nil {
			return "", err
		}
		buf, err := f.fs.readData(b, 0, nil)
		if err != nil {
			return "", err
		}
		return string(buf[:size]), nil
	}

	if size > 4*numBlocks {
		return "", fmt.Errorf("invalid symlink size")
	}
	var buf [4 * numBlocks]byte
	for i := 0; i < numBlocks; i++ {
		binary.LittleEndian.PutUint32(buf[4*i:], f.ino.Block[i])
	}
	return string(buf[:size]), nil
}
1125216
func (fs *fakeFs) ReadFile(filename string) ([]byte, error) {
	return fs.a.ReadFile(filename)
}
221166
func Link(doners ...Doner) C {
	c := make(chan struct{})
	cancel := func() { close(c) }

	var once sync.Once
	for _, d := range doners {
		Defer(d, func() { once.Do(cancel) })
	}

	return c
}
1168076
func (s *SetSpec) Link(scope Scope) (TypeSpec, error) {
	if s.linked() {
		return s, nil
	}

	var err error
	s.ValueSpec, err = s.ValueSpec.Link(scope)
	return s, err
}
853399
func (fp FsPath) ReadDir() ([]os.FileInfo, error) {
	return fp.Fs.ReadDir(fp.Path)
}
1290464
func (l *ListSpec) Link(scope Scope) (TypeSpec, error) {
	if l.linked() {
		return l, nil
	}

	var err error
	l.ValueSpec, err = l.ValueSpec.Link(scope)
	return l, err
}
854183
func ReadString(r Reader) (String, error) {
	var s String
	err := s.ReadFrom(r, UNKNOWN_LEN)
	return s, err
}
1187825
func (fs *MemFS) ReadDir(path string) ([]os.FileInfo, error) {
	fs.lock.RLock()
	defer fs.lock.RUnlock()

	path = filepath.Clean(path)
	_, fi, err := fs.fileInfo(path)
	if err != nil {
		return nil, &os.PathError{"readdir", path, err}
	}
	if fi == nil || !fi.dir {
		return nil, &os.PathError{"readdir", path, vfs.ErrNotDirectory}
	}

	fis := make([]os.FileInfo, 0, len(fi.childs))
	for _, e := range fi.childs {
		fis = append(fis, e)
	}
	sort.Sort(byName(fis))
	return fis, nil
}
380124
func (r *Reader) readRef() interface{} {
	if r.Simple {
		panic(errors.New("reference unserialization can't support in simple mode"))
	}
	return readRef(r, r.readInt())
}
1110410
func (d *driver) Readlink(p string) (string, error) {
	return os.Readlink(p)
}
1350485
func (c ConstReference) Link(scope Scope, t TypeSpec) (ConstantValue, error) {
	if t == c.Target.Type {
		return c, nil
	}
	return c.Target.Value.Link(scope, t)
}
1244807
func (rs *ResultSpec) Link(scope Scope) (err error) {
	if rs.ReturnType != nil {
		rs.ReturnType, err = rs.ReturnType.Link(scope)
		if err != nil {
			return err
		}
	}

	if err := rs.Exceptions.Link(scope); err != nil {
		return err
	}

	// verify that everything listed under throws is an exception.
	for _, exception := range rs.Exceptions {
		spec, ok := exception.Type.(*StructSpec)
		if !ok || spec.Type != ast.ExceptionType {
			return notAnExceptionError{
				FieldName: exception.ThriftName(),
				TypeName:  spec.ThriftName(),
			}
		}
	}

	return nil
}
1089152
func readFile(fpath string) (io.ReadCloser, error) {
	// Golang strips trailing / if you clean(..) or
	// EvalSymlinks(..). Adding '.' prevents it from doing so.
	if strings.HasSuffix(fpath, "/") {
		fpath = fpath + "."
	}
	fpath, e := filepath.EvalSymlinks(fpath)
	if e != nil {
		return nil, e
	}
	fileData, e := os.Open(fpath)
	if e != nil {
		return nil, e
	}
	return fileData, nil
}
847713
func (tlf *TLF) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (
	fs.Node, error) {
	dir, err := tlf.loadDir(ctx)
	if err != nil {
		return nil, err
	}
	return dir.Symlink(ctx, req)
}
1335428
func (f *FieldSpec) Link(scope Scope) (err error) {
	if f.Type, err = f.Type.Link(scope); err != nil {
		return err
	}
	if f.Default != nil {
		f.Default, err = f.Default.Link(scope, f.Type)
	}
	return err
}
1026283
func (f *Food) Linked() bool {
	barrelDir := filepath.Join(home.Home(home.HomePath).Barrel(), f.Name, f.Version)
	link, err := os.Readlink(filepath.Join(home.BinPath, f.Name))
	if err != nil {
		return false
	}
	return strings.Contains(link, barrelDir)
}
690966
func ReadPassword(fd int) ([]byte, error) {
	oldState, err := getTermios(fd)
	if err != nil {
		return nil, err
	}

	newState := oldState
	newState.Lflag &^= syscall.ECHO
	newState.Lflag |= syscall.ICANON | syscall.ISIG
	newState.Iflag |= syscall.ICRNL
	if err := setTermios(fd, newState); err != nil {
		return nil, err
	}

	defer func() {
		setTermios(fd, oldState)
	}()

	var buf [16]byte
	var ret []byte
	for {
		n, err := syscall.Read(fd, buf[:])
		if err != nil {
			return nil, err
		}
		if n == 0 {
			if len(ret) == 0 {
				return nil, io.EOF
			}
			break
		}
		if buf[n-1] == '\n' {
			n--
		}
		ret = append(ret, buf[:n]...)
		if n < len(buf) {
			break
		}
	}

	return ret, nil
}