From: Heng Li Date: Thu, 28 May 2009 10:49:35 +0000 (+0000) Subject: * minor changes to bgzf: return NULL if fd == -1 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=9c6f3bf7f9f400886daf54913c9096fce7551714;p=samtools.git * minor changes to bgzf: return NULL if fd == -1 * suggested by {kdj,jm18}@sanger.ac.uk --- diff --git a/bgzf.c b/bgzf.c index 1b5cebe..bffe8b5 100644 --- a/bgzf.c +++ b/bgzf.c @@ -132,12 +132,14 @@ bgzf_open(const char* __restrict path, const char* __restrict mode) { BGZF* fp = NULL; if (strcasecmp(mode, "r") == 0) { - int oflag = O_RDONLY; - int fd = open(path, oflag); + int oflag = O_RDONLY; + int fd = open(path, oflag); + if (fd == -1) return 0; fp = open_read(fd); } else if (strcasecmp(mode, "w") == 0) { - int oflag = O_WRONLY | O_CREAT | O_TRUNC; - int fd = open(path, oflag, 0644); + int oflag = O_WRONLY | O_CREAT | O_TRUNC; + int fd = open(path, oflag, 0644); + if (fd == -1) return 0; fp = open_write(fd); } if (fp != NULL) { @@ -149,6 +151,7 @@ bgzf_open(const char* __restrict path, const char* __restrict mode) BGZF* bgzf_fdopen(int fd, const char * __restrict mode) { + if (fd == -1) return 0; if (strcasecmp(mode, "r") == 0) { return open_read(fd); } else if (strcasecmp(mode, "w") == 0) {