エラーの調べ方 (errno と perror())

システム・プログラム

                                       電子・情報工学系
                                       新城 靖
                                       <yas@is.tsukuba.ac.jp>

このページは、次の URL にあります。
http://www.hlla.is.tsukuba.ac.jp/~yas/coins/syspro-2000/2000-04-24 /errno.html
あるいは、次のページから手繰っていくこともできます。
http://www.hlla.is.tsukuba.ac.jp/~yas/coins/
http://www.is.tsukuba.ac.jp/~yas/index-j.html

■errno と perror()

システムコールでエラーが起きた時には、errno にエラーの番号がセットされ る。それを表示するには、perror() が便利である。

----------------------------------------------------------------------
   1:	/*
   2:	        errno-perror.c -- errno, perror() のテスト
   3:	        ~yas/syspro1/cc/errno-perror.c
   4:	        $Header: /home/lab2/OS/yas/syspro1/cc/RCS/errno-perror.c,v 1.2 1998/04/27 16:36:04 yas Exp $
   5:	        Start: 1997/05/05 16:42:22
   6:	*/
   7:	
   8:	#include <errno.h>
   9:	
  10:	main()
  11:	{
  12:	        errno = 0 ;
  13:	        perror("0");
  14:	        errno = EACCES ;
  15:	        perror("EACCES");
  16:	}
----------------------------------------------------------------------

実行例。
----------------------------------------------------------------------
% ./errno-perror [←]
0: Error 0
EACCES: Permission denied
% egrep EACCES /usr/include/errno.h  [←]
% egrep EACCES /usr/include/sys/errno.h [←]
#define EACCES  13      /* Permission denied                    */
% []
----------------------------------------------------------------------

↑[もどる] ←[4月17日] ・[4月24日] →[5月01日]
Last updated: 2000/04/23 00:11:42
Yasushi Shinjo / <yas@is.tsukuba.ac.jp>