• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ err_quit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中err_quit函数的典型用法代码示例。如果您正苦于以下问题:C++ err_quit函数的具体用法?C++ err_quit怎么用?C++ err_quit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了err_quit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: main

int
main(int argc, char **argv)
{
	int		fd1, fd2, *ptr1, *ptr2;
	pid_t	childpid;
	struct stat	stat;

	if (argc != 2)
		err_quit("usage: test3 <name>");

	// shm_unlink(Px_ipc_name(argv[1]));
	// fd1 = Shm_open(Px_ipc_name(argv[1]), O_RDWR | O_CREAT | O_EXCL, FILE_MODE);
	shm_unlink(argv[1]);
	fd1 = Shm_open(argv[1], O_RDWR | O_CREAT | O_EXCL, FILE_MODE);

	Ftruncate(fd1, sizeof(int));
	fd2 = Open("/etc/motd", O_RDONLY);
	Fstat(fd2, &stat);

	if ( (childpid = Fork()) == 0) {
		/* child */
		ptr2 = Mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd2, 0);
		ptr1 = Mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE,
					MAP_SHARED, fd1, 0);
		printf("child: shm ptr = %p, motd ptr = %p\n", ptr1, ptr2);

		sleep(5);
		printf("shared memory integer = %d\n", *ptr1);
		exit(0);
	}
	/* parent: mmap in reverse order from child */
	ptr1 = Mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd1, 0);
	ptr2 = Mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd2, 0);
	printf("parent: shm ptr = %p, motd ptr = %p\n", ptr1, ptr2);
	*ptr1 = 777;
	Waitpid(childpid, NULL, 0);

	exit(0);
}
开发者ID:vonzhou,项目名称:UNPv2,代码行数:39,代码来源:test3.c


示例2: main

int
main(int argc, char *argv[])
{
    int        ret;

    if (argc != 2)
        err_quit("usage:  ftw  <starting-pathname>");

    ret = myftw(argv[1], myfunc);        /* does it all */

    if ( (ntot = nreg + ndir + nblk + nchr + nfifo + nslink + nsock) == 0)
        ntot = 1;        /* avoid divide by 0; print 0 for all counts */
    printf("regular files  = %7ld, %5.2f %%\n", nreg,  nreg*100.0/ntot);
    printf("directories    = %7ld, %5.2f %%\n", ndir,  ndir*100.0/ntot);
    printf("block special  = %7ld, %5.2f %%\n", nblk,  nblk*100.0/ntot);
    printf("char special   = %7ld, %5.2f %%\n", nchr,  nchr*100.0/ntot);
    printf("FIFOs          = %7ld, %5.2f %%\n", nfifo, nfifo*100.0/ntot);
    printf("symbolic links = %7ld, %5.2f %%\n", nslink,nslink*100.0/ntot);
    printf("sockets        = %7ld, %5.2f %%\n", nsock, nsock*100.0/ntot);

    exit(ret);
}
开发者ID:no7dw,项目名称:cpp-learning,代码行数:22,代码来源:ftw4.c


示例3: main

int main(int argc, char *argv[])
{
	int val;
	if (argc != 2)
		err_quit("usage: a.out <descriptor#>");
	if ((val = fcntl(atoi(argv[1]), F_GETFL, 0)) < 0)
		err_sys("fcntl error for fd %d", atoi(argv[1]));
	
	switch (val &O_ACCMODE) {
	case O_RDONLY:
		printf("read only");
		break;
	case O_WRONLY:
		printf("write only");
		break;
	case O_RDWR:
		printf("read write");
		break;
	default:
		err_dump("unknow access mode");
	}

	if (val &O_APPEND)
		printf(", append");
	if (val &O_NONBLOCK)
		printf(", nonblocking");

#if defined(O_SYNC)
	if (val &O_SYNC)
		printf(", syncchronous write");
#endif	

#if !defined(_POSIX_C_SOURCE) && defined(O_SYNC)
	if (val &O_FSYNC)
		printf(", syncchronous write");
#endif	
	putchar('\n');
	exit(0);
}	
开发者ID:tingxueren,项目名称:apue.2e,代码行数:39,代码来源:3-4.c


