From: Petr Danecek Date: Wed, 4 Apr 2012 10:01:49 +0000 (+0100) Subject: Removed glibc dependency (getline) X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=commitdiff_plain;h=1dc8e7ef7746a6186b1380914fd3a3f79a55dfbd Removed glibc dependency (getline) --- diff --git a/misc/bamcheck.c b/misc/bamcheck.c index 76a9f6e..d35d8a5 100644 --- a/misc/bamcheck.c +++ b/misc/bamcheck.c @@ -12,10 +12,9 @@ considered, even small overlap is good enough to include the read in the stats. */ -#define BAMCHECK_VERSION "2012-03-29" +#define BAMCHECK_VERSION "2012-04-04" #define _ISOC99_SOURCE -#define _GNU_SOURCE #include #include #include @@ -982,6 +981,40 @@ void output_stats(stats_t *stats) void bam_init_header_hash(bam_header_t *header); +size_t getline(char **line, size_t *n, FILE *fp) +{ + if (line == NULL || n == NULL || fp == NULL) + { + errno = EINVAL; + return -1; + } + if (*n==0 || !*line) + { + *line = NULL; + *n = 0; + } + + size_t nread=0; + int c; + while ((c=getc(fp))!= EOF && c!='\n') + { + if ( ++nread>=*n ) + { + *n += 255; + *line = realloc(*line, sizeof(char)*(*n)); + } + (*line)[nread-1] = c; + } + if ( nread>=*n ) + { + *n += 255; + *line = realloc(*line, sizeof(char)*(*n)); + } + (*line)[nread] = 0; + return nread>0 ? nread : -1; + +} + void init_regions(stats_t *stats, char *file) { khiter_t iter; @@ -1004,7 +1037,7 @@ void init_regions(stats_t *stats, char *file) int i = 0; while ( i=nread ) error("Could not parse the file: %s\n", file); + if ( i>=nread ) error("Could not parse the file: %s [%s]\n", file,line); line[i] = 0; iter = kh_get(str, header_hash, line);