Store into BUF (of size SIZE) a quoted string representation of P. If the representation's length is less than SIZE, return the length; the representation is not null terminated. Otherwise return SIZE, to indicate that BUF is too small. */
| 963 | length; the representation is not null terminated. Otherwise |
| 964 | return SIZE, to indicate that BUF is too small. */ |
| 965 | static ptrdiff_t |
| 966 | format_quoted_string(char *buf, ptrdiff_t size, char const *p) |
| 967 | { |
| 968 | char *b = buf; |
| 969 | ptrdiff_t s = size; |
| 970 | if (!s) |
| 971 | return size; |
| 972 | *b++ = '"', s--; |
| 973 | for (;;) { |
| 974 | char c = *p++; |
| 975 | if (s <= 1) |
| 976 | return size; |
| 977 | switch (c) { |
| 978 | default: *b++ = c, s--; continue; |
| 979 | case '\0': *b++ = '"', s--; return size - s; |
| 980 | case '"': case '\\': break; |
| 981 | case ' ': c = 's'; break; |
| 982 | case '\f': c = 'f'; break; |
| 983 | case '\n': c = 'n'; break; |
| 984 | case '\r': c = 'r'; break; |
| 985 | case '\t': c = 't'; break; |
| 986 | case '\v': c = 'v'; break; |
| 987 | } |
| 988 | *b++ = '\\', *b++ = c, s -= 2; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | /* Store into BUF (of size SIZE) a timestamp formatted by TIME_FMT. |
| 993 | TM is the broken-down time, T the seconds count, AB the time zone |