Author: imp Date: Mon Mar 28 20:16:29 2016 New Revision: 297365 URL: https://svnweb.freebsd.org/changeset/base/297365
Log: Move pccard_safe_quote() up to subr_bus.c and rename to devctl_safe_quote() so it can be used more generally. Modified: head/sys/dev/pccard/pccard.c head/sys/kern/subr_bus.c head/sys/sys/bus.h Modified: head/sys/dev/pccard/pccard.c ============================================================================== --- head/sys/dev/pccard/pccard.c Mon Mar 28 19:55:30 2016 (r297364) +++ head/sys/dev/pccard/pccard.c Mon Mar 28 20:16:29 2016 (r297365) @@ -1025,26 +1025,6 @@ pccard_child_location_str(device_t bus, return (0); } -/* XXX Maybe this should be in subr_bus? */ -static void -pccard_safe_quote(char *dst, const char *src, size_t len) -{ - char *walker = dst, *ep = dst + len - 1; - - if (len == 0) - return; - while (src != NULL && walker < ep) - { - if (*src == '"') { - if (ep - walker < 2) - break; - *walker++ = '\\'; - } - *walker++ = *src++; - } - *walker = '\0'; -} - static int pccard_child_pnpinfo_str(device_t bus, device_t child, char *buf, size_t buflen) @@ -1054,8 +1034,8 @@ pccard_child_pnpinfo_str(device_t bus, d struct pccard_softc *sc = PCCARD_SOFTC(bus); char cis0[128], cis1[128]; - pccard_safe_quote(cis0, sc->card.cis1_info[0], sizeof(cis0)); - pccard_safe_quote(cis1, sc->card.cis1_info[1], sizeof(cis1)); + devctl_safe_quote(cis0, sc->card.cis1_info[0], sizeof(cis0)); + devctl_safe_quote(cis1, sc->card.cis1_info[1], sizeof(cis1)); snprintf(buf, buflen, "manufacturer=0x%04x product=0x%04x " "cisvendor=\"%s\" cisproduct=\"%s\" function_type=%d", sc->card.manufacturer, sc->card.product, cis0, cis1, pf->function); Modified: head/sys/kern/subr_bus.c ============================================================================== --- head/sys/kern/subr_bus.c Mon Mar 28 19:55:30 2016 (r297364) +++ head/sys/kern/subr_bus.c Mon Mar 28 20:16:29 2016 (r297365) @@ -839,6 +839,38 @@ sysctl_devctl_queue(SYSCTL_HANDLER_ARGS) return (0); } +/** + * @brief safely quotes strings that might have double quotes in them. + * + * The devctl protocol relies on quoted strings having matching quotes. + * This routine quotes any internal quotes so the resulting string + * is safe to pass to snprintf to construct, for example pnp info strings. + * Strings are always terminated with a NUL, but may be truncated if longer + * than @p len bytes after quotes. + * + * @param dst Buffer to hold the string. Must be at least @p len bytes long + * @param src Original buffer. + * @param len Length of buffer pointed to by @dst, including trailing NUL + */ +void +devctl_safe_quote(char *dst, const char *src, size_t len) +{ + char *walker = dst, *ep = dst + len - 1; + + if (len == 0) + return; + while (src != NULL && walker < ep) + { + if (*src == '"') { + if (ep - walker < 2) + break; + *walker++ = '\\'; + } + *walker++ = *src++; + } + *walker = '\0'; +} + /* End of /dev/devctl code */ static TAILQ_HEAD(,device) bus_data_devices; Modified: head/sys/sys/bus.h ============================================================================== --- head/sys/sys/bus.h Mon Mar 28 19:55:30 2016 (r297364) +++ head/sys/sys/bus.h Mon Mar 28 20:16:29 2016 (r297365) @@ -141,6 +141,7 @@ void devctl_notify(const char *__system, const char *__type, const char *__data); void devctl_queue_data_f(char *__data, int __flags); void devctl_queue_data(char *__data); +void devctl_safe_quote(char *__dst, const char *__src, size_t len); /** * Device name parsers. Hook to allow device enumerators to map _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"