Changeset 368ee04 in mainline for uspace/lib/posix/source/unistd.c
- Timestamp:
- 2017-04-05T18:10:39Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/source/unistd.c
r39f892a9 r368ee04 47 47 #include "libc/stats.h" 48 48 #include "libc/malloc.h" 49 #include "libc/vfs/vfs.h" 50 51 aoff64_t posix_pos[MAX_OPEN_FILES]; 49 52 50 53 /* Array of environment variable strings (NAME=VALUE). */ … … 105 108 char *posix_getcwd(char *buf, size_t size) 106 109 { 107 char *p = getcwd(buf, size); 108 109 if (p == NULL) { 110 errno = -errno; 110 int rc = rcerrno(vfs_cwd_get, buf, size); 111 if (rc != EOK) 111 112 return NULL; 112 } 113 114 return p; 113 return buf; 115 114 } 116 115 … … 122 121 int posix_chdir(const char *path) 123 122 { 124 return negerrno(chdir, path); 123 int rc = rcerrno(vfs_cwd_set, path); 124 if (rc != EOK) 125 return -1; 126 return 0; 125 127 } 126 128 … … 175 177 int posix_close(int fildes) 176 178 { 177 return negerrno(close, fildes); 179 posix_pos[fildes] = 0; 180 int rc = rcerrno(vfs_put, fildes); 181 if (rc != EOK) 182 return -1; 183 else 184 return 0; 178 185 } 179 186 … … 188 195 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 189 196 { 190 return negerrno(read, fildes, buf, nbyte); 197 ssize_t size = rcerrno(vfs_read, fildes, &posix_pos[fildes], buf, nbyte); 198 if (size < 0) 199 return -1; 200 return size; 191 201 } 192 202 … … 201 211 ssize_t posix_write(int fildes, const void *buf, size_t nbyte) 202 212 { 203 return negerrno(write, fildes, buf, nbyte); 213 ssize_t size = rcerrno(vfs_write, fildes, &posix_pos[fildes], buf, nbyte); 214 if (size < 0) 215 return -1; 216 return size; 204 217 } 205 218 … … 215 228 posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence) 216 229 { 217 return negerrno(lseek, fildes, offset, whence); 230 struct stat st; 231 int rc; 232 233 switch (whence) { 234 case SEEK_SET: 235 posix_pos[fildes] = offset; 236 break; 237 case SEEK_CUR: 238 posix_pos[fildes] += offset; 239 break; 240 case SEEK_END: 241 rc = rcerrno(vfs_stat, fildes, &st); 242 if (rc != EOK) 243 return -1; 244 posix_pos[fildes] = st.size + offset; 245 break; 246 } 247 if (posix_pos[fildes] > INT64_MAX) { 248 /* The native width is too large for the POSIX interface. */ 249 errno = ERANGE; 250 return -1; 251 } 252 return posix_pos[fildes]; 218 253 } 219 254 … … 226 261 int posix_fsync(int fildes) 227 262 { 228 return negerrno(fsync, fildes); 263 if (rcerrno(vfs_sync, fildes) != EOK) 264 return -1; 265 else 266 return 0; 229 267 } 230 268 … … 238 276 int posix_ftruncate(int fildes, posix_off_t length) 239 277 { 240 return negerrno(ftruncate, fildes, (aoff64_t) length); 278 if (rcerrno(vfs_resize, fildes, (aoff64_t) length) != EOK) 279 return -1; 280 else 281 return 0; 241 282 } 242 283 … … 249 290 int posix_rmdir(const char *path) 250 291 { 251 return negerrno(rmdir, path); 292 if (rcerrno(vfs_unlink_path, path) != EOK) 293 return -1; 294 else 295 return 0; 252 296 } 253 297 … … 260 304 int posix_unlink(const char *path) 261 305 { 262 return negerrno(unlink, path); 306 if (rcerrno(vfs_unlink_path, path) != EOK) 307 return -1; 308 else 309 return 0; 263 310 } 264 311 … … 284 331 int posix_dup2(int fildes, int fildes2) 285 332 { 286 return negerrno( dup2, fildes, fildes2);333 return negerrno(vfs_clone, fildes, fildes2, false); 287 334 } 288 335 … … 302 349 * Check file existence by attempting to open it. 303 350 */ 304 int fd = negerrno(open, path, O_RDONLY); 305 if (fd < 0) { 306 /* errno was set by open() */ 351 int fd = posix_open(path, O_RDONLY); 352 if (fd < 0) 307 353 return -1; 308 } 309 close(fd); 354 posix_close(fd); 310 355 return 0; 311 356 } else {
Note:
See TracChangeset
for help on using the changeset viewer.