errno.hを追跡していたらひどい目にあった

エラーコード12が何なのか調べようとして気軽に「less /usr/include/errno.h」としたところ、実はこのファイルにはエラー番号の定義はないことを発見した。おそらく、ここからincludeされているにあるらしい。

/* Get the error number constants from the system-specific file.
   This file will test __need_Emath and _ERRNO_H.  */
#include <bits/errno.h>

このbits/errno.hを見てみると、しかしここにもない。

#ifdef _ERRNO_H

# undef EDOM
# undef EILSEQ
# undef ERANGE
# include <linux/errno.h>

更に、linux/errno.hがインクルードされているので、ここのようだ。中を見てみると

#ifndef _LINUX_ERRNO_H
#define _LINUX_ERRNO_H

#include <asm/errno.h>


#endif

しかしごらんのとおり、これもただasm/errno.hにエイリアスしているだけ。今度こそ、と思いきや、またも...

#include <asm-generic/errno.h>

というわけでasm-generic/errno.hを見てみると、遂にエラー番号らしき定義が!!


でも、ここにも12はない。どうもそいつらはasm-generic/errno-base.hから来ているらしい。

#define      ENOMEM         12      /* Out of memory */

というわけで、ようやく定義が見つかった。


やれやれ、これだからCはやってられないぜ。