X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fwget.h;h=1236ff14368ecb0cc585fc06b4bbdea960520f9c;hp=17733cb04bb8bc492a0debc40efcab03a2781918;hb=2cfb2d2ef6c8043787d05aae46bcf369235c7d9f;hpb=782742037815f37537214fba701abbec13c7fd13 diff --git a/src/wget.h b/src/wget.h index 17733cb0..1236ff14 100644 --- a/src/wget.h +++ b/src/wget.h @@ -148,6 +148,30 @@ char *xstrdup_debug PARAMS ((const char *, const char *, int)); #define ARRAY_SIZE(array) (sizeof (array) / sizeof (*(array))) +/* Copy the data delimited with BEG and END to alloca-allocated + storage, and zero-terminate it. BEG and END are evaluated only + once, in that order. */ +#define BOUNDED_TO_ALLOCA(beg, end, place) do { \ + const char *DTA_beg = (beg); \ + int DTA_len = (end) - DTA_beg; \ + place = alloca (DTA_len + 1); \ + memcpy (place, DTA_beg, DTA_len); \ + place[DTA_len] = '\0'; \ +} while (0) + +/* Return non-zero if string bounded between BEG and END is equal to + STRING_LITERAL. The comparison is case-sensitive. */ +#define BOUNDED_EQUAL(beg, end, string_literal) \ + ((end) - (beg) == sizeof (string_literal) - 1 \ + && !memcmp ((beg), (string_literal), \ + sizeof (string_literal) - 1)) + +/* The same as above, except the comparison is case-insensitive. */ +#define BOUNDED_EQUAL_NO_CASE(beg, end, string_literal) \ + ((end) - (beg) == sizeof (string_literal) - 1 \ + && !strncasecmp ((beg), (string_literal), \ + sizeof (string_literal) - 1)) + /* Note that this much more elegant definition cannot be used: #define STRDUP_ALLOCA(str) (strcpy ((char *)alloca (strlen (str) + 1), str))