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

C++ perror_exit函数代码示例

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

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



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

示例1: serial_open

/* open the serial port */
void serial_open(const char *dev)
{
	portfd = open(dev, O_RDWR | O_NOCTTY);
	if (portfd < 0)
		perror_exit(dev);

	/* save current port settings */
	if (tcgetattr(portfd, &oldtio) < 0)
		perror_exit("tcgetattr");

	/* set signal handlers before switching settings */
	signal(SIGHUP, handler1);
	signal(SIGINT, handler1);
	signal(SIGPIPE, handler1);
	signal(SIGTERM, handler1);

	/* configure new port settings: 9600 8N1 */
	memset(&newtio, 0, sizeof(newtio));
	newtio.c_cflag = B9600 | CS8 | CLOCAL | CREAD;
	newtio.c_iflag = IGNPAR;
	newtio.c_oflag = 0;
	/* set input mode (non-canonical, no echo,...) */
	newtio.c_lflag = 0;
	newtio.c_cc[VTIME] = 0;	/* inter-character timer unused */
	newtio.c_cc[VMIN] = 1;	/* blocking read until 1 char received */

	/* install new port settings */
	tcflush(portfd, TCIFLUSH);
	if (tcsetattr(portfd, TCSANOW, &newtio) < 0)
		perror_exit("tcsetattr");
}
开发者ID:korneliuszo,项目名称:shoehorn,代码行数:32,代码来源:serial.c


示例2: i2c_init

void i2c_init(struct plugin *p, struct plugin_set *__un1, struct plug_args *pa)
{
	char filename[FILENAME_MAX];
	struct i2c_data *i2c = p->data = g_new(struct i2c_data,1);

	i2c->is = g_tree_new(comp_int64);
	i2c->outstanding = 0;
	i2c->maxouts = 0;

	i2c->oio_f = NULL;
	if(pa->i2c_oio_f) {
		get_filename(filename, "i2c_oio", pa->i2c_oio_f, pa->end_range);
		i2c->oio_f = fopen(filename,"w");
		if(!i2c->oio_f) perror_exit("Opening I2C detail file");
	}

	i2c->oio_hist_f = NULL;
	if(pa->i2c_oio_hist_f) {
		get_filename(filename, "i2c_oio_hist", pa->i2c_oio_hist_f, pa->end_range);
		i2c->oio_hist_f = fopen(filename,"w");
		if(!i2c->oio_hist_f) perror_exit("Opening I2C detail file");
	}

	i2c->oio = NULL;
	i2c->oio_size = 0;
	i2c->oio_prev_time = UINT64_MAX;
}
开发者ID:useche,项目名称:btstats,代码行数:27,代码来源:i2c.c


示例3: dbg_dap_cmd

//-----------------------------------------------------------------------------
int dbg_dap_cmd(uint8_t *data, int size, int rsize)
{
  char cmd = data[0];
  int res;

  memset(hid_buffer, 0xff, report_size + 1);

  hid_buffer[0] = 0x00; // Report ID
  memcpy(&hid_buffer[1], data, rsize);

  res = hid_write(handle, hid_buffer, report_size + 1);
  if (res < 0)
  {
    printf("Error: %ls\n", hid_error(handle));
    perror_exit("debugger write()");
  }

  res = hid_read(handle, hid_buffer, report_size + 1);
  if (res < 0)
    perror_exit("debugger read()");

  check(res, "empty response received");

  check(hid_buffer[0] == cmd, "invalid response received");

  res--;
  memcpy(data, &hid_buffer[1], (size < res) ? size : res);

  return res;
}
开发者ID:arv3,项目名称:edbg,代码行数:31,代码来源:dbg_mac.c


示例4: load_file

//-----------------------------------------------------------------------------
int load_file(char *name, uint8_t *data, int size)
{
  struct stat stat;
  int fd, rsize;

  check(NULL != name, "input file name is not specified");

  fd = open(name, O_RDONLY | O_BINARY);

  if (fd < 0)
    perror_exit("open()");

  fstat(fd, &stat);

  check(stat.st_size <= size, "image is too big for the selected chip");

  rsize = read(fd, data, stat.st_size);

  if (rsize < 0)
    perror_exit("read()");

  check(rsize == stat.st_size, "cannot fully read file");

  close(fd);

  return rsize;
}
开发者ID:arv3,项目名称:edbg,代码行数:28,代码来源:edbg.c


