예제 #1
0
파일: aio.c 프로젝트: methodmissing/aio
static VALUE
control_block_open(int argc, VALUE *argv, VALUE cb)
{
    const char *fmode;
#ifdef RUBY19
    rb_io_t *fptr;
#else	
    OpenFile *fptr;
#endif
    VALUE file, mode;
    rb_aiocb_t *cbs = GetCBStruct(cb);
    rb_scan_args(argc, argv, "02", &file, &mode);
    fmode = NIL_P(mode) ? "r" : RSTRING_PTR(mode);
    struct stat stats;
   
    Check_Type(file, T_STRING);

    cbs->io = rb_file_open(RSTRING_PTR(file), fmode);
    GetOpenFile(cbs->io, fptr);
    rb_io_check_readable(fptr);

    if ( cbs->cb.aio_fildes == 0 && cbs->cb.aio_nbytes == 0){
#ifdef RUBY19
      cbs->cb.aio_fildes = fptr->fd;
#else	
      cbs->cb.aio_fildes = fileno(fptr->f);
#endif
      fstat(cbs->cb.aio_fildes, &stats);
      control_block_nbytes_set(cb, INT2FIX(stats.st_size));
    }
    return cb;    
}
예제 #2
0
파일: raspell.c 프로젝트: stuart/raspell
/**
 * Simple utility function to correct a file.
 * The file gets read, content will be checked and write back.
 * Please note: This method will change the file! - no backup and of course: no warranty!
 * @param filename the name of the file as String.
 * @exception Exception due to lack of read/write permissions.
 */
static VALUE aspell_correct_file(VALUE self, VALUE filename) {
    if (rb_block_given_p()) {
        VALUE content = rb_funcall(rb_cFile, rb_intern("readlines"), 1, filename);
        VALUE newcontent = aspell_correct_lines(self, content);
        VALUE file = rb_file_open(STR2CSTR(filename), "w+");
        rb_funcall(file, rb_intern("write"), 1, newcontent);
        rb_funcall(file, rb_intern("close"), 0);
    } else {
        rb_raise(cAspellError, "%s", "No block given. How to correct?");
    }
    return self;

}
예제 #3
0
파일: eruby_main.c 프로젝트: shugo/eruby
static VALUE file_open(VALUE filename)
{
    return rb_file_open((char *) filename, "r");
}