Changeset 97b1dfc2 in mainline
- Timestamp:
- 2018-09-24T15:36:21Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 34c76e2f
- Parents:
- 631281d
- git-author:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-24 15:02:32)
- git-committer:
- Jiří Zárevúcky <jiri.zarevucky@…> (2018-09-24 15:36:21)
- Location:
- uspace/lib/posix
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/include/posix/sys/types.h
r631281d r97b1dfc2 43 43 typedef unsigned int uid_t; 44 44 typedef unsigned int gid_t; 45 typedef int64_t off_t;46 45 typedef long blksize_t; 47 46 typedef long blkcnt_t; … … 49 48 typedef sysarg_t dev_t; 50 49 typedef unsigned int mode_t; 50 51 #if _FILE_OFFSET_BITS == 64 52 typedef int64_t off_t; 53 #else 54 typedef long off_t; 55 #endif 56 57 #ifdef _LARGEFILE64_SOURCE 58 typedef int64_t off64_t; 59 #endif 51 60 52 61 /* PThread Types */ -
uspace/lib/posix/include/posix/unistd.h
r631281d r97b1dfc2 80 80 extern ssize_t read(int fildes, void *buf, size_t nbyte); 81 81 extern ssize_t write(int fildes, const void *buf, size_t nbyte); 82 extern off_t lseek(int fildes,83 off_t offset, int whence);84 82 extern int fsync(int fildes); 85 83 extern int ftruncate(int fildes, off_t length); … … 88 86 extern int dup(int fildes); 89 87 extern int dup2(int fildes, int fildes2); 88 89 #ifdef _LARGEFILE64_SOURCE 90 extern off64_t lseek64(int fildes, off64_t offset, int whence); 91 #endif 92 93 #if _FILE_OFFSET_BITS == 64 94 static inline off_t lseek(int fildes, off_t offset, int whence) 95 { 96 /* Declarations visible in this function body only. */ 97 typedef int64_t off64_t; 98 extern off64_t lseek64(int fildes, off64_t offset, int whence); 99 100 /* With _FILE_OFFSET_BITS == 64, lseek is actually lseek64. */ 101 return lseek64(fildes, offset, whence); 102 } 103 #else 104 extern off_t lseek(int fildes, off_t offset, int whence); 105 #endif 90 106 91 107 /* Standard Streams */ -
uspace/lib/posix/src/unistd.c
r631281d r97b1dfc2 34 34 */ 35 35 36 #define _LARGEFILE64_SOURCE 37 #undef _FILE_OFFSET_BITS 38 36 39 #include "internal/common.h" 37 40 #include <unistd.h> … … 234 237 } 235 238 239 static off64_t _lseek(int fildes, off64_t offset, off64_t max_pos, int whence) 240 { 241 vfs_stat_t st; 242 off64_t new_pos; 243 244 switch (whence) { 245 case SEEK_SET: 246 new_pos = offset; 247 break; 248 case SEEK_CUR: 249 if (__builtin_add_overflow(posix_pos[fildes], offset, &new_pos)) { 250 errno = EOVERFLOW; 251 return -1; 252 } 253 break; 254 case SEEK_END: 255 if (failed(vfs_stat(fildes, &st))) 256 return -1; 257 258 if (__builtin_add_overflow(st.size, offset, &new_pos)) { 259 errno = EOVERFLOW; 260 return -1; 261 } 262 break; 263 default: 264 errno = EINVAL; 265 return -1; 266 } 267 268 if (new_pos < 0) { 269 errno = EINVAL; 270 return -1; 271 } 272 273 if (new_pos > max_pos) { 274 /* The resulting file offset is too large for the interface. */ 275 errno = EOVERFLOW; 276 return -1; 277 } 278 279 posix_pos[fildes] = new_pos; 280 return new_pos; 281 } 282 283 static off64_t _lseek64(int fildes, off64_t offset, int whence) 284 { 285 return _lseek(fildes, offset, INT64_MAX, whence); 286 } 287 288 off64_t lseek64(int fildes, off64_t offset, int whence) 289 { 290 return _lseek64(fildes, offset, whence); 291 } 292 236 293 /** 237 294 * Reposition read/write file offset … … 245 302 off_t lseek(int fildes, off_t offset, int whence) 246 303 { 247 vfs_stat_t st; 248 249 switch (whence) { 250 case SEEK_SET: 251 posix_pos[fildes] = offset; 252 break; 253 case SEEK_CUR: 254 posix_pos[fildes] += offset; 255 break; 256 case SEEK_END: 257 if (failed(vfs_stat(fildes, &st))) 258 return -1; 259 posix_pos[fildes] = st.size + offset; 260 break; 261 } 262 if (posix_pos[fildes] > INT64_MAX) { 263 /* The native width is too large for the POSIX interface. */ 264 errno = ERANGE; 265 return -1; 266 } 267 return posix_pos[fildes]; 304 #if LONG_MAX == INT64_MAX 305 return _lseek64(fildes, offset, whence); 306 #else 307 return _lseek(fildes, offset, LONG_MAX, whence); 308 #endif 268 309 } 269 310
Note:
See TracChangeset
for help on using the changeset viewer.