Changeset 97b1dfc2 in mainline for uspace/lib/posix/src/unistd.c
- Timestamp:
- 2018-09-24T15:36:21Z (7 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.