示例4: main

int
main(int argc, char **argv)
{
  int         sockfd;
  struct sockaddr_in  servaddr;

  if (argc != 2)
    err_quit("usage: tcpcli <IPaddress>");

  sockfd = Socket(AF_INET, SOCK_STREAM, 0);

  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(7);
  Inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

  Connect(sockfd, (SA *) &servaddr, sizeof(servaddr));

  str_cli(stdin, sockfd);   /* do it all */

  exit(0);
}
开发者ID:jiayuehua,项目名称:unpv13e,代码行数:22,代码来源:tcpcli11.c


示例5: main

int main(int argc, const char *argv[]) {
	int fdin, fdout;
	void *src, *dst;
	size_t copysz;
	struct stat sbuf;
	off_t fsz = 0;
	
	if (argc != 0)
		err_quit("usage: %s <fromfile> <tofile>", argv[0]);
	if ((fdin = open(argv[1], O_RDONLY)) < 0)
		err_sys("can`t open %s for reading", argv[1]);
	if ((fdout = open(argv[2], O_RDWR | O_CREAT | O_TRUNC,
		FILE_MODE)) < 0)
		err_sys("can`t creat %s for writing", argv[2]);
	if (fstat(fdin, &sbuf) < 0)
		err_sys("fstat error");
	if (ftruncate(fdout, sbuf.st_size) < 0)
		err_sys("ftruncate error");
	
	while (fsz < sbuf.st_size) {
		if ((sbuf.st_size - fsz) > COPYINCR)
			copysz = COPYINCR;
		else
			copysz = sbuf.st_size - fsz;
		
		if ((src = mmap(0, copysz, PROT_READ, MAP_SHARED,
			fdin, fsz)) == MAP_FAILED)
			err_sys("mmap error for input");
		if ((dst = mmap(0, copysz, PROT_READ | PROT_WRITE,
			MAP_SHARED, fdout, fsz)) == MAP_FAILED)
			err_sys("mmap error for output");
		
		memcpy(dst, src, copysz);
		munmap(src, copysz);
		munmap(dst, copysz);
		fsz += copysz;
	}
	exit(0);
}
开发者ID:dellsun,项目名称:unix,代码行数:39,代码来源:mmap_copy_test.c


示例6: main

int
main(int argc, char **argv)
{
	int					fd;

	if (argc != 2)
		err_quit("usage: checkopts <device>");

	fd = T_open(argv[1], O_RDWR, NULL);
	T_bind(fd, NULL, NULL);

	req = T_alloc(fd, T_OPTMGMT, T_ALL);
	ret = T_alloc(fd, T_OPTMGMT, T_ALL);

	xti_def_uchar_opt(fd, "T_IP_TOS", T_INET_IP, T_IP_TOS);
	xti_def_uchar_opt(fd, "T_IP_TTL", T_INET_IP, T_IP_TTL);

	xti_def_uscalar_opt(fd, "T_TCP_MAXSEG", T_INET_TCP, T_TCP_MAXSEG);
	xti_def_uscalar_opt(fd, "T_TCP_NODELAY", T_INET_TCP, T_TCP_NODELAY);

	exit(0);
}
开发者ID:337240552,项目名称:linux-programming,代码行数:22,代码来源:defaultopts.c


示例7: main

int main(int argc, char **argv)
{
	int c, id, oflag;
	char *ptr;
	size_t length;

	oflag = SVSHM_MODE | IPC_CREAT;
	while ((c = Getopt(argc, argv, "e")) != -1) {
		switch (c) {
			case 'e':
				oflag |= IPC_EXCL;
				break;
		}
	}
	if (optind != argc - 2)
		err_quit("Usage: get [-e] <pathname> <length>");
	length = atoi(argv[optind + 1]);

	id = Shmget(Ftok(argv[optind], 0), length, oflag);
	ptr = Shmat(id, NULL, 0);
	exit(0);
}
开发者ID:crazy-canux,项目名称:cAPI,代码行数:22,代码来源:get.c


示例8: main

