Changeset 44e8541 in mainline for common/stdc/calloc.c


Ignore:
Timestamp:
2023-10-27T17:38:32Z (16 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, topic/msim-upgrade, topic/simplify-dev-export
Children:
fdfb24e
Parents:
b169619
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-27 15:17:18)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-10-27 17:38:32)
Message:

Move stdlib.h and some of its function into /common

File:
1 moved

Legend:

Unmodified
Added
Removed
  • common/stdc/calloc.c

    rb169619 r44e8541  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2009 Martin Decky
     3 * Copyright (c) 2009 Petr Tuma
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 /** @addtogroup kernel_generic_mm
    30  * @{
     30#include <stdlib.h>
     31
     32#include <mem.h>
     33
     34/** Allocate memory by number of elements
     35 *
     36 * @param nmemb Number of members to allocate.
     37 * @param size  Size of one member in bytes.
     38 *
     39 * @return Allocated memory or NULL.
     40 *
    3141 */
    32 /** @file
    33  */
     42void *calloc(const size_t nmemb, const size_t size)
     43{
     44        // Check for overflow
     45        if (SIZE_MAX / size < nmemb)
     46                return NULL;
    3447
    35 #ifndef KERN_STDLIB_H_
    36 #define KERN_STDLIB_H_
     48        void *block = malloc(nmemb * size);
     49        if (block == NULL)
     50                return NULL;
    3751
    38 #include <stddef.h>
    39 
    40 extern void *malloc(size_t)
    41     __attribute__((malloc));
    42 extern void *realloc(void *, size_t)
    43     __attribute__((warn_unused_result));
    44 extern void free(void *);
    45 
    46 #endif
    47 
    48 /** @}
    49  */
     52        memset(block, 0, nmemb * size);
     53        return block;
     54}
Note: See TracChangeset for help on using the changeset viewer.