Skip to content

Instantly share code, notes, and snippets.

@mattwildig
Created January 25, 2012 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwildig/1676982 to your computer and use it in GitHub Desktop.
Save mattwildig/1676982 to your computer and use it in GitHub Desktop.
if (RTEST(rf_call(path,is_file,Qnil))) {
body = rf_call(path, id_read_file,Qnil);
/* I don't wanna deal with non-strings :D. */
/* this check means we don't need to use StringValue */
if (TYPE(body) != T_STRING) {
return -ENOENT;
}
/* We have the body, now save it the entire contents to our
* opened_file lists. */
newfile = ALLOC(opened_file);
/* these lines replace rb_str2cstr */
value = RSTRING(body)->ptr;
newfile->size = RSRING(body)->len;
newfile->value = ALLOC_N(char,(newfile->size)+1);
memcpy(newfile->value,value,newfile->size);
newfile->writesize = newfile->size+1;
newfile->path = strdup(path);
newfile->raw = 0;
newfile->zero_offset = 0;
} else
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment