This is the mail archive of the
ecos-devel@sourceware.org
mailing list for the eCos project.
Re: Elegant substitute for kzalloc() through #define?
- From: Sergei Gavrikov <sergei dot gavrikov at gmail dot com>
- To: Max SeidenstÃcker <naturally-aligned at web dot de>
- Cc: ecos-devel at ecos dot sourceware dot org
- Date: Wed, 28 Aug 2013 16:14:38 +0300 (FET)
- Subject: Re: Elegant substitute for kzalloc() through #define?
- Authentication-results: sourceware.org; auth=none
- References: <1377692630382-242405 dot post at n7 dot nabble dot com>
What's about
#define kzalloc(size, flags) calloc(size, 1)
See calloc(3) http://linux.die.net/man/3/calloc
Sergei
On Wed, 28 Aug 2013, Max SeidenstÃcker wrote:
> As I am trying to touch as few source files as possible I am looking for a
> good way to substitute a call to Linux kzalloc(). This function allocates
> and zeroes the memory before returning the pointer. So a call to malloc()
> and then memset() in eCos is my approach.
>
> How can a #define be written to do the trick, so I don't need to touch the
> source file in this area with #ifdef __ECOS ?
>
> struct jffs2_inode_info *f = kzalloc(sizeof(*f), GFP_KERNEL);
> if (!f)
> return -ENOMEM;
>
> #define kzalloc(x,y) \
> malloc(x); \
> if (HOW_TO_MAKE_SURE_MALLOC_WAS_SUCCESSFUL) { \
> memset(tmp,0,x);\
> }
>
> Regards
> Max Seidenstuecker
>
>
>
> --
> View this message in context: http://sourceware-org.1504.n7.nabble.com/Elegant-substitute-for-kzalloc-through-define-tp242405.html
> Sent from the Sourceware - ecos-devel mailing list archive at Nabble.com.
>