cmd: improve help for programs without subcommands
[openafs.git] / src / fsint / afsaux.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  *
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #ifdef KERNEL
15 #if defined(UKERNEL)
16 #include "afs/sysincludes.h"
17 #include "afsincludes.h"
18 #include "rx/xdr.h"
19 #else /* defined(UKERNEL) */
20 #if defined(AFS_NBSD50_ENV)
21 #include "afs/afs_osi.h"
22 #endif
23 #if defined(AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
24 #include "afs/sysincludes.h"
25 #include "afsincludes.h"
26 #else
27 #include "h/types.h"
28 #include "rx/xdr.h"
29 #endif
30 #if !defined(AFS_ALPHA_ENV)
31 #ifndef XDR_GETINT32
32 #define XDR_GETINT32    XDR_GETLONG
33 #endif
34 #ifndef XDR_PUTINT32
35 #define XDR_PUTINT32    XDR_PUTLONG
36 #endif
37 #endif
38 #endif /* defined(UKERNEL) */
39 #include "afsint.h"
40 #else /* KERNEL */
41 # include <roken.h>
42 # include <rx/xdr.h>
43 # include "afsint.h"
44 #endif /* KERNEL */
45
46 #ifdef KERNEL
47 #define NVALLOC(a)      osi_Alloc(a)
48 #define NVFREE(a,b)     osi_Free(a,b)
49 #else /* KERNEL */
50 #define MAXBS   2048            /* try to avoid horrible allocs */
51 static afs_int32 bslosers = 0;
52 #define NVALLOC(a)      malloc(a)
53 #define NVFREE(a,b)     free(a)
54 #endif /* KERNEL */
55
56 /* these things are defined in R (but not RX's) library.  For now, we add them
57     only for the kernel system.  Later, when R is expunged, we'll remove the ifdef */
58 #ifdef KERNEL
59 #ifndef AFS_USR_DARWIN_ENV
60 /*
61  * Wrapper for xdr_string that can be called directly from
62  * routines like clnt_call; from user-mode xdr package.
63  */
64 #ifndef AFS_SUN5_ENV
65 #ifndef AFS_HPUX110_ENV
66 bool_t
67 xdr_wrapstring(XDR * xdrs, char **cpp)
68 {
69     if (xdr_string(xdrs, cpp, 1024)) {
70         return (TRUE);
71     }
72     return (FALSE);
73 }
74 #endif /* AFS_HPUX110_ENV */
75 #endif /* AFS_SUN5_ENV */
76
77 #endif
78 #endif /* KERNEL */
79
80 #ifndef KERNEL
81 bool_t
82 xdr_CBS(XDR * x, struct CBS * abbs)
83 {
84     afs_int32 len;
85     if (x->x_op == XDR_FREE) {
86         NVFREE(abbs->SeqBody, abbs->SeqLen);
87         return TRUE;
88     }
89
90     if (x->x_op == XDR_ENCODE) {
91         xdr_afs_int32(x, &abbs->SeqLen);
92         xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
93         return TRUE;
94     } else {
95         xdr_afs_int32(x, &len);
96         if (len < 0 || len > MAXBS) {
97             bslosers++;
98             return FALSE;
99         }
100         if (!abbs->SeqBody)
101             abbs->SeqBody = NVALLOC(len);
102         abbs->SeqLen = len;
103         xdr_opaque(x, abbs->SeqBody, len);
104         return TRUE;
105     }
106 }
107
108 bool_t
109 xdr_BBS(XDR * x, struct BBS * abbs)
110 {
111     afs_int32 maxLen, len;
112     if (x->x_op == XDR_FREE) {
113         NVFREE(abbs->SeqBody, abbs->MaxSeqLen);
114         return TRUE;
115     }
116
117     if (x->x_op == XDR_ENCODE) {
118         xdr_afs_int32(x, &abbs->MaxSeqLen);
119         xdr_afs_int32(x, &abbs->SeqLen);
120         xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
121         return TRUE;
122     } else {
123         xdr_afs_int32(x, &maxLen);
124         xdr_afs_int32(x, &len);
125         if (len < 0 || len > MAXBS || len > maxLen) {
126             bslosers++;
127             return FALSE;
128         }
129         if (!abbs->SeqBody)
130             abbs->SeqBody = NVALLOC(maxLen);
131         abbs->MaxSeqLen = maxLen;
132         abbs->SeqLen = len;
133         xdr_opaque(x, abbs->SeqBody, len);
134         return TRUE;
135     }
136 }
137
138 bool_t
139 xdr_AFSAccessList(XDR * x, AFSAccessList * abbs)
140 {
141     afs_int32 maxLen, len;
142     if (x->x_op == XDR_FREE) {
143         NVFREE(abbs->SeqBody, abbs->MaxSeqLen);
144         return TRUE;
145     }
146
147     if (x->x_op == XDR_ENCODE) {
148         xdr_afs_int32(x, &abbs->MaxSeqLen);
149         xdr_afs_int32(x, &abbs->SeqLen);
150         xdr_opaque(x, abbs->SeqBody, abbs->SeqLen);
151         return TRUE;
152     } else {
153         xdr_afs_int32(x, &maxLen);
154         xdr_afs_int32(x, &len);
155         if (len < 0 || len > MAXBS || len > maxLen) {
156             bslosers++;
157             return FALSE;
158         }
159         if (!abbs->SeqBody)
160             abbs->SeqBody = NVALLOC(maxLen);
161         abbs->MaxSeqLen = maxLen;
162         abbs->SeqLen = len;
163         xdr_opaque(x, abbs->SeqBody, len);
164         return TRUE;
165     }
166 }
167 #endif /* KERNEL */