int main(int argc, char *argv[]) {
  unsigned int value = 1;
  int flags = O_RDWR | O_CREAT;

  int c;
  while ((c = getopt(argc, argv, "ei:")) != -1) {
    switch (c) {
      case 'e':
        flags |= O_EXCL;
        break;
      case 'i':
        value = atoi(optarg);
        break;
    }
  }

  if (optind != argc - 1)
    err_quit("Usage: semcreate [-e] [-i initvalue] <name>");

  sem_t *sem = sem_open(argv[optind], flags, FILE_MODE, value);
  // sem_close(sem);
}
开发者ID:mahaicheng,项目名称:network-program,代码行数:22,代码来源:semcreate.c


示例9: server

void server(int readfd, int writefd)
{
  int fd;
  ssize_t n;
  char buff[MAXLINE+1];
  
  /*从管道读路径名*/
  if( (n = Read(readfd, buff, MAXLINE)) == 0)
    err_quit("end-of -file while reading pathname");
  buff[n] = '\0';
  
  if( (fd = open(buff, O_RDONLY)) < 0){/*打开文件处理错误*/
    snprintf(buff+n, sizeof(buff) - n, ":can't open, %s\n", 
	     strerror(errno));
    n = strlen(buff);
    Write(writefd, buff, n);
  }else{
    while( (n = Read(fd, buff, MAXLINE)) > 0)/*把文件复制到管道*/
      Write(writefd, buff, n);
    Close(fd);
  }
}
开发者ID:xuyunhuan,项目名称:IPC,代码行数:22,代码来源:server.c


示例10: main

int
main(int argc, char const *argv[])
{
	DIR 			*dp;
	struct dirent 	*dirp;

	if (argc != 2)
	{
		err_quit("usage: ls directory_name");
	}

	if ((dp = opendir(argv[1])) == NULL)
	{
		err_sys("can't open %s", argv[1]);
	}

	while((dirp = readdir(dp)) != NULL)
		printf("%s\n", dirp->d_name);
	
	closedir(dp);
	exit(0);
}
开发者ID:kaiiak,项目名称:APUE,代码行数:22,代码来源:1.3.c


示例11: Remove

ElemType Remove(List list, int position)
{
  if (position < 0 || position > list->value - 1) {
    DestroyList(list);
    err_quit("Remove: position %d out of range, failed.", position);
  }

  Pos pos = list;

  int i;
  for (i = 0; i < position; ++i)
    pos = pos->next;
  
  Node p = pos->next;
  ElemType temp = p->value;

  pos->next = pos->next->next;
  free(p);

  list->value--;
  return temp;
}
开发者ID:huys,项目名称:ds-algorithm,代码行数:22,代码来源:linked_list.c


示例12: copy_identifier

/**
 * Copy identifier
 */
static char *
copy_identifier(const char *id)
{
    size_t	 count    = identifier_maxSize;
    char	*dest_buf = malloc(count + 1);
    char	*dest;

    if (!dest_buf)
	err_exit(ENOMEM, "copy_identifier");
    else {
	dest = &dest_buf[0];
    }

    while ((sw_isalnum(*id) || *id == '_') && count > 1) {
	*dest++ = *id++, count--;
    }

    *dest = '\0';
    if (count == 1)
	err_quit("In copy_identifier: fatal: string was truncated!");
    return (dest_buf);
}
开发者ID:uhlin,项目名称:swirc,代码行数:25,代码来源:interpreter.c


示例13: main

int main(int argc, char **argv) {
    int sockfd;
    int n;
    char recvline[MAXLINE+1];
    socklen_t salen;
    struct sockaddr *sa;

    if (argc != 3)
        err_quit("usage: daytimeudpcli <hostname/IPaddress> <service/port#>");

    sockfd = Udp_client(argv[1], argv[2], (void **)&sa, &salen);

    printf("sending to %s\n", Sock_ntop_host(sa, salen));

    Sendto(sockfd, "", 1, 0, sa, salen); /* send 1-byte datagram */

    n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);
    recvline[n] = '\0';
    Fputs(recvline, stdout);

    exit(0);
}
开发者ID:kitsionchen,项目名称:StudyUNP,代码行数:22,代码来源:daytimeudpcli1.c


