OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / stdlib / malloc / calloc.c
1 /* vi: set sw=4 ts=4: */
2 /* calloc for uClibc
3  *
4  * Copyright (C) 2002 by Erik Andersen <andersen@uclibc.org>
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU Library General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
14  * for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
24
25 libc_hidden_proto(memset)
26
27 void * calloc(size_t nmemb, size_t lsize)
28 {
29         void *result;
30         size_t size=lsize * nmemb;
31
32         /* guard vs integer overflow, but allow nmemb
33          * to fall through and call malloc(0) */
34         if (nmemb && lsize != (size / nmemb)) {
35                 __set_errno(ENOMEM);
36                 return NULL;
37         }
38         if ((result=malloc(size)) != NULL) {
39                 memset(result, 0, size);
40         }
41         return result;
42 }
43