_c_public_ int c_shquote_quote(char **outp,
                               size_t *n_outp,
                               const char *in,
                               size_t n_in) {
        size_t n_out = *n_outp;
        char *out = *outp;
        int r;

        /*
         * We always prepend and append a single quote. This will not produce
         * optimal output, but ensures we produce the same output as other
         * implementations do. If optimal output is needed, we can always
         * provide an alternative implementation.
         */

        r = c_shquote_append_char(&out, &n_out, '\'');
        if (r)
                return r;

        while (n_in > 0) {
                size_t len;

                if (*in == '\'') {
                        const char *escape = "'\\''";

                        c_shquote_skip_char(&in, &n_in);

                        r = c_shquote_append_str(&out, &n_out, escape, strlen(escape));
                        if (r)
                                return r;
                } else {
                        /*
                         * Consume until the next single quote. If none exists,
                         * consume the rest of the string.
                         */
                        len = c_shquote_strncspn(in, n_in, "'");
                        r = c_shquote_consume_str(&out, &n_out, &in, &n_in, len);
                        if (r)
                                return r;
                }
        }

        r = c_shquote_append_char(&out, &n_out, '\'');
        if (r)
                return r;

        *outp = out;
        *n_outp = n_out;
        return 0;
}
_c_public_ int c_shquote_quote(char **outp,
                               size_t *n_outp,
                               const char *in,
                               size_t n_in) {
        size_t n_out = *n_outp;
        char *out = *outp;
        int r;

         

        r = c_shquote_append_char(&out, &n_out, '\'');
        if (r)
                return r;

        while (n_in > 0) {
                size_t len;

                if (*in == '\'') {
                        const char *escape = "'\\''";

                        c_shquote_skip_char(&in, &n_in);

                        r = c_shquote_append_str(&out, &n_out, escape, strlen(escape));
                        if (r)
                                return r;
                } else {
                         
                        len = c_shquote_strncspn(in, n_in, "'");
                        r = c_shquote_consume_str(&out, &n_out, &in, &n_in, len);
                        if (r)
                                return r;
                }
        }

        r = c_shquote_append_char(&out, &n_out, '\'');
        if (r)
                return r;

        *outp = out;
        *n_outp = n_out;
        return 0;
}