示例14: pdapi_recvmsg

uint8_t *
pdapi_recvmsg(int sock_fd,
	      int *rdlen,
	      SA *from,
	      int *from_len,
	      struct sctp_sndrcvinfo *sri,
	      int *msg_flags)
{
	int rdsz,left,at_in_buf;
	int frmlen=0;

	if (sctp_pdapi_readbuf == NULL) {
		sctp_pdapi_readbuf = (uint8_t *)Malloc(SCTP_PDAPI_INCR_SZ);
		sctp_pdapi_rdbuf_sz = SCTP_PDAPI_INCR_SZ;
	}
	at_in_buf = Sctp_recvmsg(sock_fd, sctp_pdapi_readbuf, sctp_pdapi_rdbuf_sz,
				 from, from_len,
				 sri,msg_flags);
	if(at_in_buf < 1){
		*rdlen = at_in_buf;
		return(NULL);
	}
	while((*msg_flags & MSG_EOR) == 0) {
		left = sctp_pdapi_rdbuf_sz - at_in_buf;
		if(left < SCTP_PDAPI_NEED_MORE_THRESHOLD) {
			sctp_pdapi_readbuf = realloc(sctp_pdapi_readbuf, sctp_pdapi_rdbuf_sz+SCTP_PDAPI_INCR_SZ);
			if(sctp_pdapi_readbuf == NULL) {
				err_quit("sctp_pdapi ran out of memory");
			}
			sctp_pdapi_rdbuf_sz += SCTP_PDAPI_INCR_SZ;
			left = sctp_pdapi_rdbuf_sz - at_in_buf;
		}
		rdsz = Sctp_recvmsg(sock_fd, &sctp_pdapi_readbuf[at_in_buf], 
			     left, NULL, &frmlen, NULL, msg_flags);
		at_in_buf += rdsz;
	}
	*rdlen = at_in_buf;
	return(sctp_pdapi_readbuf);
}
开发者ID:AnSwErYWJ,项目名称:UNP,代码行数:39,代码来源:sctp_pdapircv.c


示例15: main

int main(int argc, char *argv[])
{
    int i, fd, n, maxnconn, flags, error;
    char buf[MAXLINE];
    fd_set rs, ws;
    if (argc < 5)
        err_quit("usage: web <#conn> <hostname> <homepage> <file1> ...");
    maxnconn = atoi(argv[1]);
    nfiles = min(argc - 4, MAXFILES);
    for (i = 0; i < nfiles; i++) {
        file[i].f_name = argv[i+4];
        file[i].f_host = argv[2];
        file[i].f_flags = 0;
    }
    printf("nfiles = %d\n", nfiles);

    home_page(argv[2], argv[3]);

    nlefttoread = nlefttoconn = nfiles;
    nconn = 0;

    Signal(SIGCHLD, sig_chld);

    for (i = 0; i < maxnconn; i++) {
        if (Fork() == 0) {
            /*child */
            printf("child %d started\n", getpid());
            home_page(file[i].f_host, file[i].f_name);
            exit(0);
        }
        file[i].f_flags = F_DONE;
    }

    while (nlefttoread > 0) {
        pause();
    }
    printf("all finished\n");
    return(0);
}
开发者ID:GongCun,项目名称:UNIX_Network_Programming_3thEd_Volume1,代码行数:39,代码来源:web2.c


示例16: main

int main(int argc, char** argv)
{
	int sockfd;
	socklen_t len;
	struct sockaddr_un addr1, addr2;
	
	if(argc != 2)
	{
		err_quit("usage: unixbind <pathname>");
	}
	
	sockfd = Socket(AF_LOCAL, SOCK_STREAM, 0);
	unlink(argv[1]);
	bzero(&addr1, sizeof(addr1));
	addr1.sun_family = AF_LOCAL;
	strncpy(addr1.sun_path, argv[1], sizeof(addr1.sun_path)-1);
	Bind(sockfd, (SA*)&addr1, SUN_LEN(&addr1));
	len = sizeof(addr2);
	Getsockname(sockfd, (SA*)&addr2, &len);
	printf("bound name = %s, returned len = %d\n", addr2.sun_path, len);
	exit(0);
}
开发者ID:ldjbenben,项目名称:GameServer,代码行数:22,代码来源:unixbind.c


