chiark / gitweb /
@@@ more mess
[mLib] / test / example / exfunc.c
1 /* -*-c-*-
2  *
3  * Example functionality to test
4  *
5  * (c) 2024 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of the mLib utilities library.
11  *
12  * mLib is free software: you can redistribute it and/or modify it under
13  * the terms of the GNU Library General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or (at
15  * your option) any later version.
16  *
17  * mLib is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
20  * License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with mLib.  If not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
25  * USA.
26  */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "example.h"
34
35 /*----- Main code ---------------------------------------------------------*/
36
37 /* Return the sum X + Y. */
38 int add(int x, int y)
39   { return (x + y); }
40
41 /* Generate a personalized greeting, mentioning NAME.  The greeting is
42  * written to the output buffer BUF, which has space for SZ characters.
43  * Return zero on success, or -1 on error.
44  */
45 int greet(char *buf, size_t sz, const char *name)
46 {
47   if (sz < strlen(name) + 9) return (-1);
48   sprintf(buf, "Hello, %s!", name);
49   return (0);
50 }
51
52 /*----- That's all, folks -------------------------------------------------*/