r1598: Added Win32/DLL compatibility
[uffi.git] / examples / c-test-fns.c
1 /***************************************************************************
2  * FILE IDENTIFICATION
3  *  
4  *  Name:         c-test-fns.c
5  *  Purpose:      Test functions in C for UFFI library
6  *  Programer:    Kevin M. Rosenberg
7  *  Date Started: Mar 2002
8  *
9  *  CVS Id:   $Id: c-test-fns.c,v 1.3 2002/03/21 05:29:57 kevin Exp $
10  *
11  * This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
12  *
13  * UFFI users are granted the rights to distribute and use this software
14  * as governed by the terms of the Lisp Lesser GNU Public License
15  * (http://opensource.franz.com/preamble.html), also known as the LLGPL.
16
17  * These variables are correct for GCC
18  * you'll need to modify these for other compilers
19  ***************************************************************************/
20
21 #ifdef WIN32
22 #include <windows.h>
23
24 BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll,
25                           DWORD fdwReason,
26                           LPVOID lpvReserved)
27 {
28         return 1;
29 }
30        
31 #define DLLEXPORT __declspec(dllexport)
32
33 #else
34 #define DLLEXPORT
35 #endif
36
37 #include <ctype.h>
38 #include <stdlib.h>
39
40 /* Test of constant input string */
41 DLLEXPORT
42 int
43 cs_count_upper (char* psz)
44 {
45   int count = 0;
46
47   if (psz) {
48     while (*psz) {
49       if (isupper (*psz))
50         ++count;
51       ++psz;
52     }
53     return count;
54   } else 
55     return -1;
56 }
57
58 /* Test of input and output of a string */
59 DLLEXPORT
60 void
61 cs_to_upper (char* psz)
62 {
63   if (psz) {
64     while (*psz) {
65       *psz = toupper (*psz);
66       ++psz;
67     }
68   }
69 }
70
71 /* Test of an output only string */
72 DLLEXPORT
73 void
74 cs_make_random (int size, char* buffer)
75 {
76   int i;
77   for (i = 0; i < size; i++)
78     buffer[i] = 'A' + (rand() % 26);
79 }
80
81     
82
83