]> git.donarmstrong.com Git - samtools.git/commitdiff
* minor changes to bgzf: return NULL if fd == -1
authorHeng Li <lh3@live.co.uk>
Thu, 28 May 2009 10:49:35 +0000 (10:49 +0000)
committerHeng Li <lh3@live.co.uk>
Thu, 28 May 2009 10:49:35 +0000 (10:49 +0000)
 * suggested by {kdj,jm18}@sanger.ac.uk

bgzf.c

diff --git a/bgzf.c b/bgzf.c
index 1b5cebe66a1cc91d3dcc6f892d37fe83bd03e11d..bffe8b54b4253f9aa6b3703d0cbc6cbd1d422b91 100644 (file)
--- 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) {