1 /* hello world - Self contained, using a single piece of data at
2  *               initialisation time (no data copying) */
3 
4 #define VSTR_COMPILE_INCLUDE 1
5 #include <vstr.h>
6 #include <errno.h>  /* errno variable */
7 #include <err.h>    /* BSD/Linux header see: man errx */
8 #include <unistd.h> /* for STDOUT_FILENO */
9 
main(void)10 int main(void)
11 {
12   Vstr_base *s1 = NULL;
13 
14   if (!vstr_init()) /* initialize the library */
15     err(EXIT_FAILURE, "init");
16 
17   /* create a string with data */
18   if (!(s1 = vstr_dup_cstr_buf(NULL, "Hello World\n")))
19     err(EXIT_FAILURE, "Create string");
20 
21   /* output the data to the user --
22    *    assumes POSIX, assumes blocking IO but should work without */
23   while (s1->len)
24     if (!vstr_sc_write_fd(s1, 1, s1->len, STDOUT_FILENO, NULL))
25     {
26       if ((errno != EAGAIN) && (errno != EINTR))
27         err(EXIT_FAILURE, "write");
28     }
29 
30   /* cleanup allocated resources */
31   vstr_free_base(s1);
32 
33   vstr_exit();
34 
35   exit (EXIT_SUCCESS);
36 }
37