Changeset 75406dc in mainline
- Timestamp:
- 2011-07-28T17:39:51Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 955c2b0
- Parents:
- 58115ae
- Location:
- uspace/lib/posix
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/internal/common.h
r58115ae r75406dc 43 43 __func__, __FILE__, __LINE__), abort()) 44 44 45 /* A little helper macro to avoid typing this over and over. */ 46 #define errnify(func, ...) ({ \ 47 int rc = func(__VA_ARGS__); \ 48 if (rc < 0) { \ 49 errno = -rc; \ 50 rc = -1; \ 51 } \ 52 rc; \ 53 }) 54 45 55 #endif /* LIBPOSIX_COMMON_H_ */ 46 56 -
uspace/lib/posix/stdio.c
r58115ae r75406dc 722 722 723 723 /** 724 * Rename a file or directory. 725 * 726 * @param old 727 * @param new 728 * @return Zero on success, -1 (with errno set) otherwise. 729 */ 730 int posix_rename(const char *old, const char *new) 731 { 732 return errnify(rename, old, new); 733 } 734 735 /** 724 736 * 725 737 * @param s -
uspace/lib/posix/stdio.h
r58115ae r75406dc 116 116 extern int posix_remove(const char *path); 117 117 118 /* Renaming Files */ 119 extern int posix_rename(const char *old, const char *new); 120 118 121 /* Temporary Files */ 119 122 #undef L_tmpnam … … 170 173 #define remove posix_remove 171 174 175 #define rename posix_rename 176 172 177 #define tmpnam posix_tmpnam 173 178 #endif -
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. */ -
uspace/lib/posix/unistd.h
r58115ae r75406dc 60 60 /* Working Directory */ 61 61 extern char *posix_getcwd(char *buf, size_t size); 62 extern int posix_chdir(const char *path); 62 63 63 64 /* Query Memory Parameters */ … … 69 70 extern posix_gid_t posix_getgid(void); 70 71 71 /* File Input/Output */ 72 /* File Manipulation */ 73 extern int posix_close(int fildes); 74 72 75 extern ssize_t posix_read(int fildes, void *buf, size_t nbyte); 76 extern ssize_t posix_write(int fildes, const void *buf, size_t nbyte); 73 77 74 /* Deleting Files */ 78 extern int posix_fsync(int fildes); 79 extern int posix_ftruncate(int fildes, posix_off_t length); 80 75 81 extern int posix_rmdir(const char *path); 76 82 extern int posix_unlink(const char *path); 83 84 extern int posix_dup(int fildes); 85 extern int posix_dup2(int fildes, int fildes2); 77 86 78 87 /* Standard Streams */ … … 145 154 146 155 #define getcwd posix_getcwd 156 #define chdir posix_chdir 147 157 148 158 #define isatty posix_isatty … … 155 165 #define getgid posix_getgid 156 166 167 #define close posix_close 157 168 #define read posix_read 158 169 #define write posix_write 170 #define fsync posix_fsync 171 #define ftruncate posix_ftruncate 159 172 #define rmdir posix_rmdir 160 173 #define unlink posix_unlink 174 #define dup posix_dup 175 #define dup2 posix_dup2 161 176 162 177 #define access posix_access
Note:
See TracChangeset
for help on using the changeset viewer.