Changes in uspace/lib/posix/unistd.c [2a53f71:d542aad] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/unistd.c
r2a53f71 rd542aad 110 110 return NULL; 111 111 } 112 113 /* Save the original value to comply with the "no modification on114 * success" semantics.115 */116 int orig_errno = errno;117 errno = EOK;118 119 112 char *ret = getcwd(buf, size); 120 if (ret == NULL) { 121 /* Check errno to avoid shadowing other possible errors. */ 122 if (errno == EOK) { 123 errno = ERANGE; 124 } 125 } else { 126 /* Success, restore previous errno value. */ 127 errno = orig_errno; 128 } 129 113 if (ret == NULL && errno == EOK) { 114 errno = ERANGE; 115 } 130 116 return ret; 131 }132 133 /**134 * Change the current working directory.135 *136 * @param path New working directory.137 */138 int posix_chdir(const char *path)139 {140 return errnify(chdir, path);141 117 } 142 118 … … 181 157 /* There is currently no support for user accounts in HelenOS. */ 182 158 return 0; 183 }184 185 /**186 * Close a file.187 *188 * @param fildes File descriptor of the opened file.189 * @return 0 on success, -1 on error.190 */191 int posix_close(int fildes)192 {193 return errnify(close, fildes);194 159 } 195 160 … … 204 169 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 205 170 { 206 return errnify(read, fildes, buf, nbyte); 207 } 208 209 /** 210 * Write to a file. 211 * 212 * @param fildes File descriptor of the opened file. 213 * @param buf Buffer to write. 214 * @param nbyte Size of the buffer. 215 * @return Number of written bytes on success, -1 otherwise. 216 */ 217 ssize_t posix_write(int fildes, const void *buf, size_t nbyte) 218 { 219 return errnify(write, fildes, buf, nbyte); 220 } 221 222 /** 223 * Requests outstanding data to be written to the underlying storage device. 224 * 225 * @param fildes File descriptor of the opened file. 226 * @return Zero on success, -1 otherwise. 227 */ 228 int posix_fsync(int fildes) 229 { 230 return errnify(fsync, fildes); 231 } 232 233 /** 234 * Truncate a file to a specified length. 235 * 236 * @param fildes File descriptor of the opened file. 237 * @param length New length of the file. 238 * @return Zero on success, -1 otherwise. 239 */ 240 int posix_ftruncate(int fildes, posix_off_t length) 241 { 242 return errnify(ftruncate, fildes, (aoff64_t) length); 243 } 244 245 /** 246 * Remove a directory. 247 * 248 * @param path Directory pathname. 249 * @return Zero on success, -1 otherwise. 250 */ 251 int posix_rmdir(const char *path) 252 { 253 return errnify(rmdir, path); 171 int rc = read(fildes, buf, nbyte); 172 if (rc < 0) { 173 errno = -rc; 174 return -1; 175 } else { 176 return rc; 177 } 254 178 } 255 179 … … 262 186 int posix_unlink(const char *path) 263 187 { 264 return errnify(unlink, path); 265 } 266 267 /** 268 * Duplicate an open file descriptor. 269 * 270 * @param fildes File descriptor to be duplicated. 271 * @return On success, new file descriptor for the same file, otherwise -1. 272 */ 273 int posix_dup(int fildes) 274 { 275 return posix_fcntl(fildes, F_DUPFD, 0); 276 } 277 278 /** 279 * Duplicate an open file descriptor. 280 * 281 * @param fildes File descriptor to be duplicated. 282 * @param fildes2 File descriptor to be paired with the same file description 283 * as is paired fildes. 284 * @return fildes2 on success, -1 otherwise. 285 */ 286 int posix_dup2(int fildes, int fildes2) 287 { 288 return errnify(dup2, fildes, fildes2); 188 int rc = unlink(path); 189 if (rc < 0) { 190 errno = -rc; 191 return -1; 192 } else { 193 return rc; 194 } 289 195 } 290 196 … … 298 204 int posix_access(const char *path, int amode) 299 205 { 300 if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) { 301 /* HelenOS doesn't support permissions, permission checks 302 * are equal to existence check. 303 * 304 * Check file existence by attempting to open it. 305 */ 206 if (amode == F_OK) { 207 /* Check file existence by attempt to open it. */ 306 208 int fd = open(path, O_RDONLY); 307 if (fd < 0) { 308 errno = -fd; 309 return -1; 209 if (fd != -1) { 210 close(fd); 310 211 } 311 close(fd); 212 return fd; 213 } else if (amode & (X_OK | W_OK | R_OK)) { 214 /* HelenOS doesn't support permissions, return success. */ 312 215 return 0; 313 216 } else {
Note:
See TracChangeset
for help on using the changeset viewer.