資源簡介
深入理解操作系統(tǒng)中的頭文件和源代碼,此處提供下載,免于自己敲代碼

代碼片段和文件信息
/*?$begin?csapp.c?*/
#include?“csapp.h“
/**************************?
?*?Error-handling?functions
?**************************/
/*?$begin?errorfuns?*/
/*?$begin?unixerror?*/
void?unix_error(char?*msg)?/*?unix-style?error?*/
{
????fprintf(stderr?“%s:?%s\n“?msg?strerror(errno));
????exit(0);
}
/*?$end?unixerror?*/
void?posix_error(int?code?char?*msg)?/*?posix-style?error?*/
{
????fprintf(stderr?“%s:?%s\n“?msg?strerror(code));
????exit(0);
}
void?dns_error(char?*msg)?/*?dns-style?error?*/
{
????fprintf(stderr?“%s:?DNS?error?%d\n“?msg?h_errno);
????exit(0);
}
void?app_error(char?*msg)?/*?application?error?*/
{
????fprintf(stderr?“%s\n“?msg);
????exit(0);
}
/*?$end?errorfuns?*/
/*********************************************
?*?Wrappers?for?Unix?process?control?functions
?********************************************/
/*?$begin?forkwrapper?*/
pid_t?Fork(void)?
{
????pid_t?pid;
????if?((pid?=?fork())?0)
unix_error(“Fork?error“);
????return?pid;
}
/*?$end?forkwrapper?*/
void?Execve(const?char?*filename?char?*const?argv[]?char?*const?envp[])?
{
????if?(execve(filename?argv?envp)?0)
unix_error(“Execve?error“);
}
/*?$begin?wait?*/
pid_t?Wait(int?*status)?
{
????pid_t?pid;
????if?((pid??=?wait(status))?0)
unix_error(“Wait?error“);
????return?pid;
}
/*?$end?wait?*/
pid_t?Waitpid(pid_t?pid?int?*iptr?int?options)?
{
????pid_t?retpid;
????if?((retpid??=?waitpid(pid?iptr?options))?0)?
unix_error(“Waitpid?error“);
????return(retpid);
}
/*?$begin?kill?*/
void?Kill(pid_t?pid?int?signum)?
{
????int?rc;
????if?((rc?=?kill(pid?signum))?0)
unix_error(“Kill?error“);
}
/*?$end?kill?*/
void?Pause()?
{
????(void)pause();
????return;
}
unsigned?int?Sleep(unsigned?int?secs)?
{
????unsigned?int?rc;
????if?((rc?=?sleep(secs))?0)
unix_error(“Sleep?error“);
????return?rc;
}
unsigned?int?Alarm(unsigned?int?seconds)?{
????return?alarm(seconds);
}
?
void?Setpgid(pid_t?pid?pid_t?pgid)?{
????int?rc;
????if?((rc?=?setpgid(pid?pgid))?0)
unix_error(“Setpgid?error“);
????return;
}
pid_t?Getpgrp(void)?{
????return?getpgrp();
}
/************************************
?*?Wrappers?for?Unix?signal?functions?
?***********************************/
/*?$begin?sigaction?*/
handler_t?*Signal(int?signum?handler_t?*handler)?
{
????struct?sigaction?action?old_action;
????action.sa_handler?=?handler;??
????sigemptyset(&action.sa_mask);?/*?block?sigs?of?type?being?handled?*/
????action.sa_flags?=?SA_RESTART;?/*?restart?syscalls?if?possible?*/
????if?(sigaction(signum?&action?&old_action)?0)
unix_error(“Signal?error“);
????return?(old_action.sa_handler);
}
/*?$end?sigaction?*/
void?Sigprocmask(int?how?const?sigset_t?*set?sigset_t?*oldset)
{
????if?(sigprocmask(how?set?oldset)?0)
unix_error(“Sigprocmask?error“);
????return;
}
void?Sigemptyset(sigset_t?*set)
{
????if?(sigemptyset(set)?0)
unix_error(“Sigemptyset?error“);
????return;
}
void?Sigfillset(sigset_t?*set)
{?
????if?(sigfillset(set)?0)
unix_error(“Sigfillset?error
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????17746??2011-04-02?16:02??csapp.c
?????文件???????5581??2011-04-02?14:16??csapp.h
-----------?---------??----------?-----??----
????????????????23327????????????????????2
評論
共有 條評論