blob: 6bb84bf096643c8339ae9e40f4ef0eb19e015214 [file] [log] [blame]
Mike Frysinger1fd98e02005-05-09 22:10:42 +00001/*
2 * llseek.c -- stub calling the llseek system call
3 *
4 * Copyright (C) 1994, 1995, 1996, 1997 Theodore Ts'o.
5 *
6 * %Begin-Header%
Mike Frysingerfc379ba2005-06-28 23:50:18 +00007 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
Mike Frysinger1fd98e02005-05-09 22:10:42 +00009 * %End-Header%
10 */
11
12#if HAVE_SYS_TYPES_H
13#include <sys/types.h>
14#endif
15
16#if HAVE_ERRNO_H
17#include <errno.h>
18#endif
19#if HAVE_UNISTD_H
20#include <unistd.h>
21#endif
Mike Frysingerfc379ba2005-06-28 23:50:18 +000022
Mike Frysinger1fd98e02005-05-09 22:10:42 +000023#include "ext2fs/ext2_io.h"
24
Mike Frysingerfc379ba2005-06-28 23:50:18 +000025#ifdef CONFIG_LFS
26# define my_llseek lseek64
Mike Frysinger1fd98e02005-05-09 22:10:42 +000027#else
Mike Frysingerfc379ba2005-06-28 23:50:18 +000028# define my_llseek lseek
Mike Frysinger1fd98e02005-05-09 22:10:42 +000029#endif
30
Mike Frysinger1fd98e02005-05-09 22:10:42 +000031ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
32{
33 ext2_loff_t result;
34 static int do_compat = 0;
35
36 if ((sizeof(off_t) >= sizeof(ext2_loff_t)) ||
37 (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1))))
38 return lseek(fd, (off_t) offset, origin);
39
40 if (do_compat) {
41 errno = EINVAL;
42 return -1;
43 }
44
45 result = my_llseek (fd, offset, origin);
46 if (result == -1 && errno == ENOSYS) {
47 /*
48 * Just in case this code runs on top of an old kernel
49 * which does not support the llseek system call
50 */
51 do_compat++;
52 errno = EINVAL;
53 }
54 return result;
55}