Debian Codegraph @

bcftools/bcftools.pysam.c

raw symbols SCIP
1 #include <getopt.h>
2 #include <unistd.h>
3 #include <setjmp.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 #include "bcftools.pysam.h"
9
10 FILE * bcftools_stderr = NULL;
11 FILE * bcftools_stdout = NULL;
12 const char * bcftools_stdout_fn = NULL;
13
14
15 FILE * bcftools_set_stderr(int fd)
16 {
17 if (bcftools_stderr != NULL)
18 fclose(bcftools_stderr);
19 bcftools_stderr = fdopen(fd, "w");
20 return bcftools_stderr;
21 }
22
23 void bcftools_close_stderr(void)
24 {
25 fclose(bcftools_stderr);
26 bcftools_stderr = NULL;
27 }
28
29 FILE * bcftools_set_stdout(int fd)
30 {
31 if (bcftools_stdout != NULL)
32 fclose(bcftools_stdout);
33 bcftools_stdout = fdopen(fd, "w");
34 if (bcftools_stdout == NULL)
35 {
36 fprintf(bcftools_stderr, "could not set stdout to fd %i", fd);
37 }
38 return bcftools_stdout;
39 }
40
41 void bcftools_set_stdout_fn(const char *fn)
42 {
43 bcftools_stdout_fn = fn;
44 }
45
46 void bcftools_close_stdout(void)
47 {
48 fclose(bcftools_stdout);
49 bcftools_stdout = NULL;
50 }
51
52 int bcftools_puts(const char *s)
53 {
54 if (fputs(s, bcftools_stdout) == EOF) return EOF;
55 return putc('\n', bcftools_stdout);
56 }
57
58
59 static jmp_buf bcftools_jmpbuf;
60 static int bcftools_status = 0;
61
62 int bcftools_dispatch(int argc, char *argv[])
63 {
64 /* Reset getopt()/getopt_long() processing. */
65 #if defined __GLIBC__
66 optind = 0;
67 #elif defined _OPTRESET || defined _OPTRESET_DECLARED
68 optreset = optind = 1;
69 #else
70 optind = 1;
71 #endif
72
73 if (setjmp(bcftools_jmpbuf) == 0)
74 return bcftools_main(argc, argv);
75 else
76 return bcftools_status;
77 }
78
79 void bcftools_exit(int status)
80 {
81 bcftools_status = status;
82 longjmp(bcftools_jmpbuf, 1);
83 }