/* The return value is the position of the delimiter/zero byte after the option name in p.  */
const char* get_opt_name(char *buf, int buf_size, const char *p, char delim)
/* The return value is the position of the delimiter/zero byte after the option name in p.  */
const char* get_opt_name(char *buf, int buf_size, const char *p, char delim)
{
    char *q;
    q = buf;
    while (*p != '\0' && *p != delim) {
        if (q && (q - buf) < buf_size - 1)
            *q++ = *p;
        p++;
    }
    if (q)
        *q = '\0';
    return p;
}