示例5: malloc

void *connection_handler(void *arg){
    int err,length;
    char* directory;
    QNode* node;
    int newsock = ((information*)arg)->newsock;
    int queue_size = ((information*)arg)->queue_size;
    pthread_mutex_t *clientMutex = malloc(sizeof(pthread_mutex_t));
//---------------------------------------------
    if ( err = pthread_detach(pthread_self())){
        perror2("pthread_detach",err);
        exit(1);
    }
    pthread_mutex_init(clientMutex,NULL ) ; /* Initialize client mutex */

    if (read_all(newsock,&length,sizeof(int)) != sizeof(int) )
        perror_exit("read");
    directory = malloc(length);
    if (read_all(newsock,directory,length) != length)
        perror_exit("read");
    //print directory
    //printf("directory is: %s\n",directory);
    printf("[Thread: %ld]: About to scan directory Server\n",pthread_self());
    fflush(stdout);
    findFiles(directory,newsock,queue_size,clientMutex);
    //create ack
    node = createQNode();
    node->client_sock = newsock;
    node->buf = NULL;
    node->clientMutex = clientMutex;
    place(workQueue,node,queue_size);
    pthread_cond_broadcast(&cond_empty);
    pthread_exit(NULL);
}
开发者ID:LefkotheaKatsina,项目名称:systemProgramming,代码行数:33,代码来源:functions.c


示例6: bind_sock

/* sock_bind: create and bind a new socket with @port
 * @port: the port used to bind the socket
 *
 * */
int bind_sock(int port)
{
    int listenfd;
    struct sockaddr_in socket_addr;

    /* create a new socket */
    if ((listenfd = socket(AF_INET,SOCK_STREAM,0)) < 0)
    {
        perror_exit("socket error");
    }

    /* fill the socket address struct */
    memset(&socket_addr,0,sizeof(struct sockaddr_in));
    socket_addr.sin_family = AF_INET;
    socket_addr.sin_port = htons(port);
    socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);

    /* bind the socket */
    if (bind(listenfd,(struct sockaddr *)&socket_addr,sizeof(struct sockaddr_in)) < 0)
    {
        perror_exit("bind error");
    }

    return listenfd;
}
开发者ID:kevin4fly,项目名称:network,代码行数:29,代码来源:sock_util.c


示例7: handle_connection

/* handle_connection: handle the connected clients
 * @listenfd: the socket used to accept connections
 *
 * */
void handle_connection(int listenfd)
{
    /* the number of readable fds in the pollfd array */
    int nready, i;

    /* receive buffer */
    buffer_t recvbuf;
    memset(&recvbuf,0,sizeof(buffer_t));

    /* set the listenfd to non-block */
    //setnonblock(listenfd);

    /* epollfd set to monitor the related events */
    int epollfd;
    if ( (epollfd = epoll_create(EPOLL_SIZE)) < 0 )
    {
        perror_exit("epoll create error");
    }

    /* epoll event array */
    struct epoll_event events[EPOLL_EVENTS];

    /* add the listen socket to epoll set */
    int state = EPOLLIN;
    add_epoll_event(epollfd,listenfd,state);

    while( 1 )
    {
        /* obtain the ready sockets from the epoll set */
        if ( (nready = epoll_wait(epollfd,events,EPOLL_EVENTS,INFTIM)) < 0)
        {
            perror_exit("epoll wait error");
        }

        /* traverse the ready sockets */
        for (i = 0; i < nready; ++i)
        {
            int fd = events[i].data.fd;

            /* listenfd is ready */
            if ( fd == listenfd && (events[i].events & EPOLLIN) )
            {
                do_accept(listenfd, epollfd);
            }

            /* connected sockets are ready */
            else if ( events[i].events & EPOLLIN )
            {
                do_read(fd,epollfd,&recvbuf);
            }

            /* read the data from the connected socket and echo it also */
            else if ( events[i].events & EPOLLOUT )
            {
                do_write(fd,epollfd,&recvbuf);
            }
        }
    }
}
开发者ID:kevin4fly,项目名称:network,代码行数:63,代码来源:sock_util.c


