Changeset 44e8541 in mainline for common


Ignore:
Timestamp:
2023-10-27T17:38:32Z (2 years 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

Location:
common
Files:
6 moved

Legend:

Unmodified
Added
Removed
  • common/include/stdlib.h

    rb169619 r44e8541  
    4141#include <_bits/decls.h>
    4242#include <bsearch.h>
    43 #include <malloc.h>
    4443#include <qsort.h>
    4544
     
    109108extern lldiv_t lldiv(long long, long long);
    110109
     110extern void *malloc(size_t size)
     111    __attribute__((malloc));
     112extern void *calloc(size_t nmemb, size_t size)
     113    __attribute__((malloc));
     114extern void *realloc(void *addr, size_t size)
     115    __attribute__((warn_unused_result));
     116extern void free(void *addr);
     117
     118#ifdef _HELENOS_SOURCE
     119__HELENOS_DECLS_BEGIN;
     120
     121extern void *memalign(size_t align, size_t size)
     122    __attribute__((malloc));
     123
     124__HELENOS_DECLS_END;
     125#endif
     126
    111127__C_DECLS_END;
    112128
  • 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.