Index: uspace/lib/posix/include/posix/sys/types.h
===================================================================
--- uspace/lib/posix/include/posix/sys/types.h	(revision 631281dedb2b080d5b5af149d4e4b05369d66c34)
+++ uspace/lib/posix/include/posix/sys/types.h	(revision 97b1dfc290beb228953f53022071c2f25b4686d4)
@@ -43,5 +43,4 @@
 typedef unsigned int uid_t;
 typedef unsigned int gid_t;
-typedef int64_t off_t;
 typedef long blksize_t;
 typedef long blkcnt_t;
@@ -49,4 +48,14 @@
 typedef sysarg_t dev_t;
 typedef unsigned int mode_t;
+
+#if _FILE_OFFSET_BITS == 64
+typedef int64_t off_t;
+#else
+typedef long off_t;
+#endif
+
+#ifdef _LARGEFILE64_SOURCE
+typedef int64_t off64_t;
+#endif
 
 /* PThread Types */
Index: uspace/lib/posix/include/posix/unistd.h
===================================================================
--- uspace/lib/posix/include/posix/unistd.h	(revision 631281dedb2b080d5b5af149d4e4b05369d66c34)
+++ uspace/lib/posix/include/posix/unistd.h	(revision 97b1dfc290beb228953f53022071c2f25b4686d4)
@@ -80,6 +80,4 @@
 extern ssize_t read(int fildes, void *buf, size_t nbyte);
 extern ssize_t write(int fildes, const void *buf, size_t nbyte);
-extern off_t lseek(int fildes,
-    off_t offset, int whence);
 extern int fsync(int fildes);
 extern int ftruncate(int fildes, off_t length);
@@ -88,4 +86,22 @@
 extern int dup(int fildes);
 extern int dup2(int fildes, int fildes2);
+
+#ifdef _LARGEFILE64_SOURCE
+extern off64_t lseek64(int fildes, off64_t offset, int whence);
+#endif
+
+#if _FILE_OFFSET_BITS == 64
+static inline off_t lseek(int fildes, off_t offset, int whence)
+{
+	/* Declarations visible in this function body only. */
+	typedef int64_t off64_t;
+	extern off64_t lseek64(int fildes, off64_t offset, int whence);
+
+	/* With _FILE_OFFSET_BITS == 64, lseek is actually lseek64. */
+	return lseek64(fildes, offset, whence);
+}
+#else
+extern off_t lseek(int fildes, off_t offset, int whence);
+#endif
 
 /* Standard Streams */
Index: uspace/lib/posix/src/unistd.c
===================================================================
--- uspace/lib/posix/src/unistd.c	(revision 631281dedb2b080d5b5af149d4e4b05369d66c34)
+++ uspace/lib/posix/src/unistd.c	(revision 97b1dfc290beb228953f53022071c2f25b4686d4)
@@ -34,4 +34,7 @@
  */
 
+#define _LARGEFILE64_SOURCE
+#undef _FILE_OFFSET_BITS
+
 #include "internal/common.h"
 #include <unistd.h>
@@ -234,4 +237,58 @@
 }
 
+static off64_t _lseek(int fildes, off64_t offset, off64_t max_pos, int whence)
+{
+	vfs_stat_t st;
+	off64_t new_pos;
+
+	switch (whence) {
+	case SEEK_SET:
+		new_pos = offset;
+		break;
+	case SEEK_CUR:
+		if (__builtin_add_overflow(posix_pos[fildes], offset, &new_pos)) {
+			errno = EOVERFLOW;
+			return -1;
+		}
+		break;
+	case SEEK_END:
+		if (failed(vfs_stat(fildes, &st)))
+			return -1;
+
+		if (__builtin_add_overflow(st.size, offset, &new_pos)) {
+			errno = EOVERFLOW;
+			return -1;
+		}
+		break;
+	default:
+		errno = EINVAL;
+		return -1;
+	}
+
+	if (new_pos < 0) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	if (new_pos > max_pos) {
+		/* The resulting file offset is too large for the interface. */
+		errno = EOVERFLOW;
+		return -1;
+	}
+
+	posix_pos[fildes] = new_pos;
+	return new_pos;
+}
+
+static off64_t _lseek64(int fildes, off64_t offset, int whence)
+{
+	return _lseek(fildes, offset, INT64_MAX, whence);
+}
+
+off64_t lseek64(int fildes, off64_t offset, int whence)
+{
+	return _lseek64(fildes, offset, whence);
+}
+
 /**
  * Reposition read/write file offset
@@ -245,25 +302,9 @@
 off_t lseek(int fildes, off_t offset, int whence)
 {
-	vfs_stat_t st;
-
-	switch (whence) {
-	case SEEK_SET:
-		posix_pos[fildes] = offset;
-		break;
-	case SEEK_CUR:
-		posix_pos[fildes] += offset;
-		break;
-	case SEEK_END:
-		if (failed(vfs_stat(fildes, &st)))
-			return -1;
-		posix_pos[fildes] = st.size + offset;
-		break;
-	}
-	if (posix_pos[fildes] > INT64_MAX) {
-		/* The native width is too large for the POSIX interface. */
-		errno = ERANGE;
-		return -1;
-	}
-	return posix_pos[fildes];
+#if LONG_MAX == INT64_MAX
+	return _lseek64(fildes, offset, whence);
+#else
+	return _lseek(fildes, offset, LONG_MAX, whence);
+#endif
 }
 