示例8: perror_exit

void *server(void *data)
{
	data_struct *info = data;
	int port = info->port;
	pthread_t thr_server;
	int sock, newsock,retValue =-1;
	int optval;
    struct sockaddr_in server, client;
    socklen_t clientlen;
    struct sockaddr *serverptr=(struct sockaddr *)&server;
    struct sockaddr *clientptr=(struct sockaddr *)&client;
    struct hostent *rem;
    
    /* Create socket */
    if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0)
        perror_exit("socket");
    server.sin_family = AF_INET;       /* Internet domain */
    server.sin_addr.s_addr = htonl(INADDR_ANY);
    server.sin_port = htons(port);      /* The given port */
    
    optval = 1;//make the socket reuseable fast
	setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof optval);
    
    /* Bind socket to address */
    if (bind(sock, serverptr, sizeof(server)) < 0)
        perror_exit("bind");
        
    /* Listen for connections */
    if (listen(sock, 5) < 0)
		perror_exit("listen");
    printf("Listening for connections to port %d\n", port);
    
    while (1)
    {	clientlen = sizeof(client);
        /* accept connection */
    	if ((newsock = accept(sock, clientptr, &clientlen)) < 0)
			perror_exit("accept");
	
    	printf("Accepted connection\n");
		
		info->socket = newsock;
		//thread pou tha eksyphrethsei thn aithsh
		retValue = pthread_create(&thr_server, NULL, thread_server, (void *)info);
		if(retValue == 1)
			perror2("pthread_create", retValue);
			

    	
    	//close(newsock); /* parent closes socket to client */
    }
}
开发者ID:TheQuaker,项目名称:Client-Server-Multithreading,代码行数:51,代码来源:server-client.c


示例9: join_thread

void join_thread(pthread_t thread)
{
  int ret = pthread_join(thread, NULL);
  if (ret == -1) {
      perror_exit("pthread_join failed");
  }
}
开发者ID:AllenDowney,项目名称:ThinkOS,代码行数:7,代码来源:queue_mysem_soln.c


示例10: getpwnam

struct passwd *xgetpwnam(char *name)
{
  struct passwd *up = getpwnam(name);

  if (!up) perror_exit("user '%s'", name);
  return up;
}
开发者ID:zsaleeba,项目名称:shellbox,代码行数:7,代码来源:xmisc.c


示例11: getgrgid

struct group *xgetgrgid(gid_t gid)
{
  struct group *group = getgrgid(gid);

  if (!group) perror_exit("gid %ld", (long)gid);
  return group;
}
开发者ID:zsaleeba,项目名称:shellbox,代码行数:7,代码来源:xmisc.c


示例12: do_accept

/* do_accept: establish the new connection
 * @listenfd: the listening fd
 * @epollfd: the epollfd used to monitor the listening fd and new connected fd
 *
 * */
void do_accept(int listenfd, int epollfd)
{
    int connfd;
    struct sockaddr_in clitaddr;
    socklen_t socklen;
    //while ( (connfd = accept(listenfd,(struct sockaddr *)&clitaddr,&socklen)) > 0 )
    //{
    connfd = accept(listenfd,(struct sockaddr *)&clitaddr,&socklen);
        /* show client info */
        show_peer_info(connfd);

        /* set the connfd to non-block socket */
        //setnonblock(connfd);

        /* set the connfd events to EPOLLIN | EPLLET(edge trigger) */
        //int state =  EPOLLIN | EPOLLET;
        int state = EPOLLIN;

        /* add connected fd to epoll set */
        add_epoll_event(epollfd,connfd,state);
    //}

    /* if accept error*/
    if (connfd < 0)
    {
        if (errno != EINTR)
        {
            perror_exit("accept error");
        }
    }
}
开发者ID:kevin4fly,项目名称:network,代码行数:36,代码来源:sock_util.c


示例13: xconnect

