본문 바로가기

system programing

File mode checker APUE 책에 IF - ELSE로 구현 된 것을 switch - case로 재구현 한 것. stat 스트럭쳐 의 st_mode 의 내부를 들여다 본 것. 헤더파일과 구현부로 나뉘어 있음. /* Header : myhdr.h */ #include #include #include "ourhdr.h" //Defined Values #define N_IFREG 32768 // 1000 0000 0000 0000 #define N_IFDIR 16384 // 0100 0000 0000 0000 #define N_IFCHR 8192 // 0010 0000 0000 0000 #define N_IFBLK 24576 // 0110 0000 0000 0000 #define N_IFIFO 4096 // 0001 0000 00.. 더보기
myShell 입력받은 커맨드를 실행하고, 그 실행 시간을 측정한다. 유닉스 쉘의 입력 부분만 흉내낸 것 Get command from user, then calculate the command's execute time. This is a simple UNIX shell. Just make command input part #include //for types for time and etc. #include //for wait() #include //for signal catching #include "ourhdr.h" //System Programming Default Header #include //for times() //functions static void sig_int(int); /* our signal-.. 더보기
myCAT : cat(1) 파일의 내용을 보여주거나, 둘 이상의 파일을 내용을 합쳐서 출력해주는 cat(1)을 직접 구현한 것. cat는 유닉스에 기본으로 포함되어 있는 명령어이다. #include "ourhdr.h" //기본 헤더파일 //Common header int main (int argc, char *argv[]) { FILE *file[argc-1]; //파일 포인터 배열 : 입력 받은 파일 명의 수 만큼 파일포인터를 선언 int loop; //순환문을 위한 변수 char buffer; //Read Buffer if (argc 더보기
WC : Word Count UNIX의 wc(1)의 기능을 구현한 것. #include "ourhdr.h" //System Programming Default Header enum bool {false, true}; //C dosen't support the "boolean" type. So, I defined as enumeration type. ///////////////////////////////////////// //main function //////////// //////////////////////////////////////// int main (int agrc, char *agrv[]) { int c = 0; //get character input int lines = 0, words = 0 , bytes = 0;.. 더보기
error.c Advanced Programming in the UNIX Environment 의 기본적인 error처리 library. 컴파일 해서 Object파일을 만든 후, 실제 실행파일 컴파일 시 링크시켜 줄 것. #include /* for definition of errno */ #include /* ANSI C header file */ #include "ourhdr.h" static void err_doit(int, const char *, va_list); char *pname = NULL; /* caller can set this from argv[0] */ /* Nonfatal error related to a system call. * Print a message and return. */ voi.. 더보기
ourhdr.h 역시, Advanced Programming in the UNIX Environment(이하 APUE)의 기본 헤더파일. 다운 받아도 좋고, 직접 긁어 저장해도 좋다. /* Our own header, to be included *after* all standard system headers */ #ifndef __ourhdr_h #define __ourhdr_h #include /* required for some of our prototypes */ #include /* for convenience */ #include /* for convenience */ #include /* for convenience */ #include /* for convenience */ #define MAXLINE 40.. 더보기
Advanced Programming in the UNIX Environment http://www.yendor.com/programming/unix/apue/apue.html Advanced Programming in the UNIX Environment by W. Richard Stevens Addison-Wesley Professional Computing Series 0-201-56317-7 * Hardback * 768 pages * ©1992 Web/HTML/man-page-linking by: Ariel Faigon 위 주소에 가면 이 책의 모든 소스를 구할 수 있다. 정말, 주옥같은 소스코드들이 실려있는 책이다. 아직 본격적으로 본문을 읽지는 않고, 소스코드만 보고 있는데, 그것만으로도 이 책의 진가를 알 수 있다. 더보기