Changeset 75406dc in mainline for uspace/lib/posix/unistd.c
- Timestamp:
- 2011-07-28T17:39:51Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 955c2b0
- Parents:
- 58115ae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/unistd.c
r58115ae r75406dc 111 111 } 112 112 char *ret = getcwd(buf, size); 113 if (ret == NULL && errno == EOK) {113 if (ret == NULL) { 114 114 errno = ERANGE; 115 115 } 116 116 return ret; 117 } 118 119 /** 120 * Change the current working directory. 121 * 122 * @param path New working directory. 123 */ 124 int posix_chdir(const char *path) 125 { 126 return errnify(chdir, path); 117 127 } 118 128 … … 157 167 /* There is currently no support for user accounts in HelenOS. */ 158 168 return 0; 169 } 170 171 /** 172 * Close a file. 173 * 174 * @param fildes 175 * @return 0 on success, -1 on error. 176 */ 177 int posix_close(int fildes) 178 { 179 return errnify(close, fildes); 159 180 } 160 181 … … 169 190 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 170 191 { 171 int rc = read(fildes, buf, nbyte); 172 if (rc < 0) { 173 errno = -rc; 174 return -1; 175 } else { 176 return rc; 177 } 192 return errnify(read, fildes, buf, nbyte); 193 } 194 195 /** 196 * Write to a file. 197 * 198 * @param fildes File descriptor of the opened file. 199 * @param buf Buffer to write. 200 * @param nbyte Size of the buffer. 201 * @return Number of written bytes on success, -1 otherwise. 202 */ 203 ssize_t posix_write(int fildes, const void *buf, size_t nbyte) 204 { 205 return errnify(write, fildes, buf, nbyte); 206 } 207 208 /** 209 * Requests outstanding data to be written to the underlying storage device. 210 * 211 * @param fildes 212 */ 213 int posix_fsync(int fildes) 214 { 215 return errnify(fsync, fildes); 216 } 217 218 int posix_ftruncate(int fildes, posix_off_t length) 219 { 220 return errnify(ftruncate, fildes, (aoff64_t) length); 178 221 } 179 222 … … 186 229 int posix_rmdir(const char *path) 187 230 { 188 int rc = rmdir(path); 189 if (rc != EOK) { 190 errno = -rc; 191 return -1; 192 } 193 return 0; 231 return errnify(rmdir, path); 194 232 } 195 233 … … 202 240 int posix_unlink(const char *path) 203 241 { 204 int rc = unlink(path); 205 if (rc < 0) { 206 errno = -rc; 207 return -1; 208 } else { 209 return rc; 210 } 242 return errnify(unlink, path); 243 } 244 245 int posix_dup(int fildes) 246 { 247 return posix_fcntl(fildes, F_DUPFD, 0); 248 } 249 250 int posix_dup2(int fildes, int fildes2) 251 { 252 return errnify(dup2, fildes, fildes2); 211 253 } 212 254 … … 220 262 int posix_access(const char *path, int amode) 221 263 { 222 if (amode == F_OK) { 223 /* Check file existence by attempt to open it. */ 264 if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) { 265 /* HelenOS doesn't support permissions, permission checks 266 * are equal to existence check. 267 * 268 * Check file existence by attempting to open it. 269 */ 224 270 int fd = open(path, O_RDONLY); 225 if (fd != -1) { 226 close(fd); 271 if (fd < 0) { 272 errno = -fd; 273 return 0; 227 274 } 228 return fd; 229 } else if (amode & (X_OK | W_OK | R_OK)) { 230 /* HelenOS doesn't support permissions, return success. */ 231 return 0; 275 close(fd); 276 return 1; 232 277 } else { 233 278 /* Invalid amode argument. */
Note:
See TracChangeset
for help on using the changeset viewer.