Changeset 76f382b in mainline for uspace/lib/c/generic/sysinfo.c


Ignore:
Timestamp:
2012-03-02T14:50:42Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8b9a443
Parents:
560d79f
Message:

support for listing sysinfo from uspace

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/sysinfo.c

    r560d79f r76f382b  
    4040#include <bool.h>
    4141
     42/** Get sysinfo keys size
     43 *
     44 * @param path  Sysinfo path.
     45 * @param value Pointer to store the keys size.
     46 *
     47 * @return EOK if the keys were successfully read.
     48 *
     49 */
     50static int sysinfo_get_keys_size(const char *path, size_t *size)
     51{
     52        return (int) __SYSCALL3(SYS_SYSINFO_GET_KEYS_SIZE, (sysarg_t) path,
     53            (sysarg_t) str_size(path), (sysarg_t) size);
     54}
     55
     56/** Get sysinfo keys
     57 *
     58 * @param path  Sysinfo path.
     59 * @param value Pointer to store the keys size.
     60 *
     61 * @return Keys read from sysinfo or NULL if the
     62 *         sysinfo item has no subkeys.
     63 *         The returned non-NULL pointer should be
     64 *         freed by free().
     65 *
     66 */
     67char *sysinfo_get_keys(const char *path, size_t *size)
     68{
     69        /*
     70         * The size of the keys might change during time.
     71         * Unfortunatelly we cannot allocate the buffer
     72         * and transfer the keys as a single atomic operation.
     73         */
     74       
     75        /* Get the keys size */
     76        int ret = sysinfo_get_keys_size(path, size);
     77        if ((ret != EOK) || (size == 0)) {
     78                /*
     79                 * Item with no subkeys.
     80                 */
     81                *size = 0;
     82                return NULL;
     83        }
     84       
     85        char *data = malloc(*size);
     86        if (data == NULL) {
     87                *size = 0;
     88                return NULL;
     89        }
     90       
     91        /* Get the data */
     92        size_t sz;
     93        ret = __SYSCALL5(SYS_SYSINFO_GET_KEYS, (sysarg_t) path,
     94            (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size,
     95            (sysarg_t) &sz);
     96        if (ret == EOK) {
     97                *size = sz;
     98                return data;
     99        }
     100       
     101        free(data);
     102        *size = 0;
     103        return NULL;
     104}
     105
    42106/** Get sysinfo item type
    43107 *
Note: See TracChangeset for help on using the changeset viewer.