本文整理汇总了C++中err_quit函数的典型用法代码示例。如果您正苦于以下问题:C++ err_quit函数的具体用法?C++ err_quit怎么用?C++ err_quit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了err_quit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}