-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_server.c
56 lines (42 loc) · 1.01 KB
/
calc_server.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* This is sample code generated by rpcgen
* Modified by yesilzeytin for calculator
*/
#include "calc.h"
int *
add_1_svc(numbers *argp, struct svc_req *rqstp)
{
static int result;
printf("add(%d, %d) is called\n", argp->a, argp->b);
result = argp->a + argp->b;
return &result;
}
int *
sub_1_svc(numbers *argp, struct svc_req *rqstp)
{
static int result;
printf("sub(%d, %d) is called\n", argp->a, argp->b);
result = argp->a - argp->b;
return &result;
}
int *
mul_1_svc(numbers *argp, struct svc_req *rqstp)
{
static int result;
printf("mul(%d, %d) is called\n", argp->a, argp->b);
result = argp->a * argp->b;
return &result;
}
int *
div_1_svc(numbers *argp, struct svc_req *rqstp)
{
static int result;
printf("div(%d, %d) is called\n", argp->a, argp->b);
if (argp->b != 0)
result = argp->a / argp->b;
else {
printf("You have tried a zero division. Do not trust the output (it's divided by 1) and please don't try to divide something with 0.\n");
result = argp->a;
}
return &result;
}