Changeset 221afc9e in mainline
- Timestamp:
- 2011-07-12T02:43:56Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2346e78
- Parents:
- 46ac986
- Location:
- uspace/lib/posix
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/fcntl.h
r46ac986 r221afc9e 71 71 #define FD_CLOEXEC 1 /* Close on exec. */ 72 72 73 #undef open 74 #define open(path, oflag, ...) \ 75 ({ \ 76 int rc = open(path, oflag, ##__VA_ARGS__); \ 77 if (rc < 0) { \ 78 errno = -rc; \ 79 rc = -1; \ 80 } \ 81 rc; \ 82 }) 83 73 84 extern int posix_fcntl(int fd, int cmd, ...); 74 85 -
uspace/lib/posix/stdio.c
r46ac986 r221afc9e 86 86 s[0] = '\0'; 87 87 return s; 88 } 89 90 /** 91 * Put a string on the stream. 92 * 93 * @param s String to be written. 94 * @param stream Output stream. 95 * @return Non-negative on success, EOF on failure. 96 */ 97 int posix_fputs(const char *restrict s, FILE *restrict stream) 98 { 99 int rc = fputs(s, stream); 100 if (rc == 0) { 101 return EOF; 102 } else { 103 return 0; 104 } 88 105 } 89 106 … … 394 411 395 412 /** 413 * Discard prefetched data or write unwritten data. 414 * 415 * @param stream Stream that shall be flushed. 416 * @return Zero on success, EOF on failure. 417 */ 418 int posix_fflush(FILE *stream) 419 { 420 int rc = fflush(stream); 421 if (rc < 0) { 422 errno = -rc; 423 return EOF; 424 } else { 425 return 0; 426 } 427 } 428 429 /** 396 430 * Print formatted output to the opened file. 397 431 * -
uspace/lib/posix/stdio.h
r46ac986 r221afc9e 53 53 #undef putc 54 54 #define putc fputc 55 extern int posix_fputs(const char *restrict s, FILE *restrict stream); 55 56 #undef getc 56 57 #define getc fgetc … … 79 80 extern long posix_ftell(FILE *stream); 80 81 extern posix_off_t posix_ftello(FILE *stream); 82 83 /* Flushing Buffers */ 84 extern int posix_fflush(FILE *stream); 81 85 82 86 /* Formatted Output */ … … 122 126 #define clearerr posix_clearerr 123 127 128 #define fputs posix_fputs 124 129 #define ungetc posix_ungetc 125 130 #define getdelim posix_getdelim … … 139 144 #define ftell posix_ftell 140 145 #define ftello posix_ftello 146 147 #define fflush posix_fflush 141 148 142 149 #define dprintf posix_dprintf -
uspace/lib/posix/unistd.c
r46ac986 r221afc9e 94 94 95 95 /** 96 * Get the pathname of the current working directory. 97 * 98 * @param buf Buffer into which the pathname shall be put. 99 * @param size Size of the buffer. 100 * @return Buffer pointer on success, NULL on failure. 101 */ 102 char *posix_getcwd(char *buf, size_t size) 103 { 104 /* Native getcwd() does not set any errno despite the fact that general 105 * usage pattern of this function depends on it (caller is repeatedly 106 * guessing the required size of the buffer by checking for ERANGE on 107 * failure). */ 108 if (size == 0) { 109 errno = EINVAL; 110 return NULL; 111 } 112 char *ret = getcwd(buf, size); 113 if (ret == NULL && errno == EOK) { 114 errno = ERANGE; 115 } 116 return ret; 117 } 118 119 /** 96 120 * Determine the page size of the current run of the process. 97 121 * … … 133 157 /* There is currently no support for user accounts in HelenOS. */ 134 158 return 0; 159 } 160 161 /** 162 * Read from a file. 163 * 164 * @param fildes File descriptor of the opened file. 165 * @param buf Buffer to which the read bytes shall be stored. 166 * @param nbyte Upper limit on the number of read bytes. 167 * @return Number of read bytes on success, -1 otherwise. 168 */ 169 ssize_t posix_read(int fildes, void *buf, size_t nbyte) 170 { 171 int rc = read(fildes, buf, nbyte); 172 if (rc < 0) { 173 errno = -rc; 174 return -1; 175 } else { 176 return rc; 177 } 178 } 179 180 /** 181 * Remove a link to a file. 182 * 183 * @param path File pathname. 184 * @return Zero on success, -1 otherwise. 185 */ 186 int posix_unlink(const char *path) 187 { 188 int rc = unlink(path); 189 if (rc < 0) { 190 errno = -rc; 191 return -1; 192 } else { 193 return rc; 194 } 135 195 } 136 196 -
uspace/lib/posix/unistd.h
r46ac986 r221afc9e 51 51 extern char **posix_environ; 52 52 53 /* Login Information */ 53 54 extern char *posix_getlogin(void); 54 55 extern int posix_getlogin_r(char *name, size_t namesize); … … 56 57 /* Identifying Terminals */ 57 58 extern int posix_isatty(int fd); 59 60 /* Working Directory */ 61 extern char *posix_getcwd(char *buf, size_t size); 58 62 59 63 /* Query Memory Parameters */ … … 64 68 extern posix_uid_t posix_getuid(void); 65 69 extern posix_gid_t posix_getgid(void); 70 71 /* File Input/Output */ 72 extern ssize_t posix_read(int fildes, void *buf, size_t nbyte); 73 74 /* Deleting Files */ 75 extern int posix_unlink(const char *path); 66 76 67 77 /* Standard Streams */ … … 129 139 #ifndef LIBPOSIX_INTERNAL 130 140 #define environ posix_environ 141 131 142 #define getlogin posix_getlogin 132 143 #define getlogin_r posix_getlogin_r 144 145 #define getcwd posix_getcwd 133 146 134 147 #define isatty posix_isatty … … 140 153 #define getuid posix_getuid 141 154 #define getgid posix_getgid 155 156 #define read posix_read 157 158 #define unlink posix_unlink 142 159 143 160 #define access posix_access
Note:
See TracChangeset
for help on using the changeset viewer.