]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - tools/rpcgen/rpc_cout.c
Replace the Sun RPC license with the BSD license,
[nfs-utils.git] / tools / rpcgen / rpc_cout.c
index af9288dcbc4ada484da27f04f3d463c9a0b4fdee..a61214fdbef078cf7bf3a45c174af703c117acde 100644 (file)
@@ -1,34 +1,32 @@
 /*
- * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
- * unrestricted use provided that this legend is included on all tape
- * media and as a part of the software program in whole or part.  Users
- * may copy or modify Sun RPC without charge, but are not authorized
- * to license or distribute it to anyone else except as part of a product or
- * program developed by the user or with the express written consent of
- * Sun Microsystems, Inc.
+ * Copyright (c) 2009, Sun Microsystems, Inc.
+ * All rights reserved.
  *
- * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
- * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * - Neither the name of Sun Microsystems, Inc. nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
  *
- * Sun RPC is provided with no support and without any obligation on the
- * part of Sun Microsystems, Inc. to assist in its use, correction,
- * modification or enhancement.
- *
- * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
- * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
- * OR ANY PART THEREOF.
- *
- * In no event will Sun Microsystems, Inc. be liable for any lost revenue
- * or profits or other special, indirect and consequential damages, even if
- * Sun has been advised of the possibility of such damages.
- *
- * Sun Microsystems, Inc.
- * 2550 Garcia Avenue
- * Mountain View, California  94043
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef lint
+#if 0
 static char sccsid[] = "@(#)rpc_cout.c 1.13 89/02/22 (C) 1987 SMI";
 #endif
 
@@ -164,8 +162,6 @@ print_header(definition *def)
 
        if (Inline == 0)
                return;
-       /* May cause lint to complain. but  ... */
-       f_print(fout, "\t register int32_t *buf;\n\n");
 }
 
 static void
@@ -266,7 +262,8 @@ print_ifstat(int indent, char *prefix, char *type, relation rel,
                        } else {
                                print_ifopen(indent, "array");
                        }
-                       print_ifarg("(char **)");
+                       /* The (void*) avoids a gcc-4.1 warning */
+                       print_ifarg("(char **)(void*)");
                        if (*objname == '&') {
                                f_print(fout, "%s.%s_val, (u_int *)%s.%s_len",
                                        objname, name, objname, name);
@@ -390,18 +387,13 @@ emit_struct(definition *def)
        char           *sizestr, *plus;
        char            ptemp[256];
        int             can_inline;
+       const char      *buf_declaration;
 
 
        if (Inline == 0) {
                for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
                        print_stat(1, &dl->decl);
        } else {
-
-               for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
-                       if (dl->decl.rel == REL_VECTOR) {
-                               f_print(fout, "\t int i;\n");
-                               break;
-                       }
                size = 0;
                can_inline = 0;
                for (dl = def->def.st.decls; dl != NULL; dl = dl->next)
@@ -444,6 +436,7 @@ emit_struct(definition *def)
                        i = 0;
                        size = 0;
                        sizestr = NULL;
+                       buf_declaration = "int32_t *";
                        for (dl = def->def.st.decls; dl != NULL; dl = dl->next) {       /* xxx */
 
                                /* now walk down the list and check for basic types */
@@ -497,16 +490,17 @@ emit_struct(definition *def)
 
                                                        /* were already looking at a xdr_inlineable structure */
                                                        if (sizestr == NULL)
-                                                               f_print(fout, "\t buf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);",
-                                                                       size);
+                                                               f_print(fout, "\t %sbuf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);",
+                                                                       buf_declaration, size);
                                                        else if (size == 0)
                                                                f_print(fout,
-                                                                       "\t buf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);",
-                                                                       sizestr);
+                                                                       "\t %sbuf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);",
+                                                                       buf_declaration, sizestr);
                                                        else
                                                                f_print(fout,
-                                                                       "\t buf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);",
-                                                                       size, sizestr);
+                                                                       "\t %sbuf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);",
+                                                                       buf_declaration, size, sizestr);
+                                                       buf_declaration = "";
 
                                                        f_print(fout, "\n\t   if (buf == NULL) {\n");
 
@@ -546,16 +540,17 @@ emit_struct(definition *def)
 
                                        /* were already looking at a xdr_inlineable structure */
                                        if (sizestr == NULL)
-                                               f_print(fout, "\t\tbuf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);",
-                                                       size);
+                                               f_print(fout, "\t\t%sbuf = XDR_INLINE(xdrs,%d * BYTES_PER_XDR_UNIT);",
+                                                       buf_declaration, size);
                                        else if (size == 0)
                                                f_print(fout,
-                                                       "\t\tbuf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);",
-                                                       sizestr);
+                                                       "\t\t%sbuf = XDR_INLINE(xdrs,%s * BYTES_PER_XDR_UNIT);",
+                                                       buf_declaration, sizestr);
                                        else
                                                f_print(fout,
-                                                       "\t\tbuf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);",
-                                                       size, sizestr);
+                                                       "\t\t%sbuf = XDR_INLINE(xdrs,(%d + %s)* BYTES_PER_XDR_UNIT);",
+                                                       buf_declaration, size, sizestr);
+                                       buf_declaration = "";
 
                                        f_print(fout, "\n\t\tif (buf == NULL) {\n");
 
@@ -632,6 +627,7 @@ emit_inline(declaration *decl, int flag)
                break;
        case REL_VECTOR:
                f_print(fout, "\t\t{ register %s *genp; \n", decl->type);
+               f_print(fout, "\t\t  int i;\n");
                f_print(fout, "\t\t  for ( i = 0,genp=objp->%s;\n \t\t\ti < %s; i++){\n\t\t",
                        decl->name, decl->array_max);
                emit_single_in_line(decl, flag, REL_VECTOR);
@@ -649,7 +645,7 @@ emit_single_in_line(declaration *decl, int flag, relation rel)
        int freed=0;
 
        if(flag == PUT)
-               f_print(fout,"\t\t IXDR_PUT_");
+               f_print(fout,"\t\t (void) IXDR_PUT_");
        else    
                if(rel== REL_ALIAS)
                        f_print(fout,"\t\t objp->%s = IXDR_GET_",decl->name);
@@ -694,7 +690,7 @@ upcase(char *str)
        char           *ptr, *hptr;
 
 
-       ptr = (char *) malloc(strlen(str));
+       ptr = (char *) malloc(strlen(str)+1);
        if (ptr == (char *) NULL) {
                f_print(stderr, "malloc failed \n");
                exit(1);