本文整理汇总了C++中err_exit函数的典型用法代码示例。如果您正苦于以下问题:C++ err_exit函数的具体用法?C++ err_exit怎么用?C++ err_exit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了err_exit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: verrx
void
verrx(int eval, const char *fmt, va_list ap)
{
if (err_file == NULL)
err_set_file(NULL);
fprintf(err_file, "%s: ", _getprogname());
if (fmt != NULL)
vfprintf(err_file, fmt, ap);
fprintf(err_file, "\n");
if (err_exit)
err_exit(eval);
exit(eval);
}
示例2: main
int
main(void)
{
int err;
pthread_t tid1, tid2;
struct foo *fp;
err = pthread_create(&tid1, NULL, thr_fn1, NULL);
if (err != 0)
err_exit(err, "can't create thread 1");
err = pthread_join(tid1, (void *)&fp);
if (err != 0)
err_exit(err, "can't join with thread 1");
sleep(1);
printf("parent starting second thread\n");
err = pthread_create(&tid2, NULL, thr_fn2, NULL);
if (err != 0)
err_exit(err, "can't create thread 2");
sleep(1);
printfoo("parent:\n", fp);
exit(0);
}
示例3: main
int main(void)
{
int err;
pthread_t tid1, tid2;
void *tret;
err = pthread_create(&tid1, NULL, thr_fn1, (void *)1);
if (err != 0)
err_exit(err, "can't create thread 1");
err = pthread_create(&tid2, NULL, thr_fn2, (void *)1);
if (err != 0)
err_exit(err, "can't create thread 2");
err = pthread_join(tid1, &tret);
if (err != 0)
err_exit(err, "can't join with thread 1");
printf("thread 1 exit code %ld\n", (long)tret);
err = pthread_join(tid2, &tret);
if (err != 0)
err_exit(err, "can't join with thread 2");
printf("thread 2 exit code %ld\n", (long)tret);
exit(0);
}
示例4: extract_mtk_boot
void extract_mtk_boot(const char *filename, const char *outname) {
char buf[MTK_PBL_SIZE];
int n;
FILE *in = fopen(filename, "rb");
if (in == NULL)
err_exit("Can't open file %s\n", filename);
FILE *out = fopen(outname, "wb");
if (out == NULL)
err_exit("Can't open file %s for writing\n", outname);
n = fread(&buf, 1, MTK_PBL_SIZE, in);
if (n != MTK_PBL_SIZE) {
fclose(in);
err_exit("Error: PBL size mismatch!\n");
}
fclose(in);
fwrite(&buf, 1, MTK_PBL_SIZE, out);
fclose(out);
}
示例5: exec_lstopo
/*
* Execute lstopo from user's PATH sending full topology XML over stdin.
* Pass any extra options along to lstopo(1).
*
* If running lstopo fails with ENOENT, try lstopo-no-graphics.
*/
static int exec_lstopo (optparse_t *p, int ac, char *av[], const char *topo)
{
int status;
FILE *fp;
char *argz;
size_t argz_len;
pid_t pid;
const char *cmds[] = { "lstopo", "lstopo-no-graphics", NULL };
const char **cp = cmds;
/* Ignore SIGPIPE so we don't get killed when exec() fails */
signal (SIGPIPE, SIG_IGN);
/* Initialize argz with first command in cmds above: */
lstopo_argz_init ((char *) *cp, &argz, &argz_len, av+1);
while (true) {
const char *next = *(cp+1);
if (!(fp = argz_popen (argz, argz_len, &pid)))
err_exit ("popen (lstopo)");
fputs (topo, fp);
fclose (fp);
if (waitpid (pid, &status, 0) < 0)
err_exit ("waitpid");
/* Break out of loop if exec() was succcessful, failed with
* an error other than "File not found", or we ran out programs
* to try.
*/
if (status == 0 || !next || WEXITSTATUS (status) != ENOENT)
break;
/* Replace previous cmd in argz with next command to try:
*/
argz_replace (&argz, &argz_len, *(cp++), next, NULL);
}
return (status);
}
示例6: is_nfsb
int is_nfsb(const char *filename) {
FILE *file = fopen(filename, "rb");
if (file == NULL)
err_exit("Can't open file %s\n\n", filename);
char header[0x11];
if (fread(&header, 1, sizeof(header), file) != sizeof(header))
return 0;
fclose(file);
if (memcmp(&header, "NFSB", 4) == 0)
return !memcmp(&header[0xE], "md5", 3);
return 0;
}
示例7: save_score
/* save current score in the score file */
void save_score(const int time_taken) {
time_t tm = time(NULL);
struct tm *today = localtime(&tm);
char tmpbuffer[129];
today = localtime(&tm);
char appdata_dir[4096]; //XXX why _PC_PATH_MAX is only 4?
const char *score_filename = "4digits.4digits.scores";
strcpy(appdata_dir, getenv("HOME"));
strcat(appdata_dir, "/.4digits/");
char *scorefile = (char*)malloc(strlen(appdata_dir) + strlen(score_filename) + 1);
if(!scorefile)
err_exit(_("Memory allocation error.\n"));
strcpy(scorefile, appdata_dir);
strcat(scorefile, score_filename);
FILE *sfp = fopen(scorefile, "a+");
if (!sfp) {
if (errno == ENOENT) {
DIR *dp = opendir(appdata_dir);
if(!dp)
if (errno == ENOENT) {
int ret = mkdir(appdata_dir, 0700);
if (ret == -1)
err_exit(_("Cannot open score file.\n"));
sfp = fopen(scorefile, "a+");
}
}
else
err_exit(_("Cannot open score file.\n"));
}
strftime(tmpbuffer, 128, "%a %b %d %H:%M:%S %Y", today);
struct passwd *pwd;
pwd = getpwuid(geteuid());
// but getenv("USERNAME") conforms to C99 thus is more portable.
fprintf(sfp, "%s %ds %s\n", pwd->pw_name, time_taken, tmpbuffer);
free(scorefile);
}
示例8: main
int main(int argc,cahr ** argv)
{
int err;
pthread_t tid;
char *cmd;
struct sigaction sa;
if((cmd=strrchr(argv[0],'/'))==NULL)
cmd=argv[0];
else
cmd++;
daemonize(cmd);
if(already_running())
{
syslog(LOG_ERR,"daemon already running");
exit(1);
}
sa.sa_handler=SIG_DEL;
sigemptyset(&sa.sa_mask);
sa.sa_flags=0;
if(sigaction(SIGHUP,&sa,NULL)<0)
err_quit("%s:can't restore SIGHUP default");
sigfillset(&mask);
if((err=pthread_sigmask(SIG_BLOCK,&mask,NULL))!=0)
err_exit(err,"SIG_BLOCK error");
err=pthread_create(&tid,NULL,thr_fn,0);
if(err!=0)
err_exit(err,"can't create the thread");
exit(0);
}
示例9: dlinfo_connect
/*
* Store the file descriptor to the '*sockfd' which is connected to
* server already. and return the socket file descriptor also.
*/
int dlinfo_connect(struct dlinfo *dl)
{
int s;
int fd;
struct addrinfo hints;
struct addrinfo *res;
struct addrinfo *ai;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
errno = 0;
if ((s = getaddrinfo(dl->di_host, dl->di_serv, &hints, &res)) != 0)
err_exit("getaddrinfo: %s, host: %s:%s", gai_strerror(s),
dl->di_host, dl->di_serv);
for (ai = res; ai; ai = ai->ai_next) {
if ((fd = socket(ai->ai_family, ai->ai_socktype,
ai->ai_protocol)) == -1) {
err_sys("socket");
continue;
}
if (connect(fd, ai->ai_addr, ai->ai_addrlen) == 0)
break;
err_sys("connect");
if (close(fd) == -1)
err_sys("close");
}
if (NULL == ai)
err_exit("Couldn't connection to: %s", dl->di_host);
freeaddrinfo(res);
return fd;
}
示例10: main
int main(int argc, char *argv[])
{
int fd, fd2;
unsigned short sectors, dummy;
long size, addr1, padd_size, i;
unsigned char ch;
if (argc == 1) {
fprintf(stderr, "Usage: imgsize PNX_IMG ADDR1\n");
return 0;
}
if ((fd = open(argv[1], O_RDWR)) < 0) err_exit(1);
if ((fd2 = open("ifem.bin", O_RDWR)) < 0) err_exit(1);
if ((addr1 = lseek(fd2,0,SEEK_END)) < 0) err_exit(1);
addr1 += 0x600;
close(fd2);
if ((size = lseek(fd,0,SEEK_END)) < 0) err_exit(1);
sectors = (size - 512) / 512 + 1;
if (lseek(fd, 2, SEEK_SET) < 0) err_exit(1);
if (write(fd, (char *)§ors, sizeof(sectors)) <= 0) err_exit(1);
if (write(fd, (char *)&addr1, sizeof(addr1)) <= 0) err_exit(1);
padd_size = size % 512;
if (lseek(fd, 0, SEEK_END) < 0) err_exit(1);
for (ch=0, i=padd_size; i>0; i--)
if (write(fd, &ch, 1) < 0) err_exit(1);
close(fd);
fprintf(stderr, "===============\n");
fprintf(stderr, "ImgSize Report:\n");
fprintf(stderr, "===============\n");
fprintf(stderr, "Kernel image size = %ld bytes\n", size);
fprintf(stderr, "Kernel image size = %d sectors\n", sectors);
fprintf(stderr, "Padding size = %ld bytes\n", padd_size);
fprintf(stderr, "Kernel image successfully modified!\n");
return 0;
}
示例11: main
/* Changing the msg_qbytes setting of a System V message queue */
int main(int argc, char *argv[])
{
struct msqid_ds ds;
int msqid;
if (argc != 3 || strcmp(argv[1], "--help") == 0)
usage_err("%s msqid max-bytes\n", argv[0]);
/* Retrive copy of associate data struct from kernel */
msqid = get_int(argv[1], 0, "msqid");
if (msgctrl(msqid, IPC_STAT, &ids) == -1)
err_exit("msgctl");
d.msg_qbytes = get_int(argv[2], 0, "max-bytes");
/* Update associated data structure in kernel */
if (msgctl(msqid, IPC_SET, &ds) == -1)
err_exit("msgctl");
exit(EXIT_SUCCESS);
}
示例12: init_double_link
dll_t *
init_double_link( )
{
dll_t *dll;
dll = (dll_t*)calloc(1,sizeof(dll_t));
if(dll == NULL) {
err_exit("calloc error\n");
}
dll->prev = dll;/*??prev == NULL or prev = itself??*/
dll->next = dll;
return dll;
}
示例13: isSTRfile
int isSTRfile(const char *filename) {
FILE *file = fopen(filename, "rb");
if (file == NULL) {
err_exit("Can't open file %s\n", filename);
}
size_t headerSize = 0xC0 * 4;
unsigned char buffer[headerSize];
int read = fread(&buffer, 1, headerSize, file);
int result = 0;
if (read == headerSize && buffer[4] == 0x47 && buffer[0xC0 + 4] == 0x47 && buffer[0xC0 * 2 + 4] == 0x47 && buffer[0xC0 * 3 + 4] == 0x47)
result = 1;
fclose(file);
return result;
}
示例14: main
int main (int argc, char *argv[])
{
flux_t h;
int ch;
bool uopt = false;
bool dopt = false;
fmt_t fmt = FMT_RANGED;
ns_t *ns;
log_init ("flux-up");
while ((ch = getopt_long (argc, argv, OPTIONS, longopts, NULL)) != -1) {
switch (ch) {
case 'c': /* --comma */
fmt = FMT_COMMA;
break;
case 'n': /* --newline */
fmt = FMT_NEWLINE;
break;
case 'u': /* --up */
uopt = true;
break;
case 'd': /* --down */
dopt = true;
break;
default:
usage ();
break;
}
}
if (optind != argc)
usage ();
if (!(h = flux_open (NULL, 0)))
err_exit ("flux_open");
if (!(ns = ns_fromkvs (h)))
ns = ns_guess (h);
if (dopt)
ns_print_down (ns, fmt);
else if (uopt)
ns_print_up (ns, fmt);
else
ns_print_all (ns, fmt);
ns_destroy (ns);
flux_close (h);
log_fini ();
return 0;
}
示例15: push2queueout
/*
*
* Read from input stream the field from current position upto and including next delimiter.
*
*/
static void push2queueout(struct streams *s, struct queues *q, int c)
{
int i,len;
struct streams *t;
t=&outstream;
queuec_siz=QUEUEC_S;
q->cont=malloc(queuec_siz*sizeof(char));
if (q->cont==NULL) err_exit(ERR_PRO_QUE);
len=0;
while ((i=fgetc(s->fp)) != c) {
if (len+1 > queuec_siz) {
queuec_siz*=2;
q->cont=realloc(q->cont,queuec_siz*sizeof(char));
if (q->cont==NULL) err_exit(ERR_PRO_QUE);
}
q->cont[len++]=i;
}
q->cont[len]='\0';
if (c != *(s->delim)) ungetc(i,s->fp);
fprintf(t->fp,"%s",q->cont);
}