test4.c

00001 /* $Id: test4.c 11432 2007-05-23 11:37:23Z jlaako $ */
00002 
00003 /*
00004 
00005     Shared memory object for POSIX/IEEE-1003.1 compliant systems.
00006 
00007     Copyright (C) 2005-2007 Nokia Corporation.
00008 
00009     Contact: Jussi Laako <jussi.laako@nokia.com>
00010 
00011     This library is free software; you can redistribute it and/or
00012     modify it under the terms of the GNU Lesser General Public
00013     License as published by the Free Software Foundation; either
00014     version 2.1 of the License, or (at your option) any later version.
00015 
00016     This library is distributed in the hope that it will be useful,
00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019     Lesser General Public License for more details.
00020 
00021     You should have received a copy of the GNU Lesser General Public
00022     License along with this library; if not, write to the Free Software
00023     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00024 
00025 */
00026 
00027 
00028 #include <stdio.h>
00029 #include <string.h>
00030 
00031 #include "sharedmem.h"
00032 
00033 
00034 typedef struct _test_t
00035 {
00036     unsigned int u1;
00037     unsigned int u2;
00038     unsigned int u3;
00039     unsigned int u4;
00040     unsigned long long ull1;
00041     unsigned long long ull2;
00042 } test_t;
00043 
00044 
00045 int main (int argc, char *argv[])
00046 {
00047     unsigned int i;
00048     test_t *t;
00049     sharedmem_t shm;
00050 
00051     if (sharedmem_create(&shm, "/test4.shm", 1024 * sizeof(test_t)) != 0)
00052     {
00053         puts(sharedmem_get_error_string(&shm));
00054         return 1;
00055     }
00056     t = (test_t *) SHAREDMEM_PTR(&shm);
00057     memset(t, 0x00, 1024 * sizeof(test_t));
00058     
00059     for (i = 0; i < 1024; i++)
00060     {
00061         t[i].u1 = i;
00062         t[i].u2 = t[i].u1 + 1;
00063         t[i].u3 = t[i].u2 + 1;
00064         t[i].u4 = t[i].u3 + 1;
00065         t[i].ull1 = (unsigned long long) i << 32;
00066         t[i].ull2 = t[i].ull1 + 1;
00067     }    
00068 
00069     if (sharedmem_close(&shm) != 0)
00070     {
00071         puts("sharedmem_close() failed");
00072         return 1;
00073     }
00074     
00075     return 0;
00076 }

Generated on Thu Sep 13 18:14:21 2007 for libsharedmem by  doxygen 1.5.1