blob: 82388dd63c527730c59282f9303ed2e827155e6c [file] [log] [blame]
Mike Frysinger38a33f92005-05-09 22:13:22 +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%
7 * This file may be redistributed under the terms of the
8 * GNU Lesser General Public License.
9 * %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 Frysinger38a33f92005-05-09 22:13:22 +000022
23#include "blkidP.h"
24
Mike Frysingerfc379ba2005-06-28 23:50:18 +000025#ifdef CONFIG_LFS
26# define my_llseek lseek64
Mike Frysinger38a33f92005-05-09 22:13:22 +000027#else
Mike Frysingerfc379ba2005-06-28 23:50:18 +000028# define my_llseek lseek
Mike Frysinger38a33f92005-05-09 22:13:22 +000029#endif
Mike Frysinger38a33f92005-05-09 22:13:22 +000030
31blkid_loff_t blkid_llseek(int fd, blkid_loff_t offset, int whence)
32{
33 blkid_loff_t result;
34 static int do_compat = 0;
35
36 if ((sizeof(off_t) >= sizeof(blkid_loff_t)) ||
37 (offset < ((blkid_loff_t) 1 << ((sizeof(off_t)*8) -1))))
38 return lseek(fd, (off_t) offset, whence);
39
40 if (do_compat) {
41 errno = EOVERFLOW;
42 return -1;
43 }
44
45 result = my_llseek(fd, offset, whence);
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 = EOVERFLOW;
53 }
54 return result;
55}