我正在为STM32F7编写嵌入式软件,而我的libc是newlib-2.4.0.20160527。
我已经实现_sbrk()
如下:
extern intptr_t g_bss_end; /* value after the last byte in .bss */
extern intptr_t g_msp_lim; /* stack buffer starts at this address */
intptr_t _sbrk(ptrdiff_t heap_incr)
{
static intptr_t heap_end = 0;
intptr_t prev_heap_end;
intptr_t new_heap_end;
if(heap_end == 0) {
heap_end = (intptr_t)&g_bss_end;
}
prev_heap_end = heap_end;
new_heap_end = prev_heap_end + heap_incr;
if(new_heap_end >= g_msp_lim) {
errno = ENOMEM;
return -1;
}
heap_end = new_heap_end;
return prev_heap_end;
}
Run Code Online (Sandbox Code Playgroud)
然后,当我执行以下操作时:
/* total capacity of my heap is …
Run Code Online (Sandbox Code Playgroud) 我想从 Linux Kernel v3.0.8 中检查文件的内容,只知道struct inode *
. 我只需要读取这个 inode 指向的文件的开头,然后关闭并返回。我不关心文件名/挂载点等附加信息。事实上,文件可能没有名称(如已删除但仍打开)。是否可以?
我使用了以下代码:
auto t = numeric_limits<decltype(m)>::max() - 1;
Run Code Online (Sandbox Code Playgroud)
后来,我需要#include <Windows.h>
哪个#define max(a, b)
指令,所以我不能使用::max()
方法.有没有办法在::max()
不使用时调用时抑制宏扩展#undef max
?
c ×2
c++ ×1
embedded ×1
file ×1
inode ×1
linux-kernel ×1
malloc ×1
newlib ×1
preprocessor ×1
sbrk ×1