char * single_quote(const char *s) { char *p; startstackstr(&p); do { char *q; size_t len; len = strchrnul(s, '\'') - s; q = p = makestrspace(len + 3, p); *q++ = '\''; q = (char *)mempcpy(q, s, len); *q++ = '\''; s += len; stadjust(q - p, &p); len = strspn(s, "'"); if (!len) break; q = p = makestrspace(len + 3, p); *q++ = '"'; q = (char *)mempcpy(q, s, len); *q++ = '"'; s += len; stadjust(q - p, &p); } while (*s); ustputc(0, &p); return stackblock(); }
char * single_quote(const char *s) { char *p; STARTSTACKSTR(p); do { char *q; size_t len; len = strchrnul(s, '\'') - s; q = p = makestrspace(len + 3, p); *q++ = '\''; q = mempcpy(q, s, len); *q++ = '\''; s += len; STADJUST(q - p, p); len = strspn(s, "'"); if (!len) break; q = p = makestrspace(len + 3, p); *q++ = '"'; q = mempcpy(q, s, len); *q++ = '"'; s += len; STADJUST(q - p, p); } while (*s); USTPUTC(0, p); return stackblock(); }
static char * mklong(const char *str, const char *ch) { char *copy; size_t len; len = ch - str + 3; STARTSTACKSTR(copy); copy = makestrspace(len, copy); memcpy(copy, str, len - 3); copy[len - 3] = 'j'; copy[len - 2] = *ch; copy[len - 1] = '\0'; return (copy); }
static char * mklong(const char *str, const char *ch) { char *copy; size_t len; size_t pridmax_len = strlen(PRIdMAX); len = ch - str + pridmax_len; STARTSTACKSTR(copy); copy = makestrspace(len + 1, copy); memcpy(copy, str, len - pridmax_len); memcpy(copy + len - pridmax_len, PRIdMAX, pridmax_len - 1); copy[len - 1] = *ch; copy[len] = '\0'; return (copy); }
static char * mklong(const char *str, const char *ch) { /* * Replace a string like "%92.3u" with "%92.3"PRIuMAX. * * Although C99 does not guarantee it, we assume PRIiMAX, * PRIoMAX, PRIuMAX, PRIxMAX, and PRIXMAX are all the same * as PRIdMAX with the final 'd' replaced by the corresponding * character. */ char *copy; size_t len; len = ch - str + sizeof(PRIdMAX); STARTSTACKSTR(copy); copy = makestrspace(len, copy); memcpy(copy, str, len - sizeof(PRIdMAX)); memcpy(copy + len - sizeof(PRIdMAX), PRIdMAX, sizeof(PRIdMAX)); copy[len - 2] = *ch; return (copy); }