Changeset cc3652db in mainline for uspace/lib/posix/stdlib.c


Ignore:
Timestamp:
2011-06-25T13:59:44Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
be64a84
Parents:
2b83add
Message:

Add a few functions to stdlib.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/stdlib.c

    r2b83add rcc3652db  
    8686}
    8787
     88posix_div_t posix_div(int numer, int denom)
     89{
     90        return (posix_div_t) { .quot = numer / denom, .rem = numer % denom };
     91}
     92
     93posix_ldiv_t posix_ldiv(long numer, long denom)
     94{
     95        return (posix_ldiv_t) { .quot = numer / denom, .rem = numer % denom };
     96}
     97
     98posix_lldiv_t posix_lldiv(long long numer, long long denom)
     99{
     100        return (posix_lldiv_t) { .quot = numer / denom, .rem = numer % denom };
     101}
     102
    88103/**
    89104 * Private helper function that serves as a compare function for qsort().
     
    117132
    118133/**
     134 * Binary search in a sorted array.
     135 *
     136 * @param key Object to search for.
     137 * @param base Pointer to the first element of the array.
     138 * @param nmemb Number of elements in the array.
     139 * @param size Size of each array element.
     140 * @param compar Comparison function.
     141 * @return Pointer to a matching element, or NULL if none can be found.
     142 */
     143void *posix_bsearch(const void *key, const void *base,
     144    size_t nmemb, size_t size, int (*compar)(const void *, const void *))
     145{
     146        while (nmemb > 0) {
     147                const void *middle = base + (nmemb / 2) * size;
     148                int cmp = compar(key, middle);
     149                if (cmp == 0) {
     150                        return (void *) middle;
     151                }
     152                if (middle == base) {
     153                        /* There is just one member left to check and it
     154                         * didn't match the key. Avoid infinite loop.
     155                         */
     156                        break;
     157                }
     158                if (cmp < 0) {
     159                        nmemb = nmemb / 2;
     160                } else if (cmp > 0) {
     161                        nmemb = nmemb - (nmemb / 2);
     162                        base = middle;
     163                }
     164        }
     165       
     166        return NULL;
     167}
     168
     169/**
    119170 * Retrieve a value of the given environment variable.
    120171 * Since HelenOS doesn't support env variables at the moment,
     
    139190        // TODO: low priority, just a compile-time dependency of binutils
    140191        not_implemented();
     192}
     193
     194/**
     195 *
     196 * @param string String to be passed to a command interpreter.
     197 * @return
     198 */
     199int posix_system(const char *string) {
     200        // TODO: does nothing at the moment
     201        return 0;
    141202}
    142203
Note: See TracChangeset for help on using the changeset viewer.