From a6dab975f7711f27fb3ae6641069b75c4d7265e7 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 22 Nov 2017 22:45:12 +0000 Subject: [PATCH] factor out ICONV_CONST from headers --- charset.c | 32 +++++++++++++++----------------- charset.h | 5 ++--- handler.c | 4 ++-- ncrypt/gnupgparse.c | 4 ++-- rfc2047.c | 30 +++++++++++++++--------------- sendlib.c | 6 +++--- 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/charset.c b/charset.c index 8530469e6..01b152157 100644 --- a/charset.c +++ b/charset.c @@ -366,19 +366,18 @@ iconv_t mutt_iconv_open(const char *tocode, const char *fromcode, int flags) * If you're supplying inrepls, the source charset should be stateless; * if you're supplying an outrepl, the target charset should be. */ -size_t mutt_iconv(iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - ICONV_CONST char **inrepls, const char *outrepl) +size_t mutt_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, + size_t *outbytesleft, const char **inrepls, const char *outrepl) { size_t rc = 0, ret1; - ICONV_CONST char *ib = *inbuf; + const char *ib = *inbuf; size_t ibl = *inbytesleft; char *ob = *outbuf; size_t obl = *outbytesleft; while (true) { - ret1 = iconv(cd, &ib, &ibl, &ob, &obl); + ret1 = iconv(cd, (ICONV_CONST char **) &ib, &ibl, &ob, &obl); if (ret1 != (size_t) -1) rc += ret1; if (ibl && obl && errno == EILSEQ) @@ -386,14 +385,14 @@ size_t mutt_iconv(iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, if (inrepls) { /* Try replacing the input */ - ICONV_CONST char **t = NULL; + const char **t = NULL; for (t = inrepls; *t; t++) { - ICONV_CONST char *ib1 = *t; + const char *ib1 = *t; size_t ibl1 = strlen(*t); char *ob1 = ob; size_t obl1 = obl; - iconv(cd, &ib1, &ibl1, &ob1, &obl1); + iconv(cd, (ICONV_CONST char **) &ib1, &ibl1, &ob1, &obl1); if (!ibl1) { ib++; @@ -410,7 +409,7 @@ size_t mutt_iconv(iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, /* Replace the output */ if (!outrepl) outrepl = "?"; - iconv(cd, 0, 0, &ob, &obl); + iconv(cd, NULL, NULL, &ob, &obl); if (obl) { int n = strlen(outrepl); @@ -425,7 +424,7 @@ size_t mutt_iconv(iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, ob += n; obl -= n; rc++; - iconv(cd, 0, 0, 0, 0); /* for good measure */ + iconv(cd, NULL, NULL, NULL, NULL); /* for good measure */ continue; } } @@ -446,7 +445,7 @@ size_t mutt_iconv(iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, int mutt_convert_string(char **ps, const char *from, const char *to, int flags) { iconv_t cd; - ICONV_CONST char *repls[] = { "\357\277\275", "?", 0 }; + const char *repls[] = { "\357\277\275", "?", 0 }; char *s = *ps; if (!s || !*s) @@ -455,10 +454,10 @@ int mutt_convert_string(char **ps, const char *from, const char *to, int flags) if (to && from && (cd = mutt_iconv_open(to, from, flags)) != (iconv_t) -1) { int len; - ICONV_CONST char *ib = NULL; + const char *ib = NULL; char *buf = NULL, *ob = NULL; size_t ibl, obl; - ICONV_CONST char **inrepls = NULL; + const char **inrepls = NULL; char *outrepl = NULL; if (mutt_is_utf8(to)) @@ -507,7 +506,7 @@ struct FgetConv char *ob; char *ib; size_t ibl; - ICONV_CONST char **inrepls; + const char **inrepls; }; /** @@ -529,7 +528,7 @@ FGETCONV *fgetconv_open(FILE *file, const char *from, const char *to, int flags) { struct FgetConv *fc = NULL; iconv_t cd = (iconv_t) -1; - static ICONV_CONST char *repls[] = { "\357\277\275", "?", 0 }; + static const char *repls[] = { "\357\277\275", "?", 0 }; if (from && to) cd = mutt_iconv_open(to, from, flags); @@ -613,8 +612,7 @@ int fgetconv(FGETCONV *_fc) if (fc->ibl) { size_t obl = sizeof(fc->bufo); - mutt_iconv(fc->cd, (ICONV_CONST char **) &fc->ib, &fc->ibl, &fc->ob, &obl, - fc->inrepls, 0); + mutt_iconv(fc->cd, (const char **) &fc->ib, &fc->ibl, &fc->ob, &obl, fc->inrepls, 0); if (fc->p < fc->ob) return (unsigned char) *(fc->p)++; } diff --git a/charset.h b/charset.h index 61725ef42..2576c1a47 100644 --- a/charset.h +++ b/charset.h @@ -30,9 +30,8 @@ int mutt_convert_string(char **ps, const char *from, const char *to, int flags); iconv_t mutt_iconv_open(const char *tocode, const char *fromcode, int flags); -size_t mutt_iconv(iconv_t cd, ICONV_CONST char **inbuf, size_t *inbytesleft, - char **outbuf, size_t *outbytesleft, - ICONV_CONST char **inrepls, const char *outrepl); +size_t mutt_iconv(iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, + size_t *outbytesleft, const char **inrepls, const char *outrepl); typedef void *FGETCONV; diff --git a/handler.c b/handler.c index d07842ae1..eae529880 100644 --- a/handler.c +++ b/handler.c @@ -92,7 +92,7 @@ static void print_part_line(struct State *s, struct Body *b, int n) static void convert_to_state(iconv_t cd, char *bufi, size_t *l, struct State *s) { char bufo[BUFO_SIZE]; - ICONV_CONST char *ib = NULL; + const char *ib = NULL; char *ob = NULL; size_t ibl, obl; @@ -101,7 +101,7 @@ static void convert_to_state(iconv_t cd, char *bufi, size_t *l, struct State *s) if (cd != (iconv_t)(-1)) { ob = bufo, obl = sizeof(bufo); - iconv(cd, 0, 0, &ob, &obl); + iconv(cd, NULL, NULL, &ob, &obl); if (ob != bufo) state_prefix_put(bufo, ob - bufo, s); } diff --git a/ncrypt/gnupgparse.c b/ncrypt/gnupgparse.c index 510a24940..7277d7224 100644 --- a/ncrypt/gnupgparse.c +++ b/ncrypt/gnupgparse.c @@ -94,7 +94,7 @@ static void fix_uid(char *uid) { int n = s - uid + 1; /* chars available in original buffer */ char *buf = NULL; - ICONV_CONST char *ib = NULL; + const char *ib = NULL; char *ob = NULL; size_t ibl, obl; @@ -103,7 +103,7 @@ static void fix_uid(char *uid) ibl = d - uid + 1; ob = buf; obl = n; - iconv(cd, &ib, &ibl, &ob, &obl); + iconv(cd, (ICONV_CONST char **) &ib, &ibl, &ob, &obl); if (!ibl) { if (ob - buf < n) diff --git a/rfc2047.c b/rfc2047.c index 1effca00b..367c9edbe 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -53,9 +53,9 @@ extern char RFC822Specials[]; -typedef size_t (*encoder_t)(char *s, ICONV_CONST char *d, size_t dlen, const char *tocode); +typedef size_t (*encoder_t)(char *s, const char *d, size_t dlen, const char *tocode); -static size_t convert_string(ICONV_CONST char *f, size_t flen, const char *from, +static size_t convert_string(const char *f, size_t flen, const char *from, const char *to, char **t, size_t *tlen) { iconv_t cd; @@ -68,8 +68,8 @@ static size_t convert_string(ICONV_CONST char *f, size_t flen, const char *from, return (size_t)(-1); obl = 4 * flen + 1; ob = buf = mutt_mem_malloc(obl); - n = iconv(cd, &f, &flen, &ob, &obl); - if (n == (size_t)(-1) || iconv(cd, 0, 0, &ob, &obl) == (size_t)(-1)) + n = iconv(cd, (ICONV_CONST char **) &f, &flen, &ob, &obl); + if (n == (size_t)(-1) || iconv(cd, NULL, NULL, &ob, &obl) == (size_t)(-1)) { e = errno; FREE(&buf); @@ -189,7 +189,7 @@ char *mutt_choose_charset(const char *fromcode, const char *charsets, char *u, return tocode; } -static size_t b_encoder(char *s, ICONV_CONST char *d, size_t dlen, const char *tocode) +static size_t b_encoder(char *s, const char *d, size_t dlen, const char *tocode) { char *s0 = s; @@ -219,7 +219,7 @@ static size_t b_encoder(char *s, ICONV_CONST char *d, size_t dlen, const char *t return s - s0; } -static size_t q_encoder(char *s, ICONV_CONST char *d, size_t dlen, const char *tocode) +static size_t q_encoder(char *s, const char *d, size_t dlen, const char *tocode) { static const char hex[] = "0123456789ABCDEF"; char *s0 = s; @@ -250,7 +250,7 @@ static size_t q_encoder(char *s, ICONV_CONST char *d, size_t dlen, const char *t } /** - * try_block - Attempt to convert a block ot text + * try_block - Attempt to convert a block of text * @param d String to convert * @param dlen Length of string * @param fromcode Original encoding @@ -267,12 +267,12 @@ static size_t q_encoder(char *s, ICONV_CONST char *d, size_t dlen, const char *t * tocode, unless fromcode is 0, in which case the data is assumed to * be already in tocode, which should be 8-bit and stateless. */ -static size_t try_block(ICONV_CONST char *d, size_t dlen, const char *fromcode, +static size_t try_block(const char *d, size_t dlen, const char *fromcode, const char *tocode, encoder_t *encoder, size_t *wlen) { char buf1[ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 1]; iconv_t cd; - ICONV_CONST char *ib = NULL; + const char *ib = NULL; char *ob = NULL; size_t ibl, obl; int count, len, len_b, len_q; @@ -285,8 +285,8 @@ static size_t try_block(ICONV_CONST char *d, size_t dlen, const char *fromcode, ibl = dlen; ob = buf1; obl = sizeof(buf1) - strlen(tocode); - if (iconv(cd, &ib, &ibl, &ob, &obl) == (size_t)(-1) || - iconv(cd, 0, 0, &ob, &obl) == (size_t)(-1)) + if (iconv(cd, (ICONV_CONST char **) &ib, &ibl, &ob, &obl) == (size_t)(-1) || + iconv(cd, NULL, NULL, &ob, &obl) == (size_t)(-1)) { assert(errno == E2BIG); iconv_close(cd); @@ -353,7 +353,7 @@ static size_t encode_block(char *s, char *d, size_t dlen, const char *fromcode, { char buf1[ENCWORD_LEN_MAX - ENCWORD_LEN_MIN + 1]; iconv_t cd; - ICONV_CONST char *ib = NULL; + const char *ib = NULL; char *ob = NULL; size_t ibl, obl, n1, n2; @@ -365,8 +365,8 @@ static size_t encode_block(char *s, char *d, size_t dlen, const char *fromcode, ibl = dlen; ob = buf1; obl = sizeof(buf1) - strlen(tocode); - n1 = iconv(cd, &ib, &ibl, &ob, &obl); - n2 = iconv(cd, 0, 0, &ob, &obl); + n1 = iconv(cd, (ICONV_CONST char **) &ib, &ibl, &ob, &obl); + n2 = iconv(cd, NULL, NULL, &ob, &obl); assert(n1 != (size_t)(-1) && n2 != (size_t)(-1)); iconv_close(cd); return (*encoder)(s, buf1, ob - buf1, tocode); @@ -425,7 +425,7 @@ static size_t choose_block(char *d, size_t dlen, int col, const char *fromcode, * The input data is assumed to be a single line starting at column col; * if col is non-zero, the preceding character was a space. */ -static int rfc2047_encode(ICONV_CONST char *d, size_t dlen, int col, const char *fromcode, +static int rfc2047_encode(const char *d, size_t dlen, int col, const char *fromcode, const char *charsets, char **e, size_t *elen, char *specials) { int rc = 0; diff --git a/sendlib.c b/sendlib.c index dbdacfbff..c0a3cacb6 100644 --- a/sendlib.c +++ b/sendlib.c @@ -684,7 +684,7 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, { iconv_t cd1, *cd = NULL; char bufi[256], bufu[512], bufo[4 * sizeof(bufi)]; - ICONV_CONST char *ib = NULL, *ub = NULL; + const char *ib = NULL, *ub = NULL; char *ob = NULL; size_t ibl, obl, ubl, ubl1, n, ret; struct Content *infos = NULL; @@ -724,7 +724,7 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, ib = bufi; ob = bufu; obl = sizeof(bufu); - n = iconv(cd1, ibl ? &ib : 0, &ibl, &ob, &obl); + n = iconv(cd1, (ICONV_CONST char **) (ibl ? &ib : 0), &ibl, &ob, &obl); assert(n == (size_t)(-1) || !n); if (n == (size_t)(-1) && ((errno != EINVAL && errno != E2BIG) || ib == bufi)) { @@ -743,7 +743,7 @@ static size_t convert_file_to(FILE *file, const char *fromcode, int ncodes, ubl = ubl1; ob = bufo; obl = sizeof(bufo); - n = iconv(cd[i], (ibl || ubl) ? &ub : 0, &ubl, &ob, &obl); + n = iconv(cd[i], (ICONV_CONST char **) ((ibl || ubl) ? &ub : 0), &ubl, &ob, &obl); if (n == (size_t)(-1)) { assert(errno == E2BIG || (BUGGY_ICONV && (errno == EILSEQ || errno == ENOENT))); -- 2.40.0