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 str;
        VALUE length;

        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);
        }
        str = rb_tainted_str_new(0,len);

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