From 6b5a3a31f542a7f8aa5f1779a7218c19e5b8b32a Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Thu, 11 Feb 2010 15:47:54 +0000 Subject: [PATCH] Abstract writing the file header into NYTP_write_header(), add a wrapper and use it from nytprofmerge. --- FileHandle.h | 1 + FileHandle.xs | 12 ++++++++++++ NYTProf.xs | 2 +- bin/nytprofmerge | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/FileHandle.h b/FileHandle.h index 3ed961c..9cbfd92 100644 --- a/FileHandle.h +++ b/FileHandle.h @@ -61,6 +61,7 @@ const char *NYTP_type_of_offset(NYTP_file file); void NYTProf_croak_if_not_stdio(NYTP_file file, const char *function); +size_t NYTP_write_header(NYTP_file ofile, unsigned int major, unsigned int minor); size_t NYTP_write_comment(NYTP_file ofile, const char *format, ...); size_t NYTP_write_attribute_string(NYTP_file ofile, const char *key, size_t key_len, diff --git a/FileHandle.xs b/FileHandle.xs index b9ec005..a23655a 100644 --- a/FileHandle.xs +++ b/FileHandle.xs @@ -704,6 +704,12 @@ output_nv(NYTP_file file, NV nv) } size_t +NYTP_write_header(NYTP_file ofile, unsigned int major, unsigned int minor) +{ + return NYTP_printf(ofile, "NYTProf %u %u\n", major, minor); +} + +size_t NYTP_write_comment(NYTP_file ofile, const char *format, ...) { size_t retval; size_t retval2; @@ -1275,3 +1281,9 @@ SV *text size_t NYTP_write_discount(handle) NYTP_file handle + +size_t +NYTP_write_header(handle, major, minor) +NYTP_file handle +unsigned int major +unsigned int minor diff --git a/NYTProf.xs b/NYTProf.xs index 2ce92be..b19a151 100644 --- a/NYTProf.xs +++ b/NYTProf.xs @@ -429,7 +429,7 @@ output_header(pTHX) assert(out != NULL); /* File header with "magic" string, with file major and minor version */ - NYTP_printf(out, "NYTProf %d %d\n", NYTP_FILE_MAJOR_VERSION, NYTP_FILE_MINOR_VERSION); + NYTP_write_header(out, NYTP_FILE_MAJOR_VERSION, NYTP_FILE_MINOR_VERSION); /* Human readable comments and attributes follow * comments start with '#', end with '\n', and are discarded * attributes start with ':', a word, '=', then the value, then '\n' diff --git a/bin/nytprofmerge b/bin/nytprofmerge index 00146a3..dcd2d69 100755 --- a/bin/nytprofmerge +++ b/bin/nytprofmerge @@ -96,7 +96,7 @@ my %dispatcher = unless $this_version eq $version; } else { $version = $this_version; - $out->write("NYTProf $version\n"); + $out->write_header($major, $minor); } }, COMMENT => sub { -- 1.6.0