int xconnect(char *host, char *port, int family, int socktype, int protocol, int flags)
{
  struct addrinfo info, *ai, *ai2;
  int fd;

  memset(&info, 0, sizeof(struct addrinfo));
  info.ai_family = family;
  info.ai_socktype = socktype;
  info.ai_protocol = protocol;
  info.ai_flags = flags;

  fd = getaddrinfo(host, port, &info, &ai);
  if (fd || !ai)
    error_exit("Connect '%s%s%s': %s", host, port ? ":" : "", port ? port : "",
      fd ? gai_strerror(fd) : "not found");

  // Try all the returned addresses. Report errors if last entry can't connect.
  for (ai2 = ai; ai; ai = ai->ai_next) {
    fd = (ai->ai_next ? socket : xsocket)(ai->ai_family, ai->ai_socktype,
      ai->ai_protocol);
    if (!connect(fd, ai->ai_addr, ai->ai_addrlen)) break;
    else if (!ai2->ai_next) perror_exit("connect");
    close(fd);
  }
  freeaddrinfo(ai2);

  return fd;
}
开发者ID:benravago,项目名称:spin-up-tools,代码行数:28,代码来源:toys.c


示例14: setnonblock

/* setnonblock: set the non-blocking @fd
 * @fd: the fd to be set
 *
 * */
void setnonblock(int fd)
{
    int opt;
    /* get the orignal option */
    if ( (opt = fcntl(fd,F_GETFD)) < 0 )
    {
        perror_exit("fctl error");
    }

    /* set non-block option */
    opt |= O_NONBLOCK;
    if ( (opt = fcntl(fd,F_SETFD)) < 0 )
    {
        perror_exit("fcntl error");
    }
}
开发者ID:kevin4fly,项目名称:network,代码行数:20,代码来源:sock_util.c


示例15: listen_sock

/* sock_listen: listen the @listenfd socket
 * @listenfd: the socket used for listening
 *
 * */
void listen_sock(int listenfd)
{
    if (listen(listenfd,LISTENQ) < 0)
    {
        perror_exit("listen error");
    }
}
开发者ID:kevin4fly,项目名称:network,代码行数:11,代码来源:sock_util.c


示例16: do_read

void do_read(int fd, int epollfd, buffer_t *recvbuf)
{
    int space = buffer_hasspace(recvbuf);
    if (space > 0)
    {
        int nread = read(fd,recvbuf->buffer + recvbuf->in,space);

        /* read error */
        if (nread < 0)
        {
            perror_exit("read error");
        }

        /* read "FIN" from client */
        else if (nread == 0)
        {
            delete_epoll_event(epollfd,fd,EPOLLIN);
            close(fd);
        }

        else
        {
            recvbuf->in += nread;

            /* data is ready for writing */
            modify_epoll_event(epollfd,fd,EPOLLOUT);
        }
    }
}
开发者ID:kevin4fly,项目名称:network,代码行数:29,代码来源:sock_util.c


示例17: toy_init

// Full init needed by multiplexer or reentrant calls, calls singleinit at end
void toy_init(struct toy_list *which, char *argv[])
{
  void *oldwhich = toys.which;

  // Drop permissions for non-suid commands.

  if (CFG_TOYBOX_SUID) {
    if (!toys.which) toys.which = toy_list;

    uid_t uid = getuid(), euid = geteuid();

    if (!(which->flags & TOYFLAG_STAYROOT)) {
      if (uid != euid) {
        if (setuid(uid)) perror_exit("setuid %d->%d", euid, uid); // drop root
        euid = uid;
        toys.wasroot++;
      }
    } else if (CFG_TOYBOX_DEBUG && uid && which != toy_list)
      error_msg("Not installed suid root");

    if ((which->flags & TOYFLAG_NEEDROOT) && euid) help_exit("Not root");
  }

  // Free old toys contents (to be reentrant), but leave rebound if any
  // don't blank old optargs if our new argc lives in the old optargs.
  if (argv<toys.optargs || argv>toys.optargs+toys.optc) free(toys.optargs);
  memset(&toys, 0, offsetof(struct toy_context, rebound));
  if (oldwhich) memset(&this, 0, sizeof(this));

  // Continue to portion of init needed by standalone commands
  toy_singleinit(which, argv);
}
开发者ID:OoOverflow,项目名称:toybox,代码行数:33,代码来源:main.c


示例18: insmod_main

