C sbrk(0)会失败吗?

C sbrk(0)会失败吗?,c,glibc,sbrk,C,Glibc,Sbrk,我想知道是否有人已经看到sbrk(0)失败了 我的意思是,如果你能达到这个功能,你显然有权访问内存,所以检查当前的中断位置应该是可以的,对吗 < P>编辑:我是否应该考虑一个错误异常(例如:< P>): sbrk() increments the program's data space by increment bytes. Calling sbrk() with an increment of 0 can be used to find the current locati

我想知道是否有人已经看到sbrk(0)失败了

我的意思是,如果你能达到这个功能,你显然有权访问内存,所以检查当前的中断位置应该是可以的,对吗

< P>编辑:我是否应该考虑一个错误异常(例如:

< P>):
   sbrk() increments the program's data space by increment bytes.
   Calling sbrk() with an increment of 0 can be used to find the current
   location of the program break.

  ...

   On success, sbrk() returns the previous program break.  (If the break
   was increased, then this value is a pointer to the start of the newly
   allocated memory).  On error, (void *) -1 is returned, and errno is
   set to ENOMEM.
如果您查看实现,您将看到:

extern void *__curbrk;
  ...
void *
__sbrk (intptr_t increment)
{
  ...
  if (increment == 0)
    return __curbrk; 
  ...

它不可能失败,因为如果
increment
为零,它只返回
\uuu curbrk
的当前值。

我认为它失败了?我使用它的方式至少从来没有引导我出错。有趣的是,根据文档中松散的措辞,它实际上可能会失败。当然,这完全是胡说八道。
sbrk(2)
的Mac OS X文档中说:
sbrk(0)
可靠地返回了程序中断的当前值。非常感谢你终于得到了它。也看了一眼:)