ourhead.h

来自「linux 高级编程的例子源码,包括了本书上的所有代码」· C头文件 代码 · 共 70 行

H
70
字号
/*filename:ourhead.h*/
#ifndef _OURHEAD_H
#define _OURHEAD_H

#include <error.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/un.h>
#include <sys/select.h>
#include <poll.h>
#include <string.h>
#include <sys/ioctl.h>
#include <pthread.h>
#define LISTENQ 1024
#ifndef MAXLINE
#define MAXLINE 4096
#endif
#define BUFFERSIZE 8192
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
ssize_t readline(int fd,void *vptr,size_t maxlen)
 {
	 ssize_t rc,n;
	 char c,*ptr;

	 ptr=vptr;
         
  for (n=1;n<maxlen;n++)
	 {
   again:
	   if((rc=read(fd,&c,1))==1)
	   {
		   *ptr++=c;
		   if (c=='\n')
			   break;   
	   }
	   else if (rc==0)
	   {
		   if (n==1)
			   return 0;  /*EOF ,no data read*/
		   else 
			   break;     /*EOF,some data read*/
	   }
	   else
	   {
		   if (errno==EINTR)
			   goto again;
		   return (-1);
	   }
	 }
	 *ptr=0;
	 return n;
 }
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?