diff options
author | Philip Chimento <philip@endlessm.com> | 2013-04-10 12:17:07 +0100 |
---|---|---|
committer | P. F. Chimento <philip.chimento@gmail.com> | 2013-04-17 17:14:21 +0200 |
commit | 408f93ec2327a8647030139a2e6f295e8b2c8de1 (patch) | |
tree | c0a796adc7ca6981b8eb0b53e8c21b5101dd2962 /endless/hello.c | |
parent | 5299f7acf85200a46679334a6bd230d4e2101b7f (diff) |
Skeleton build system to build a shared library
Builds a dummy shared library that exports one symbol for testing,
eos_hello_sample_function().
[#1]
Diffstat (limited to 'endless/hello.c')
-rw-r--r-- | endless/hello.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/endless/hello.c b/endless/hello.c new file mode 100644 index 0000000..1db6f90 --- /dev/null +++ b/endless/hello.c @@ -0,0 +1,69 @@ +/* Copyright 2013 Endless Mobile, Inc. */ + +#include <string.h> +#include <glib.h> +#include <gio/gio.h> + +#include <endless/endless.h> + +/** + * SECTION:hello + * @short_description: Sample skeleton function + * @title: Hello + * + * This is a sample skeleton function that says hello either to the terminal or + * a file. + */ + +/** + * eos_hello_sample_function: + * @file: (allow-none): #GFile to write to, or %NULL + * @error: (allow-none): Return location for a #GError, or %NULL to ignore. + * + * A sample API function to say hello with. Prints on the terminal if @file is + * %NULL, or else appends it to @file. + * + * Returns: %TRUE on success, %FALSE on error. + */ +gboolean +eos_hello_sample_function(GFile *file, + GError **error) +{ + char hello_string[] = "Hello, world!\n"; + GFileOutputStream *stream; + ssize_t write_count; + gboolean success; + + g_return_val_if_fail (G_IS_FILE (file) || file == NULL, FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + /* Print to terminal */ + if (file == NULL) + { + g_print ("%s", hello_string); + return TRUE; + } + + stream = g_file_append_to (file, + G_FILE_CREATE_NONE, + NULL, /* cancellable */ + error); + if(!stream) + return FALSE; + + write_count = g_output_stream_write (G_OUTPUT_STREAM (stream), + hello_string, + strlen (hello_string), + NULL, /* cancellable */ + error); + success = g_output_stream_close (G_OUTPUT_STREAM (stream), + NULL, /* cancellable */ + error); + g_object_unref (stream); + + if (write_count == -1 || !success) + return FALSE; + + return TRUE; +} + |