]> git.donarmstrong.com Git - fastq-tools.git/blob - src/fastq-common.c
a new and improved parser
[fastq-tools.git] / src / fastq-common.c
1
2 /*
3  * This file is part of fastq-tools.
4  *
5  * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
6  *
7  */
8
9
10 #include "fastq-common.h"
11 #include <stdlib.h>
12
13
14 void or_die(int b, const char* msg)
15 {
16     if (b == 0) {
17         fputs(msg, stderr);
18         exit(1);
19     }
20 }
21
22
23 void* malloc_or_die(size_t n)
24 {
25     void* p = malloc(n);
26     if (p == NULL) {
27         fprintf(stderr, "Can not allocate %zu bytes.\n", n);
28         exit(1);
29     }
30     return p;
31 }
32
33
34 void* realloc_or_die(void* ptr, size_t n)
35 {
36     void* p = realloc(ptr, n);
37     if (p == NULL) {
38         fprintf(stderr, "Can not allocate %zu bytes.\n", n);
39         exit(1);
40     }
41     return p;
42 }
43
44
45 FILE* fopen_or_die(const char* path, const char* mode)
46 {
47     FILE* f = fopen(path, mode);
48     if (f == NULL) {
49         fprintf(stderr, "Can not open file %s with mode %s.\n", path, mode);
50         exit(1);
51     }
52     return f;
53 }
54
55
56