Changeset 60898b6 in mainline for uspace/srv


Ignore:
Timestamp:
2010-11-05T16:17:48Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
08042bd
Parents:
a63ff7d (diff), a66e2993 (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 mainline changes.

Location:
uspace/srv/devman
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/devman.c

    ra63ff7d r60898b6  
    7676        .remove_callback = devices_remove_callback
    7777};
     78
     79/**
     80 * Initialize the list of device driver's.
     81 *
     82 * @param drv_list the list of device driver's.
     83 *
     84 */
     85void init_driver_list(driver_list_t *drv_list)
     86{
     87        assert(drv_list != NULL);
     88       
     89        list_initialize(&drv_list->drivers);
     90        fibril_mutex_initialize(&drv_list->drivers_mutex);
     91}
    7892
    7993/** Allocate and initialize a new driver structure.
     
    548562}
    549563
     564/** Initialize device driver structure.
     565 *
     566 * @param drv           The device driver structure.
     567 */
     568void init_driver(driver_t *drv)
     569{
     570        assert(drv != NULL);
     571
     572        memset(drv, 0, sizeof(driver_t));
     573        list_initialize(&drv->match_ids.ids);
     574        list_initialize(&drv->devices);
     575        fibril_mutex_initialize(&drv->driver_mutex);
     576}
     577
     578/** Device driver structure clean-up.
     579 *
     580 * @param drv           The device driver structure.
     581 */
     582void clean_driver(driver_t *drv)
     583{
     584        assert(drv != NULL);
     585
     586        free_not_null(drv->name);
     587        free_not_null(drv->binary_path);
     588
     589        clean_match_ids(&drv->match_ids);
     590
     591        init_driver(drv);
     592}
     593
     594/** Delete device driver structure.
     595 *
     596 * @param drv           The device driver structure.
     597 */
     598void delete_driver(driver_t *drv)
     599{
     600        assert(drv != NULL);
     601       
     602        clean_driver(drv);
     603        free(drv);
     604}
    550605
    551606/** Create devmap path and name for the device. */
     
    685740}
    686741
     742/* Device nodes */
     743
     744/** Create a new device node.
     745 *
     746 * @return              A device node structure.
     747 */
     748node_t *create_dev_node(void)
     749{
     750        node_t *res = malloc(sizeof(node_t));
     751       
     752        if (res != NULL) {
     753                memset(res, 0, sizeof(node_t));
     754                list_initialize(&res->children);
     755                list_initialize(&res->match_ids.ids);
     756                list_initialize(&res->classes);
     757        }
     758       
     759        return res;
     760}
     761
     762/** Delete a device node.
     763 *
     764 * @param node          The device node structure.
     765 */
     766void delete_dev_node(node_t *node)
     767{
     768        assert(list_empty(&node->children));
     769        assert(node->parent == NULL);
     770        assert(node->drv == NULL);
     771       
     772        clean_match_ids(&node->match_ids);
     773        free_not_null(node->name);
     774        free_not_null(node->pathname);
     775        free(node);
     776}
     777
     778/** Find the device node structure of the device witch has the specified handle.
     779 *
     780 * Device tree's rwlock should be held at least for reading.
     781 *
     782 * @param tree          The device tree where we look for the device node.
     783 * @param handle        The handle of the device.
     784 * @return              The device node.
     785 */
     786node_t *find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
     787{
     788        unsigned long key = handle;
     789        link_t *link = hash_table_find(&tree->devman_devices, &key);
     790        return hash_table_get_instance(link, node_t, devman_link);
     791}
     792
     793/** Find the device node structure of the device witch has the specified handle.
     794 *
     795 * @param tree          The device tree where we look for the device node.
     796 * @param handle        The handle of the device.
     797 * @return              The device node.
     798 */
     799node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
     800{
     801        node_t *node = NULL;
     802       
     803        fibril_rwlock_read_lock(&tree->rwlock);
     804        node = find_dev_node_no_lock(tree, handle);
     805        fibril_rwlock_read_unlock(&tree->rwlock);
     806       
     807        return node;
     808}
     809
     810
    687811/** Create and set device's full path in device tree.
    688812 *
     
    825949        return NULL;
    826950}
     951
     952/* Device classes */
     953
     954/** Create device class.
     955 *
     956 * @return      Device class.
     957 */
     958dev_class_t *create_dev_class(void)
     959{
     960        dev_class_t *cl;
     961       
     962        cl = (dev_class_t *) malloc(sizeof(dev_class_t));
     963        if (cl != NULL) {
     964                memset(cl, 0, sizeof(dev_class_t));
     965                list_initialize(&cl->devices);
     966                fibril_mutex_initialize(&cl->mutex);
     967        }
     968       
     969        return cl;
     970}
     971
     972/** Create device class info.
     973 *
     974 * @return              Device class info.
     975 */
     976dev_class_info_t *create_dev_class_info(void)
     977{
     978        dev_class_info_t *info;
     979       
     980        info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
     981        if (info != NULL)
     982                memset(info, 0, sizeof(dev_class_info_t));
     983       
     984        return info;
     985}
     986
     987size_t get_new_class_dev_idx(dev_class_t *cl)
     988{
     989        size_t dev_idx;
     990       
     991        fibril_mutex_lock(&cl->mutex);
     992        dev_idx = ++cl->curr_dev_idx;
     993        fibril_mutex_unlock(&cl->mutex);
     994       
     995        return dev_idx;
     996}
     997
    827998
    828999/** Create unique device name within the class.
     
    9211092}
    9221093
     1094void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
     1095{
     1096        list_append(&cl->link, &class_list->classes);
     1097}
     1098
    9231099void init_class_list(class_list_t *class_list)
    9241100{
     
    9301106
    9311107
    932 /* devmap devices */
     1108/* Devmap devices */
    9331109
    9341110node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle)
     
    9671143}
    9681144
     1145void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     1146{
     1147        unsigned long key = (unsigned long) cli->devmap_handle;
     1148       
     1149        fibril_rwlock_write_lock(&class_list->rwlock);
     1150        hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     1151        fibril_rwlock_write_unlock(&class_list->rwlock);
     1152}
     1153
     1154void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
     1155{
     1156        unsigned long key = (unsigned long) node->devmap_handle;
     1157        fibril_rwlock_write_lock(&tree->rwlock);
     1158        hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     1159        fibril_rwlock_write_unlock(&tree->rwlock);
     1160}
     1161
    9691162/** @}
    9701163 */
  • uspace/srv/devman/devman.h

    ra63ff7d r60898b6  
    283283/* Drivers */
    284284
    285 /**
    286  * Initialize the list of device driver's.
    287  *
    288  * @param drv_list the list of device driver's.
    289  *
    290  */
    291 static inline void init_driver_list(driver_list_t *drv_list)
    292 {
    293         assert(drv_list != NULL);
    294        
    295         list_initialize(&drv_list->drivers);
    296         fibril_mutex_initialize(&drv_list->drivers_mutex);
    297 }
    298 
     285extern void init_driver_list(driver_list_t *);
    299286extern driver_t *create_driver(void);
    300287extern bool get_driver_info(const char *, const char *, driver_t *);
     
    311298extern driver_t *find_driver(driver_list_t *, const char *);
    312299extern void set_driver_phone(driver_t *, ipcarg_t);
    313 void initialize_running_driver(driver_t *, dev_tree_t *);
    314 
    315 /** Initialize device driver structure.
    316  *
    317  * @param drv           The device driver structure.
    318  */
    319 static inline void init_driver(driver_t *drv)
    320 {
    321         assert(drv != NULL);
    322 
    323         memset(drv, 0, sizeof(driver_t));
    324         list_initialize(&drv->match_ids.ids);
    325         list_initialize(&drv->devices);
    326         fibril_mutex_initialize(&drv->driver_mutex);
    327 }
    328 
    329 /** Device driver structure clean-up.
    330  *
    331  * @param drv           The device driver structure.
    332  */
    333 static inline void clean_driver(driver_t *drv)
    334 {
    335         assert(drv != NULL);
    336 
    337         free_not_null(drv->name);
    338         free_not_null(drv->binary_path);
    339 
    340         clean_match_ids(&drv->match_ids);
    341 
    342         init_driver(drv);
    343 }
    344 
    345 /** Delete device driver structure.
    346  *
    347  * @param drv           The device driver structure.
    348  */
    349 static inline void delete_driver(driver_t *drv)
    350 {
    351         assert(drv != NULL);
    352        
    353         clean_driver(drv);
    354         free(drv);
    355 }
    356 
     300extern void initialize_running_driver(driver_t *, dev_tree_t *);
     301
     302extern void init_driver(driver_t *);
     303extern void clean_driver(driver_t *);
     304extern void delete_driver(driver_t *);
    357305
    358306/* Device nodes */
    359307
    360 /** Create a new device node.
    361  *
    362  * @return              A device node structure.
    363  */
    364 static inline node_t *create_dev_node(void)
    365 {
    366         node_t *res = malloc(sizeof(node_t));
    367        
    368         if (res != NULL) {
    369                 memset(res, 0, sizeof(node_t));
    370                 list_initialize(&res->children);
    371                 list_initialize(&res->match_ids.ids);
    372                 list_initialize(&res->classes);
    373         }
    374        
    375         return res;
    376 }
    377 
    378 /** Delete a device node.
    379  *
    380  * @param node          The device node structure.
    381  */
    382 static inline void delete_dev_node(node_t *node)
    383 {
    384         assert(list_empty(&node->children));
    385         assert(node->parent == NULL);
    386         assert(node->drv == NULL);
    387        
    388         clean_match_ids(&node->match_ids);
    389         free_not_null(node->name);
    390         free_not_null(node->pathname);
    391         free(node);
    392 }
    393 
    394 /** Find the device node structure of the device witch has the specified handle.
    395  *
    396  * Device tree's rwlock should be held at least for reading.
    397  *
    398  * @param tree          The device tree where we look for the device node.
    399  * @param handle        The handle of the device.
    400  * @return              The device node.
    401  */
    402 static inline node_t *find_dev_node_no_lock(dev_tree_t *tree,
    403     device_handle_t handle)
    404 {
    405         unsigned long key = handle;
    406         link_t *link = hash_table_find(&tree->devman_devices, &key);
    407         return hash_table_get_instance(link, node_t, devman_link);
    408 }
    409 
    410 /** Find the device node structure of the device witch has the specified handle.
    411  *
    412  * @param tree          The device tree where we look for the device node.
    413  * @param handle        The handle of the device.
    414  * @return              The device node.
    415  */
    416 static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
    417 {
    418         node_t *node = NULL;
    419        
    420         fibril_rwlock_read_lock(&tree->rwlock);
    421         node = find_dev_node_no_lock(tree, handle);
    422         fibril_rwlock_read_unlock(&tree->rwlock);
    423        
    424         return node;
    425 }
    426 
     308extern node_t *create_dev_node(void);
     309extern void delete_dev_node(node_t *node);
     310extern node_t *find_dev_node_no_lock(dev_tree_t *tree,
     311    device_handle_t handle);
     312extern node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle);
    427313extern node_t *find_dev_node_by_path(dev_tree_t *, char *);
    428314extern node_t *find_node_child(node_t *, const char *);
    429 
    430315
    431316/* Device tree */
     
    435320extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *);
    436321
    437 
    438322/* Device classes */
    439323
    440 /** Create device class.
    441  *
    442  * @return      Device class.
    443  */
    444 static inline dev_class_t *create_dev_class(void)
    445 {
    446         dev_class_t *cl;
    447        
    448         cl = (dev_class_t *) malloc(sizeof(dev_class_t));
    449         if (cl != NULL) {
    450                 memset(cl, 0, sizeof(dev_class_t));
    451                 list_initialize(&cl->devices);
    452                 fibril_mutex_initialize(&cl->mutex);
    453         }
    454        
    455         return cl;
    456 }
    457 
    458 /** Create device class info.
    459  *
    460  * @return              Device class info.
    461  */
    462 static inline dev_class_info_t *create_dev_class_info(void)
    463 {
    464         dev_class_info_t *info;
    465        
    466         info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
    467         if (info != NULL)
    468                 memset(info, 0, sizeof(dev_class_info_t));
    469        
    470         return info;
    471 }
    472 
    473 static inline size_t get_new_class_dev_idx(dev_class_t *cl)
    474 {
    475         size_t dev_idx;
    476        
    477         fibril_mutex_lock(&cl->mutex);
    478         dev_idx = ++cl->curr_dev_idx;
    479         fibril_mutex_unlock(&cl->mutex);
    480        
    481         return dev_idx;
    482 }
    483 
     324extern dev_class_t *create_dev_class(void);
     325extern dev_class_info_t *create_dev_class_info(void);
     326extern size_t get_new_class_dev_idx(dev_class_t *);
    484327extern char *create_dev_name_for_class(dev_class_t *, const char *);
    485328extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *,
     
    490333extern dev_class_t *get_dev_class(class_list_t *, char *);
    491334extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
    492 
    493 static inline void add_dev_class_no_lock(class_list_t *class_list,
    494     dev_class_t *cl)
    495 {
    496         list_append(&cl->link, &class_list->classes);
    497 }
    498 
     335extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
    499336
    500337/* Devmap devices */
     
    503340extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t);
    504341
    505 static inline void class_add_devmap_device(class_list_t *class_list,
    506     dev_class_info_t *cli)
    507 {
    508         unsigned long key = (unsigned long) cli->devmap_handle;
    509        
    510         fibril_rwlock_write_lock(&class_list->rwlock);
    511         hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
    512         fibril_rwlock_write_unlock(&class_list->rwlock);
    513 }
    514 
    515 static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
    516 {
    517         unsigned long key = (unsigned long) node->devmap_handle;
    518         fibril_rwlock_write_lock(&tree->rwlock);
    519         hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
    520         fibril_rwlock_write_unlock(&tree->rwlock);
    521 }
     342extern void class_add_devmap_device(class_list_t *, dev_class_info_t *);
     343extern void tree_add_devmap_device(dev_tree_t *, node_t *);
    522344
    523345#endif
  • uspace/srv/devman/main.c

    ra63ff7d r60898b6  
    6666static driver_t *devman_driver_register(void)
    6767{
     68        ipc_call_t icall;
     69        ipc_callid_t iid;
     70        driver_t *driver = NULL;
     71
    6872        printf(NAME ": devman_driver_register \n");
    6973       
    70         ipc_call_t icall;
    71         ipc_callid_t iid = async_get_call(&icall);
    72         driver_t *driver = NULL;
    73        
     74        iid = async_get_call(&icall);
    7475        if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) {
    7576                ipc_answer_0(iid, EREFUSED);
     
    8586                return NULL;
    8687        }
     88
    8789        printf(NAME ": the %s driver is trying to register by the service.\n",
    8890            drv_name);
     
    9193        driver = find_driver(&drivers_list, drv_name);
    9294       
    93         if (NULL == driver) {
     95        if (driver == NULL) {
    9496                printf(NAME ": no driver named %s was found.\n", drv_name);
    9597                free(drv_name);
     
    146148        }
    147149       
    148         if (NULL == match_id) {
     150        if (match_id == NULL) {
    149151                printf(NAME ": ERROR: devman_receive_match_id - failed to "
    150152                    "allocate match id.\n");
     
    160162        rc = async_data_write_accept((void **) &match_id_str, true, 0, 0, 0, 0);
    161163        match_id->id = match_id_str;
    162         if (EOK != rc) {
     164        if (rc != EOK) {
    163165                delete_match_id(match_id);
    164166                printf(NAME ": devman_receive_match_id - failed to receive "
     
    181183 * @return              Zero on success, negative error code otherwise.
    182184 */
    183 static int
    184 devman_receive_match_ids(ipcarg_t match_count, match_id_list_t *match_ids)
     185static int devman_receive_match_ids(ipcarg_t match_count,
     186    match_id_list_t *match_ids)
    185187{
    186188        int ret = EOK;
     
    205207       
    206208        fibril_rwlock_write_lock(&tree->rwlock);
    207         node_t *parent =  find_dev_node_no_lock(&device_tree, parent_handle);
    208        
    209         if (NULL == parent) {
     209        node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle);
     210       
     211        if (parent == NULL) {
    210212                fibril_rwlock_write_unlock(&tree->rwlock);
    211213                ipc_answer_0(callid, ENOENT);
    212214                return;
    213         }       
     215        }
    214216       
    215217        char *dev_name = NULL;
    216218        int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
    217         if (EOK != rc) {
     219        if (rc != EOK) {
    218220                fibril_rwlock_write_unlock(&tree->rwlock);
    219221                ipc_answer_0(callid, rc);
     
    227229                ipc_answer_0(callid, ENOMEM);
    228230                return;
    229         }       
     231        }
     232
    230233        fibril_rwlock_write_unlock(&tree->rwlock);
    231234       
     
    245248        /* Create devmap path and name for the device. */
    246249        char *devmap_pathname = NULL;
     250
    247251        asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,
    248252            cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
    249         if (NULL == devmap_pathname)
     253        if (devmap_pathname == NULL)
    250254                return;
    251255       
     
    279283       
    280284        node_t *dev = find_dev_node(&device_tree, handle);
    281         if (NULL == dev) {
     285        if (dev == NULL) {
    282286                ipc_answer_0(callid, ENOENT);
    283287                return;
     
    318322       
    319323        driver_t *driver = devman_driver_register();
    320         if (NULL == driver)
     324        if (driver == NULL)
    321325                return;
    322326       
     
    373377        free(pathname);
    374378
    375         if (NULL == dev) {
     379        if (dev == NULL) {
    376380                ipc_answer_0(iid, ENOENT);
    377381                return;
     
    404408                                ipc_answer_0(callid, ENOENT);
    405409                }
    406         }       
    407 }
    408 
    409 static void
    410 devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent)
     410        }
     411}
     412
     413static void devman_forward(ipc_callid_t iid, ipc_call_t *icall,
     414    bool drv_to_parent)
    411415{
    412416        device_handle_t handle = IPC_GET_ARG2(*icall);
    413417       
    414418        node_t *dev = find_dev_node(&device_tree, handle);
    415         if (NULL == dev) {
     419        if (dev == NULL) {
    416420                printf(NAME ": devman_forward error - no device with handle %x "
    417421                    "was found.\n", handle);
     
    423427       
    424428        if (drv_to_parent) {
    425                 if (NULL != dev->parent)
     429                if (dev->parent != NULL)
    426430                        driver = dev->parent->drv;
    427         } else if (DEVICE_USABLE == dev->state) {
     431        } else if (dev->state == DEVICE_USABLE) {
    428432                driver = dev->drv;
    429                 assert(NULL != driver);
    430         }
    431        
    432         if (NULL == driver) {
     433                assert(driver != NULL);
     434        }
     435       
     436        if (driver == NULL) {
    433437                printf(NAME ": devman_forward error - the device is not in "
    434438                    "usable state.\n", handle);
     
    450454                return;
    451455        }
     456
    452457        printf(NAME ": devman_forward: forward connection to device %s to "
    453458            "driver %s.\n", dev->pathname, driver->name);
     
    460465{
    461466        dev_handle_t devmap_handle = IPC_GET_METHOD(*icall);
    462        
    463         node_t *dev = find_devmap_tree_device(&device_tree, devmap_handle);
    464         if (NULL == dev)
     467        node_t *dev;
     468
     469        dev = find_devmap_tree_device(&device_tree, devmap_handle);
     470        if (dev == NULL)
    465471                dev = find_devmap_class_device(&class_list, devmap_handle);
    466472       
    467         if (NULL == dev || NULL == dev->drv) {
     473        if (dev == NULL || dev->drv == NULL) {
    468474                ipc_answer_0(iid, ENOENT);
    469475                return;
    470476        }
    471477       
    472         if (DEVICE_USABLE != dev->state || dev->drv->phone <= 0) {
     478        if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
    473479                ipc_answer_0(iid, EINVAL);
    474480                return;
     
    493499         * passes device handle to the driver as an ipc method.)
    494500         */
    495         if (IPC_M_CONNECT_ME_TO != IPC_GET_METHOD(*icall))
     501        if (IPC_GET_METHOD(*icall) != IPC_M_CONNECT_ME_TO)
    496502                devman_connection_devmapper(iid, icall);
    497503
     
    531537        /* Initialize list of available drivers. */
    532538        init_driver_list(&drivers_list);
    533         if (0 == lookup_available_drivers(&drivers_list,
    534             DRIVER_DEFAULT_STORE)) {
     539        if (lookup_available_drivers(&drivers_list,
     540            DRIVER_DEFAULT_STORE) == 0) {
    535541                printf(NAME " no drivers found.");
    536542                return false;
    537543        }
     544
    538545        printf(NAME ": devman_init  - list of drivers has been initialized.\n");
    539546
  • uspace/srv/devman/match.c

    ra63ff7d r60898b6  
    5555                match_id_t *tmp_ma_id;
    5656       
    57                 if (0 == str_cmp(drv_id->id, dev_id->id)) {
     57                if (str_cmp(drv_id->id, dev_id->id) == 0) {
    5858                        /*
    5959                         * We found a match.
     
    6767                 * list of match ids.
    6868                 */
    69                 if (drv_head != drv_link->next) {
     69                if (drv_link->next != drv_head) {
    7070                        tmp_ma_id = list_get_instance(drv_link->next,
    7171                            match_id_t, link);
     
    7979                 * list of match ids.
    8080                 */
    81                 if (dev_head != dev_link->next) {
     81                if (dev_link->next != dev_head) {
    8282                        tmp_ma_id = list_get_instance(dev_link->next,
    8383                            match_id_t, link);
     
    9999                }
    100100               
    101         } while (drv_head != drv_link->next && dev_head != dev_link->next);
     101        } while (drv_link->next != drv_head && dev_link->next != dev_head);
    102102       
    103103        return 0;
  • uspace/srv/devman/util.c

    ra63ff7d r60898b6  
    6161char *get_path_elem_end(char *path)
    6262{
    63         while (0 != *path && '/' != *path)
     63        while (*path != '\0' && *path != '/')
    6464                path++;
    6565        return path;
    6666}
    6767
     68bool skip_spaces(char **buf)
     69{
     70        while (isspace(**buf))
     71                (*buf)++;
     72        return *buf != 0;
     73}
     74
     75size_t get_nonspace_len(const char *str)
     76{
     77        size_t len = 0;
     78       
     79        while(*str != '\0' && !isspace(*str)) {
     80                len++;
     81                str++;
     82        }
     83
     84        return len;
     85}
     86
     87void free_not_null(const void *ptr)
     88{
     89        if (ptr != NULL)
     90                free(ptr);
     91}
     92
     93char *clone_string(const char *s)
     94{
     95        size_t size = str_size(s) + 1;
     96        char *str;
     97       
     98        str = (char *) malloc(size);
     99        if (str != NULL)
     100                str_cpy(str, size, s);
     101        return str;
     102}
     103
     104void replace_char(char *str, char orig, char repl)
     105{
     106        while (*str) {
     107                if (*str == orig)
     108                        *str = repl;
     109                str++;
     110        }
     111}
     112
    68113/** @}
    69114 */
  • uspace/srv/devman/util.h

    ra63ff7d r60898b6  
    4141extern char *get_path_elem_end(char *);
    4242
    43 static inline bool skip_spaces(char **buf)
    44 {
    45         while (isspace(**buf))
    46                 (*buf)++;
    47         return *buf != 0;
    48 }
    49 
    50 static inline size_t get_nonspace_len(const char *str)
    51 {
    52         size_t len = 0;
    53        
    54         while(*str != 0 && !isspace(*str)) {
    55                 len++;
    56                 str++;
    57         }
    58         return len;
    59 }
    60 
    61 static inline void free_not_null(const void *ptr)
    62 {
    63         if (NULL != ptr)
    64                 free(ptr);
    65 }
    66 
    67 static inline char *clone_string(const char *s)
    68 {
    69         size_t size = str_size(s) + 1;
    70         char *str;
    71        
    72         str = (char *) malloc(size);
    73         if (NULL != str)
    74                 str_cpy(str, size, s);
    75         return str;
    76 }
    77 
    78 static inline void replace_char(char *str, char orig, char repl)
    79 {
    80         while (*str) {
    81                 if (orig == *str)
    82                         *str = repl;
    83                 str++;
    84         }
    85 }
     43extern bool skip_spaces(char **);
     44extern size_t get_nonspace_len(const char *);
     45extern void free_not_null(const void *);
     46extern char *clone_string(const char *);
     47extern void replace_char(char *, char, char);
    8648
    8749#endif
Note: See TracChangeset for help on using the changeset viewer.