read (PGlarge)

    /*
     * call-seq:
     *    lrg.read( [length] )
     *
     * Attempts to read _length_ bytes from large object.
     * If no _length_ is given, reads all data.
     */
    static VALUE
    pglarge_read(argc, argv, obj)
        int argc;
        VALUE *argv;
        VALUE obj;
    {
            int len;
            PGlarge *pglarge = get_pglarge(obj);
            VALUE length;
            char *buffer;

            rb_scan_args(argc, argv, "01", &length);
            if (NIL_P(length)) {
                    return loread_all(obj);
            }

            len = NUM2INT(length);
            if (len < 0){
                    rb_raise(rb_ePGError,"nagative length %d given", len);
            }
            buffer = ALLOCA_N(char, len);

            if((len = lo_read(pglarge->pgconn, pglarge->lo_fd, buffer, len)) < 0) {
                    rb_raise(rb_ePGError, "error while reading");
            }
            if (len == 0) return Qnil;
            return rb_str_new(buffer,len);
    }