3 * This file is part of fastq-tools.
5 * Copyright (c) 2011 by Daniel C. Jones <dcjones@cs.washington.edu>
22 void print_version(FILE *f, const char* prog_name)
24 fprintf(f, "%s (fastq-tools) %s\n",
25 prog_name, FASTQ_TOOLS_VERSION);
29 void or_die(int b, const char* msg)
38 void* malloc_or_die(size_t n)
42 fprintf(stderr, "Can not allocate %zu bytes.\n", n);
49 void* realloc_or_die(void* ptr, size_t n)
51 void* p = realloc(ptr, n);
53 fprintf(stderr, "Can not allocate %zu bytes.\n", n);
60 FILE* fopen_or_die(const char* path, const char* mode)
62 FILE* f = fopen(path, mode);
64 fprintf(stderr, "Can not open file %s with mode %s.\n", path, mode);
71 /* Open a file for writing, creating it if it doesn't exist, and complaining if
73 FILE* open_without_clobber(const char* filename)
75 int fd = open(filename, O_WRONLY | O_CREAT | O_BINARY | O_EXCL,
79 if (errno == EEXIST) {
80 fprintf(stderr, "Refusing to overwrite %s.\n", filename);
84 fprintf(stderr, "Cannot open %s for writing.\n", filename);
89 FILE* f = fdopen(fd, "wb");
91 fprintf(stderr, "Cannot open %s for writing.\n", filename);