Changeset eccd20e6 in mainline


Ignore:
Timestamp:
2011-07-21T22:34:14Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c6f4681, e478cebf
Parents:
df0956ee (diff), cfbb5d18 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix changes.

Location:
uspace/lib/posix
Files:
47 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/Makefile

    rdf0956ee reccd20e6  
    6363$(INCLUDE_LIBC): ../c/include
    6464        ln -s -f -n $^ $@
    65 
  • uspace/lib/posix/assert.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Program assertion.
    3333 */
    3434
     
    5252/** @}
    5353 */
    54 
  • uspace/lib/posix/ctype.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Character classification.
    3434 */
    3535
     
    4343 * Checks whether character is a hexadecimal digit.
    4444 *
    45  * @param c
    46  * @return
     45 * @param c Character to inspect.
     46 * @return Non-zero if character match the definition, zero otherwise.
    4747 */
    4848int posix_isxdigit(int c)
     
    5656 * Checks whether character is a word separator.
    5757 *
    58  * @param c
    59  * @return
     58 * @param c Character to inspect.
     59 * @return Non-zero if character match the definition, zero otherwise.
    6060 */
    6161int posix_isblank(int c)
     
    6767 * Checks whether character is a control character.
    6868 *
    69  * @param c
    70  * @return
     69 * @param c Character to inspect.
     70 * @return Non-zero if character match the definition, zero otherwise.
    7171 */
    7272int posix_iscntrl(int c)
     
    7878 * Checks whether character is any printing character except space.
    7979 *
    80  * @param c
    81  * @return
     80 * @param c Character to inspect.
     81 * @return Non-zero if character match the definition, zero otherwise.
    8282 */
    8383int posix_isgraph(int c)
     
    8989 * Checks whether character is a printing character.
    9090 *
    91  * @param c
    92  * @return
     91 * @param c Character to inspect.
     92 * @return Non-zero if character match the definition, zero otherwise.
    9393 */
    9494int posix_isprint(int c)
     
    100100 * Checks whether character is a punctuation.
    101101 *
    102  * @param c
    103  * @return
     102 * @param c Character to inspect.
     103 * @return Non-zero if character match the definition, zero otherwise.
    104104 */
    105105int posix_ispunct(int c)
    106106{
    107         return !isspace(c) && !isalnum(c);
     107        return !isspace(c) && !isalnum(c) && posix_isprint(c);
    108108}
    109109
     
    111111 * Checks whether character is ASCII. (obsolete)
    112112 *
    113  * @param c
    114  * @return
     113 * @param c Character to inspect.
     114 * @return Non-zero if character match the definition, zero otherwise.
    115115 */
    116116extern int posix_isascii(int c)
     
    122122 * Converts argument to a 7-bit ASCII character. (obsolete)
    123123 *
    124  * @param c
    125  * @return
     124 * @param c Character to convert.
     125 * @return Coverted character.
    126126 */
    127127extern int posix_toascii(int c)
  • uspace/lib/posix/ctype.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Character classification.
    3434 */
    3535
  • uspace/lib/posix/errno.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file System error numbers.
    3333 */
    3434
     
    5151/** @}
    5252 */
    53 
  • uspace/lib/posix/errno.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file System error numbers.
    3333 */
    3434
     
    325325/** @}
    326326 */
    327 
  • uspace/lib/posix/fcntl.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file File control.
    3333 */
    3434
  • uspace/lib/posix/fcntl.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file File control.
    3333 */
    3434
  • uspace/lib/posix/float.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Floating type support.
    3333 */
    3434
  • uspace/lib/posix/fnmatch.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Filename-matching.
    3333 */
    3434
     
    4545#include "internal/common.h"
    4646#include "fnmatch.h"
     47
     48// TODO: documentation
    4749
    4850#define INVALID_PATTERN -1
     
    169171};
    170172
     173/**
     174 *
     175 * @param key
     176 * @param elem
     177 * @return
     178 */
    171179static int _class_compare(const void *key, const void *elem)
    172180{
     
    175183}
    176184
     185/**
     186 *
     187 * @param cname
     188 * @param c
     189 * @return
     190 */
    177191static bool _is_in_class (const char *cname, int c)
    178192{
     
    191205}
    192206
     207/**
     208 *
     209 * @param pattern
     210 * @param str
     211 * @param flags
     212 * @return
     213 */
    193214static int _match_char_class(const char **pattern, const char *str, int flags)
    194215{
     
    204225/************** END CHARACTER CLASSES ****************/
    205226
     227/**
     228 *
     229 * @param pattern
     230 * @param flags
     231 * @return
     232 */
    206233static _coll_elm_t _next_coll_elm(const char **pattern, int flags)
    207234{
     
    240267
    241268/**
    242  *
     269 *
     270 * @param pattern
     271 * @param str
     272 * @param flags
     273 * @return
    243274 */
    244275static int _match_bracket_expr(const char **pattern, const char *str, int flags)
     
    327358
    328359/**
    329  *
     360 *
     361 * @param pattern
     362 * @param string
     363 * @param flags
     364 * @return
    330365 */
    331366static bool _partial_match(const char **pattern, const char **string, int flags)
     
    421456}
    422457
     458/**
     459 *
     460 * @param pattern
     461 * @param string
     462 * @param flags
     463 * @return
     464 */
    423465static bool _full_match(const char *pattern, const char *string, int flags)
    424466{
     
    476518}
    477519
     520/**
     521 *
     522 * @param s
     523 * @return
     524 */
    478525static char *_casefold(const char *s)
    479526{
     
    506553
    507554        if ((flags & FNM_CASEFOLD) != 0) {
    508                 free((char *) pattern);
    509                 free((char *) string);
     555                if (pattern) {
     556                        free((char *) pattern);
     557                }
     558                if (string) {
     559                        free((char *) string);
     560                }
    510561        }
    511562
     
    604655/** @}
    605656 */
    606 
  • uspace/lib/posix/fnmatch.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Filename-matching.
    3333 */
    3434
     
    3636#define POSIX_FNMATCH_H_
    3737
    38 /* Error Values. */
     38/* Error Values */
    3939#undef FNM_NOMATCH
    4040#define FNM_NOMATCH 1
     
    6666/** @}
    6767 */
    68 
  • uspace/lib/posix/internal/common.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Helper definitions common for all libposix files.
    3333 */
    3434
  • uspace/lib/posix/inttypes.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Fixed size integer types.
    3333 */
    3434
     
    3939#include "libc/inttypes.h"
    4040
     41extern posix_intmax_t posix_strtoimax(const char *restrict nptr,
     42    char **restrict endptr, int base);
     43extern posix_uintmax_t posix_strtoumax(const char *restrict nptr,
     44    char **restrict endptr, int base);
     45
     46#ifndef LIBPOSIX_INTERNAL
     47        #define strtoimax posix_strtoimax
     48        #define strtoumax posix_strtoumax
     49#endif
     50
    4151#endif /* POSIX_INTTYPES_H_ */
    4252
  • uspace/lib/posix/iso646.h

    rdf0956ee reccd20e6  
     1/*
     2 * Copyright (c) 2011 Jiri Zarevucky
     3 * All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 *
     9 * - Redistributions of source code must retain the above copyright
     10 *   notice, this list of conditions and the following disclaimer.
     11 * - Redistributions in binary form must reproduce the above copyright
     12 *   notice, this list of conditions and the following disclaimer in the
     13 *   documentation and/or other materials provided with the distribution.
     14 * - The name of the author may not be used to endorse or promote products
     15 *   derived from this software without specific prior written permission.
     16 *
     17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 */
    128
    229/** @addtogroup libposix
    330 * @{
    431 */
    5 /** @file
     32/** @file Alternative spellings.
    633 */
    734
     
    2552/** @}
    2653 */
    27 
  • uspace/lib/posix/limits.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Implementation-defined limit constants.
    3333 */
    3434
  • uspace/lib/posix/locale.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Locale-specific definitions.
    3333 */
    3434
     
    4141#include "limits.h"
    4242#include "string.h"
     43
     44// TODO: documentation
    4345
    4446struct __posix_locale {
     
    7375};
    7476
     77/**
     78 *
     79 * @param category
     80 * @param locale
     81 * @return
     82 */
    7583char *posix_setlocale(int category, const char *locale)
    7684{
     
    8391}
    8492
     93/**
     94 *
     95 * @return
     96 */
    8597struct posix_lconv *posix_localeconv(void)
    8698{
     
    89101}
    90102
     103/**
     104 *
     105 * @param locobj
     106 * @return
     107 */
    91108posix_locale_t posix_duplocale(posix_locale_t locobj)
    92109{
     
    104121}
    105122
     123/**
     124 *
     125 * @param locobj
     126 */
    106127void posix_freelocale(posix_locale_t locobj)
    107128{
    108         free(locobj);
     129        if (locobj) {
     130                free(locobj);
     131        }
    109132}
    110133
     134/**
     135 *
     136 * @param category_mask
     137 * @param locale
     138 * @param base
     139 * @return
     140 */
    111141posix_locale_t posix_newlocale(int category_mask, const char *locale,
    112142    posix_locale_t base)
     
    129159}
    130160
    131 posix_locale_t posix_uselocale (posix_locale_t newloc)
     161/**
     162 *
     163 * @param newloc
     164 * @return
     165 */
     166posix_locale_t posix_uselocale(posix_locale_t newloc)
    132167{
    133168        // TODO
  • uspace/lib/posix/locale.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Locale-specific definitions.
    3333 */
    3434
    3535#ifndef POSIX_LOCALE_H_
    3636#define POSIX_LOCALE_H_
     37
     38// TODO: documentation
    3739
    3840#ifndef NULL
     
    8385
    8486struct posix_lconv {
    85         char    *currency_symbol;
    86         char    *decimal_point;
    87         char     frac_digits;
    88         char    *grouping;
    89         char    *int_curr_symbol;
    90         char     int_frac_digits;
    91         char     int_n_cs_precedes;
    92         char     int_n_sep_by_space;
    93         char     int_n_sign_posn;
    94         char     int_p_cs_precedes;
    95         char     int_p_sep_by_space;
    96         char     int_p_sign_posn;
    97         char    *mon_decimal_point;
    98         char    *mon_grouping;
    99         char    *mon_thousands_sep;
    100         char    *negative_sign;
    101         char     n_cs_precedes;
    102         char     n_sep_by_space;
    103         char     n_sign_posn;
    104         char    *positive_sign;
    105         char     p_cs_precedes;
    106         char     p_sep_by_space;
    107         char     p_sign_posn;
    108         char    *thousands_sep;
     87        char *currency_symbol;
     88        char *decimal_point;
     89        char  frac_digits;
     90        char *grouping;
     91        char *int_curr_symbol;
     92        char  int_frac_digits;
     93        char  int_n_cs_precedes;
     94        char  int_n_sep_by_space;
     95        char  int_n_sign_posn;
     96        char  int_p_cs_precedes;
     97        char  int_p_sep_by_space;
     98        char  int_p_sign_posn;
     99        char *mon_decimal_point;
     100        char *mon_grouping;
     101        char *mon_thousands_sep;
     102        char *negative_sign;
     103        char  n_cs_precedes;
     104        char  n_sep_by_space;
     105        char  n_sign_posn;
     106        char *positive_sign;
     107        char  p_cs_precedes;
     108        char  p_sep_by_space;
     109        char  p_sign_posn;
     110        char *thousands_sep;
    109111};
    110112
     
    117119extern posix_locale_t posix_newlocale(int category_mask, const char *locale,
    118120    posix_locale_t base);
    119 extern posix_locale_t posix_uselocale (posix_locale_t newloc);
     121extern posix_locale_t posix_uselocale(posix_locale_t newloc);
    120122
    121123#ifndef LIBPOSIX_INTERNAL
     
    131133#endif
    132134
    133 
    134135#endif /* POSIX_LOCALE_H_ */
    135136
  • uspace/lib/posix/math.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Mathematical operations.
    3333 */
    3434
  • uspace/lib/posix/math.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Mathematical operations.
    3333 */
    3434
  • uspace/lib/posix/pwd.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Password handling.
    3333 */
    3434
    3535#define LIBPOSIX_INTERNAL
     36
    3637#include "pwd.h"
    3738#include "string.h"
    3839#include "errno.h"
    3940
     41// TODO: documentation
    4042
    4143static bool entry_read = false;
     
    5355 * Since HelenOS doesn't have user accounts, this always returns
    5456 * the same made-up entry.
     57 *
     58 * @return
    5559 */
    5660struct posix_passwd *posix_getpwent(void)
     
    178182/** @}
    179183 */
    180 
  • uspace/lib/posix/pwd.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Password handling.
    3333 */
    3434
    3535#ifndef POSIX_PWD_H_
    3636#define POSIX_PWD_H_
     37
     38// TODO: documentation
    3739
    3840#include "sys/types.h"
     
    7678/** @}
    7779 */
    78 
  • uspace/lib/posix/signal.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Signal handling.
    3333 */
    3434
     
    4545#include "libc/task.h"
    4646
     47// TODO: documentation
     48
    4749/* Used to serialize signal handling. */
    4850static FIBRIL_MUTEX_INITIALIZE(_signal_mutex);
     
    6365};
    6466
     67/**
     68 *
     69 * @param signo
     70 */
    6571void __posix_default_signal_handler(int signo)
    6672{
     
    118124}
    119125
     126/**
     127 *
     128 * @param signo
     129 */
    120130void __posix_hold_signal_handler(int signo)
    121131{
     
    123133}
    124134
     135/**
     136 *
     137 * @param signo
     138 */
    125139void __posix_ignore_signal_handler(int signo)
    126140{
     
    128142}
    129143
    130 
     144/**
     145 *
     146 * @param set
     147 * @return
     148 */
    131149int posix_sigemptyset(posix_sigset_t *set)
    132150{
     
    137155}
    138156
     157/**
     158 *
     159 * @param set
     160 * @return
     161 */
    139162int posix_sigfillset(posix_sigset_t *set)
    140163{
     
    145168}
    146169
     170/**
     171 *
     172 * @param set
     173 * @param signo
     174 * @return
     175 */
    147176int posix_sigaddset(posix_sigset_t *set, int signo)
    148177{
     
    153182}
    154183
     184/**
     185 *
     186 * @param set
     187 * @param signo
     188 * @return
     189 */
    155190int posix_sigdelset(posix_sigset_t *set, int signo)
    156191{
     
    161196}
    162197
     198/**
     199 *
     200 * @param set
     201 * @param signo
     202 * @return
     203 */
    163204int posix_sigismember(const posix_sigset_t *set, int signo)
    164205{
     
    168209}
    169210
     211/**
     212 *
     213 * @param sig
     214 * @param act
     215 * @param oact
     216 */
    170217static void _sigaction_unsafe(int sig, const struct posix_sigaction *restrict act,
    171218    struct posix_sigaction *restrict oact)
     
    182229}
    183230
     231/**
     232 *
     233 * @param sig
     234 * @param act
     235 * @param oact
     236 * @return
     237 */
    184238int posix_sigaction(int sig, const struct posix_sigaction *restrict act,
    185239    struct posix_sigaction *restrict oact)
     
    206260}
    207261
     262/**
     263 *
     264 * @param sig
     265 * @param func
     266 * @return
     267 */
    208268void (*posix_signal(int sig, void (*func)(int)))(int)
    209269{
     
    222282}
    223283
     284/**
     285 *
     286 * @param signo
     287 * @param siginfo
     288 * @return
     289 */
    224290static int _raise_sigaction(int signo, posix_siginfo_t *siginfo)
    225291{
     
    259325}
    260326
     327/**
     328 *
     329 * @param sig
     330 * @return
     331 */
    261332int posix_raise(int sig)
    262333{
     
    273344}
    274345
     346/**
     347 *
     348 * @param pid
     349 * @param signo
     350 * @return
     351 */
    275352int posix_kill(posix_pid_t pid, int signo)
    276353{
     
    303380}
    304381
     382/**
     383 *
     384 * @param pid
     385 * @param sig
     386 * @return
     387 */
    305388int posix_killpg(posix_pid_t pid, int sig)
    306389{
     
    309392}
    310393
     394/**
     395 *
     396 * @param pinfo
     397 * @param message
     398 */
    311399void posix_psiginfo(const posix_siginfo_t *pinfo, const char *message)
    312400{
     
    316404}
    317405
     406/**
     407 *
     408 * @param signum
     409 * @param message
     410 */
    318411void posix_psignal(int signum, const char *message)
    319412{
     
    326419}
    327420
     421/**
     422 *
     423 * @param how
     424 * @param set
     425 * @param oset
     426 * @return
     427 */
    328428int posix_thread_sigmask(int how, const posix_sigset_t *restrict set,
    329429    posix_sigset_t *restrict oset)
     
    358458}
    359459
     460/**
     461 *
     462 * @param how
     463 * @param set
     464 * @param oset
     465 * @return
     466 */
    360467int posix_sigprocmask(int how, const posix_sigset_t *restrict set,
    361468    posix_sigset_t *restrict oset)
     
    371478/** @}
    372479 */
    373 
  • uspace/lib/posix/signal.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Signal handling.
    3333 */
    3434
    3535#ifndef POSIX_SIGNAL_H_
    3636#define POSIX_SIGNAL_H_
     37
     38// TODO: documentation
    3739
    3840#include "libc/errno.h"
     
    107109        posix_mcontext_t uc_mcontext;
    108110} posix_ucontext_t;
    109 
    110111
    111112/* Values of posix_sigevent::sigev_notify */
     
    154155#define SIGSTKSZ 0
    155156
    156 /* full POSIX set */
     157/* Full POSIX set */
    157158enum {
    158159        /* Termination Signals */
     
    214215
    215216/* Values for sigaction field si_code. */
    216 
    217217enum {
    218218        SI_USER,
     
    287287                #define sigevent posix_sigevent
    288288        #endif
    289         #define sigaction posix_sigaction
    290289        #define mcontext_t posix_mcontext_t
    291290        #define ucontext_t posix_ucontext_t
    292291        #define stack_t posix_stack_t
    293292        #define siginfo_t posix_siginfo_t
     293
     294        #define sigaction posix_sigaction
    294295
    295296        #define signal posix_signal
  • uspace/lib/posix/stdbool.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Boolean type and values.
    3333 */
    3434
     
    5050
    5151#endif /* POSIX_STDBOOL_H_ */
    52 
  • uspace/lib/posix/stddef.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Standard type definitions.
    3333 */
    3434
  • uspace/lib/posix/stdint.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Integer types.
    3333 */
    3434
     
    8888#define AOFF64_MIN  UINT64_MIN
    8989
     90#undef INTMAX_MIN
     91#undef INTMAX_MAX
     92#define INTMAX_MIN INT64_MIN
     93#define INTMAX_MAX INT64_MAX
     94
     95#undef UINTMAX_MIN
     96#undef UINTMAX_MAX
     97#define UINTMAX_MIN UINT64_MIN
     98#define UINTMAX_MAX UINT64_MAX
     99
    90100#include "libc/sys/types.h"
    91101
  • uspace/lib/posix/stdio.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Standard buffered input/output.
    3434 */
    3535
     
    355355{
    356356        off64_t ret = ftell(stream);
    357         if (ret == -1) {
    358                 return errno;
    359         }
    360         pos->offset = ret;
    361         return 0;
     357        if (ret != -1) {
     358                pos->offset = ret;
     359                return 0;
     360        } else {
     361                return -1;
     362        }
    362363}
    363364
  • uspace/lib/posix/stdio.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Standard buffered input/output.
    3434 */
    3535
  • uspace/lib/posix/stdio/scanf.c

    rdf0956ee reccd20e6  
    303303        self->fetched = 0;
    304304        self->cursor = NULL;
    305         free(self->window);
    306         self->window = NULL;
     305        if (self->window) {
     306                free(self->window);
     307                self->window = NULL;
     308        }
    307309        self->window_size = 0;
    308310        self->state = _PROV_CONSTRUCTED;
     
    653655                                /* Update the cursor so it can be returned to the provider. */
    654656                                cur_borrowed += cur_updated - cur_limited;
    655                                 if (width != -1) {
     657                                if (width != -1 && cur_limited != NULL) {
    656658                                        /* Deallocate duplicated part of the cursor view. */
    657659                                        free(cur_limited);
     
    833835                                /* Update the cursor so it can be returned to the provider. */
    834836                                cur_borrowed += cur_updated - cur_limited;
    835                                 if (width != -1) {
     837                                if (width != -1 && cur_limited != NULL) {
    836838                                        /* Deallocate duplicated part of the cursor view. */
    837839                                        free(cur_limited);
  • uspace/lib/posix/stdlib.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Standard library definitions.
    3434 */
    3535
     
    4040
    4141#include "errno.h"
     42#include "limits.h"
    4243
    4344#include "libc/sort.h"
     
    5960
    6061/**
     62 * Integer absolute value.
    6163 *
    6264 * @param i Input value.
     
    6971
    7072/**
     73 * Long integer absolute value.
    7174 *
    7275 * @param i Input value.
     
    7982
    8083/**
     84 * Long long integer absolute value.
    8185 *
    8286 * @param i Input value.
     
    8892}
    8993
     94/**
     95 * Compute the quotient and remainder of an integer division.
     96 *
     97 * @param numer Numerator.
     98 * @param denom Denominator.
     99 * @return Quotient and remainder packed into structure.
     100 */
    90101posix_div_t posix_div(int numer, int denom)
    91102{
     
    93104}
    94105
     106/**
     107 * Compute the quotient and remainder of a long integer division.
     108 *
     109 * @param numer Numerator.
     110 * @param denom Denominator.
     111 * @return Quotient and remainder packed into structure.
     112 */
    95113posix_ldiv_t posix_ldiv(long numer, long denom)
    96114{
     
    98116}
    99117
     118/**
     119 * Compute the quotient and remainder of a long long integer division.
     120 *
     121 * @param numer Numerator.
     122 * @param denom Denominator.
     123 * @return Quotient and remainder packed into structure.
     124 */
    100125posix_lldiv_t posix_lldiv(long long numer, long long denom)
    101126{
     
    109134 * @param elem2 Second element to compare.
    110135 * @param compare Comparison function without userdata parameter.
    111  *
    112136 * @return Relative ordering of the elements.
    113137 */
     
    115139{
    116140        int (*compare)(const void *, const void *) = userdata;
    117         return compare(elem1, elem2);
     141        int ret = compare(elem1, elem2);
     142       
     143        /* Native qsort internals expect this. */
     144        if (ret < 0) {
     145                return -1;
     146        } else if (ret > 0) {
     147                return 1;
     148        } else {
     149                return 0;
     150        }
    118151}
    119152
     
    121154 * Array sorting utilizing the quicksort algorithm.
    122155 *
    123  * @param array
    124  * @param count
    125  * @param size
    126  * @param compare
     156 * @param array Array of elements to sort.
     157 * @param count Number of elements in the array.
     158 * @param size Width of each element.
     159 * @param compare Decides relative ordering of two elements.
    127160 */
    128161void posix_qsort(void *array, size_t count, size_t size,
     
    171204/**
    172205 * Retrieve a value of the given environment variable.
     206 *
    173207 * Since HelenOS doesn't support env variables at the moment,
    174208 * this function always returns NULL.
    175209 *
    176  * @param name
    177  * @return Always NULL.
     210 * @param name Name of the variable.
     211 * @return Value of the variable or NULL if such variable does not exist.
    178212 */
    179213char *posix_getenv(const char *name)
     
    195229
    196230/**
    197  *
    198  * @param string String to be passed to a command interpreter.
    199  * @return
     231 * Issue a command.
     232 *
     233 * @param string String to be passed to a command interpreter or NULL.
     234 * @return Termination status of the command if the command is not NULL,
     235 *     otherwise indicate whether there is a command interpreter (non-zero)
     236 *     or not (zero).
    200237 */
    201238int posix_system(const char *string) {
     
    205242
    206243/**
    207  *
    208  * @param name
    209  * @param resolved
    210  * @return
    211  */
    212 char *posix_realpath(const char *name, char *resolved)
     244 * Resolve absolute pathname.
     245 *
     246 * @param name Pathname to be resolved.
     247 * @param resolved Either buffer for the resolved absolute pathname or NULL.
     248 * @return On success, either resolved (if it was not NULL) or pointer to the
     249 *     newly allocated buffer containing the absolute pathname (if resolved was
     250 *     NULL). Otherwise NULL.
     251 *
     252 */
     253char *posix_realpath(const char *restrict name, char *restrict resolved)
    213254{
    214255        #ifndef PATH_MAX
     
    254295 * its native representation. See posix_strtold().
    255296 *
    256  * @param nptr
    257  * @return
     297 * @param nptr String representation of a floating-point number.
     298 * @return Double-precision number resulting from the string conversion.
    258299 */
    259300double posix_atof(const char *nptr)
     
    266307 * its native representation. See posix_strtold().
    267308 *
    268  * @param nptr
    269  * @param endptr
    270  * @return
     309 * @param nptr String representation of a floating-point number.
     310 * @param endptr Pointer to the final part of the string which
     311 *     was not used for conversion.
     312 * @return Single-precision number resulting from the string conversion.
    271313 */
    272314float posix_strtof(const char *restrict nptr, char **restrict endptr)
     
    279321 * its native representation. See posix_strtold().
    280322 *
    281  * @param nptr
    282  * @param endptr
    283  * @return
     323 * @param nptr String representation of a floating-point number.
     324 * @param endptr Pointer to the final part of the string which
     325 *     was not used for conversion.
     326 * @return Double-precision number resulting from the string conversion.
    284327 */
    285328double posix_strtod(const char *restrict nptr, char **restrict endptr)
     
    289332
    290333/**
    291  *
    292  * @param size
    293  * @return
     334 * Allocate memory chunk.
     335 *
     336 * @param size Size of the chunk to allocate.
     337 * @return Either pointer to the allocated chunk or NULL if not possible.
    294338 */
    295339void *posix_malloc(size_t size)
     
    299343
    300344/**
    301  *
    302  * @param nelem
    303  * @param elsize
    304  * @return
     345 * Allocate memory for an array of elements.
     346 *
     347 * @param nelem Number of elements in the array.
     348 * @param elsize Size of each element.
     349 * @return Either pointer to the allocated array or NULL if not possible.
    305350 */
    306351void *posix_calloc(size_t nelem, size_t elsize)
     
    310355
    311356/**
    312  *
    313  * @param ptr
    314  * @param size
    315  * @return
     357 * Reallocate memory chunk to a new size.
     358 *
     359 * @param ptr Memory chunk to reallocate. Might be NULL.
     360 * @param size Size of the reallocated chunk. Might be zero.
     361 * @return Either NULL or the pointer to the newly reallocated chunk.
    316362 */
    317363void *posix_realloc(void *ptr, size_t size)
    318364{
    319         return realloc(ptr, size);
    320 }
    321 
    322 /**
    323  *
    324  * @param ptr
     365        if (ptr != NULL && size == 0) {
     366                /* Native realloc does not handle this special case. */
     367                free(ptr);
     368                return NULL;
     369        } else {
     370                return realloc(ptr, size);
     371        }
     372}
     373
     374/**
     375 * Free allocated memory chunk.
     376 *
     377 * @param ptr Memory chunk to be freed.
    325378 */
    326379void posix_free(void *ptr)
     
    343396
    344397/**
    345  * Should read system load statistics. Not supported. Always returns -1.
    346  *
    347  * @param loadavg
    348  * @param nelem
    349  * @return
     398 * Get system load average statistics.
     399 *
     400 * Not supported. Always returns -1.
     401 *
     402 * @param loadavg Array where the load averages shall be placed.
     403 * @param nelem Maximum number of elements to be placed into the array.
     404 * @return Number of elements placed into the array on success, -1 otherwise.
    350405 */
    351406int bsd_getloadavg(double loadavg[], int nelem)
  • uspace/lib/posix/stdlib.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Standard library definitions.
    3434 */
    3535
     
    5656extern long long posix_llabs(long long i);
    5757
    58 /* Integer division */
     58/* Integer Division */
    5959
    6060typedef struct {
     
    8080    size_t nmemb, size_t size, int (*compar)(const void *, const void *));
    8181
    82 
    8382/* Environment Access */
    8483extern char *posix_getenv(const char *name);
    8584extern int posix_putenv(char *string);
    86 
    8785extern int posix_system(const char *string);
    88 
    8986
    9087/* Symbolic Links */
     
    10198extern long int posix_atol(const char *nptr);
    10299extern long long int posix_atoll(const char *nptr);
    103 
    104100extern long int posix_strtol(const char *restrict nptr,
    105101    char **restrict endptr, int base);
     
    110106extern unsigned long long int posix_strtoull(
    111107    const char *restrict nptr, char **restrict endptr, int base);
    112 
    113108
    114109/* Memory Allocation */
  • uspace/lib/posix/stdlib/strtol.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Backend for integer conversions.
    3333 */
    3434
     
    3838#include "../stdlib.h"
    3939
    40 #include "../limits.h"
    4140#include "../ctype.h"
    4241#include "../errno.h"
    43 
    44 // TODO: documentation
    45 
     42#include "../inttypes.h"
     43#include "../limits.h"
     44
     45#define intmax_t posix_intmax_t
     46#define uintmax_t posix_uintmax_t
     47
     48/**
     49 * Decides whether a digit belongs to a particular base.
     50 *
     51 * @param c Character representation of the digit.
     52 * @param base Base against which the digit shall be tested.
     53 * @return True if the digit belongs to the base, false otherwise.
     54 */
    4655static inline bool is_digit_in_base(int c, int base)
    4756{
     
    5463}
    5564
    56 static inline int get_digit_in_base(int c, int base)
     65/**
     66 * Derive a digit from its character representation.
     67 *
     68 * @param c Character representation of the digit.
     69 * @return Digit value represented by an integer.
     70 */
     71static inline int digit_value(int c)
    5772{
    5873        if (c <= '9') {
     
    6378}
    6479
    65 static inline unsigned long long internal_strtol(
     80/**
     81 * Generic function for parsing an integer from it's string representation.
     82 * Different variants differ in lower and upper bounds.
     83 * The parsed string returned by this function is always positive, sign
     84 * information is provided via a dedicated parameter.
     85 *
     86 * @param nptr Input string.
     87 * @param endptr If non-NULL, *endptr is set to the position of the first
     88 *     unrecognized character. If no digit has been parsed, value of
     89 *     nptr is stored there (regardless of any skipped characters at the
     90 *     beginning).
     91 * @param base Expected base of the string representation. If 0, base is
     92 *    determined to be decimal, octal or hexadecimal using the same rules
     93 *    as C syntax. Otherwise, value must be between 2 and 36, inclusive.
     94 * @param min_value Lower bound for the resulting conversion.
     95 * @param max_value Upper bound for the resulting conversion.
     96 * @param out_negative Either NULL for unsigned conversion or a pointer to the
     97 *     bool variable into which shall be placed the negativity of the resulting
     98 *     converted value.
     99 * @return The absolute value of the parsed value, or the closest in-range value
     100 *     if the parsed value is out of range. If the input is invalid, zero is
     101 *     returned and errno is set to EINVAL.
     102 */
     103static inline uintmax_t internal_strtol(
    66104    const char *restrict nptr, char **restrict endptr, int base,
    67     const long long min_value, const unsigned long long max_value,
     105    const intmax_t min_value, const uintmax_t max_value,
    68106    bool *restrict out_negative)
    69107{
     
    78116        }
    79117       
    80         unsigned long long real_max_value = max_value;
     118        /* The maximal absolute value that can be returned in this run.
     119         * Depends on sign.
     120         */
     121        uintmax_t real_max_value = max_value;
    81122       
    82123        /* Current index in the input string. */
    83         int i = 0;
     124        size_t i = 0;
    84125        bool negative = false;
    85126       
     
    93134        case '-':
    94135                negative = true;
    95                 real_max_value = -min_value;
     136               
     137                /* The strange computation is are there to avoid a corner case
     138                 * where -min_value can't be represented in intmax_t.
     139                 * (I'm not exactly sure what the semantics are in such a
     140                 *  case, but this should be safe for any case.)
     141                 */
     142                real_max_value = (min_value == 0)
     143                    ? 0
     144                    :(((uintmax_t) -(min_value + 1)) + 1);
     145               
    96146                /* fallthrough */
    97147        case '+':
     
    104154                if (nptr[i] == '0') {
    105155                        if (tolower(nptr[i + 1]) == 'x') {
     156                                /* 0x... is hex. */
    106157                                base = 16;
    107158                                i += 2;
    108159                        } else {
     160                                /* 0... is octal. */
    109161                                base = 8;
    110162                        }
    111163                } else {
     164                        /* Anything else is decimal by default. */
    112165                        base = 10;
    113166                }
    114167                break;
    115168        case 16:
     169                /* Allow hex number to be prefixed with "0x". */
    116170                if (nptr[i] == '0' && tolower(nptr[i + 1]) == 'x') {
    117171                        i += 2;
     
    133187         * of overflow.
    134188         */
    135         unsigned long long max_safe_value = (real_max_value - base + 1) / base;
    136        
    137         unsigned long long result = 0;
     189        uintmax_t max_safe_value = (real_max_value - base + 1) / base;
     190       
     191        uintmax_t result = 0;
    138192       
    139193        if (real_max_value == 0) {
     
    145199                        if (nptr[i] != '0') {
    146200                                errno = ERANGE;
    147                                 result = max_value;
     201                                result = 0;
    148202                        }
    149203                        i++;
     
    152206       
    153207        while (is_digit_in_base(nptr[i], base)) {
    154                 int digit = get_digit_in_base(nptr[i], base);
     208                int digit = digit_value(nptr[i]);
    155209               
    156210                if (result > max_safe_value) {
    157211                        /* corner case, check for overflow */
    158212                       
    159                         unsigned long long
    160                             boundary = (real_max_value - digit) / base;
     213                        uintmax_t boundary = (real_max_value - digit) / base;
    161214                       
    162215                        if (result > boundary) {
    163216                                /* overflow */
    164217                                errno = ERANGE;
    165                                 result = max_value;
     218                                result = real_max_value;
    166219                                break;
    167220                        }
     
    188241}
    189242
     243/**
     244 * Convert a string to an integer.
     245 *
     246 * @param nptr Input string.
     247 * @return Result of the conversion.
     248 */
    190249int posix_atoi(const char *nptr)
    191250{
    192251        bool neg = false;
    193         unsigned long long result =
     252        uintmax_t result =
    194253            internal_strtol(nptr, NULL, 10, INT_MIN, INT_MAX, &neg);
    195254
    196         return (int) (neg ? -result : result);
    197 }
    198 
     255        return (neg ? ((int) -result) : (int) result);
     256}
     257
     258/**
     259 * Convert a string to a long integer.
     260 *
     261 * @param nptr Input string.
     262 * @return Result of the conversion.
     263 */
    199264long posix_atol(const char *nptr)
    200265{
    201266        bool neg = false;
    202         unsigned long long result =
     267        uintmax_t result =
    203268            internal_strtol(nptr, NULL, 10, LONG_MIN, LONG_MAX, &neg);
    204269
    205         return (long) (neg ? -result : result);
    206 }
    207 
     270        return (neg ? ((long) -result) : (long) result);
     271}
     272
     273/**
     274 * Convert a string to a long long integer.
     275 *
     276 * @param nptr Input string.
     277 * @return Result of the conversion.
     278 */
    208279long long posix_atoll(const char *nptr)
    209280{
    210281        bool neg = false;
    211         unsigned long long result =
     282        uintmax_t result =
    212283            internal_strtol(nptr, NULL, 10, LLONG_MIN, LLONG_MAX, &neg);
    213284
    214         return (long long) (neg ? -result : result);
    215 }
    216 
     285        return (neg ? ((long long) -result) : (long long) result);
     286}
     287
     288/**
     289 * Convert a string to a long integer.
     290 *
     291 * @param nptr Input string.
     292 * @param endptr Pointer to the final part of the string which
     293 *     was not used for conversion.
     294 * @param base Expected base of the string representation.
     295 * @return Result of the conversion.
     296 */
    217297long posix_strtol(const char *restrict nptr, char **restrict endptr, int base)
    218298{
    219299        bool neg = false;
    220         unsigned long long result =
     300        uintmax_t result =
    221301            internal_strtol(nptr, endptr, base, LONG_MIN, LONG_MAX, &neg);
    222302
    223         return (long) (neg ? -result : result);
    224 }
    225 
     303        return (neg ? ((long) -result) : ((long) result));
     304}
     305
     306/**
     307 * Convert a string to a long long integer.
     308 *
     309 * @param nptr Input string.
     310 * @param endptr Pointer to the final part of the string which
     311 *     was not used for conversion.
     312 * @param base Expected base of the string representation.
     313 * @return Result of the conversion.
     314 */
    226315long long posix_strtoll(
    227316    const char *restrict nptr, char **restrict endptr, int base)
    228317{
    229318        bool neg = false;
    230         unsigned long long result =
     319        uintmax_t result =
    231320            internal_strtol(nptr, endptr, base, LLONG_MIN, LLONG_MAX, &neg);
    232321
    233         return (long long) (neg ? -result : result);
    234 }
    235 
     322        return (neg ? ((long long) -result) : (long long) result);
     323}
     324
     325/**
     326 * Convert a string to a largest signed integer type.
     327 *
     328 * @param nptr Input string.
     329 * @param endptr Pointer to the final part of the string which
     330 *     was not used for conversion.
     331 * @param base Expected base of the string representation.
     332 * @return Result of the conversion.
     333 */
     334intmax_t posix_strtoimax(
     335    const char *restrict nptr, char **restrict endptr, int base)
     336{
     337        bool neg = false;
     338        uintmax_t result =
     339            internal_strtol(nptr, endptr, base, INTMAX_MIN, INTMAX_MAX, &neg);
     340
     341        return (neg ? ((intmax_t) -result) : (intmax_t) result);
     342}
     343
     344/**
     345 * Convert a string to an unsigned long integer.
     346 *
     347 * @param nptr Input string.
     348 * @param endptr Pointer to the final part of the string which
     349 *     was not used for conversion.
     350 * @param base Expected base of the string representation.
     351 * @return Result of the conversion.
     352 */
    236353unsigned long posix_strtoul(
    237354    const char *restrict nptr, char **restrict endptr, int base)
    238355{
    239         unsigned long long result =
     356        uintmax_t result =
    240357            internal_strtol(nptr, endptr, base, 0, ULONG_MAX, NULL);
    241358
     
    243360}
    244361
     362/**
     363 * Convert a string to an unsigned long long integer.
     364 *
     365 * @param nptr Input string.
     366 * @param endptr Pointer to the final part of the string which
     367 *     was not used for conversion.
     368 * @param base Expected base of the string representation.
     369 * @return Result of the conversion.
     370 */
    245371unsigned long long posix_strtoull(
    246372    const char *restrict nptr, char **restrict endptr, int base)
    247373{
    248         return internal_strtol(nptr, endptr, base, 0, ULLONG_MAX, NULL);
    249 }
    250 
     374        uintmax_t result =
     375            internal_strtol(nptr, endptr, base, 0, ULLONG_MAX, NULL);
     376
     377        return (unsigned long long) result;
     378}
     379
     380/**
     381 * Convert a string to a largest unsigned integer type.
     382 *
     383 * @param nptr Input string.
     384 * @param endptr Pointer to the final part of the string which
     385 *     was not used for conversion.
     386 * @param base Expected base of the string representation.
     387 * @return Result of the conversion.
     388 */
     389uintmax_t posix_strtoumax(
     390    const char *restrict nptr, char **restrict endptr, int base)
     391{
     392        uintmax_t result =
     393            internal_strtol(nptr, endptr, base, 0, UINTMAX_MAX, NULL);
     394
     395        return result;
     396}
    251397
    252398/** @}
    253399 */
    254 
  • uspace/lib/posix/stdlib/strtold.c

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Backend for floating point conversions.
    3333 */
    3434
     
    5555#endif
    5656
    57 // TODO: clean up, documentation
     57// TODO: clean up
    5858
    5959// FIXME: ensure it builds and works on all platforms
     
    116116};
    117117
     118/**
     119 * Decides whether the argument is still in range representable by
     120 * long double or not.
     121 *
     122 * @param num Floating point number to be checked.
     123 * @return True if the argument is out of range, false otherwise.
     124 */
    118125static inline bool out_of_range(long double num)
    119126{
     
    127134 * @param base Number to be multiplied.
    128135 * @param exponent Base 5 exponent.
    129  * @return base multiplied by 5**exponent
     136 * @return base multiplied by 5**exponent.
    130137 */
    131138static long double mul_pow5(long double base, int exponent)
     
    173180 * @param base Number to be multiplied.
    174181 * @param exponent Base 2 exponent.
    175  * @return base multiplied by 2**exponent
     182 * @return base multiplied by 2**exponent.
    176183 */
    177184static long double mul_pow2(long double base, int exponent)
     
    212219}
    213220
    214 
     221/**
     222 * Convert decimal string representation of the floating point number.
     223 * Function expects the string pointer to be already pointed at the first
     224 * digit (i.e. leading optional sign was already consumed by the caller).
     225 *
     226 * @param sptr Pointer to the storage of the string pointer. Upon successful
     227 *     conversion, the string pointer is updated to point to the first
     228 *     unrecognized character.
     229 * @return An approximate representation of the input floating-point number.
     230 */
    215231static long double parse_decimal(const char **sptr)
    216232{
     
    315331}
    316332
     333/**
     334 * Derive a hexadecimal digit from its character representation.
     335 *
     336 * @param ch Character representation of the hexadecimal digit.
     337 * @return Digit value represented by an integer.
     338 */
    317339static inline int hex_value(char ch)
    318340{
     
    325347
    326348/**
     349 * Get the count of leading zero bits up to the maximum of 3 zero bits.
     350 *
    327351 * @param val Integer value.
    328352 * @return How many leading zero bits there are. (Maximum is 3)
     
    339363}
    340364
     365/**
     366 * Convert hexadecimal string representation of the floating point number.
     367 * Function expects the string pointer to be already pointed at the first
     368 * digit (i.e. leading optional sign and 0x prefix were already consumed
     369 * by the caller).
     370 *
     371 * @param sptr Pointer to the storage of the string pointer. Upon successful
     372 *     conversion, the string pointer is updated to point to the first
     373 *     unrecognized character.
     374 * @return Representation of the input floating-point number.
     375 */
    341376static long double parse_hexadecimal(const char **sptr)
    342377{
     
    478513 * @param nptr Input string.
    479514 * @param endptr If non-NULL, *endptr is set to the position of the first
    480  *    unrecognized character.
     515 *     unrecognized character.
    481516 * @return An approximate representation of the input floating-point number.
    482517 */
     
    512547               
    513548                if (endptr != NULL) {
    514                         *endptr = (char *) &nptr[i + 3];
    515                 }
    516                 errno = ERANGE;
    517                 return negative ? -0.0l : +0.0l;
     549                        *endptr = (char *) nptr;
     550                }
     551                errno = EINVAL;
     552                return 0;
    518553        }
    519554       
     
    567602/** @}
    568603 */
    569 
  • uspace/lib/posix/string.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file String manipulation.
    3434 */
    3535
     
    4848
    4949/**
    50  * Returns true if s2 is a prefix of s1.
    51  *
    52  * @param s1
    53  * @param s2
    54  * @return
     50 * Decides whether s2 is a prefix of s1.
     51 *
     52 * @param s1 String in which to look for a prefix.
     53 * @param s2 Prefix string to look for.
     54 * @return True if s2 is a prefix of s1, false otherwise.
    5555 */
    5656static bool begins_with(const char *s1, const char *s2)
     
    6969 * if no occurence is found.
    7070 *
    71  * @param s1
    72  * @param s2
    73  * @return
     71 * @param s1 String in which to look for the bytes.
     72 * @param s2 String of bytes to look for.
     73 * @return Pointer to the found byte on success, pointer to the
     74 *     string terminator otherwise.
    7475 */
    7576static char *strpbrk_null(const char *s1, const char *s2)
     
    8384
    8485/**
    85  *
    86  * @param dest
    87  * @param src
    88  * @return
    89  */
    90 char *posix_strcpy(char *dest, const char *src)
     86 * Copy a string.
     87 *
     88 * @param dest Destination pre-allocated buffer.
     89 * @param src Source string to be copied.
     90 * @return Pointer to the destination buffer.
     91 */
     92char *posix_strcpy(char *restrict dest, const char *restrict src)
    9193{
    9294        posix_stpcpy(dest, src);
     
    9597
    9698/**
    97  *
    98  * @param dest
    99  * @param src
    100  * @param n
    101  * @return
    102  */
    103 char *posix_strncpy(char *dest, const char *src, size_t n)
     99 * Copy fixed length string.
     100 *
     101 * @param dest Destination pre-allocated buffer.
     102 * @param src Source string to be copied.
     103 * @param n Number of bytes to be stored into destination buffer.
     104 * @return Pointer to the destination buffer.
     105 */
     106char *posix_strncpy(char *restrict dest, const char *restrict src, size_t n)
    104107{
    105108        posix_stpncpy(dest, src, n);
     
    108111
    109112/**
    110  *
    111  * @param dest
    112  * @param src
    113  * @return Pointer to the nul character in the dest string
     113 * Copy a string.
     114 *
     115 * @param dest Destination pre-allocated buffer.
     116 * @param src Source string to be copied.
     117 * @return Pointer to the nul character in the destination string.
    114118 */
    115119char *posix_stpcpy(char *restrict dest, const char *restrict src)
     
    132136
    133137/**
    134  *
    135  * @param dest
    136  * @param src
    137  * @param n
    138  * @return Pointer to the first written nul character or &dest[n]
     138 * Copy fixed length string.
     139 *
     140 * @param dest Destination pre-allocated buffer.
     141 * @param src Source string to be copied.
     142 * @param n Number of bytes to be stored into destination buffer.
     143 * @return Pointer to the first written nul character or &dest[n].
    139144 */
    140145char *posix_stpncpy(char *restrict dest, const char *restrict src, size_t n)
     
    162167
    163168/**
    164  *
    165  * @param dest
    166  * @param src
    167  * @return
    168  */
    169 char *posix_strcat(char *dest, const char *src)
     169 * Concatenate two strings.
     170 *
     171 * @param dest String to which src shall be appended.
     172 * @param src String to be appended after dest.
     173 * @return Pointer to destination buffer.
     174 */
     175char *posix_strcat(char *restrict dest, const char *restrict src)
    170176{
    171177        assert(dest != NULL);
     
    177183
    178184/**
    179  *
    180  * @param dest
    181  * @param src
    182  * @param n
    183  * @return
    184  */
    185 char *posix_strncat(char *dest, const char *src, size_t n)
     185 * Concatenate a string with part of another.
     186 *
     187 * @param dest String to which part of src shall be appended.
     188 * @param src String whose part shall be appended after dest.
     189 * @param n Number of bytes to append after dest.
     190 * @return Pointer to destination buffer.
     191 */
     192char *posix_strncat(char *restrict dest, const char *restrict src, size_t n)
    186193{
    187194        assert(dest != NULL);
     
    195202
    196203/**
    197  *
    198  * @param dest
    199  * @param src
    200  * @param c
    201  * @param n
     204 * Copy limited number of bytes in memory.
     205 *
     206 * @param dest Destination buffer.
     207 * @param src Source buffer.
     208 * @param c Character after which the copying shall stop.
     209 * @param n Number of bytes that shall be copied if not stopped earlier by c.
    202210 * @return Pointer to the first byte after c in dest if found, NULL otherwise.
    203211 */
    204 void *posix_memccpy(void *dest, const void *src, int c, size_t n)
     212void *posix_memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
    205213{
    206214        assert(dest != NULL);
     
    223231
    224232/**
    225  *
    226  * @param s
    227  * @return Newly allocated string
     233 * Duplicate a string.
     234 *
     235 * @param s String to be duplicated.
     236 * @return Newly allocated copy of the string.
    228237 */
    229238char *posix_strdup(const char *s)
     
    233242
    234243/**
    235  *
    236  * @param s
    237  * @param n
    238  * @return Newly allocated string of length at most n
     244 * Duplicate a specific number of bytes from a string.
     245 *
     246 * @param s String to be duplicated.
     247 * @param n Maximum length of the resulting string..
     248 * @return Newly allocated string copy of length at most n.
    239249 */
    240250char *posix_strndup(const char *s, size_t n)
     
    255265
    256266/**
    257  *
    258  * @param mem1
    259  * @param mem2
    260  * @param n
     267 * Compare bytes in memory.
     268 *
     269 * @param mem1 First area of memory to be compared.
     270 * @param mem2 Second area of memory to be compared.
     271 * @param n Maximum number of bytes to be compared.
    261272 * @return Difference of the first pair of inequal bytes,
    262  *     or 0 if areas have the same content
     273 *     or 0 if areas have the same content.
    263274 */
    264275int posix_memcmp(const void *mem1, const void *mem2, size_t n)
     
    272283        for (size_t i = 0; i < n; ++i) {
    273284                if (s1[i] != s2[i]) {
    274                         return s2[i] - s1[i];
     285                        return s1[i] - s2[i];
    275286                }
    276287        }
     
    280291
    281292/**
    282  *
    283  * @param s1
    284  * @param s2
    285  * @return
     293 * Compare two strings.
     294 *
     295 * @param s1 First string to be compared.
     296 * @param s2 Second string to be compared.
     297 * @return Difference of the first pair of inequal characters,
     298 *     or 0 if strings have the same content.
    286299 */
    287300int posix_strcmp(const char *s1, const char *s2)
     
    294307
    295308/**
    296  *
    297  * @param s1
    298  * @param s2
    299  * @param n
    300  * @return
     309 * Compare part of two strings.
     310 *
     311 * @param s1 First string to be compared.
     312 * @param s2 Second string to be compared.
     313 * @param n Maximum number of characters to be compared.
     314 * @return Difference of the first pair of inequal characters,
     315 *     or 0 if strings have the same content.
    301316 */
    302317int posix_strncmp(const char *s1, const char *s2, size_t n)
     
    307322        for (size_t i = 0; i < n; ++i) {
    308323                if (s1[i] != s2[i]) {
    309                         return s2[i] - s1[i];
     324                        return s1[i] - s2[i];
    310325                }
    311326                if (s1[i] == '\0') {
     
    318333
    319334/**
    320  *
    321  * @param mem
    322  * @param c
    323  * @param n
    324  * @return
     335 * Find byte in memory.
     336 *
     337 * @param mem Memory area in which to look for the byte.
     338 * @param c Byte to look for.
     339 * @param n Maximum number of bytes to be inspected.
     340 * @return Pointer to the specified byte on success,
     341 *     NULL pointer otherwise.
    325342 */
    326343void *posix_memchr(const void *mem, int c, size_t n)
     
    339356
    340357/**
    341  *
    342  * @param s
    343  * @param c
    344  * @return
     358 * Scan string for a first occurence of a character.
     359 *
     360 * @param s String in which to look for the character.
     361 * @param c Character to look for.
     362 * @return Pointer to the specified character on success,
     363 *     NULL pointer otherwise.
    345364 */
    346365char *posix_strchr(const char *s, int c)
     
    353372
    354373/**
    355  *
    356  * @param s
    357  * @param c
    358  * @return
     374 * Scan string for a last occurence of a character.
     375 *
     376 * @param s String in which to look for the character.
     377 * @param c Character to look for.
     378 * @return Pointer to the specified character on success,
     379 *     NULL pointer otherwise.
    359380 */
    360381char *posix_strrchr(const char *s, int c)
     
    376397}
    377398
     399/**
     400 * Scan string for a first occurence of a character.
     401 *
     402 * @param s String in which to look for the character.
     403 * @param c Character to look for.
     404 * @return Pointer to the specified character on success, pointer to the
     405 *     string terminator otherwise.
     406 */
    378407char *gnu_strchrnul(const char *s, int c)
    379408{
     
    388417
    389418/**
    390  *
    391  * @param s1
    392  * @param s2
    393  * @return
     419 * Scan a string for a first occurence of one of provided bytes.
     420 *
     421 * @param s1 String in which to look for the bytes.
     422 * @param s2 String of bytes to look for.
     423 * @return Pointer to the found byte on success,
     424 *     NULL pointer otherwise.
    394425 */
    395426char *posix_strpbrk(const char *s1, const char *s2)
     
    403434
    404435/**
    405  *
    406  * @param s1
    407  * @param s2
    408  * @return
     436 * Get the length of a complementary substring.
     437 *
     438 * @param s1 String that shall be searched for complementary prefix.
     439 * @param s2 String of bytes that shall not occur in the prefix.
     440 * @return Length of the prefix.
    409441 */
    410442size_t posix_strcspn(const char *s1, const char *s2)
     
    418450
    419451/**
    420  *
    421  * @param s1
    422  * @param s2
    423  * @return
     452 * Get length of a substring.
     453 *
     454 * @param s1 String that shall be searched for prefix.
     455 * @param s2 String of bytes that the prefix must consist of.
     456 * @return Length of the prefix.
    424457 */
    425458size_t posix_strspn(const char *s1, const char *s2)
     
    438471
    439472/**
    440  *
    441  * @param s1
    442  * @param s2
    443  * @return
     473 * Find a substring.
     474 *
     475 * @param s1 String in which to look for a substring.
     476 * @param s2 Substring to look for.
     477 * @return Pointer to the first character of the substring in s1, or NULL if
     478 *     not found.
    444479 */
    445480char *posix_strstr(const char *s1, const char *s2)
     
    467502
    468503/**
     504 * String comparison using collating information.
     505 *
    469506 * Currently ignores locale and just calls strcmp.
    470507 *
    471  * @param s1
    472  * @param s2
    473  * @return
     508 * @param s1 First string to be compared.
     509 * @param s2 Second string to be compared.
     510 * @return Difference of the first pair of inequal characters,
     511 *     or 0 if strings have the same content.
    474512 */
    475513int posix_strcoll(const char *s1, const char *s2)
     
    482520
    483521/**
    484  * strcoll is equal to strcmp here, so this just makes a copy.
    485  *
    486  * @param s1
    487  * @param s2
    488  * @param n
    489  * @return
    490  */
    491 size_t posix_strxfrm(char *s1, const char *s2, size_t n)
     522 * Transform a string in such a way that the resulting string yields the same
     523 * results when passed to the strcmp as if the original string is passed to
     524 * the strcoll.
     525 *
     526 * Since strcoll is equal to strcmp here, this just makes a copy.
     527 *
     528 * @param s1 Transformed string.
     529 * @param s2 Original string.
     530 * @param n Maximum length of the transformed string.
     531 * @return Length of the transformed string.
     532 */
     533size_t posix_strxfrm(char *restrict s1, const char *restrict s2, size_t n)
    492534{
    493535        assert(s1 != NULL || n == 0);
     
    504546
    505547/**
    506  *
    507  * @param errnum
    508  * @return
     548 * Get error message string.
     549 *
     550 * @param errnum Error code for which to obtain human readable string.
     551 * @return Error message.
    509552 */
    510553char *posix_strerror(int errnum)
     
    518561
    519562/**
    520  *
    521  * @param errnum Error code
    522  * @param buf Buffer to store a human readable string to
    523  * @param bufsz Size of buffer pointed to by buf
    524  * @return
     563 * Get error message string.
     564 *
     565 * @param errnum Error code for which to obtain human readable string.
     566 * @param buf Buffer to store a human readable string to.
     567 * @param bufsz Size of buffer pointed to by buf.
     568 * @return Zero on success, errno otherwise.
    525569 */
    526570int posix_strerror_r(int errnum, char *buf, size_t bufsz)
     
    541585
    542586/**
    543  *
    544  * @param s
    545  * @return
     587 * Get length of the string.
     588 *
     589 * @param s String which length shall be determined.
     590 * @return Length of the string.
    546591 */
    547592size_t posix_strlen(const char *s)
     
    553598
    554599/**
    555  *
    556  * @param s
    557  * @param n
    558  * @return
     600 * Get limited length of the string.
     601 *
     602 * @param s String which length shall be determined.
     603 * @param n Maximum number of bytes that can be examined to determine length.
     604 * @return The lower of either string length or n limit.
    559605 */
    560606size_t posix_strnlen(const char *s, size_t n)
     
    573619
    574620/**
    575  *
    576  * @param signum
    577  * @return
     621 * Get description of a signal.
     622 *
     623 * @param signum Signal number.
     624 * @return Human readable signal description.
    578625 */
    579626char *posix_strsignal(int signum)
  • uspace/lib/posix/string.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file String manipulation.
    3434 */
    3535
     
    103103extern size_t posix_strnlen(const char *s, size_t n);
    104104
    105 /* Signal messages */
     105/* Signal Messages */
    106106extern char *posix_strsignal(int signum);
    107107
    108 /* Legacy declarations */
     108/* Legacy Declarations */
    109109#ifndef POSIX_STRINGS_H_
    110110extern int posix_ffs(int i);
  • uspace/lib/posix/strings.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Additional string manipulation.
    3434 */
    3535
     
    4545
    4646/**
     47 * Find first set bit (beginning with the least significant bit).
    4748 *
    48  * @param i
    49  * @return
     49 * @param i Integer in which to look for the first set bit.
     50 * @return Index of first set bit. Bits are numbered starting at one.
    5051 */
    5152int posix_ffs(int i)
     
    8283
    8384/**
     85 * Compare two strings (case-insensitive).
    8486 *
    85  * @param s1
    86  * @param s2
    87  * @return
     87 * @param s1 First string to be compared.
     88 * @param s2 Second string to be compared.
     89 * @return Difference of the first pair of inequal characters,
     90 *     or 0 if strings have the same content.
    8891 */
    8992int posix_strcasecmp(const char *s1, const char *s2)
     
    9396
    9497/**
     98 * Compare part of two strings (case-insensitive).
    9599 *
    96  * @param s1
    97  * @param s2
    98  * @param n
    99  * @return
     100 * @param s1 First string to be compared.
     101 * @param s2 Second string to be compared.
     102 * @param n Maximum number of characters to be compared.
     103 * @return Difference of the first pair of inequal characters,
     104 *     or 0 if strings have the same content.
    100105 */
    101106int posix_strncasecmp(const char *s1, const char *s2, size_t n)
     
    116121
    117122/**
     123 * Compare two memory areas.
    118124 *
    119  * @param mem1
    120  * @param mem2
    121  * @param n
    122  * @return
     125 * @param mem1 Pointer to the first area to compare.
     126 * @param mem2 Pointer to the second area to compare.
     127 * @param n Common size of both areas.
     128 * @return If n is 0, return zero. If the areas match, return
     129 *     zero. Otherwise return non-zero.
    123130 */
    124131int posix_bcmp(const void *mem1, const void *mem2, size_t n)
     
    128135
    129136/**
     137 * Copy bytes in memory with overlapping areas.
    130138 *
    131  * @param dest
    132  * @param src
    133  * @param n
     139 * @param src Source area.
     140 * @param dest Destination area.
     141 * @param n Number of bytes to copy.
    134142 */
    135 void posix_bcopy(const void *dest, void *src, size_t n)
     143void posix_bcopy(const void *src, void *dest, size_t n)
    136144{
    137145        /* Note that memmove has different order of arguments. */
    138         memmove(src, dest, n);
     146        memmove(dest, src, n);
    139147}
    140148
    141149/**
     150 * Reset bytes in memory area to zero.
    142151 *
    143  * @param mem
    144  * @param n
     152 * @param mem Memory area to be zeroed.
     153 * @param n Number of bytes to reset.
    145154 */
    146155void posix_bzero(void *mem, size_t n)
     
    150159
    151160/**
     161 * Scan string for a first occurence of a character.
    152162 *
    153  * @param s
    154  * @param c
    155  * @return
     163 * @param s String in which to look for the character.
     164 * @param c Character to look for.
     165 * @return Pointer to the specified character on success,
     166 *     NULL pointer otherwise.
    156167 */
    157168char *posix_index(const char *s, int c)
     
    161172
    162173/**
    163  *
    164  * @param s
    165  * @param c
    166  * @return
     174 * Scan string for a last occurence of a character.
     175 *
     176 * @param s String in which to look for the character.
     177 * @param c Character to look for.
     178 * @return Pointer to the specified character on success,
     179 *     NULL pointer otherwise.
    167180 */
    168181char *posix_rindex(const char *s, int c)
  • uspace/lib/posix/strings.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Additional string manipulation.
    3434 */
    3535
     
    3737#define POSIX_STRINGS_H_
    3838
     39/* Search Functions */
    3940#ifndef POSIX_STRING_H_
    40 /* Search Functions */
    4141extern int posix_ffs(int i);
    4242#endif
     
    5656/* Legacy Functions */
    5757extern int posix_bcmp(const void *mem1, const void *mem2, size_t n);
    58 extern void posix_bcopy(const void *dest, void *src, size_t n);
     58extern void posix_bcopy(const void *src, void *dest, size_t n);
    5959extern void posix_bzero(void *mem, size_t n);
    6060extern char *posix_index(const char *s, int c);
  • uspace/lib/posix/sys/mman.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Memory management declarations.
    3333 */
    3434
  • uspace/lib/posix/sys/stat.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file File status handling.
    3434 */
    3535
     
    8080        int rc = fstat(fd, &hst);
    8181        if (rc < 0) {
    82                 /* fstat() returns negative error code instead of using errno.
    83                  */
     82                /* fstat() returns negative error code instead of using errno. */
    8483                errno = -rc;
    8584                return -1;
     
    9695 * @return Zero on success, -1 otherwise.
    9796 */
    98 int posix_lstat(const char *path, struct posix_stat *st)
     97int posix_lstat(const char *restrict path, struct posix_stat *restrict st)
    9998{
    10099        /* There are currently no symbolic links in HelenOS. */
     
    109108 * @return Zero on success, -1 otherwise.
    110109 */
    111 int posix_stat(const char *path, struct posix_stat *st)
     110int posix_stat(const char *restrict path, struct posix_stat *restrict st)
    112111{
    113112        struct stat hst;
    114113        int rc = stat(path, &hst);
    115114        if (rc < 0) {
    116                 /* stat() returns negative error code instead of using errno.
    117                  */
     115                /* stat() returns negative error code instead of using errno. */
    118116                errno = -rc;
    119117                return -1;
  • uspace/lib/posix/sys/stat.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file File status handling.
    3434 */
    3535
  • uspace/lib/posix/sys/types.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Data types definitions.
    3434 */
    3535
     
    4949typedef sysarg_t posix_dev_t;
    5050
    51 /* PThread types */
     51/* PThread Types */
    5252typedef struct posix_thread_attr posix_thread_attr_t;
    5353
    54 /* Clock types */
     54/* Clock Types */
    5555typedef long posix_clock_t;
    5656typedef int posix_clockid_t;
  • uspace/lib/posix/sys/wait.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Support for waiting.
    3434 */
    3535
     
    6565/** @}
    6666 */
    67 
  • uspace/lib/posix/sys/wait.h

    rdf0956ee reccd20e6  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Support for waiting.
    3333 */
    3434
  • uspace/lib/posix/time.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Time measurement support.
    3434 */
    3535
     
    6363#define SECS_PER_DAY (SECS_PER_HOUR * HOURS_PER_DAY)
    6464
     65/**
     66 *
     67 * @param year
     68 * @return
     69 */
    6570static bool _is_leap_year(time_t year)
    6671{
     
    7681}
    7782
     83/**
     84 *
     85 * @param year
     86 * @param mon
     87 * @return
     88 */
    7889static int _days_in_month(time_t year, time_t mon)
    7990{
     
    92103}
    93104
     105/**
     106 *
     107 * @param year
     108 * @param mon
     109 * @param mday
     110 * @return
     111 */
    94112static int _day_of_year(time_t year, time_t mon, time_t mday)
    95113{
     
    102120}
    103121
    104 /* Integer division that rounds to negative infinity.
     122/**
     123 * Integer division that rounds to negative infinity.
     124 *
     125 * @param op1
     126 * @param op2
     127 * @return
    105128 */
    106129static time_t _floor_div(time_t op1, time_t op2)
     
    113136}
    114137
    115 /* Modulo that rounds to negative infinity.
     138/**
     139 * Modulo that rounds to negative infinity.
     140 *
     141 * @param op1
     142 * @param op2
     143 * @return
    116144 */
    117145static time_t _floor_mod(time_t op1, time_t op2)
     
    132160}
    133161
     162/**
     163 *
     164 * @param year
     165 * @param mon
     166 * @param mday
     167 * @return
     168 */
    134169static time_t _days_since_epoch(time_t year, time_t mon, time_t mday)
    135170{
     
    139174}
    140175
    141 /* Assumes normalized broken-down time. */
     176/**
     177 * Assumes normalized broken-down time.
     178 *
     179 * @param tm
     180 * @return
     181 */
    142182static time_t _secs_since_epoch(const struct posix_tm *tm)
    143183{
     
    147187}
    148188
     189/**
     190 *
     191 * @param year
     192 * @param mon
     193 * @param mday
     194 * @return
     195 */
    149196static int _day_of_week(time_t year, time_t mon, time_t mday)
    150197{
     
    165212};
    166213
     214/**
     215 *
     216 * @param ltm
     217 * @param ptm
     218 */
    167219static void _posix_to_long_tm(struct _long_tm *ltm, struct posix_tm *ptm)
    168220{
     
    179231}
    180232
     233/**
     234 *
     235 * @param ptm
     236 * @param ltm
     237 */
    181238static void _long_to_posix_tm(struct posix_tm *ptm, struct _long_tm *ltm)
    182239{
     
    196253}
    197254
     255/**
     256 *
     257 * @param tm
     258 */
    198259static void _normalize_time(struct _long_tm *tm)
    199260{
     
    241302}
    242303
    243 /* Which day the week-based year starts on relative to the first calendar day.
     304/**
     305 * Which day the week-based year starts on relative to the first calendar day.
    244306 * E.g. if the year starts on December 31st, the return value is -1.
     307 *
     308 * @param year
     309 * @return
    245310 */
    246311static int _wbyear_offset(int year)
     
    250315}
    251316
    252 /* Returns week-based year of the specified time.
     317/**
     318 * Returns week-based year of the specified time.
    253319 * Assumes normalized broken-down time.
     320 *
     321 * @param tm
     322 * @return
    254323 */
    255324static int _wbyear(const struct posix_tm *tm)
     
    268337}
    269338
    270 /** Week number of the year, assuming weeks start on sunday.
    271  *  The first Sunday of January is the first day of week 1;
    272  *  days in the new year before this are in week 0.
     339/**
     340 * Week number of the year, assuming weeks start on sunday.
     341 * The first Sunday of January is the first day of week 1;
     342 * days in the new year before this are in week 0.
    273343 *
    274344 * @param tm Normalized broken-down time.
     
    281351}
    282352
    283 /** Week number of the year, assuming weeks start on monday.
    284  *  If the week containing January 1st has four or more days in the new year,
    285  *  then it is considered week 1. Otherwise, it is the last week of the previous
    286  *  year, and the next week is week 1. Both January 4th and the first Thursday
    287  *  of January are always in week 1.
     353/**
     354 * Week number of the year, assuming weeks start on monday.
     355 * If the week containing January 1st has four or more days in the new year,
     356 * then it is considered week 1. Otherwise, it is the last week of the previous
     357 * year, and the next week is week 1. Both January 4th and the first Thursday
     358 * of January are always in week 1.
    288359 *
    289360 * @param tm Normalized broken-down time.
     
    305376}
    306377
    307 /** Week number of the year, assuming weeks start on monday.
    308  *  The first Monday of January is the first day of week 1;
    309  *  days in the new year before this are in week 0.
     378/**
     379 * Week number of the year, assuming weeks start on monday.
     380 * The first Monday of January is the first day of week 1;
     381 * days in the new year before this are in week 0.
    310382 *
    311383 * @param tm Normalized broken-down time.
     
    324396char *posix_tzname[2];
    325397
     398/**
     399 *
     400 */
    326401void posix_tzset(void)
    327402{
     
    333408}
    334409
     410/**
     411 *
     412 * @param time1
     413 * @param time0
     414 * @return
     415 */
    335416double posix_difftime(time_t time1, time_t time0)
    336417{
     
    338419}
    339420
    340 /** This function first normalizes the provided broken-down time
    341  *  (moves all values to their proper bounds) and then tries to
    342  *  calculate the appropriate time_t representation.
    343  *
    344  * @param timeptr Broken-down time.
     421/**
     422 * This function first normalizes the provided broken-down time
     423 * (moves all values to their proper bounds) and then tries to
     424 * calculate the appropriate time_t representation.
     425 *
     426 * @param tm Broken-down time.
    345427 * @return time_t representation of the time, undefined value on overflow
    346428 */
     
    358440}
    359441
     442/**
     443 *
     444 * @param timer
     445 * @return
     446 */
    360447struct posix_tm *posix_gmtime(const time_t *timer)
    361448{
     
    364451}
    365452
     453/**
     454 *
     455 * @param timer
     456 * @param result
     457 * @return
     458 */
    366459struct posix_tm *posix_gmtime_r(const time_t *restrict timer,
    367460    struct posix_tm *restrict result)
     
    394487/**
    395488 *
    396  * @param timep
     489 * @param timer
    397490 * @return
    398491 */
     
    403496}
    404497
     498/**
     499 *
     500 * @param timer
     501 * @param result
     502 * @return
     503 */
    405504struct posix_tm *posix_localtime_r(const time_t *restrict timer,
    406505    struct posix_tm *restrict result)
     
    413512/**
    414513 *
    415  * @param tm
     514 * @param timeptr
    416515 * @return
    417516 */
     
    422521}
    423522
     523/**
     524 *
     525 * @param timeptr
     526 * @param buf
     527 * @return
     528 */
    424529char *posix_asctime_r(const struct posix_tm *restrict timeptr,
    425530    char *restrict buf)
     
    448553/**
    449554 *
    450  * @param timep
     555 * @param timer
    451556 * @return
    452557 */
     
    460565}
    461566
     567/**
     568 *
     569 * @param timer
     570 * @param buf
     571 * @return
     572 */
    462573char *posix_ctime_r(const time_t *timer, char *buf)
    463574{
     
    477588 * @return
    478589 */
    479 size_t posix_strftime(char *s, size_t maxsize,
    480     const char *format, const struct posix_tm *tm)
     590size_t posix_strftime(char *restrict s, size_t maxsize,
     591    const char *restrict format, const struct posix_tm *restrict tm)
    481592{
    482593        // TODO: use locale
     
    655766}
    656767
     768/**
     769 *
     770 * @param s
     771 * @param maxsize
     772 * @param format
     773 * @param tm
     774 * @param loc
     775 * @return
     776 */
     777extern size_t posix_strftime_l(char *restrict s, size_t maxsize,
     778    const char *restrict format, const struct posix_tm *restrict tm,
     779    posix_locale_t loc)
     780{
     781        // TODO
     782        not_implemented();
     783}
     784
     785/**
     786 *
     787 * @param clock_id
     788 * @param res
     789 * @return
     790 */
    657791int posix_clock_getres(posix_clockid_t clock_id, struct posix_timespec *res)
    658792{
     
    670804}
    671805
     806/**
     807 *
     808 * @param clock_id
     809 * @param tp
     810 * @return
     811 */
    672812int posix_clock_gettime(posix_clockid_t clock_id, struct posix_timespec *tp)
    673813{
     
    688828}
    689829
     830/**
     831 *
     832 * @param clock_id
     833 * @param tp
     834 * @return
     835 */
    690836int posix_clock_settime(posix_clockid_t clock_id,
    691837    const struct posix_timespec *tp)
     
    706852}
    707853
     854/**
     855 *
     856 * @param clock_id
     857 * @param flags
     858 * @param rqtp
     859 * @param rmtp
     860 * @return
     861 */
    708862int posix_clock_nanosleep(posix_clockid_t clock_id, int flags,
    709863    const struct posix_timespec *rqtp, struct posix_timespec *rmtp)
     
    735889};
    736890
     891/**
     892 *
     893 * @param clockid
     894 * @param evp
     895 * @param timerid
     896 * @return
     897 */
    737898int posix_timer_create(posix_clockid_t clockid,
    738899    struct posix_sigevent *restrict evp,
     
    743904}
    744905
     906/**
     907 *
     908 * @param timerid
     909 * @return
     910 */
    745911int posix_timer_delete(posix_timer_t timerid)
    746912{
     
    749915}
    750916
     917/**
     918 *
     919 * @param timerid
     920 * @return
     921 */
    751922int posix_timer_getoverrun(posix_timer_t timerid)
    752923{
     
    755926}
    756927
     928/**
     929 *
     930 * @param timerid
     931 * @param value
     932 * @return
     933 */
    757934int posix_timer_gettime(posix_timer_t timerid,
    758935    struct posix_itimerspec *value)
     
    762939}
    763940
     941/**
     942 *
     943 * @param timerid
     944 * @param flags
     945 * @param value
     946 * @param ovalue
     947 * @return
     948 */
    764949int posix_timer_settime(posix_timer_t timerid, int flags,
    765950    const struct posix_itimerspec *restrict value,
     
    783968        if (task_stats) {
    784969                total_cycles = (posix_clock_t) (task_stats->kcycles + task_stats->ucycles);
    785         }
    786         free(task_stats);
    787         task_stats = 0;
     970                free(task_stats);
     971                task_stats = 0;
     972        }
    788973
    789974        return total_cycles;
  • uspace/lib/posix/time.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Time measurement support.
    3434 */
    3535
     
    9494
    9595/* Timezones */
    96 
    9796extern int posix_daylight;
    9897extern long posix_timezone;
    9998extern char *posix_tzname[2];
    100 
    10199extern void posix_tzset(void);
    102100
    103 /* time_t */
    104 
     101/* Elapsed Time */
    105102extern double posix_difftime(time_t time1, time_t time0);
    106103
    107104/* Broken-down Time */
    108 extern time_t posix_mktime(struct posix_tm *timeptr);
     105extern time_t posix_mktime(struct posix_tm *tm);
    109106extern struct posix_tm *posix_gmtime(const time_t *timer);
    110107extern struct posix_tm *posix_gmtime_r(const time_t *restrict timer,
     
    120117extern char *posix_ctime(const time_t *timer);
    121118extern char *posix_ctime_r(const time_t *timer, char *buf);
    122 
    123119extern size_t posix_strftime(char *restrict s, size_t maxsize,
    124120    const char *restrict format, const struct posix_tm *restrict tm);
    125 
    126121extern size_t posix_strftime_l(char *restrict s, size_t maxsize,
    127122    const char *restrict format, const struct posix_tm *restrict tm,
    128123    posix_locale_t loc);
    129124
    130 /* Clocks. */
    131 
     125/* Clocks */
    132126extern int posix_clock_getres(posix_clockid_t clock_id,
    133127    struct posix_timespec *res);
     
    139133    const struct posix_timespec *rqtp, struct posix_timespec *rmtp);
    140134
    141 /* Timers. */
    142 
    143135#if 0
    144136
     137/* Timers */
    145138extern int posix_timer_create(posix_clockid_t clockid,
    146139    struct posix_sigevent *restrict evp,
     
    159152extern posix_clock_t posix_clock(void);
    160153
    161 
    162154#ifndef LIBPOSIX_INTERNAL
    163155        #define tm posix_tm
    164 
    165156        #define timespec posix_timespec
    166157        #define itimerspec posix_itimerspec
    167158        #define timer_t posix_timer_t
    168159
     160        #define daylight posix_daylight
     161        #define timezone posix_timezone
     162        #define tzname posix_tzname
     163        #define tzset posix_tzset
     164
    169165        #define difftime posix_difftime
     166
    170167        #define mktime posix_mktime
    171168        #define gmtime posix_gmtime
     
    174171        #define localtime_r posix_localtime_r
    175172
    176         #define daylight posix_daylight
    177         #define timezone posix_timezone
    178         #define tzname posix_tzname
    179         #define tzset posix_tzset
    180 
    181173        #define asctime posix_asctime
    182174        #define asctime_r posix_asctime_r
     
    184176        #define ctime_r posix_ctime_r
    185177        #define strftime posix_strftime
     178        #define strftime_l posix_strftime_l
    186179
    187180        #define clock_getres posix_clock_getres
  • uspace/lib/posix/unistd.c

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Miscellaneous standard definitions.
    3434 */
    3535
     
    9090        /* Always returns false, because there is no easy way to find
    9191     * out under HelenOS. */
    92         return false;
     92        return 0;
    9393}
    9494
     
    207207                /* Check file existence by attempt to open it. */
    208208                int fd = open(path, O_RDONLY);
    209                 if (fd < 0) {
    210                         /* FIXME: open() returns error code as negative retval. */
    211                         errno = -fd;
    212                         fd = -1;
    213                 } else {
     209                if (fd != -1) {
    214210                        close(fd);
    215211                }
     
    239235                clk_tck = ((long) cpu_stats[0].frequency_mhz) * 1000000L;
    240236        }
    241         free(cpu_stats);
    242         cpu_stats = 0;
     237        if (cpu_stats) {
     238                free(cpu_stats);
     239                cpu_stats = 0;
     240        }
    243241
    244242        long phys_pages = 0;
     
    248246                phys_pages = (long) (mem_stats->total / getpagesize());
    249247                avphys_pages = (long) (mem_stats->free / getpagesize());
    250         }
    251         free(mem_stats);
    252         mem_stats = 0;
     248                free(mem_stats);
     249                mem_stats = 0;
     250        }
    253251
    254252        switch (name) {
  • uspace/lib/posix/unistd.h

    rdf0956ee reccd20e6  
    3131 * @{
    3232 */
    33 /** @file
     33/** @file Miscellaneous standard definitions.
    3434 */
    3535
Note: See TracChangeset for help on using the changeset viewer.