From 1837f0b0ece6bd2ba811842b8a1721bef4ad8681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano-Tarumi?= Date: Tue, 30 Oct 2018 18:28:12 -0400 Subject: [PATCH] build as C++14 --- Makefile | 4 ++-- README.md | 3 ++- opustags.c => opustags.cc | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 16 deletions(-) rename opustags.c => opustags.cc (94%) diff --git a/Makefile b/Makefile index d51c975..0981d2f 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ DESTDIR=/usr/local MANDEST=share/man -CFLAGS=-Wall +CXXFLAGS=-Wall -std=c++14 LDFLAGS=-logg all: opustags -opustags: opustags.c +opustags: opustags.cc man: opustags.1 gzip opustags.1.gz diff --git a/README.md b/README.md index 5d92cd4..1349c29 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,8 @@ See also these libraries if you need a lower-level access: Requirements ------------ -* A POSIX-compliant system, +* a C++14 compiler, +* a POSIX-compliant system, * libogg. Installing diff --git a/opustags.c b/opustags.cc similarity index 94% rename from opustags.c rename to opustags.cc index 6d3ee30..973b1e3 100644 --- a/opustags.c +++ b/opustags.cc @@ -38,10 +38,10 @@ int parse_tags(char *data, long len, opus_tags *tags){ tags->count = le32toh(*((uint32_t*) (data + pos))); if(tags->count == 0) return 0; - tags->lengths = calloc(tags->count, sizeof(uint32_t)); + tags->lengths = static_cast(calloc(tags->count, sizeof(uint32_t))); if(tags->lengths == NULL) return -1; - tags->comment = calloc(tags->count, sizeof(char*)); + tags->comment = static_cast(calloc(tags->count, sizeof(char*))); if(tags->comment == NULL){ free(tags->lengths); return -1; @@ -74,7 +74,7 @@ int render_tags(opus_tags *tags, ogg_packet *op){ for(i=0; icount; i++) len += 4 + tags->lengths[i]; op->bytes = len; - char *data = malloc(len); + char *data = static_cast(malloc(len)); if(!data) return -1; op->packet = (unsigned char*) data; @@ -128,8 +128,8 @@ void delete_tags(opus_tags *tags, const char *field){ int add_tags(opus_tags *tags, const char **tags_to_add, uint32_t count){ if(count == 0) return 0; - uint32_t *lengths = realloc(tags->lengths, (tags->count + count) * sizeof(uint32_t)); - const char **comment = realloc(tags->comment, (tags->count + count) * sizeof(char*)); + uint32_t *lengths = static_cast(realloc(tags->lengths, (tags->count + count) * sizeof(uint32_t))); + const char **comment = static_cast(realloc(tags->comment, (tags->count + count) * sizeof(char*))); if(lengths == NULL || comment == NULL) return -1; tags->lengths = lengths; @@ -146,8 +146,7 @@ int add_tags(opus_tags *tags, const char **tags_to_add, uint32_t count){ void print_tags(opus_tags *tags){ if(tags->count == 0) puts("no tags"); - int i; - for(i=0; icount; i++){ + for(uint32_t i=0; icount; i++){ fwrite(tags->comment[i], 1, tags->lengths[i], stdout); puts(""); } @@ -161,9 +160,9 @@ void free_tags(opus_tags *tags){ } int write_page(ogg_page *og, FILE *stream){ - if(fwrite(og->header, 1, og->header_len, stream) < og->header_len) + if((ssize_t) fwrite(og->header, 1, og->header_len, stream) < og->header_len) return -1; - if(fwrite(og->body, 1, og->body_len, stream) < og->body_len) + if((ssize_t) fwrite(og->body, 1, og->body_len, stream) < og->body_len) return -1; return 0; } @@ -206,7 +205,8 @@ int main(int argc, char **argv){ fputs(usage, stdout); return EXIT_SUCCESS; } - char *path_in, *path_out = NULL, *inplace = NULL; + char *path_in, *path_out = NULL; + const char *inplace = NULL; const char* to_add[argc]; const char* to_delete[argc]; int count_add = 0, count_delete = 0; @@ -300,7 +300,7 @@ int main(int argc, char **argv){ } FILE *out = NULL; if(inplace != NULL){ - path_out = malloc(strlen(path_in) + strlen(inplace) + 1); + path_out = static_cast(malloc(strlen(path_in) + strlen(inplace) + 1)); if(path_out == NULL){ fputs("failure to allocate memory\n", stderr); fclose(in); @@ -338,7 +338,7 @@ int main(int argc, char **argv){ ogg_sync_init(&oy); char *buf; size_t len; - char *error = NULL; + const char *error = NULL; int packet_count = -1; while(error == NULL){ // Read until we complete a page. @@ -408,7 +408,7 @@ int main(int argc, char **argv){ } char *raw_tags = NULL; if(set_all){ - raw_tags = malloc(16384); + raw_tags = static_cast(malloc(16384)); if(raw_tags == NULL){ error = "malloc: not enough memory for buffering stdin"; free(raw_tags);