annotate old/tmp/test.c @ 596:f1c2e11a2ef4 draft

add xdr_getpos
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 04 Nov 2009 22:52:06 +0900
parents 2f138c672969
children d38d9896dfa4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
595
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include <stdio.h>
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <stdlib.h>
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <sys/types.h>
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #define FALSE 0
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 #define TRUE 1
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 typedef int bool_t;
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 typedef int enum_t;
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include <rpc/xdr.h>
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #define CHUNK 1024
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 int
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 main()
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 {
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 XDR xdrs;
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 double dp[6];
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 int size = CHUNK;
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 char *addr = (char*)malloc(size);
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 int i;
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 double d = 0.1;
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 xdrmem_create(&xdrs, addr, size, XDR_ENCODE);
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 for (i = 0; i< 6; i++) {
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 dp[i] = d * i;
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 xdr_double(&xdrs, &dp[i]);
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 }
596
f1c2e11a2ef4 add xdr_getpos
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 595
diff changeset
34 int pos = xdr_getpos(&xdrs);
f1c2e11a2ef4 add xdr_getpos
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 595
diff changeset
35 printf("xdr written %d\n",pos);
595
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 for (i = 0; i< 6; i++) dp[i] = 0.0;
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 xdrmem_create(&xdrs, addr, size, XDR_DECODE);
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 for (i = 0; i< 6; i++) {
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 xdr_double(&xdrs, &dp[i]);
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 printf("%g ",dp[i]);
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 }
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 printf("\n");
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 }
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
2f138c672969 add xdr test routine...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52