strbuf_nl_to_crlf() converts all occurrences of \n to \r\n */
| 55 | |
| 56 | /* strbuf_nl_to_crlf() converts all occurrences of \n to \r\n */ |
| 57 | void |
| 58 | strbuf_nl_to_crlf(strbuf_t *strbuf) |
| 59 | { |
| 60 | if (strbuf->str) { |
| 61 | int len = (int) strlen(strbuf->str); |
| 62 | int count = 0; |
| 63 | char *cp = strbuf->str; |
| 64 | |
| 65 | while (*cp) |
| 66 | if (*cp++ == '\n') |
| 67 | count++; |
| 68 | if (count) { |
| 69 | strbuf_reserve(strbuf, len + count + 1); |
| 70 | for (cp = strbuf->str + len + count; count; --cp) |
| 71 | if ((*cp = cp[-count]) == '\n') { |
| 72 | *--cp = '\r'; |
| 73 | --count; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /* strlen() but returns unsigned and panics if string is unreasonably long; |
| 80 | used by dlb as well as by nethack */ |
no test coverage detected