示例17: err_quit

ssp_lowner_t *ssp_lock_test (int fd, short type, short whence, off_t start,
	off_t len)
{
	flock_t lock;
	static ssp_lowner_t lock_owner;

	lock.l_type = type;
	lock.l_whence = whence;
	lock.l_start = start;
	lock.l_len = len;

	if (fcntl (fd, F_GETLK, &lock) == -1)
		err_quit ("fcntl failed");

	if (lock.l_type == F_UNLCK)
		return (NULL);

	lock_owner.sysid = lock.l_sysid;
	lock_owner.pid = lock.l_pid;

	return (&lock_owner);
}
开发者ID:AlexKordic,项目名称:sandbox,代码行数:22,代码来源:ssp_lock_test.c


示例18: main

main()
{
    int fd[2], on, n;
    char buf[100];
    struct fcred cred;

    if (socketpair(AF_LOCAL, SOCK_STREAM, 0, fd) < 0)
        err_sys("socketpair error");

    /* must set the socket option on the *receiving* socket */
    on = 1;
    Setsockopt(fd[1], 0, LOCAL_CREDS, &on, sizeof(on));

    Write(fd[0], "hello, world\n", 13);

    if ((n = recv_cred(fd[1], buf, sizeof(buf), &cred)) < 0)
        err_sys("recv_cred error");
    else if (n == 0)
        err_quit("recv_cred, unexpected EOF");

    buf[n] = 0; /* null terminate */
    printf("data: %s", buf);

    if (cred.fc_ngroups == 0)
        printf("(no credentials returned)\n");
    else {
        printf("real user ID = %d\n", cred.fc_ruid);
        printf("real group ID = %d\n", cred.fc_rgid);
        printf("login name = %-*s\n", MAXLOGNAME, cred.fc_login);
        printf("effective user ID = %d\n", cred.fc_uid);
        printf("effective group ID = %d\n", cred.fc_gid);
        printf("%d supplementary groups:", cred.fc_ngroups - 1);
        for (n = 1; n < cred.fc_ngroups; n++) /* [0] is the egid */
            printf(" %d", cred.fc_groups[n]);
        printf("\n");
    }

    exit(0);
}
开发者ID:kingfree,项目名称:haut,代码行数:39,代码来源:tfcred01.c


示例19: child_main

void child_main(int fd,socklen_t addrlen)
{
	socklen_t clilen;
	struct sockaddr *cliaddr;
	int	connfd;

	cliaddr = malloc(addrlen);
	for(;;)
	{
		clilen = addrlen;
		my_lock_wait();
		if((connfd = accept(listenfd,cliaddr,&clilen)) < 0)
		{
			if(errno = EINTR)
				continue;
			else
				err_quit("accept error!");
		}
		my_lock_release();
		web_child(connfd);
	}
}
开发者ID:hu010354,项目名称:kaizer,代码行数:22,代码来源:serv03.c


示例20: main

int main(int argc, char **argv) {
	int connfd, n;
	char recvline[MAXLINE + 1];
	connfd = socket(AF_INET, SOCK_STREAM, 0); 
	struct sockaddr_in addr;
	bzero(&addr, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(13);
	if (inet_pton(AF_INET, argv[1], &addr.sin_addr) < 0)
		err_quit("inet_pton error");
	if (connect(connfd, (struct sockaddr*)&addr, sizeof(addr)) < 0)
		err_sys("Connect error");
	while ((n = read(connfd, recvline, MAXLINE)) > 0) {
		recvline[n] = 0;
		if (fputs(recvline, stdout) == EOF) {
			err_sys("fputs error");
		}
	}
	if (n < 0)
		err_sys("read error");
	exit(0);
}
开发者ID:songzhengxuan,项目名称:kata,代码行数:22,代码来源:ttimeclient.c



注:本文中的err_quit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ err_ret函数代码示例发布时间:2022-05-30
下一篇:
C++ err_push函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap