0

I am trying to employ the function os_zalloc(), but can't seem to find which header file to include. According to a stackoverflow question: What is zalloc in embedded programming?, the definition should be given in mem.h. including mem.h without specifying a particular path gives the error:

test.c:1:17: fatal error: mem.h: No such file or directory  
#include <mem.h>

I have a couple of files that claim they are mem.h. The two first files contain no data. While the next two files don't have os_zalloc() defined.

root@main:/# find / -name "mem.h"
usr/src/linux-headers-3.13.0-32-generic/include/config/infiniband/user/mem.h
/usr/src/linux-headers-3.13.0-32-generic/include/config/fix/earlycon/mem.h
/usr/src/linux-headers-3.13.0-32/arch/um/include/shared/mem.h
/usr/src/linux-headers-3.13.0-32/arch/mips/include/asm/mach-loongson/mem.h

Therefore, including any of these files in the program and compiling them with the specified path results in the error:

test.c:328: undefined reference to `os_zalloc'
collect2: error: ld returned 1 exit status

I have also tried to include memory.h. This works fine. But the function os_zalloc don't seem to be specified here either:

#include <memory.h>

The short question is that I would like to employ the function os_zalloc() but I can't seem to know what to include it (or if it even exist on my system). Does anybody have any suggestion?

Itchydon
  • 2,572
  • 6
  • 19
  • 33
Madde
  • 471
  • 1
  • 7
  • 22
  • Why do you want to use it and are you writing *kernel* or *userspace* code? –  Aug 17 '17 at 11:26
  • @Felix Palmen i am writting a userspace program to communicate with nl80211. I have had problems understanding how to communicate correctly with nl80211 as there is quite sparse with documentation. I therefore decided to look at the source code of hostapd, where they among other things use os_zalloc(). – Madde Aug 17 '17 at 11:32
  • The places where you found declarations don't seem to be for userspace usage. My linux system doesn't provide such a function. Maybe what you found uses some SDK (along with a library) providing this function... –  Aug 17 '17 at 11:43
  • If you need zeroed-out memory, what keeps you from using `calloc()` then? For userspace programs this should perfectly do. If cooking copypasta and being lazy just add a `#define os_zalloc(size) calloc(size, 1)` at the appropriate place. – alk Aug 17 '17 at 11:47
  • @alk i am fairly new to C programming, but is there no specific differences between calloc and zalloc? Do the functions accomplishes the exact same? – Madde Aug 17 '17 at 11:55
  • 1
    @Madde: `calloc()` is a *standard C function*. With a complete implementation of C, you can use it (include `stdlib.h`). `zalloc()` / `os_zalloc()` aren't. –  Aug 17 '17 at 12:25
  • To be honest I do not know `os_zalloc()`. It isn't part of C. So if you are just after a vanilla memory allocation of heap memory go for what (Standard) C provides, that is `malloc()` and `calloc()` which in fact do the same in terms of allocation, the latter just uses an a bit more complicated way to receive the number of bytes to allocate and it `0`s out the allocated memory whereas the former leaves any garbage in. – alk Aug 17 '17 at 12:27

0 Answers0