void insmod_main(void)
{
  int fd = !strcmp(*toys.optargs, "-") ? 0 : xopen(*toys.optargs, O_RDONLY);
  int i, rc;

  i = 1;
  while (toys.optargs[i] &&
    strlen(toybuf) + strlen(toys.optargs[i]) + 2 < sizeof(toybuf))
  {
    strcat(toybuf, toys.optargs[i++]);
    strcat(toybuf, " ");
  }

  // finit_module was new in Linux 3.8, and doesn't work on stdin,
  // so we fall back to init_module if necessary.
  rc = finit_module(fd, toybuf, 0);
  if (rc && (fd == 0 || errno == ENOSYS)) {
    off_t len = 0;
    char *path = !strcmp(*toys.optargs, "-") ? "/dev/stdin" : *toys.optargs;
    char *buf = readfileat(AT_FDCWD, path, NULL, &len);

    rc = init_module(buf, len, toybuf);
    if (CFG_TOYBOX_FREE) free(buf);
  }

  if (rc) perror_exit("failed to load %s", toys.optargs[0]);

  if (CFG_TOYBOX_FREE) close(fd);
}
开发者ID:drinkcat,项目名称:toybox,代码行数:29,代码来源:insmod.c


示例19: recv_handler

int
recv_handler(struct request *req)
{
    int cc;
    int base = req->rank * req->len;

    set_sock_blocking(req->fd, 0);
    while (req->count < req->len) {
	cc = read(req->fd, &recvbuf[base + req->count],
		  req->len - req->count);
	nr_read++;

	if (cc < 0) {
	    if (errno == EAGAIN || errno == EWOULDBLOCK)
		return 0;
	    else
		perror_exit("read", 1);
	} else if (cc == 0) {
	    fprintf(stderr, "recv: connection closed\n");
	    exit(1);
	}
	req->count += cc;
	rcnt += cc;
    }

    return 0;
}
开发者ID:oraccha,项目名称:tcpbench,代码行数:27,代码来源:tcpa2a.c


示例20: do_id

void do_id(char *username)
{
  int flags, i, ngroups, cmd_groups = toys.which->name[0] == 'g';
  struct passwd *pw;
  struct group *grp;
  uid_t uid = getuid(), euid = geteuid();
  gid_t gid = getgid(), egid = getegid(), *groups;

  if (cmd_groups)
      toys.optflags |= FLAG_G | FLAG_n;

  flags = toys.optflags;

  // check if a username is given
  if (username) {
    pw = xgetpwnam(username);
    uid = euid = pw->pw_uid;
    gid = egid = pw->pw_gid;
    if (cmd_groups) printf("%s : ", pw->pw_name);
  }

  i = flags & FLAG_r;
  pw = xgetpwuid(i ? uid : euid);
  if (flags & FLAG_u) s_or_u(pw->pw_name, pw->pw_uid, 1);

  grp = xgetgrgid(i ? gid : egid);
  if (flags & FLAG_g) s_or_u(grp->gr_name, grp->gr_gid, 1);

  if (!(flags & FLAG_G)) {
    showid("uid=", pw->pw_uid, pw->pw_name);
    showid(" gid=", grp->gr_gid, grp->gr_name);

    if (!i) {
      if (uid != euid) {
        pw = xgetpwuid(euid);
        showid(" euid=", pw->pw_uid, pw->pw_name);
      }
      if (gid != egid) {
        grp = xgetgrgid(egid);
        showid(" egid=", grp->gr_gid, grp->gr_name);
      }
    }

    showid(" groups=", grp->gr_gid, grp->gr_name);
  }

  groups = (gid_t *)toybuf;
  i = sizeof(toybuf)/sizeof(gid_t);
  ngroups = username ? getgrouplist(username, gid, groups, &i)
    : getgroups(i, groups);
  if (ngroups<0) perror_exit(0);

  for (i = 0; i<ngroups; i++) {
    if (i) xputc(' ');
    if (!(grp = getgrgid(groups[i]))) perror_msg(0);
    else if (flags & FLAG_G) s_or_u(grp->gr_name, grp->gr_gid, 0);
    else if (grp->gr_gid != egid) showid("", grp->gr_gid, grp->gr_name);
  }
  xputc('\n');
}
开发者ID:luckboy,项目名称:toybox,代码行数:60,代码来源:id.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ perror_msg函数代码示例发布时间:2022-05-30
下一篇:
C++ perror函数代码示例发布时间: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