[prev in list] [next in list] [prev in thread] [next in thread] 

List:       freebsd-bugs
Subject:    lseek bug?
From:       Kent Boortz <kent () erlang ! ericsson ! se>
Date:       1998-03-30 23:53:05
[Download RAW message or body]


In FreeBSD 2.2.5 lseek moves the file position without any error
checks. If the resulting position is negative we have the problem that
the result value -1 can mean two things, that there was an error or
that the file position was set to -1 and no error. We have to clear
errno before the call and examine errno after the call to find out if
there was an error or not.

If the resulting position is to be negative, Linux and Solaris will
preserve the file position before the call to lseek and return an
error.

Is this a bug in FreeBSD or a different interpretations of the POSIX
standard?

/kgb


int
lseek(p, uap, retval)
        struct proc *p;
        register struct lseek_args *uap;
        int *retval;
{
        struct ucred *cred = p->p_ucred;
        register struct filedesc *fdp = p->p_fd;
        register struct file *fp;
        struct vattr vattr;
        int error;

        if ((u_int)uap->fd >= fdp->fd_nfiles ||
            (fp = fdp->fd_ofiles[uap->fd]) == NULL)
                return (EBADF);
        if (fp->f_type != DTYPE_VNODE)
                return (ESPIPE);
        switch (uap->whence) {
        case L_INCR:
                fp->f_offset += uap->offset;
                break;
        case L_XTND:
                error=VOP_GETATTR((struct vnode *)fp->f_data, &vattr, cred, p);
                if (error)
                        return (error);
                fp->f_offset = uap->offset + vattr.va_size;
                break;
        case L_SET:
                fp->f_offset = uap->offset;
                break;
        default:
                return (EINVAL);
        }
        *(off_t *)retval = fp->f_offset;
        return (0);
}

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic