Created
June 3, 2016 17:06
-
-
Save mbrubeck/a5a86f932b4f08dd3b9eabbcf73c1094 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate gcc; | |
fn main() { | |
gcc::compile_library("libtest.a", &["test.c"]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "segv" | |
version = "0.1.0" | |
build = "build.rs" | |
[[bin]] | |
name = "segv" | |
path = "main.rs" | |
[build-dependencies] | |
gcc = "0.3" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern { | |
fn test(str: *const u8, len: usize) -> *mut u8; | |
} | |
fn main() { | |
let s = "hello"; | |
unsafe { | |
test(s.as_ptr(), s.len()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <string.h> | |
#include <stdlib.h> | |
char *test(const char *str, size_t len) | |
{ | |
char *new_str; | |
new_str = malloc(len + 1); | |
if (!new_str) | |
return NULL; | |
memcpy(new_str, str, len); | |
new_str[len] = '\0'; | |
return new_str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment