Created
November 29, 2014 13:29
-
-
Save yashi/46dae815b3c5a4751204 to your computer and use it in GitHub Desktop.
This file contains 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
/* -*- compile-command: "gcc -Wall -Wextra -g $(pkg-config --cflags --libs gio-2.0) transfer-full-in.c" -*- */ | |
#include <glib.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
int main() | |
{ | |
void *buf; | |
gsize len; | |
GBytes *bytes; | |
len = 100; | |
buf = malloc(len); | |
sprintf(buf, "%s", "hello"); | |
bytes = g_bytes_new_take(buf, len); | |
// It might be a good idea to remove the reference to the buf. | |
// This ensures that we are no longer able to free it by | |
// accident. | |
buf = NULL; | |
len = 0; | |
fwrite(g_bytes_get_data(bytes, NULL), | |
g_bytes_get_size(bytes),1, stdout); | |
// buf will be freed when byts are freed | |
g_bytes_unref(bytes); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment