Changeset 7f9df7b9 in mainline for uspace/lib/posix/src
- Timestamp:
- 2018-01-22T22:42:57Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7a08c70
- Parents:
- e0f47f5
- Location:
- uspace/lib/posix/src
- Files:
-
- 1 deleted
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/src/dlfcn.c
re0f47f5 r7f9df7b9 31 31 */ 32 32 33 #define LIBPOSIX_INTERNAL34 #define __POSIX_DEF__(x) posix_##x35 36 33 #include "internal/common.h" 37 34 #include "posix/dlfcn.h" 38 35 39 #include "libc/dlfcn.h" 36 _HIDE_LIBC_SYMBOL(dlopen) 37 extern void *__helenos_libc_dlopen(const char *filename, int flags); 40 38 41 void * posix_dlopen(const char *filename, int flags)39 void *dlopen(const char *filename, int flags) 42 40 { 43 41 if (flags != 0) { … … 45 43 } 46 44 47 return dlopen(filename, 0);45 return __helenos_libc_dlopen(filename, 0); 48 46 } 49 47 50 void *posix_dlsym(void *handle, const char *symbol) 51 { 52 return dlsym(handle, symbol); 53 } 54 55 int posix_dlclose(void *handle) 48 int dlclose(void *handle) 56 49 { 57 50 not_implemented(); … … 59 52 } 60 53 61 char * posix_dlerror(void)54 char *dlerror(void) 62 55 { 63 56 not_implemented(); -
uspace/lib/posix/src/fcntl.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "internal/common.h" 39 36 #include "posix/fcntl.h" … … 51 48 * to the requested operation. 52 49 */ 53 int posix_fcntl(int fd, int cmd, ...)50 int fcntl(int fd, int cmd, ...) 54 51 { 55 52 int flags; … … 102 99 * @param posix_flags Access mode flags. 103 100 */ 104 int posix_open(const char *pathname, int posix_flags, ...)101 int open(const char *pathname, int posix_flags, ...) 105 102 { 106 posix_mode_t posix_mode = 0;103 mode_t posix_mode = 0; 107 104 if (posix_flags & O_CREAT) { 108 105 va_list args; 109 106 va_start(args, posix_flags); 110 posix_mode = va_arg(args, posix_mode_t);107 posix_mode = va_arg(args, mode_t); 111 108 va_end(args); 112 109 (void) posix_mode; -
uspace/lib/posix/src/fnmatch.c
re0f47f5 r7f9df7b9 41 41 * will be fairly straightforward. 42 42 */ 43 44 #define LIBPOSIX_INTERNAL45 #define __POSIX_DEF__(x) posix_##x46 43 47 44 #include "libc/stdbool.h" … … 205 202 { 206 203 const struct _char_class *class = elem; 207 return posix_strcmp((const char *) key, class->name);204 return strcmp((const char *) key, class->name); 208 205 } 209 206 … … 218 215 { 219 216 /* Search for class in the array of supported character classes. */ 220 const struct _char_class *class = posix_bsearch(cname, _char_classes,217 const struct _char_class *class = bsearch(cname, _char_classes, 221 218 sizeof(_char_classes) / sizeof(struct _char_class), 222 219 sizeof(struct _char_class), _class_compare); … … 582 579 { 583 580 assert(s != NULL); 584 char *result = posix_strdup(s);581 char *result = strdup(s); 585 582 for (char *i = result; *i != '\0'; ++i) { 586 583 *i = tolower(*i); … … 598 595 * @return Zero if the string matches the pattern, FNM_NOMATCH otherwise. 599 596 */ 600 int posix_fnmatch(const char *pattern, const char *string, int flags)597 int fnmatch(const char *pattern, const char *string, int flags) 601 598 { 602 599 assert(pattern != NULL); … … 637 634 #undef assert 638 635 #define assert(x) { if (x) printf("SUCCESS: "#x"\n"); else { printf("FAILED: "#x"\n"); fail++; } } 639 #define match(s1, s2, flags) assert( posix_fnmatch(s1, s2, flags) == 0)640 #define nomatch(s1, s2, flags) assert( posix_fnmatch(s1, s2, flags) == FNM_NOMATCH)636 #define match(s1, s2, flags) assert(fnmatch(s1, s2, flags) == 0) 637 #define nomatch(s1, s2, flags) assert(fnmatch(s1, s2, flags) == FNM_NOMATCH) 641 638 642 639 static_assert(FNM_PATHNAME == FNM_FILE_NAME); -
uspace/lib/posix/src/internal/common.h
re0f47f5 r7f9df7b9 50 50 } while (0) 51 51 52 // Just a marker for external tools. 53 #define _HIDE_LIBC_SYMBOL(symbol) 54 52 55 /* Checks if the value is a failing error code. 53 56 * If so, writes the error code to errno and returns true. -
uspace/lib/posix/src/locale.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "internal/common.h" 39 36 #include "posix/locale.h" … … 54 51 }; 55 52 56 const struct posix_lconv C_LOCALE = {53 const struct lconv C_LOCALE = { 57 54 .currency_symbol = (char *) "", 58 55 .decimal_point = (char *) ".", … … 88 85 * @return Original locale name on success, NULL on failure. 89 86 */ 90 char * posix_setlocale(int category, const char *locale)87 char *setlocale(int category, const char *locale) 91 88 { 92 89 // TODO 93 90 if (locale == NULL || *locale == '\0' || 94 posix_strcmp(locale, "C") == 0) {91 strcmp(locale, "C") == 0) { 95 92 return (char *) "C"; 96 93 } … … 103 100 * @return Information about the current locale. 104 101 */ 105 struct posix_lconv *posix_localeconv(void)102 struct lconv *localeconv(void) 106 103 { 107 104 // TODO 108 return (struct posix_lconv *) &C_LOCALE;105 return (struct lconv *) &C_LOCALE; 109 106 } 110 107 … … 115 112 * @return Duplicated object. 116 113 */ 117 posix_locale_t posix_duplocale(posix_locale_t locobj)114 locale_t duplocale(locale_t locobj) 118 115 { 119 116 if (locobj == NULL) { … … 121 118 return NULL; 122 119 } 123 posix_locale_t copy = malloc(sizeof(struct __posix_locale));120 locale_t copy = malloc(sizeof(struct __posix_locale)); 124 121 if (copy == NULL) { 125 122 errno = ENOMEM; … … 135 132 * @param locobj Object to free. 136 133 */ 137 void posix_freelocale(posix_locale_t locobj)134 void freelocale(locale_t locobj) 138 135 { 139 136 if (locobj) { … … 150 147 * @return The new/modified locale object. 151 148 */ 152 posix_locale_t posix_newlocale(int category_mask, const char *locale,153 posix_locale_t base)149 locale_t newlocale(int category_mask, const char *locale, 150 locale_t base) 154 151 { 155 152 if (locale == NULL || … … 159 156 } 160 157 // TODO 161 posix_locale_t new = malloc(sizeof(struct __posix_locale));158 locale_t new = malloc(sizeof(struct __posix_locale)); 162 159 if (new == NULL) { 163 160 errno = ENOMEM; … … 165 162 } 166 163 if (base != NULL) { 167 posix_freelocale(base);164 freelocale(base); 168 165 } 169 166 return new; … … 176 173 * @return The previously set locale or LC_GLOBAL_LOCALE 177 174 */ 178 posix_locale_t posix_uselocale(posix_locale_t newloc)175 locale_t uselocale(locale_t newloc) 179 176 { 180 177 // TODO -
uspace/lib/posix/src/pthread/condvar.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "posix/pthread.h" 39 36 #include "errno.h" … … 66 63 67 64 int pthread_cond_timedwait(pthread_cond_t *restrict condvar, 68 pthread_mutex_t *restrict mutex, const struct __POSIX_DEF__(timespec)*restrict timeout)65 pthread_mutex_t *restrict mutex, const struct timespec *restrict timeout) 69 66 { 70 67 not_implemented(); -
uspace/lib/posix/src/pthread/keys.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "posix/stdlib.h" 39 36 #include "posix/pthread.h" -
uspace/lib/posix/src/pthread/mutex.c
re0f47f5 r7f9df7b9 32 32 /** @file Pthread: mutexes. 33 33 */ 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 34 38 35 #include "posix/pthread.h" -
uspace/lib/posix/src/pthread/threads.c
re0f47f5 r7f9df7b9 32 32 /** @file Pthread: thread management. 33 33 */ 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 34 38 35 #include "posix/pthread.h" -
uspace/lib/posix/src/pwd.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "libc/stdbool.h" 39 36 #include "posix/pwd.h" … … 45 42 46 43 /* dummy user account */ 47 static const struct p osix_passwd dummy_pwd = {44 static const struct passwd dummy_pwd = { 48 45 .pw_name = (char *) "user", 49 46 .pw_uid = 0, … … 62 59 * doesn't have user accounts, this always returns the same made-up entry. 63 60 */ 64 struct p osix_passwd *posix_getpwent(void)61 struct passwd *getpwent(void) 65 62 { 66 63 if (entry_read) { … … 69 66 70 67 entry_read = true; 71 return (struct p osix_passwd *) &dummy_pwd;68 return (struct passwd *) &dummy_pwd; 72 69 } 73 70 … … 75 72 * Rewind the user list. 76 73 */ 77 void posix_setpwent(void)74 void setpwent(void) 78 75 { 79 76 entry_read = false; … … 83 80 * Ends enumerating and releases all resources. (Noop) 84 81 */ 85 void posix_endpwent(void)82 void endpwent(void) 86 83 { 87 84 /* noop */ … … 94 91 * @return Either found entry or NULL if no such entry exists. 95 92 */ 96 struct p osix_passwd *posix_getpwnam(const char *name)93 struct passwd *getpwnam(const char *name) 97 94 { 98 95 assert(name != NULL); 99 96 100 if ( posix_strcmp(name, "user") != 0) {97 if (strcmp(name, "user") != 0) { 101 98 return NULL; 102 99 } 103 100 104 return (struct p osix_passwd *) &dummy_pwd;101 return (struct passwd *) &dummy_pwd; 105 102 } 106 103 … … 116 113 * non-zero error number if error occured. 117 114 */ 118 int posix_getpwnam_r(const char *name, struct posix_passwd *pwd,119 char *buffer, size_t bufsize, struct p osix_passwd **result)115 int getpwnam_r(const char *name, struct passwd *pwd, 116 char *buffer, size_t bufsize, struct passwd **result) 120 117 { 121 118 assert(name != NULL); … … 124 121 assert(result != NULL); 125 122 126 if ( posix_strcmp(name, "user") != 0) {123 if (strcmp(name, "user") != 0) { 127 124 *result = NULL; 128 125 return 0; 129 126 } 130 127 131 return posix_getpwuid_r(0, pwd, buffer, bufsize, result);128 return getpwuid_r(0, pwd, buffer, bufsize, result); 132 129 } 133 130 … … 138 135 * @return Either found entry or NULL if no such entry exists. 139 136 */ 140 struct p osix_passwd *posix_getpwuid(posix_uid_t uid)137 struct passwd *getpwuid(uid_t uid) 141 138 { 142 139 if (uid != 0) { … … 144 141 } 145 142 146 return (struct p osix_passwd *) &dummy_pwd;143 return (struct passwd *) &dummy_pwd; 147 144 } 148 145 … … 158 155 * non-zero error number if error occured. 159 156 */ 160 int posix_getpwuid_r(posix_uid_t uid, struct posix_passwd *pwd,161 char *buffer, size_t bufsize, struct p osix_passwd **result)157 int getpwuid_r(uid_t uid, struct passwd *pwd, 158 char *buffer, size_t bufsize, struct passwd **result) 162 159 { 163 160 assert(pwd != NULL); … … 184 181 pwd->pw_dir = (char *) bf + 5; 185 182 pwd->pw_shell = (char *) bf + 7; 186 *result = (struct p osix_passwd *) pwd;183 *result = (struct passwd *) pwd; 187 184 188 185 return 0; -
uspace/lib/posix/src/signal.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "posix/signal.h" 39 36 #include "internal/common.h" … … 61 58 static LIST_INITIALIZE(_signal_queue); 62 59 63 static posix_sigset_t _signal_mask = 0;60 static sigset_t _signal_mask = 0; 64 61 65 62 #define DEFAULT_HANDLER { .sa_handler = SIG_DFL, \ … … 67 64 68 65 /* Actions associated with each signal number. */ 69 static struct posix_sigaction _signal_actions[_TOP_SIGNAL + 1] = {66 static struct sigaction _signal_actions[_TOP_SIGNAL + 1] = { 70 67 DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 71 68 DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, … … 111 108 case SIGILL: 112 109 case SIGSEGV: 113 p osix_psignal(signo, "Hardware exception raised by user code");110 psignal(signo, "Hardware exception raised by user code"); 114 111 abort(); 115 112 case SIGSYS: … … 124 121 case SIGTTIN: 125 122 case SIGTTOU: 126 p osix_psignal(signo, "Unsupported signal caught");123 psignal(signo, "Unsupported signal caught"); 127 124 abort(); 128 125 case SIGCHLD: … … 164 161 * @return Always returns zero. 165 162 */ 166 int posix_sigemptyset(posix_sigset_t *set)163 int sigemptyset(sigset_t *set) 167 164 { 168 165 assert(set != NULL); … … 178 175 * @return Always returns zero. 179 176 */ 180 int posix_sigfillset(posix_sigset_t *set)177 int sigfillset(sigset_t *set) 181 178 { 182 179 assert(set != NULL); … … 193 190 * @return Always returns zero. 194 191 */ 195 int posix_sigaddset(posix_sigset_t *set, int signo)192 int sigaddset(sigset_t *set, int signo) 196 193 { 197 194 assert(set != NULL); … … 208 205 * @return Always returns zero. 209 206 */ 210 int posix_sigdelset(posix_sigset_t *set, int signo)207 int sigdelset(sigset_t *set, int signo) 211 208 { 212 209 assert(set != NULL); … … 223 220 * @return 1 if the signal is in the set, 0 otherwise. 224 221 */ 225 int posix_sigismember(const posix_sigset_t *set, int signo)222 int sigismember(const sigset_t *set, int signo) 226 223 { 227 224 assert(set != NULL); … … 239 236 * @param oact 240 237 */ 241 static void _sigaction_unsafe(int sig, const struct posix_sigaction *restrict act,242 struct posix_sigaction *restrict oact)238 static void _sigaction_unsafe(int sig, const struct sigaction *restrict act, 239 struct sigaction *restrict oact) 243 240 { 244 241 if (oact != NULL) { 245 242 memcpy(oact, &_signal_actions[sig], 246 sizeof(struct posix_sigaction));243 sizeof(struct sigaction)); 247 244 } 248 245 249 246 if (act != NULL) { 250 247 memcpy(&_signal_actions[sig], act, 251 sizeof(struct posix_sigaction));248 sizeof(struct sigaction)); 252 249 } 253 250 } … … 263 260 * @return -1 with errno set on failure, 0 on success. 264 261 */ 265 int posix_sigaction(int sig, const struct posix_sigaction *restrict act,266 struct posix_sigaction *restrict oact)262 int sigaction(int sig, const struct sigaction *restrict act, 263 struct sigaction *restrict oact) 267 264 { 268 265 if (sig > _TOP_SIGNAL || (act != NULL && … … 273 270 274 271 if (sig > _TOP_CATCHABLE_SIGNAL) { 275 p osix_psignal(sig,272 psignal(sig, 276 273 "WARNING: registering handler for a partially" 277 274 " or fully unsupported signal. This handler may only be" … … 294 291 * @return SIG_ERR on failure, original handler on success. 295 292 */ 296 void (* posix_signal(int sig, void (*func)(int)))(int)297 { 298 struct posix_sigaction new = {293 void (*signal(int sig, void (*func)(int)))(int) 294 { 295 struct sigaction new = { 299 296 .sa_handler = func, 300 297 .sa_mask = 0, … … 302 299 .sa_sigaction = NULL 303 300 }; 304 struct posix_sigaction old;305 if ( posix_sigaction(sig, func == NULL ? NULL : &new, &old) == 0) {301 struct sigaction old; 302 if (sigaction(sig, func == NULL ? NULL : &new, &old) == 0) { 306 303 return old.sa_handler; 307 304 } else { … … 313 310 link_t link; 314 311 int signo; 315 posix_siginfo_t siginfo;312 siginfo_t siginfo; 316 313 } signal_queue_item; 317 314 … … 322 319 * @param siginfo Additional information about the signal. 323 320 */ 324 static void _queue_signal(int signo, posix_siginfo_t *siginfo)321 static void _queue_signal(int signo, siginfo_t *siginfo) 325 322 { 326 323 assert(signo >= 0 && signo <= _TOP_SIGNAL); … … 330 327 link_initialize(&(item->link)); 331 328 item->signo = signo; 332 memcpy(&item->siginfo, siginfo, sizeof( posix_siginfo_t));329 memcpy(&item->siginfo, siginfo, sizeof(siginfo_t)); 333 330 list_append(&(item->link), &_signal_queue); 334 331 } … … 343 340 * blocked. 344 341 */ 345 static int _raise_sigaction(int signo, posix_siginfo_t *siginfo)342 static int _raise_sigaction(int signo, siginfo_t *siginfo) 346 343 { 347 344 assert(signo >= 0 && signo <= _TOP_SIGNAL); … … 350 347 fibril_mutex_lock(&_signal_mutex); 351 348 352 struct posix_sigaction action = _signal_actions[signo];353 354 if ( posix_sigismember(&_signal_mask, signo) ||349 struct sigaction action = _signal_actions[signo]; 350 351 if (sigismember(&_signal_mask, signo) || 355 352 action.sa_handler == SIG_HOLD) { 356 353 _queue_signal(signo, siginfo); … … 364 361 365 362 if ((action.sa_flags & SA_RESETHAND) && signo != SIGILL && signo != SIGTRAP) { 366 _signal_actions[signo] = (struct posix_sigaction) DEFAULT_HANDLER;363 _signal_actions[signo] = (struct sigaction) DEFAULT_HANDLER; 367 364 } 368 365 … … 394 391 list_get_instance(iterator, signal_queue_item, link); 395 392 396 if (! posix_sigismember(&_signal_mask, item->signo) &&393 if (!sigismember(&_signal_mask, item->signo) && 397 394 _signal_actions[item->signo].sa_handler != SIG_HOLD) { 398 395 list_remove(&(item->link)); … … 411 408 * @return -1 with errno set on failure, 0 on success. 412 409 */ 413 int posix_raise(int sig)410 int raise(int sig) 414 411 { 415 412 if (sig >= 0 && sig <= _TOP_SIGNAL) { 416 posix_siginfo_t siginfo = {413 siginfo_t siginfo = { 417 414 .si_signo = sig, 418 415 .si_code = SI_USER … … 433 430 * action, invalid signal number, lack of permissions, etc.), 0 on success. 434 431 */ 435 int posix_kill(posix_pid_t pid, int signo)432 int kill(pid_t pid, int signo) 436 433 { 437 434 if (pid < 1) { … … 446 443 } 447 444 448 if (pid == (p osix_pid_t) task_get_id()) {449 return posix_raise(signo);445 if (pid == (pid_t) task_get_id()) { 446 return raise(signo); 450 447 } 451 448 … … 471 468 * @return -1 on failure, 0 on success (see kill()). 472 469 */ 473 int posix_killpg(posix_pid_t pid, int sig)470 int killpg(pid_t pid, int sig) 474 471 { 475 472 assert(pid > 1); 476 return posix_kill(-pid, sig);473 return kill(-pid, sig); 477 474 } 478 475 … … 483 480 * @param message String to output alongside human-readable signal description. 484 481 */ 485 void p osix_psiginfo(const posix_siginfo_t *pinfo, const char *message)482 void psiginfo(const siginfo_t *pinfo, const char *message) 486 483 { 487 484 assert(pinfo != NULL); 488 p osix_psignal(pinfo->si_signo, message);485 psignal(pinfo->si_signo, message); 489 486 // TODO: print si_code 490 487 } … … 496 493 * @param message String to output alongside human-readable signal description. 497 494 */ 498 void p osix_psignal(int signum, const char *message)499 { 500 char *sigmsg = posix_strsignal(signum);495 void psignal(int signum, const char *message) 496 { 497 char *sigmsg = strsignal(signum); 501 498 if (message == NULL || *message == '\0') { 502 499 fprintf(stderr, "%s\n", sigmsg); … … 514 511 * @return 0 success, errorcode on failure. 515 512 */ 516 int posix_thread_sigmask(int how, const posix_sigset_t *restrict set,517 posix_sigset_t *restrict oset)513 int thread_sigmask(int how, const sigset_t *restrict set, 514 sigset_t *restrict oset) 518 515 { 519 516 fibril_mutex_lock(&_signal_mutex); … … 554 551 * @return 0 on success, -1 with errno set on failure. 555 552 */ 556 int posix_sigprocmask(int how, const posix_sigset_t *restrict set,557 posix_sigset_t *restrict oset)558 { 559 int result = posix_thread_sigmask(how, set, oset);553 int sigprocmask(int how, const sigset_t *restrict set, 554 sigset_t *restrict oset) 555 { 556 int result = thread_sigmask(how, set, oset); 560 557 if (result != 0) { 561 558 errno = result; -
uspace/lib/posix/src/stdio.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/stdio.h" … … 55 52 #include "libc/adt/list.h" 56 53 57 /** Clears the stream's error and end-of-file indicators.58 *59 * @param stream Stream whose indicators shall be cleared.60 */61 void posix_clearerr(FILE *stream)62 {63 clearerr(stream);64 }65 66 54 /** 67 55 * Generate a pathname for the controlling terminal. … … 70 58 * @return Either s or static location filled with the requested pathname. 71 59 */ 72 char * posix_ctermid(char *s)60 char *ctermid(char *s) 73 61 { 74 62 /* Currently always returns an error value (empty string). */ … … 83 71 s[0] = '\0'; 84 72 return s; 85 }86 87 /**88 * Put a string on the stream.89 *90 * @param s String to be written.91 * @param stream Output stream.92 * @return Non-negative on success, EOF on failure.93 */94 int posix_fputs(const char *restrict s, FILE *restrict stream)95 {96 return fputs(s, stream);97 }98 99 /**100 * Push byte back into input stream.101 *102 * @param c Byte to be pushed back.103 * @param stream Stream to where the byte shall be pushed.104 * @return Provided byte on success or EOF if not possible.105 */106 int posix_ungetc(int c, FILE *stream)107 {108 return ungetc(c, stream);109 73 } 110 74 … … 122 86 * or -1 on error (set in errno). 123 87 */ 124 ssize_t posix_getdelim(char **restrict lineptr, size_t *restrict n,88 ssize_t getdelim(char **restrict lineptr, size_t *restrict n, 125 89 int delimiter, FILE *restrict stream) 126 90 { … … 194 158 * or -1 on error (set in errno). 195 159 */ 196 ssize_t posix_getline(char **restrict lineptr, size_t *restrict n,160 ssize_t getline(char **restrict lineptr, size_t *restrict n, 197 161 FILE *restrict stream) 198 162 { 199 return posix_getdelim(lineptr, n, '\n', stream); 200 } 201 202 /** 203 * Reopen a file stream. 204 * 205 * @param filename Pathname of a file to be reopened or NULL for changing 206 * the mode of the stream. 207 * @param mode Mode to be used for reopening the file or changing current 208 * mode of the stream. 209 * @param stream Current stream associated with the opened file. 210 * @return On success, either a stream of the reopened file or the provided 211 * stream with a changed mode. NULL otherwise. 212 */ 213 FILE *posix_freopen(const char *restrict filename, 214 const char *restrict mode, FILE *restrict stream) 215 { 216 return freopen(filename, mode, stream); 163 return getdelim(lineptr, n, '\n', stream); 217 164 } 218 165 … … 222 169 * @param s Error message. 223 170 */ 224 void p osix_perror(const char *s)171 void perror(const char *s) 225 172 { 226 173 if (s == NULL || s[0] == '\0') { 227 fprintf(stderr, "%s\n", posix_strerror(errno));174 fprintf(stderr, "%s\n", strerror(errno)); 228 175 } else { 229 fprintf(stderr, "%s: %s\n", s, posix_strerror(errno));176 fprintf(stderr, "%s: %s\n", s, strerror(errno)); 230 177 } 231 178 } … … 237 184 * @return Zero on success, non-zero (with errno set) on failure 238 185 */ 239 int posix_fsetpos(FILE *stream, const posix_fpos_t *pos)186 int fsetpos(FILE *stream, const fpos_t *pos) 240 187 { 241 188 return fseek64(stream, pos->offset, SEEK_SET); … … 248 195 * @return Zero on success, non-zero (with errno set) on failure 249 196 */ 250 int posix_fgetpos(FILE *restrict stream, posix_fpos_t *restrict pos)197 int fgetpos(FILE *restrict stream, fpos_t *restrict pos) 251 198 { 252 199 off64_t ret = ftell64(stream); … … 267 214 * @return Zero on success, -1 otherwise. 268 215 */ 269 int posix_fseek(FILE *stream, long offset, int whence) 270 { 271 return fseek(stream, offset, whence); 272 } 273 274 /** 275 * Reposition a file-position indicator in a stream. 276 * 277 * @param stream Stream to seek in. 278 * @param offset Direction and amount of bytes to seek. 279 * @param whence From where to seek. 280 * @return Zero on success, -1 otherwise. 281 */ 282 int posix_fseeko(FILE *stream, posix_off_t offset, int whence) 216 int fseeko(FILE *stream, off_t offset, int whence) 283 217 { 284 218 return fseek64(stream, offset, whence); … … 291 225 * @return Current offset or -1 if not possible. 292 226 */ 293 long posix_ftell(FILE *stream) 294 { 295 return ftell(stream); 296 } 297 298 /** 299 * Discover current file offset in a stream. 300 * 301 * @param stream Stream for which the offset shall be retrieved. 302 * @return Current offset or -1 if not possible. 303 */ 304 posix_off_t posix_ftello(FILE *stream) 227 off_t ftello(FILE *stream) 305 228 { 306 229 return ftell64(stream); … … 308 231 309 232 /** 310 * Discard prefetched data or write unwritten data.311 *312 * @param stream Stream that shall be flushed.313 * @return Zero on success, EOF on failure.314 */315 int posix_fflush(FILE *stream)316 {317 return fflush(stream);318 }319 320 /**321 233 * Print formatted output to the opened file. 322 234 * … … 325 237 * @return Either the number of printed characters or negative value on error. 326 238 */ 327 int posix_dprintf(int fildes, const char *restrict format, ...)239 int dprintf(int fildes, const char *restrict format, ...) 328 240 { 329 241 va_list list; 330 242 va_start(list, format); 331 int result = posix_vdprintf(fildes, format, list);243 int result = vdprintf(fildes, format, list); 332 244 va_end(list); 333 245 return result; … … 392 304 * @return Either the number of printed characters or negative value on error. 393 305 */ 394 int posix_vdprintf(int fildes, const char *restrict format, va_list ap)306 int vdprintf(int fildes, const char *restrict format, va_list ap) 395 307 { 396 308 printf_spec_t spec = { … … 411 323 * negative value on error. 412 324 */ 413 int posix_sprintf(char *s, const char *restrict format, ...)325 int sprintf(char *s, const char *restrict format, ...) 414 326 { 415 327 va_list list; 416 328 va_start(list, format); 417 int result = posix_vsprintf(s, format, list);329 int result = vsprintf(s, format, list); 418 330 va_end(list); 419 331 return result; … … 429 341 * negative value on error. 430 342 */ 431 int posix_vsprintf(char *s, const char *restrict format, va_list ap)343 int vsprintf(char *s, const char *restrict format, va_list ap) 432 344 { 433 345 return vsnprintf(s, STR_NO_LIMIT, format, ap); … … 441 353 * @return The number of converted output items or EOF on failure. 442 354 */ 443 int posix_fscanf(FILE *restrict stream, const char *restrict format, ...)355 int fscanf(FILE *restrict stream, const char *restrict format, ...) 444 356 { 445 357 va_list list; 446 358 va_start(list, format); 447 int result = posix_vfscanf(stream, format, list);359 int result = vfscanf(stream, format, list); 448 360 va_end(list); 449 361 return result; … … 456 368 * @return The number of converted output items or EOF on failure. 457 369 */ 458 int posix_scanf(const char *restrict format, ...)370 int scanf(const char *restrict format, ...) 459 371 { 460 372 va_list list; 461 373 va_start(list, format); 462 int result = posix_vscanf(format, list);374 int result = vscanf(format, list); 463 375 va_end(list); 464 376 return result; … … 472 384 * @return The number of converted output items or EOF on failure. 473 385 */ 474 int posix_vscanf(const char *restrict format, va_list arg)475 { 476 return posix_vfscanf(stdin, format, arg);386 int vscanf(const char *restrict format, va_list arg) 387 { 388 return vfscanf(stdin, format, arg); 477 389 } 478 390 … … 484 396 * @return The number of converted output items or EOF on failure. 485 397 */ 486 int posix_sscanf(const char *restrict s, const char *restrict format, ...)398 int sscanf(const char *restrict s, const char *restrict format, ...) 487 399 { 488 400 va_list list; 489 401 va_start(list, format); 490 int result = posix_vsscanf(s, format, list);402 int result = vsscanf(s, format, list); 491 403 va_end(list); 492 404 return result; … … 498 410 * @param file File stream to lock. 499 411 */ 500 void posix_flockfile(FILE *file)412 void flockfile(FILE *file) 501 413 { 502 414 /* dummy */ … … 509 421 * @return Zero for success and non-zero if the lock cannot be acquired. 510 422 */ 511 int posix_ftrylockfile(FILE *file)423 int ftrylockfile(FILE *file) 512 424 { 513 425 /* dummy */ … … 520 432 * @param file File stream to unlock. 521 433 */ 522 void posix_funlockfile(FILE *file)434 void funlockfile(FILE *file) 523 435 { 524 436 /* dummy */ … … 531 443 * @return Either read byte or EOF. 532 444 */ 533 int posix_getc_unlocked(FILE *stream)445 int getc_unlocked(FILE *stream) 534 446 { 535 447 return getc(stream); … … 541 453 * @return Either read byte or EOF. 542 454 */ 543 int posix_getchar_unlocked(void)455 int getchar_unlocked(void) 544 456 { 545 457 return getchar(); … … 553 465 * @return Either written byte or EOF. 554 466 */ 555 int p osix_putc_unlocked(int c, FILE *stream)467 int putc_unlocked(int c, FILE *stream) 556 468 { 557 469 return putc(c, stream); … … 564 476 * @return Either written byte or EOF. 565 477 */ 566 int p osix_putchar_unlocked(int c)478 int putchar_unlocked(int c) 567 479 { 568 480 return putchar(c); 569 }570 571 /**572 * Remove a file or directory.573 *574 * @param path Pathname of the file that shall be removed.575 * @return Zero on success, -1 (with errno set) otherwise.576 */577 int posix_remove(const char *path)578 {579 if (failed(vfs_unlink_path(path)))580 return -1;581 else582 return 0;583 }584 585 /**586 * Rename a file or directory.587 *588 * @param old Old pathname.589 * @param new New pathname.590 * @return Zero on success, -1 (with errno set) otherwise.591 */592 int posix_rename(const char *old, const char *new)593 {594 if (failed(vfs_rename_path(old, new)))595 return -1;596 else597 return 0;598 481 } 599 482 … … 604 487 * @return The value of s on success, NULL on failure. 605 488 */ 606 char * posix_tmpnam(char *s)607 { 608 assert(L_tmpnam >= posix_strlen("/tmp/tnXXXXXX"));489 char *tmpnam(char *s) 490 { 491 assert(L_tmpnam >= strlen("/tmp/tnXXXXXX")); 609 492 610 493 static char buffer[L_tmpnam + 1]; … … 613 496 } 614 497 615 posix_strcpy(s, "/tmp/tnXXXXXX");616 posix_mktemp(s);498 strcpy(s, "/tmp/tnXXXXXX"); 499 mktemp(s); 617 500 618 501 if (*s == '\0') { … … 631 514 * @return Newly allocated unique path for temporary file. NULL on failure. 632 515 */ 633 char * posix_tempnam(const char *dir, const char *pfx)516 char *tempnam(const char *dir, const char *pfx) 634 517 { 635 518 /* Sequence number of the filename. */ 636 519 static int seq = 0; 637 520 638 size_t dir_len = posix_strlen(dir);521 size_t dir_len = strlen(dir); 639 522 if (dir[dir_len - 1] == '/') { 640 523 dir_len--; 641 524 } 642 525 643 size_t pfx_len = posix_strlen(pfx);526 size_t pfx_len = strlen(pfx); 644 527 if (pfx_len > 5) { 645 528 pfx_len = 5; … … 655 538 656 539 char *res_ptr = result; 657 posix_strncpy(res_ptr, dir, dir_len);540 strncpy(res_ptr, dir, dir_len); 658 541 res_ptr += dir_len; 659 posix_strncpy(res_ptr, pfx, pfx_len);542 strncpy(res_ptr, pfx, pfx_len); 660 543 res_ptr += pfx_len; 661 544 … … 666 549 errno = EOK; 667 550 /* Check if the file exists. */ 668 if ( posix_access(result, F_OK) == -1) {551 if (access(result, F_OK) == -1) { 669 552 if (errno == ENOENT) { 670 553 errno = orig_errno; … … 694 577 * @return Newly allocated unique path for temporary file. NULL on failure. 695 578 */ 696 FILE * posix_tmpfile(void)579 FILE *tmpfile(void) 697 580 { 698 581 char filename[] = "/tmp/tfXXXXXX"; 699 int fd = posix_mkstemp(filename);582 int fd = mkstemp(filename); 700 583 if (fd == -1) { 701 584 /* errno set by mkstemp(). */ … … 704 587 705 588 /* Unlink the created file, so that it's removed on close(). */ 706 posix_unlink(filename);589 unlink(filename); 707 590 return fdopen(fd, "w+"); 708 591 } -
uspace/lib/posix/src/stdio/scanf.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include <assert.h> 39 36 … … 119 116 /* Initialize internal structures. */ 120 117 self->consumed = 0; 121 ssize_t fetched = posix_getline(118 ssize_t fetched = getline( 122 119 &self->window, &self->window_size, self->source.stream); 123 120 if (fetched != -1) { … … 140 137 /* Initialize internal structures. */ 141 138 self->consumed = 0; 142 self->fetched = posix_strlen(self->source.string);139 self->fetched = strlen(self->source.string); 143 140 self->window = (char *) self->source.string; 144 141 self->window_size = self->fetched + 1; … … 158 155 /* Do we need to fetch a new line from the source? */ 159 156 if (*self->cursor == '\0') { 160 ssize_t fetched = posix_getline(&self->window,157 ssize_t fetched = getline(&self->window, 161 158 &self->window_size, self->source.stream); 162 159 if (fetched != -1) { … … 208 205 * containing newline, while at the same time newline is the character 209 206 * that breaks the matching process. */ 210 int rc = posix_fseek( 211 self->source.stream, -1, SEEK_CUR); 207 int rc = fseek(self->source.stream, -1, SEEK_CUR); 212 208 if (rc == -1) { 213 209 /* Seek failed. */ 214 210 return 0; 215 211 } 216 ssize_t fetched = posix_getline(&self->window,212 ssize_t fetched = getline(&self->window, 217 213 &self->window_size, self->source.stream); 218 214 if (fetched != -1) { … … 266 262 if (*self->cursor == '\0') { 267 263 /* Window was completely consumed, fetch new data. */ 268 ssize_t fetched = posix_getline(&self->window,264 ssize_t fetched = getline(&self->window, 269 265 &self->window_size, self->source.stream); 270 266 if (fetched != -1) { … … 298 294 /* Try to correct the difference between the stream position and what was 299 295 * actually consumed. If it is not possible, continue anyway. */ 300 posix_fseek(self->source.stream, self->consumed - self->fetched, SEEK_CUR);296 fseek(self->source.stream, self->consumed - self->fetched, SEEK_CUR); 301 297 302 298 /* Destruct internal structures. */ … … 638 634 * than allowed by width. */ 639 635 if (width != -1) { 640 cur_duplicated = posix_strndup(cur_borrowed, width);636 cur_duplicated = strndup(cur_borrowed, width); 641 637 cur_limited = cur_duplicated; 642 638 } else { … … 812 808 * than allowed by width. */ 813 809 if (width != -1) { 814 cur_duplicated = posix_strndup(cur_borrowed, width);810 cur_duplicated = strndup(cur_borrowed, width); 815 811 cur_limited = cur_duplicated; 816 812 } else { … … 826 822 switch (length_mod) { 827 823 case LMOD_NONE: 828 fres = posix_strtof(cur_limited, (char **) &cur_updated);824 fres = strtof(cur_limited, (char **) &cur_updated); 829 825 break; 830 826 case LMOD_l: 831 dres = posix_strtod(cur_limited, (char **) &cur_updated);827 dres = strtod(cur_limited, (char **) &cur_updated); 832 828 break; 833 829 case LMOD_L: 834 ldres = posix_strtold(cur_limited, (char **) &cur_updated);830 ldres = strtold(cur_limited, (char **) &cur_updated); 835 831 break; 836 832 default: … … 1194 1190 * @return The number of converted output items or EOF on failure. 1195 1191 */ 1196 int posix_vfscanf(1192 int vfscanf( 1197 1193 FILE *restrict stream, const char *restrict format, va_list arg) 1198 1194 { … … 1214 1210 * @return The number of converted output items or EOF on failure. 1215 1211 */ 1216 int posix_vsscanf(1212 int vsscanf( 1217 1213 const char *restrict s, const char *restrict format, va_list arg) 1218 1214 { -
uspace/lib/posix/src/stdlib.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/stdlib.h" … … 60 57 * @param compare 61 58 */ 62 int posix_atexit(void (*func)(void))59 int atexit(void (*func)(void)) 63 60 { 64 61 // TODO: low priority, just a compile-time dependency of binutils … … 73 70 * @return Absolute value of the parameter. 74 71 */ 75 int posix_abs(int i)72 int abs(int i) 76 73 { 77 74 return i < 0 ? -i : i; … … 84 81 * @return Absolute value of the parameter. 85 82 */ 86 long posix_labs(long i)83 long labs(long i) 87 84 { 88 85 return i < 0 ? -i : i; … … 95 92 * @return Absolute value of the parameter. 96 93 */ 97 long long posix_llabs(long long i)94 long long llabs(long long i) 98 95 { 99 96 return i < 0 ? -i : i; … … 107 104 * @return Quotient and remainder packed into structure. 108 105 */ 109 posix_div_t posix_div(int numer, int denom)110 { 111 return ( posix_div_t) { .quot = numer / denom, .rem = numer % denom };106 div_t div(int numer, int denom) 107 { 108 return (div_t) { .quot = numer / denom, .rem = numer % denom }; 112 109 } 113 110 … … 119 116 * @return Quotient and remainder packed into structure. 120 117 */ 121 posix_ldiv_t posix_ldiv(long numer, long denom)122 { 123 return ( posix_ldiv_t) { .quot = numer / denom, .rem = numer % denom };118 ldiv_t ldiv(long numer, long denom) 119 { 120 return (ldiv_t) { .quot = numer / denom, .rem = numer % denom }; 124 121 } 125 122 … … 131 128 * @return Quotient and remainder packed into structure. 132 129 */ 133 posix_lldiv_t posix_lldiv(long long numer, long long denom) 134 { 135 return (posix_lldiv_t) { .quot = numer / denom, .rem = numer % denom }; 136 } 137 138 /** 139 * Array sorting utilizing the quicksort algorithm. 140 * 141 * @param array Array of elements to sort. 142 * @param count Number of elements in the array. 143 * @param size Width of each element. 144 * @param compare Decides relative ordering of two elements. 145 */ 146 void posix_qsort(void *array, size_t count, size_t size, 147 int (*compare)(const void *, const void *)) 148 { 149 qsort(array, count, size, compare); 130 lldiv_t lldiv(long long numer, long long denom) 131 { 132 return (lldiv_t) { .quot = numer / denom, .rem = numer % denom }; 150 133 } 151 134 … … 160 143 * @return Pointer to a matching element, or NULL if none can be found. 161 144 */ 162 void * posix_bsearch(const void *key, const void *base,145 void *bsearch(const void *key, const void *base, 163 146 size_t nmemb, size_t size, int (*compar)(const void *, const void *)) 164 147 { … … 195 178 * @return Value of the variable or NULL if such variable does not exist. 196 179 */ 197 char * posix_getenv(const char *name)180 char *getenv(const char *name) 198 181 { 199 182 return NULL; … … 206 189 * @return 207 190 */ 208 int p osix_putenv(char *string)191 int putenv(char *string) 209 192 { 210 193 // TODO: low priority, just a compile-time dependency of binutils … … 221 204 * or not (zero). 222 205 */ 223 int posix_system(const char *string) {206 int system(const char *string) { 224 207 // TODO: does nothing at the moment 225 208 not_implemented(); … … 237 220 * 238 221 */ 239 char * posix_realpath(const char *restrict name, char *restrict resolved)222 char *realpath(const char *restrict name, char *restrict resolved) 240 223 { 241 224 #ifndef PATH_MAX … … 279 262 /** 280 263 * Converts a string representation of a floating-point number to 281 * its native representation. See posix_strtold().264 * its native representation. See strtold(). 282 265 * 283 266 * @param nptr String representation of a floating-point number. 284 267 * @return Double-precision number resulting from the string conversion. 285 268 */ 286 double posix_atof(const char *nptr)287 { 288 return posix_strtod(nptr, NULL);269 double atof(const char *nptr) 270 { 271 return strtod(nptr, NULL); 289 272 } 290 273 291 274 /** 292 275 * Converts a string representation of a floating-point number to 293 * its native representation. See posix_strtold().276 * its native representation. See strtold(). 294 277 * 295 278 * @param nptr String representation of a floating-point number. … … 298 281 * @return Single-precision number resulting from the string conversion. 299 282 */ 300 float posix_strtof(const char *restrict nptr, char **restrict endptr)301 { 302 return (float) posix_strtold(nptr, endptr);283 float strtof(const char *restrict nptr, char **restrict endptr) 284 { 285 return (float) strtold(nptr, endptr); 303 286 } 304 287 305 288 /** 306 289 * Converts a string representation of a floating-point number to 307 * its native representation. See posix_strtold().290 * its native representation. See strtold(). 308 291 * 309 292 * @param nptr String representation of a floating-point number. … … 312 295 * @return Double-precision number resulting from the string conversion. 313 296 */ 314 double posix_strtod(const char *restrict nptr, char **restrict endptr) 315 { 316 return (double) posix_strtold(nptr, endptr); 317 } 318 319 /** 320 * Allocate memory chunk. 321 * 322 * @param size Size of the chunk to allocate. 323 * @return Either pointer to the allocated chunk or NULL if not possible. 324 */ 325 void *posix_malloc(size_t size) 326 { 327 return malloc(size); 328 } 329 330 /** 331 * Allocate memory for an array of elements. 332 * 333 * @param nelem Number of elements in the array. 334 * @param elsize Size of each element. 335 * @return Either pointer to the allocated array or NULL if not possible. 336 */ 337 void *posix_calloc(size_t nelem, size_t elsize) 338 { 339 return calloc(nelem, elsize); 340 } 341 342 /** 343 * Reallocate memory chunk to a new size. 344 * 345 * @param ptr Memory chunk to reallocate. Might be NULL. 346 * @param size Size of the reallocated chunk. Might be zero. 347 * @return Either NULL or the pointer to the newly reallocated chunk. 348 */ 349 void *posix_realloc(void *ptr, size_t size) 350 { 351 if (ptr != NULL && size == 0) { 352 /* Native realloc does not handle this special case. */ 353 free(ptr); 354 return NULL; 355 } else { 356 return realloc(ptr, size); 357 } 358 } 359 360 /** 361 * Free allocated memory chunk. 362 * 363 * @param ptr Memory chunk to be freed. 364 */ 365 void posix_free(void *ptr) 366 { 367 if (ptr) { 368 free(ptr); 369 } 370 } 371 372 /** 373 * Generate a pseudo random integer in the range 0 to RAND_MAX inclusive. 374 * 375 * @return The pseudo random integer. 376 */ 377 int posix_rand(void) 378 { 379 return (int) rand(); 380 } 381 382 /** 383 * Initialize a new sequence of pseudo-random integers. 384 * 385 * @param seed The seed of the new sequence. 386 */ 387 void posix_srand(unsigned int seed) 388 { 389 srand(seed); 297 double strtod(const char *restrict nptr, char **restrict endptr) 298 { 299 return (double) strtold(nptr, endptr); 390 300 } 391 301 … … 396 306 * @return The opened file descriptor or -1 on error. 397 307 */ 398 int posix_mkstemp(char *tmpl)308 int mkstemp(char *tmpl) 399 309 { 400 310 int fd = -1; 401 311 402 char *tptr = tmpl + posix_strlen(tmpl) - 6;312 char *tptr = tmpl + strlen(tmpl) - 6; 403 313 404 314 while (fd < 0) { 405 if (* posix_mktemp(tmpl) == '\0') {315 if (*mktemp(tmpl) == '\0') { 406 316 /* Errno set by mktemp(). */ 407 317 return -1; 408 318 } 409 319 410 fd = posix_open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);320 fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); 411 321 412 322 if (fd == -1) { … … 427 337 * reduced to an empty string. 428 338 */ 429 char * posix_mktemp(char *tmpl)430 { 431 int tmpl_len = posix_strlen(tmpl);339 char *mktemp(char *tmpl) 340 { 341 int tmpl_len = strlen(tmpl); 432 342 if (tmpl_len < 6) { 433 343 errno = EINVAL; … … 437 347 438 348 char *tptr = tmpl + tmpl_len - 6; 439 if ( posix_strcmp(tptr, "XXXXXX") != 0) {349 if (strcmp(tptr, "XXXXXX") != 0) { 440 350 errno = EINVAL; 441 351 *tmpl = '\0'; … … 451 361 errno = 0; 452 362 /* Check if the file exists. */ 453 if ( posix_access(tmpl, F_OK) == -1) {363 if (access(tmpl, F_OK) == -1) { 454 364 if (errno == ENOENT) { 455 365 errno = orig_errno; -
uspace/lib/posix/src/stdlib/strtold.c
re0f47f5 r7f9df7b9 32 32 /** @file Backend for floating point conversions. 33 33 */ 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 34 38 35 #include "../internal/common.h" … … 407 404 * @return An approximate representation of the input floating-point number. 408 405 */ 409 long double posix_strtold(const char *restrict nptr, char **restrict endptr)406 long double strtold(const char *restrict nptr, char **restrict endptr) 410 407 { 411 408 assert(nptr != NULL); … … 433 430 434 431 /* check for NaN */ 435 if ( posix_strncasecmp(&nptr[i], "nan", 3) == 0) {432 if (strncasecmp(&nptr[i], "nan", 3) == 0) { 436 433 // FIXME: return NaN 437 434 // TODO: handle the parenthesised case … … 445 442 446 443 /* check for Infinity */ 447 if ( posix_strncasecmp(&nptr[i], "inf", 3) == 0) {444 if (strncasecmp(&nptr[i], "inf", 3) == 0) { 448 445 i += 3; 449 if ( posix_strncasecmp(&nptr[i], "inity", 5) == 0) {446 if (strncasecmp(&nptr[i], "inity", 5) == 0) { 450 447 i += 5; 451 448 } -
uspace/lib/posix/src/string.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/string.h" … … 62 59 static char *strpbrk_null(const char *s1, const char *s2) 63 60 { 64 while (! posix_strchr(s2, *s1)) {61 while (!strchr(s2, *s1)) { 65 62 ++s1; 66 63 } … … 76 73 * @return Pointer to the destination buffer. 77 74 */ 78 char * posix_strcpy(char *restrict dest, const char *restrict src)79 { 80 posix_stpcpy(dest, src);75 char *strcpy(char *restrict dest, const char *restrict src) 76 { 77 stpcpy(dest, src); 81 78 return dest; 82 79 } … … 90 87 * @return Pointer to the destination buffer. 91 88 */ 92 char * posix_strncpy(char *restrict dest, const char *restrict src, size_t n)93 { 94 posix_stpncpy(dest, src, n);89 char *strncpy(char *restrict dest, const char *restrict src, size_t n) 90 { 91 stpncpy(dest, src, n); 95 92 return dest; 96 93 } … … 103 100 * @return Pointer to the nul character in the destination string. 104 101 */ 105 char * posix_stpcpy(char *restrict dest, const char *restrict src)102 char *stpcpy(char *restrict dest, const char *restrict src) 106 103 { 107 104 assert(dest != NULL); … … 129 126 * @return Pointer to the first written nul character or &dest[n]. 130 127 */ 131 char * posix_stpncpy(char *restrict dest, const char *restrict src, size_t n)128 char *stpncpy(char *restrict dest, const char *restrict src, size_t n) 132 129 { 133 130 assert(dest != NULL); … … 159 156 * @return Pointer to destination buffer. 160 157 */ 161 char * posix_strcat(char *restrict dest, const char *restrict src)158 char *strcat(char *restrict dest, const char *restrict src) 162 159 { 163 160 assert(dest != NULL); 164 161 assert(src != NULL); 165 162 166 posix_strcpy(posix_strchr(dest, '\0'), src);163 strcpy(strchr(dest, '\0'), src); 167 164 return dest; 168 165 } … … 176 173 * @return Pointer to destination buffer. 177 174 */ 178 char * posix_strncat(char *restrict dest, const char *restrict src, size_t n)175 char *strncat(char *restrict dest, const char *restrict src, size_t n) 179 176 { 180 177 assert(dest != NULL); 181 178 assert(src != NULL); 182 179 183 char *zeroptr = posix_strncpy(posix_strchr(dest, '\0'), src, n);180 char *zeroptr = strncpy(strchr(dest, '\0'), src, n); 184 181 /* strncpy doesn't append the nul terminator, so we do it here */ 185 182 zeroptr[n] = '\0'; … … 196 193 * @return Pointer to the first byte after c in dest if found, NULL otherwise. 197 194 */ 198 void * posix_memccpy(void *restrict dest, const void *restrict src, int c, size_t n)195 void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n) 199 196 { 200 197 assert(dest != NULL); … … 222 219 * @return Newly allocated copy of the string. 223 220 */ 224 char * posix_strdup(const char *s)225 { 226 return posix_strndup(s, SIZE_MAX);221 char *strdup(const char *s) 222 { 223 return strndup(s, SIZE_MAX); 227 224 } 228 225 … … 234 231 * @return Newly allocated string copy of length at most n. 235 232 */ 236 char * posix_strndup(const char *s, size_t n)233 char *strndup(const char *s, size_t n) 237 234 { 238 235 assert(s != NULL); 239 236 240 size_t len = posix_strnlen(s, n);237 size_t len = strnlen(s, n); 241 238 char *dup = malloc(len + 1); 242 239 if (dup == NULL) { … … 248 245 249 246 return dup; 250 }251 252 /**253 * Compare bytes in memory.254 *255 * @param mem1 First area of memory to be compared.256 * @param mem2 Second area of memory to be compared.257 * @param n Maximum number of bytes to be compared.258 * @return Difference of the first pair of inequal bytes,259 * or 0 if areas have the same content.260 */261 int posix_memcmp(const void *mem1, const void *mem2, size_t n)262 {263 assert(mem1 != NULL);264 assert(mem2 != NULL);265 266 const unsigned char *s1 = mem1;267 const unsigned char *s2 = mem2;268 269 for (size_t i = 0; i < n; ++i) {270 if (s1[i] != s2[i]) {271 return s1[i] - s2[i];272 }273 }274 275 return 0;276 247 } 277 248 … … 284 255 * or 0 if strings have the same content. 285 256 */ 286 int posix_strcmp(const char *s1, const char *s2)257 int strcmp(const char *s1, const char *s2) 287 258 { 288 259 assert(s1 != NULL); 289 260 assert(s2 != NULL); 290 261 291 return posix_strncmp(s1, s2, STR_NO_LIMIT);262 return strncmp(s1, s2, STR_NO_LIMIT); 292 263 } 293 264 … … 301 272 * or 0 if strings have the same content. 302 273 */ 303 int posix_strncmp(const char *s1, const char *s2, size_t n)274 int strncmp(const char *s1, const char *s2, size_t n) 304 275 { 305 276 assert(s1 != NULL); … … 327 298 * NULL pointer otherwise. 328 299 */ 329 void * posix_memchr(const void *mem, int c, size_t n)300 void *memchr(const void *mem, int c, size_t n) 330 301 { 331 302 assert(mem != NULL); … … 349 320 * NULL pointer otherwise. 350 321 */ 351 char * posix_strchr(const char *s, int c)322 char *strchr(const char *s, int c) 352 323 { 353 324 assert(s != NULL); … … 365 336 * NULL pointer otherwise. 366 337 */ 367 char * posix_strrchr(const char *s, int c)338 char *strrchr(const char *s, int c) 368 339 { 369 340 assert(s != NULL); 370 341 371 const char *ptr = posix_strchr(s, '\0');342 const char *ptr = strchr(s, '\0'); 372 343 373 344 /* the same as in strchr, except it loops in reverse direction */ … … 410 381 * NULL pointer otherwise. 411 382 */ 412 char * posix_strpbrk(const char *s1, const char *s2)383 char *strpbrk(const char *s1, const char *s2) 413 384 { 414 385 assert(s1 != NULL); … … 426 397 * @return Length of the prefix. 427 398 */ 428 size_t posix_strcspn(const char *s1, const char *s2)399 size_t strcspn(const char *s1, const char *s2) 429 400 { 430 401 assert(s1 != NULL); … … 442 413 * @return Length of the prefix. 443 414 */ 444 size_t posix_strspn(const char *s1, const char *s2)415 size_t strspn(const char *s1, const char *s2) 445 416 { 446 417 assert(s1 != NULL); … … 449 420 const char *ptr; 450 421 for (ptr = s1; *ptr != '\0'; ++ptr) { 451 if (! posix_strchr(s2, *ptr)) {422 if (!strchr(s2, *ptr)) { 452 423 break; 453 424 } … … 464 435 * not found. 465 436 */ 466 char * posix_strstr(const char *haystack, const char *needle)437 char *strstr(const char *haystack, const char *needle) 467 438 { 468 439 assert(haystack != NULL); … … 475 446 476 447 /* Preprocess needle. */ 477 size_t nlen = posix_strlen(needle);448 size_t nlen = strlen(needle); 478 449 size_t prefix_table[nlen + 1]; 479 450 … … 521 492 * exists. 522 493 */ 523 char * posix_strtok(char *s, const char *delim)494 char *strtok(char *s, const char *delim) 524 495 { 525 496 static char *next; 526 497 527 return posix_strtok_r(s, delim, &next);498 return strtok_r(s, delim, &next); 528 499 } 529 500 … … 541 512 * exists. 542 513 */ 543 char * posix_strtok_r(char *s, const char *delim, char **next)514 char *strtok_r(char *s, const char *delim, char **next) 544 515 { 545 516 char *start, *end; … … 549 520 550 521 /* Skip over leading delimiters. */ 551 while (*s && ( posix_strchr(delim, *s) != NULL)) ++s;522 while (*s && (strchr(delim, *s) != NULL)) ++s; 552 523 start = s; 553 524 554 525 /* Skip over token characters. */ 555 while (*s && ( posix_strchr(delim, *s) == NULL)) ++s;526 while (*s && (strchr(delim, *s) == NULL)) ++s; 556 527 end = s; 557 528 *next = (*s ? s + 1 : s); … … 576 547 * or 0 if strings have the same content. 577 548 */ 578 int posix_strcoll(const char *s1, const char *s2)549 int strcoll(const char *s1, const char *s2) 579 550 { 580 551 assert(s1 != NULL); 581 552 assert(s2 != NULL); 582 553 583 return posix_strcmp(s1, s2);554 return strcmp(s1, s2); 584 555 } 585 556 … … 596 567 * @return Length of the transformed string. 597 568 */ 598 size_t posix_strxfrm(char *restrict s1, const char *restrict s2, size_t n)569 size_t strxfrm(char *restrict s1, const char *restrict s2, size_t n) 599 570 { 600 571 assert(s1 != NULL || n == 0); 601 572 assert(s2 != NULL); 602 573 603 size_t len = posix_strlen(s2);574 size_t len = strlen(s2); 604 575 605 576 if (n > len) { 606 posix_strcpy(s1, s2);577 strcpy(s1, s2); 607 578 } 608 579 … … 616 587 * @return Error message. 617 588 */ 618 char * posix_strerror(int errnum)589 char *strerror(int errnum) 619 590 { 620 591 // FIXME: move strerror() and strerror_r() to libc. … … 630 601 * @return Zero on success, errno otherwise. 631 602 */ 632 int posix_strerror_r(int errnum, char *buf, size_t bufsz)603 int strerror_r(int errnum, char *buf, size_t bufsz) 633 604 { 634 605 assert(buf != NULL); 635 606 636 char *errstr = posix_strerror(errnum);637 638 if ( posix_strlen(errstr) + 1 > bufsz) {607 char *errstr = strerror(errnum); 608 609 if (strlen(errstr) + 1 > bufsz) { 639 610 return ERANGE; 640 611 } else { 641 posix_strcpy(buf, errstr);612 strcpy(buf, errstr); 642 613 } 643 614 … … 651 622 * @return Length of the string. 652 623 */ 653 size_t posix_strlen(const char *s)624 size_t strlen(const char *s) 654 625 { 655 626 assert(s != NULL); 656 627 657 return (size_t) ( posix_strchr(s, '\0') - s);628 return (size_t) (strchr(s, '\0') - s); 658 629 } 659 630 … … 665 636 * @return The lower of either string length or n limit. 666 637 */ 667 size_t posix_strnlen(const char *s, size_t n)638 size_t strnlen(const char *s, size_t n) 668 639 { 669 640 assert(s != NULL); … … 685 656 * @return Human readable signal description. 686 657 */ 687 char * posix_strsignal(int signum)658 char *strsignal(int signum) 688 659 { 689 660 static const char *const sigstrings[] = { -
uspace/lib/posix/src/strings.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/strings.h" … … 52 49 * @return Index of first set bit. Bits are numbered starting at one. 53 50 */ 54 int posix_ffs(int i)51 int ffs(int i) 55 52 { 56 53 if (i == 0) { … … 92 89 * or 0 if strings have the same content. 93 90 */ 94 int posix_strcasecmp(const char *s1, const char *s2)91 int strcasecmp(const char *s1, const char *s2) 95 92 { 96 return posix_strncasecmp(s1, s2, STR_NO_LIMIT);93 return strncasecmp(s1, s2, STR_NO_LIMIT); 97 94 } 98 95 … … 106 103 * or 0 if strings have the same content. 107 104 */ 108 int posix_strncasecmp(const char *s1, const char *s2, size_t n)105 int strncasecmp(const char *s1, const char *s2, size_t n) 109 106 { 110 107 for (size_t i = 0; i < n; ++i) { … … 131 128 * zero. Otherwise return non-zero. 132 129 */ 133 int posix_bcmp(const void *mem1, const void *mem2, size_t n)130 int bcmp(const void *mem1, const void *mem2, size_t n) 134 131 { 135 132 return memcmp(mem1, mem2, n); … … 143 140 * @param n Number of bytes to copy. 144 141 */ 145 void posix_bcopy(const void *src, void *dest, size_t n)142 void bcopy(const void *src, void *dest, size_t n) 146 143 { 147 144 /* Note that memmove has different order of arguments. */ … … 155 152 * @param n Number of bytes to reset. 156 153 */ 157 void posix_bzero(void *mem, size_t n)154 void bzero(void *mem, size_t n) 158 155 { 159 156 memset(mem, 0, n); … … 168 165 * NULL pointer otherwise. 169 166 */ 170 char * posix_index(const char *s, int c)167 char *index(const char *s, int c) 171 168 { 172 return posix_strchr(s, c);169 return strchr(s, c); 173 170 } 174 171 … … 181 178 * NULL pointer otherwise. 182 179 */ 183 char * posix_rindex(const char *s, int c)180 char *rindex(const char *s, int c) 184 181 { 185 return posix_strrchr(s, c);182 return strrchr(s, c); 186 183 } 187 184 -
uspace/lib/posix/src/sys/mman.c
re0f47f5 r7f9df7b9 33 33 */ 34 34 35 #define LIBPOSIX_INTERNAL36 #define __POSIX_DEF__(x) posix_##x37 38 35 #include "../internal/common.h" 39 36 #include <posix/sys/mman.h> … … 42 39 #include <posix/unistd.h> 43 40 44 void * posix_mmap(void *start, size_t length, int prot, int flags, int fd,45 __POSIX_DEF__(off_t)offset)41 void *mmap(void *start, size_t length, int prot, int flags, int fd, 42 off_t offset) 46 43 { 47 44 if (!start) … … 57 54 } 58 55 59 int posix_munmap(void *start, size_t length)56 int munmap(void *start, size_t length) 60 57 { 61 58 int rc = as_area_destroy(start); -
uspace/lib/posix/src/sys/stat.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "../internal/common.h" 40 37 #include "posix/sys/stat.h" … … 52 49 * @return 0 on success, -1 on error. 53 50 */ 54 static int stat_to_posix(struct posix_stat *dest, vfs_stat_t *src)51 static int stat_to_posix(struct stat *dest, vfs_stat_t *src) 55 52 { 56 memset(dest, 0, sizeof(struct posix_stat));53 memset(dest, 0, sizeof(struct stat)); 57 54 58 55 dest->st_dev = src->service; … … 86 83 * @return Zero on success, -1 otherwise. 87 84 */ 88 int posix_fstat(int fd, struct posix_stat *st)85 int fstat(int fd, struct stat *st) 89 86 { 90 87 vfs_stat_t hst; … … 101 98 * @return Zero on success, -1 otherwise. 102 99 */ 103 int posix_lstat(const char *restrict path, struct posix_stat *restrict st)100 int lstat(const char *restrict path, struct stat *restrict st) 104 101 { 105 102 /* There are currently no symbolic links in HelenOS. */ 106 return posix_stat(path, st);103 return stat(path, st); 107 104 } 108 105 … … 114 111 * @return Zero on success, -1 otherwise. 115 112 */ 116 int posix_stat(const char *restrict path, struct posix_stat *restrict st)113 int stat(const char *restrict path, struct stat *restrict st) 117 114 { 118 115 vfs_stat_t hst; … … 129 126 * @return Zero on success, -1 otherwise. 130 127 */ 131 int posix_chmod(const char *path, posix_mode_t mode)128 int chmod(const char *path, mode_t mode) 132 129 { 133 130 /* HelenOS doesn't support permissions, return success. */ … … 142 139 * @return Previous file mode creation mask. 143 140 */ 144 posix_mode_t posix_umask(posix_mode_t mask)141 mode_t umask(mode_t mask) 145 142 { 146 143 /* HelenOS doesn't support permissions, return empty mask. */ … … 155 152 * @return Zero on success, -1 otherwise. 156 153 */ 157 int posix_mkdir(const char *path, posix_mode_t mode)154 int mkdir(const char *path, mode_t mode) 158 155 { 159 156 if (failed(vfs_link_path(path, KIND_DIRECTORY, NULL))) -
uspace/lib/posix/src/sys/wait.c
re0f47f5 r7f9df7b9 33 33 /** @file Support for waiting. 34 34 */ 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 35 39 36 #include "../internal/common.h" … … 76 73 * -1 on signal interrupt, (pid_t)-1 otherwise. 77 74 */ 78 p osix_pid_t posix_wait(int *stat_ptr)75 pid_t wait(int *stat_ptr) 79 76 { 80 77 /* HelenOS does not support this. */ 81 78 errno = ENOSYS; 82 return (p osix_pid_t) -1;79 return (pid_t) -1; 83 80 } 84 81 … … 94 91 * no child process whose status can be reported, (pid_t)-1 otherwise. 95 92 */ 96 p osix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options)93 pid_t waitpid(pid_t pid, int *stat_ptr, int options) 97 94 { 98 95 assert(stat_ptr != NULL); … … 104 101 if (failed(task_wait_task_id((task_id_t) pid, &texit, &retval))) { 105 102 /* Unable to retrieve status. */ 106 return (p osix_pid_t) -1;103 return (pid_t) -1; 107 104 } 108 105 -
uspace/lib/posix/src/time.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/time.h" … … 70 67 * Set timezone conversion information. 71 68 */ 72 void posix_tzset(void)69 void tzset(void) 73 70 { 74 71 // TODO: read environment … … 80 77 81 78 /** 82 * Get the time in seconds83 *84 * @param t If t is non-NULL, the return value is also stored in the memory85 * pointed to by t.86 * @return On success, the value of time in seconds since the Epoch87 * is returned. On error, (time_t)-1 is returned.88 */89 time_t posix_time(time_t *t)90 {91 return time(t);92 }93 94 /**95 79 * Converts a time value to a broken-down UTC time. 96 80 * … … 99 83 * @return Value of result on success, NULL on overflow. 100 84 */ 101 struct tm * posix_gmtime_r(const time_t *restrict timer,85 struct tm *gmtime_r(const time_t *restrict timer, 102 86 struct tm *restrict result) 103 87 { … … 117 101 * the result, NULL in case of error. 118 102 */ 119 struct tm * posix_gmtime(const time_t *restrict timep)103 struct tm *gmtime(const time_t *restrict timep) 120 104 { 121 105 static struct tm result; 122 106 123 return posix_gmtime_r(timep, &result);107 return gmtime_r(timep, &result); 124 108 } 125 109 … … 131 115 * @return Value of result on success, NULL on overflow. 132 116 */ 133 struct tm * posix_localtime_r(const time_t *restrict timer,117 struct tm *localtime_r(const time_t *restrict timer, 134 118 struct tm *restrict result) 135 119 { 136 120 // TODO: deal with timezone 137 121 // currently assumes system and all times are in GMT 138 return posix_gmtime_r(timer, result);122 return gmtime_r(timer, result); 139 123 } 140 124 … … 147 131 * the result, NULL in case of error. 148 132 */ 149 struct tm * posix_localtime(const time_t *restrict timep)133 struct tm *localtime(const time_t *restrict timep) 150 134 { 151 135 static struct tm result; 152 136 153 return posix_localtime_r(timep, &result);137 return localtime_r(timep, &result); 154 138 } 155 139 … … 163 147 * @return Value of buf. 164 148 */ 165 char * posix_asctime_r(const struct tm *restrict timeptr,149 char *asctime_r(const struct tm *restrict timeptr, 166 150 char *restrict buf) 167 151 { … … 179 163 * the result, NULL in case of error. 180 164 */ 181 char * posix_asctime(const struct tm *restrict timeptr)165 char *asctime(const struct tm *restrict timeptr) 182 166 { 183 167 static char buf[ASCTIME_BUF_LEN]; 184 168 185 return posix_asctime_r(timeptr, buf);169 return asctime_r(timeptr, buf); 186 170 } 187 171 … … 195 179 * @return Pointer to buf on success, NULL on failure. 196 180 */ 197 char * posix_ctime_r(const time_t *timer, char *buf)181 char *ctime_r(const time_t *timer, char *buf) 198 182 { 199 183 if (failed(time_local2str(*timer, buf))) { … … 213 197 * the result, NULL in case of error. 214 198 */ 215 char * posix_ctime(const time_t *timep)199 char *ctime(const time_t *timep) 216 200 { 217 201 static char buf[ASCTIME_BUF_LEN]; 218 202 219 return posix_ctime_r(timep, buf);203 return ctime_r(timep, buf); 220 204 } 221 205 … … 227 211 * @return 0 on success, -1 with errno set on failure. 228 212 */ 229 int posix_clock_getres(posix_clockid_t clock_id, struct posix_timespec *res)213 int clock_getres(clockid_t clock_id, struct timespec *res) 230 214 { 231 215 assert(res != NULL); … … 249 233 * @return 0 on success, -1 with errno on failure. 250 234 */ 251 int posix_clock_gettime(posix_clockid_t clock_id, struct posix_timespec *tp)235 int clock_gettime(clockid_t clock_id, struct timespec *tp) 252 236 { 253 237 assert(tp != NULL); … … 275 259 * @return 0 on success, -1 with errno on failure. 276 260 */ 277 int posix_clock_settime(posix_clockid_t clock_id,278 const struct posix_timespec *tp)261 int clock_settime(clockid_t clock_id, 262 const struct timespec *tp) 279 263 { 280 264 assert(tp != NULL); … … 302 286 * @return 0 on success, -1 with errno set on failure. 303 287 */ 304 int posix_clock_nanosleep(posix_clockid_t clock_id, int flags,305 const struct posix_timespec *rqtp, struct posix_timespec *rmtp)288 int clock_nanosleep(clockid_t clock_id, int flags, 289 const struct timespec *rqtp, struct timespec *rmtp) 306 290 { 307 291 assert(rqtp != NULL); … … 329 313 * @return Consumed CPU cycles by this process or -1 if not available. 330 314 */ 331 posix_clock_t posix_clock(void)332 { 333 posix_clock_t total_cycles = -1;315 clock_t clock(void) 316 { 317 clock_t total_cycles = -1; 334 318 stats_task_t *task_stats = stats_get_task(task_get_id()); 335 319 if (task_stats) { 336 total_cycles = ( posix_clock_t) (task_stats->kcycles +320 total_cycles = (clock_t) (task_stats->kcycles + 337 321 task_stats->ucycles); 338 322 free(task_stats); -
uspace/lib/posix/src/unistd.c
re0f47f5 r7f9df7b9 34 34 */ 35 35 36 #define LIBPOSIX_INTERNAL37 #define __POSIX_DEF__(x) posix_##x38 39 36 #include "internal/common.h" 40 37 #include "posix/unistd.h" … … 70 67 * @return Always 0 on HelenOS. 71 68 */ 72 unsigned int posix_sleep(unsigned int seconds)69 unsigned int sleep(unsigned int seconds) 73 70 { 74 71 return thread_sleep(seconds); … … 80 77 * @return User name (static) string or NULL if not found. 81 78 */ 82 char * posix_getlogin(void)79 char *getlogin(void) 83 80 { 84 81 /* There is currently no support for user accounts in HelenOS. */ … … 93 90 * @return Zero on success, error code otherwise. 94 91 */ 95 int posix_getlogin_r(char *name, size_t namesize)92 int getlogin_r(char *name, size_t namesize) 96 93 { 97 94 /* There is currently no support for user accounts in HelenOS. */ 98 95 if (namesize >= 5) { 99 posix_strcpy(name, (char *) "user");96 strcpy(name, (char *) "user"); 100 97 return 0; 101 98 } else { … … 111 108 * @return Boolean result of the test. 112 109 */ 113 int posix_isatty(int fd)110 int isatty(int fd) 114 111 { 115 112 // TODO … … 126 123 * @return Buffer pointer on success, NULL on failure. 127 124 */ 128 char * posix_getcwd(char *buf, size_t size)125 char *getcwd(char *buf, size_t size) 129 126 { 130 127 if (failed(vfs_cwd_get(buf, size))) … … 138 135 * @param path New working directory. 139 136 */ 140 int posix_chdir(const char *path)137 int chdir(const char *path) 141 138 { 142 139 if (failed(vfs_cwd_set(path))) … … 150 147 * @return Page size of the process. 151 148 */ 152 int posix_getpagesize(void)149 int getpagesize(void) 153 150 { 154 151 return PAGE_SIZE; … … 160 157 * @return Process ID. 161 158 */ 162 p osix_pid_t posix_getpid(void)159 pid_t getpid(void) 163 160 { 164 161 return task_get_id(); … … 170 167 * @return User ID. 171 168 */ 172 posix_uid_t posix_getuid(void)169 uid_t getuid(void) 173 170 { 174 171 /* There is currently no support for user accounts in HelenOS. */ … … 181 178 * @return Group ID. 182 179 */ 183 posix_gid_t posix_getgid(void)180 gid_t getgid(void) 184 181 { 185 182 /* There is currently no support for user accounts in HelenOS. */ … … 193 190 * @return 0 on success, -1 on error. 194 191 */ 195 int posix_close(int fildes)192 int close(int fildes) 196 193 { 197 194 posix_pos[fildes] = 0; … … 210 207 * @return Number of read bytes on success, -1 otherwise. 211 208 */ 212 ssize_t posix_read(int fildes, void *buf, size_t nbyte)209 ssize_t read(int fildes, void *buf, size_t nbyte) 213 210 { 214 211 size_t nread; … … 226 223 * @return Number of written bytes on success, -1 otherwise. 227 224 */ 228 ssize_t posix_write(int fildes, const void *buf, size_t nbyte)225 ssize_t write(int fildes, const void *buf, size_t nbyte) 229 226 { 230 227 size_t nwr; … … 243 240 * as measured in bytes from the beginning of the file, -1 otherwise. 244 241 */ 245 posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)242 off_t lseek(int fildes, off_t offset, int whence) 246 243 { 247 244 vfs_stat_t st; … … 274 271 * @return Zero on success, -1 otherwise. 275 272 */ 276 int posix_fsync(int fildes)273 int fsync(int fildes) 277 274 { 278 275 if (failed(vfs_sync(fildes))) … … 289 286 * @return Zero on success, -1 otherwise. 290 287 */ 291 int posix_ftruncate(int fildes, posix_off_t length)288 int ftruncate(int fildes, off_t length) 292 289 { 293 290 if (failed(vfs_resize(fildes, (aoff64_t) length))) … … 303 300 * @return Zero on success, -1 otherwise. 304 301 */ 305 int posix_rmdir(const char *path)302 int rmdir(const char *path) 306 303 { 307 304 if (failed(vfs_unlink_path(path))) … … 317 314 * @return Zero on success, -1 otherwise. 318 315 */ 319 int posix_unlink(const char *path)316 int unlink(const char *path) 320 317 { 321 318 if (failed(vfs_unlink_path(path))) … … 331 328 * @return On success, new file descriptor for the same file, otherwise -1. 332 329 */ 333 int posix_dup(int fildes)334 { 335 return posix_fcntl(fildes, F_DUPFD, 0);330 int dup(int fildes) 331 { 332 return fcntl(fildes, F_DUPFD, 0); 336 333 } 337 334 … … 344 341 * @return fildes2 on success, -1 otherwise. 345 342 */ 346 int posix_dup2(int fildes, int fildes2)343 int dup2(int fildes, int fildes2) 347 344 { 348 345 int file; … … 360 357 * @return Zero on success, -1 otherwise. 361 358 */ 362 int posix_access(const char *path, int amode)359 int access(const char *path, int amode) 363 360 { 364 361 if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) { … … 368 365 * Check file existence by attempting to open it. 369 366 */ 370 int fd = posix_open(path, O_RDONLY);367 int fd = open(path, O_RDONLY); 371 368 if (fd < 0) 372 369 return -1; 373 posix_close(fd);370 close(fd); 374 371 return 0; 375 372 } else { … … 386 383 * @return Variable value. 387 384 */ 388 long posix_sysconf(int name)385 long sysconf(int name) 389 386 { 390 387 long clk_tck = 0; … … 403 400 stats_physmem_t *mem_stats = stats_get_physmem(); 404 401 if (mem_stats) { 405 phys_pages = (long) (mem_stats->total / posix_getpagesize());406 avphys_pages = (long) (mem_stats->free / posix_getpagesize());402 phys_pages = (long) (mem_stats->total / getpagesize()); 403 avphys_pages = (long) (mem_stats->free / getpagesize()); 407 404 free(mem_stats); 408 405 mem_stats = 0; … … 415 412 return avphys_pages; 416 413 case _SC_PAGESIZE: 417 return posix_getpagesize();414 return getpagesize(); 418 415 case _SC_CLK_TCK: 419 416 return clk_tck; … … 430 427 * @return 431 428 */ 432 long p osix_pathconf(const char *path, int name)429 long pathconf(const char *path, int name) 433 430 { 434 431 // TODO: low priority, just a compile-time dependency of binutils … … 441 438 * @return 442 439 */ 443 p osix_pid_t posix_fork(void)440 pid_t fork(void) 444 441 { 445 442 // TODO: low priority, just a compile-time dependency of binutils … … 454 451 * @return 455 452 */ 456 int posix_execv(const char *path, char *const argv[])453 int execv(const char *path, char *const argv[]) 457 454 { 458 455 // TODO: low priority, just a compile-time dependency of binutils … … 467 464 * @return 468 465 */ 469 int posix_execvp(const char *file, char *const argv[])466 int execvp(const char *file, char *const argv[]) 470 467 { 471 468 // TODO: low priority, just a compile-time dependency of binutils … … 479 476 * @return 480 477 */ 481 int p osix_pipe(int fildes[2])478 int pipe(int fildes[2]) 482 479 { 483 480 // TODO: low priority, just a compile-time dependency of binutils … … 486 483 } 487 484 488 unsigned int posix_alarm(unsigned int seconds)485 unsigned int alarm(unsigned int seconds) 489 486 { 490 487 not_implemented();
Note:
See TracChangeset
for help on using the changeset viewer.