* fname_encode() * * Args: * legal zero-terminated list of acceptable file name characters * quotechar lead-in character used to quote illegal characters as * hex digits * s string to encode * callerbuf buffer to house result * bufsz size of callerbuf * * Notes: * The hex digits 0-9 and A-F are always part of t
| 252 | * "This%20is%20a%20%25%20test%21" |
| 253 | */ |
| 254 | char * |
| 255 | fname_encode( |
| 256 | const char *legal, |
| 257 | char quotechar, |
| 258 | char *s, |
| 259 | char *callerbuf, |
| 260 | int bufsz) |
| 261 | { |
| 262 | char *sp, *op; |
| 263 | int cnt = 0; |
| 264 | static char hexdigits[] = "0123456789ABCDEF"; |
| 265 | |
| 266 | sp = s; |
| 267 | op = callerbuf; |
| 268 | *op = '\0'; |
| 269 | |
| 270 | while (*sp) { |
| 271 | /* Do we have room for one more character or encoding? */ |
| 272 | if ((bufsz - cnt) <= 4) |
| 273 | return callerbuf; |
| 274 | |
| 275 | if (*sp == quotechar) { |
| 276 | (void) sprintf(op, "%c%02X", quotechar, *sp); |
| 277 | op += 3; |
| 278 | cnt += 3; |
| 279 | } else if ((strchr(legal, *sp) != 0) |
| 280 | || (strchr(hexdigits, *sp) != 0)) { |
| 281 | *op++ = *sp; |
| 282 | *op = '\0'; |
| 283 | cnt++; |
| 284 | } else { |
| 285 | (void) sprintf(op, "%c%02X", quotechar, *sp); |
| 286 | op += 3; |
| 287 | cnt += 3; |
| 288 | } |
| 289 | sp++; |
| 290 | } |
| 291 | return callerbuf; |
| 292 | } |
| 293 | |
| 294 | /* |
| 295 | * fname_decode() |
no outgoing calls
no test coverage detected