文档详情

Linux系统调用-uname函数详解.doc

发布:2017-07-05约2.86千字共3页下载文档
文本预览下载声明
Function : uname() Header in #include sys/utsname.h theory of functions:extern int uname (struct utsname *__name) __THROW; return 0 if success, return -1 if failed, when errno is setted EFAULT, it means buffer is invalid。 you can use “man uname” to know it in detail。 Argument __name :store system information. struct utsname ? { char sysname[_UTSNAME_SYSNAME_LENGTH];// current operating system name ?? char nodename[_UTSNAME_NODENAME_LENGTH];//the name of the network ?? char release[_UTSNAME_RELEASE_LENGTH];//the curren release level ?? char version[_UTSNAME_VERSION_LENGTH];//the current release ?? char machine[_UTSNAME_MACHINE_LENGTH];//types of current hardware systems #if _UTSNAME_DOMAIN_LENGTH - 0 ??? /* Name of the domain of this node on the network.? */ # ifdef __USE_GNU ??? char domainname[_UTSNAME_DOMAIN_LENGTH]; //current domain’s name # else ??? char __domainname[_UTSNAME_DOMAIN_LENGTH]; # endif #endif ? }; for example: #include sys/utsname.h #include stdio.h #include stdlib.h int main() { ??? struct utsname testbuff; ??? int fb=0; ??? fb=uname(testbuff); ??? if(fb0) ??? { ??????? perror(uname); ??????? return 0; ??? }else ??? { ??????? printf( sysname:%s\n nodename:%s\n release:%s\n version:%s\n machine:%s\n \n ,\ ??????????????????? testbuff.sysname,\ ??????????????????? testbuff.nodename,\ ??????????????????? testbuff.release,\ ??????????????????? testbuff.version,\ ??????????????????? testbuff.machine); #if _UTSNAME_DOMAIN_LENGTH - 0 # ifdef __USE_GNU ??? printf( domainame:%s\n ,testbuff.domainname); ??? //char domainname[_UTSNAME_DOMAIN_LENGTH]; //current domain’s name # else ??? printf( __domainame:%s\n ,testbuff.__domainname); ??? //char __domainname[_UTSNAME_DOMAIN_LENGTH]; # endif #endif ??? } return 0; } for my machine : the program is to test byte order #include unp.h #include sys/utsname.h int main(int argc, char **argv) { struct utsname testbuff; int fb=0; union { short s; char c[sizeof(short)]; } un; fb=uname(te
显示全部
相似文档