Add missing export of fallocate64 on 32-bit platforms.
[glibc.git] / sunrpc / rpc_clntout.c
blob08d96012123b7a4274f0d0aa9188d6acfb403acc
1 /*
2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user or with the express written consent of
8 * Sun Microsystems, Inc.
10 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 * Sun RPC is provided with no support and without any obligation on the
15 * part of Sun Microsystems, Inc. to assist in its use, correction,
16 * modification or enhancement.
18 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20 * OR ANY PART THEREOF.
22 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23 * or profits or other special, indirect and consequential damages, even if
24 * Sun has been advised of the possibility of such damages.
26 * Sun Microsystems, Inc.
27 * 2550 Garcia Avenue
28 * Mountain View, California 94043
32 * From: @(#)rpc_clntout.c 1.11 89/02/22 (C) 1987 SMI
36 * rpc_clntout.c, Client-stub outputter for the RPC protocol compiler
37 * Copyright (C) 1987, Sun Microsystems, Inc.
39 #include <stdio.h>
40 #include <string.h>
41 #include <rpc/types.h>
42 #include "rpc_parse.h"
43 #include "rpc_util.h"
44 #include "proto.h"
46 #define DEFAULT_TIMEOUT 25 /* in seconds */
47 static const char RESULT[] = "clnt_res";
49 static void write_program (definition * def);
50 static void printbody (proc_list * proc);
51 static const char *ampr (const char *type);
52 static void printbody (proc_list * proc);
55 void
56 write_stubs (void)
58 list *l;
59 definition *def;
61 fprintf (fout,
62 "\n/* Default timeout can be changed using clnt_control() */\n");
63 fprintf (fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
64 DEFAULT_TIMEOUT);
65 for (l = defined; l != NULL; l = l->next)
67 def = (definition *) l->val;
68 if (def->def_kind == DEF_PROGRAM)
70 write_program (def);
75 static void
76 write_program (definition * def)
78 version_list *vp;
79 proc_list *proc;
81 for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
83 for (proc = vp->procs; proc != NULL; proc = proc->next)
85 fprintf (fout, "\n");
86 if (mtflag == 0)
88 ptype (proc->res_prefix, proc->res_type, 1);
89 fprintf (fout, "*\n");
90 pvname (proc->proc_name, vp->vers_num);
91 printarglist (proc, RESULT, "clnt", "CLIENT *");
93 else
95 fprintf (fout, "enum clnt_stat \n");
96 pvname (proc->proc_name, vp->vers_num);
97 printarglist (proc, RESULT, "clnt", "CLIENT *");
99 fprintf (fout, "{\n");
100 printbody (proc);
101 fprintf (fout, "}\n");
106 /* Writes out declarations of procedure's argument list.
107 In either ANSI C style, in one of old rpcgen style (pass by reference),
108 or new rpcgen style (multiple arguments, pass by value);
111 /* sample addargname = "clnt"; sample addargtype = "CLIENT * " */
113 void
114 printarglist (proc_list * proc, const char *result,
115 const char *addargname, const char *addargtype)
118 decl_list *l;
120 if (!newstyle)
121 { /* old style: always pass argument by reference */
122 if (Cflag)
123 { /* C++ style heading */
124 fprintf (fout, "(");
125 ptype (proc->args.decls->decl.prefix,
126 proc->args.decls->decl.type, 1);
128 if (mtflag)
129 {/* Generate result field */
130 fprintf (fout, "*argp, ");
131 ptype(proc->res_prefix, proc->res_type, 1);
132 fprintf (fout, "*%s, %s%s)\n", result, addargtype, addargname);
134 else
135 fprintf (fout, "*argp, %s%s)\n", addargtype, addargname);
137 else
139 if (!mtflag)
140 fprintf (fout, "(argp, %s)\n", addargname);
141 else
142 fprintf (fout, "(argp, %s, %s)\n", result, addargname);
143 fprintf (fout, "\t");
144 ptype (proc->args.decls->decl.prefix,
145 proc->args.decls->decl.type, 1);
146 fprintf (fout, "*argp;\n");
147 if (mtflag)
149 fprintf (fout, "\t");
150 ptype (proc->res_prefix, proc->res_type, 1);
151 fprintf (fout, "*%s;\n", result);
155 else if (streq (proc->args.decls->decl.type, "void"))
157 /* newstyle, 0 argument */
158 if (mtflag)
160 fprintf (fout, "(");
161 if (Cflag)
163 ptype(proc->res_prefix, proc->res_type, 1);
164 fprintf (fout, "*%s, %s%s)\n", result, addargtype, addargname);
166 else
167 fprintf (fout, "(%s)\n", addargname);
169 else if (Cflag)
170 fprintf (fout, "(%s%s)\n", addargtype, addargname);
171 else
172 fprintf (fout, "(%s)\n", addargname);
174 else
176 /* new style, 1 or multiple arguments */
177 if (!Cflag)
179 fprintf (fout, "(");
180 for (l = proc->args.decls; l != NULL; l = l->next)
181 fprintf (fout, "%s, ", l->decl.name);
182 if (mtflag)
183 fprintf (fout, "%s, ", result);
184 fprintf (fout, "%s)\n", addargname);
185 for (l = proc->args.decls; l != NULL; l = l->next)
187 pdeclaration (proc->args.argname, &l->decl, 1, ";\n");
189 if (mtflag)
191 fprintf (fout, "\t");
192 ptype (proc->res_prefix, proc->res_type, 1);
193 fprintf (fout, "*%s;\n", result);
196 else
197 { /* C++ style header */
198 fprintf (fout, "(");
199 for (l = proc->args.decls; l != NULL; l = l->next)
201 pdeclaration (proc->args.argname, &l->decl, 0, ", ");
203 if (mtflag)
205 ptype (proc->res_prefix, proc->res_type, 1);
206 fprintf (fout, "*%s, ", result);
208 fprintf (fout, " %s%s)\n", addargtype, addargname);
212 if (!Cflag)
213 fprintf (fout, "\t%s%s;\n", addargtype, addargname);
217 static
218 const char *
219 ampr (const char *type)
221 if (isvectordef (type, REL_ALIAS))
223 return "";
225 else
227 return "&";
231 static void
232 printbody (proc_list * proc)
234 decl_list *l;
235 bool_t args2 = (proc->arg_num > 1);
236 /* int i; */
238 /* For new style with multiple arguments, need a structure in which
239 to stuff the arguments. */
240 if (newstyle && args2)
242 fprintf (fout, "\t%s", proc->args.argname);
243 fprintf (fout, " arg;\n");
245 if (!mtflag)
247 fprintf (fout, "\tstatic ");
248 if (streq (proc->res_type, "void"))
250 fprintf (fout, "char ");
252 else
254 ptype (proc->res_prefix, proc->res_type, 0);
256 fprintf (fout, "%s;\n", RESULT);
257 fprintf (fout, "\n");
258 fprintf (fout, "\tmemset((char *)%s%s, 0, sizeof(%s));\n",
259 ampr (proc->res_type), RESULT, RESULT);
261 if (newstyle && !args2 && (streq (proc->args.decls->decl.type, "void")))
263 /* newstyle, 0 arguments */
264 if (mtflag)
265 fprintf (fout, "\t return ");
266 else
267 fprintf (fout, "\t if ");
268 fprintf (fout,
269 "(clnt_call (clnt, %s, (xdrproc_t) xdr_void, ", proc->proc_name);
271 fprintf (fout,
272 "(caddr_t) NULL,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
273 stringfix(proc->res_type), (mtflag)?"":ampr(proc->res_type),
274 RESULT);
275 if (mtflag)
276 fprintf (fout, "\n\t\tTIMEOUT));\n\n");
277 else
278 fprintf (fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
280 else if (newstyle && args2)
282 /* newstyle, multiple arguments: stuff arguments into structure */
283 for (l = proc->args.decls; l != NULL; l = l->next)
285 fprintf (fout, "\targ.%s = %s;\n",
286 l->decl.name, l->decl.name);
288 if (mtflag)
289 fprintf (fout, "\treturn ");
290 else
291 fprintf (fout, "\tif ");
293 fprintf (fout,
294 "(clnt_call (clnt, %s, (xdrproc_t) xdr_%s", proc->proc_name,
295 proc->args.argname);
296 fprintf (fout,
297 ", (caddr_t) &arg,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,",
298 stringfix(proc->res_type), (mtflag)?"":ampr(proc->res_type),
299 RESULT);
300 if (mtflag)
301 fprintf (fout, "\n\t\tTIMEOUT));\n");
302 else
303 fprintf (fout, "\n\t\tTIMEOUT) != RPC_SUCCESS) {\n");
305 else
306 { /* single argument, new or old style */
307 if (!mtflag)
308 fprintf (fout,
309 "\tif (clnt_call (clnt, %s,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,\n\t\tTIMEOUT) != RPC_SUCCESS) {\n",
310 proc->proc_name,
311 stringfix (proc->args.decls->decl.type),
312 (newstyle ? "&" : ""),
313 (newstyle ? proc->args.decls->decl.name : "argp"),
314 stringfix (proc->res_type), ampr (proc->res_type),
315 RESULT);
316 else
317 fprintf(fout,
318 "\treturn (clnt_call(clnt, %s,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,\n\t\t(xdrproc_t) xdr_%s, (caddr_t) %s%s,\n\t\tTIMEOUT));\n",
319 proc->proc_name,
320 stringfix (proc->args.decls->decl.type),
321 (newstyle ? "&" : ""),
322 (newstyle ? proc->args.decls->decl.name : "argp"),
323 stringfix (proc->res_type), "",
324 RESULT);
326 if (!mtflag)
328 fprintf (fout, "\t\treturn (NULL);\n");
329 fprintf (fout, "\t}\n");
330 if (streq (proc->res_type, "void"))
332 fprintf (fout, "\treturn ((void *)%s%s);\n",
333 ampr (proc->res_type), RESULT);
335 else
337 fprintf (fout, "\treturn (%s%s);\n", ampr (proc->res_type), RESULT);