Skip to content

Commit 060b48c

Browse files
committed
Allow sam_write1 to take a NULL header parameter.
1 parent b3c7a61 commit 060b48c

File tree

4 files changed

+8
-19
lines changed

4 files changed

+8
-19
lines changed

hts.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ int hts_close(htsFile *fp)
12311231
hts_idx_destroy(fp->idx);
12321232
free(fp->fn);
12331233
free(fp->fn_aux);
1234-
free(fp->fnidx);
1234+
free((void *)fp->fnidx);
12351235
free(fp->line.s);
12361236
free(fp);
12371237
errno = save;
@@ -1243,11 +1243,6 @@ const htsFormat *hts_get_format(htsFile *fp)
12431243
return fp? &fp->format : NULL;
12441244
}
12451245

1246-
const struct sam_hdr_t *hts_get_hdr(htsFile *fp)
1247-
{
1248-
return fp? fp->bam_header : NULL;
1249-
}
1250-
12511246
const char *hts_get_fn(htsFile *fp)
12521247
{
12531248
return fp? fp->fn : NULL;

htslib/hts.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ typedef struct {
238238
void *state; // format specific state information
239239
htsFormat format;
240240
hts_idx_t *idx;
241-
char *fnidx;
241+
const char *fnidx;
242242
struct sam_hdr_t *bam_header;
243243
} htsFile;
244244

@@ -508,14 +508,6 @@ int hts_close(htsFile *fp);
508508
HTSLIB_EXPORT
509509
const htsFormat *hts_get_format(htsFile *fp);
510510

511-
/*!
512-
@abstract Returns the file's header field
513-
@param fp The file handle
514-
@return Read-only pointer to the file's bam_header field.
515-
*/
516-
HTSLIB_EXPORT
517-
const struct sam_hdr_t *hts_get_hdr(htsFile *fp);
518-
519511
/*!
520512
@abstract Returns the file's name
521513
@param fp The file handle

htslib/sam.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,7 @@ int bam_set_qname(bam1_t *b, const char *qname);
10891089
/** @param fp File handle for the data file being written.
10901090
@param h Bam header structured (needed for BAI and CSI).
10911091
@param min_shift 0 for BAI, or larger for CSI (CSI defaults to 14).
1092-
@param fnidx Filename to write index to. This pointer must remain valid
1093-
until after sam_idx_save is called.
1092+
@param fnidx Filename to write index to.
10941093
@return 0 on success, <0 on failure.
10951094
10961095
@note This must be called after the header has been written, but before
@@ -1357,7 +1356,8 @@ const char *sam_parse_region(sam_hdr_t *h, const char *s, int *tid,
13571356
int sam_read1(samFile *fp, sam_hdr_t *h, bam1_t *b) HTS_RESULT_USED;
13581357
/// sam_write1 - Write a record to a file
13591358
/** @param fp Pointer to the destination file
1360-
* @param h Pointer to the header structure previously read
1359+
* @param h Pointer to the header structure previously read. Can be NULL,
1360+
* if fp has a non-NULL pointer to a valid header struct.
13611361
* @param b Pointer to the record to be written
13621362
* @return >= 0 on successfully writing the record, -1 on error
13631363
*/

sam.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3218,8 +3218,10 @@ int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str)
32183218

32193219
// Sadly we need to be able to modify the bam_hdr here so we can
32203220
// reference count the structure.
3221-
int sam_write1(htsFile *fp, const sam_hdr_t *h, const bam1_t *b)
3221+
int sam_write1(htsFile *fp, const sam_hdr_t *hdr, const bam1_t *b)
32223222
{
3223+
const sam_hdr_t *h = hdr;
3224+
if (!h) h = fp->bam_header;
32233225
switch (fp->format.format) {
32243226
case binary_format:
32253227
fp->format.category = sequence_data;

0 commit comments

Comments
 (0)