open (PGlarge)

    /*
     * call-seq:
     *    lrg.open( [mode] )
     *
     * Opens a large object.
     * The _mode_ argument specifies the mode for the opened large object,
     * which is either +INV_READ+ or +INV_WRITE+.
     */
    static VALUE
    pglarge_open(argc, argv, obj)
        int argc;
        VALUE *argv;
        VALUE obj;
    {
        PGlarge *pglarge = get_pglarge(obj);
        VALUE nmode;
        int fd;
        int mode;

        if (rb_scan_args(argc, argv, "01", &nmode) == 0) {
            mode = INV_READ;
        }
        else {
            mode = FIX2INT(nmode);
        }

        if((fd = lo_open(pglarge->pgconn, pglarge->lo_oid, mode)) < 0) {
            rb_raise(rb_ePGError, "can't open large object");
        }
        pglarge->lo_fd = fd;

        return INT2FIX(pglarge->lo_fd);
    }