summaryrefslogtreecommitdiff
path: root/os/src/lseek.c
blob: 1e904a575cf1bc5cd81706b11f327761e8e239a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <reent.h>
#include <osdebug.h>
#include <errno.h>
#include "fio.h"
#include "osdebug.h"

_off_t _lseek_r(struct _reent * reent, int fd, _off_t seek, int wheel) {
    off_t r;
//    DBGOUT("_lseek_r(%p, %i, %i, %i)\r\n", reent, fd, seek, wheel);
    
    if ((wheel != SEEK_SET) && (wheel != SEEK_CUR) && (wheel != SEEK_END)) {
        reent->_errno = EINVAL;
        return -1;
    }
    
    if (!fio_is_open(fd)) {
        reent->_errno = EBADF;
        return -1;
    }
    
    r = fio_seek(fd, seek, wheel);
    
    if (r < 0)
        reent->_errno = EINVAL;
    
    return r;
}