3 * This file is part of fastq-tools.
5 * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
21 void print_version(FILE *f, const char* prog_name)
23 fprintf(f, "%s (fastq-tools) %s\n",
24 prog_name, FASTQ_TOOLS_VERSION);
28 void or_die(int b, const char* msg)
37 void* malloc_or_die(size_t n)
41 fprintf(stderr, "Can not allocate %zu bytes.\n", n);
48 void* realloc_or_die(void* ptr, size_t n)
50 void* p = realloc(ptr, n);
52 fprintf(stderr, "Can not allocate %zu bytes.\n", n);
59 FILE* fopen_or_die(const char* path, const char* mode)
61 FILE* f = fopen(path, mode);
63 fprintf(stderr, "Can not open file %s with mode %s.\n", path, mode);
70 /* Open a file for writing, creating it if it doesn't exist, and complaining if
72 FILE* open_without_clobber(const char* filename)
74 int fd = open(filename, O_WRONLY | O_CREAT | O_BINARY | O_EXCL,
78 if (errno == EEXIST) {
79 fprintf(stderr, "Refusing to overwrite %s.\n", filename);
83 fprintf(stderr, "Cannot open %s for writing.\n", filename);
88 FILE* f = fdopen(fd, "wb");
90 fprintf(stderr, "Cannot open %s for writing.\n", filename);