2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2004, The GROMACS development team.
6 * Copyright (c) 2013,2015,2018,2019, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
38 #ifndef GMX_FILEIO_GMX_SYSTEM_XDR_H
39 #define GMX_FILEIO_GMX_SYSTEM_XDR_H
46 * This header file is ONLY used on windows systems, since these do
47 * not include the XDR routines present on a unix machine. It will
48 * most probably work on other platforms too, but make sure you
49 * test that the xtc files produced are ok before using it.
51 * This header file contains Gromacs versions of the definitions for
52 * Sun External Data Representation (XDR) headers and routines.
54 * On most UNIX systems this is already present as part of your
55 * system libraries, but since we want to make Gromacs portable to
56 * platforms like Microsoft Windows we have created a private version
57 * of the necessary routines and distribute them with the Gromacs source.
59 * Although the rest of Gromacs is LGPL, you can copy and use the XDR
60 * routines in any way you want as long as you obey Sun's license:
62 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
63 * unrestricted use provided that this legend is included on all tape
64 * media and as a part of the software program in whole or part. Users
65 * may copy or modify Sun RPC without charge, but are not authorized
66 * to license or distribute it to anyone else except as part of a product or
67 * program developed by the user.
69 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
70 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
71 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
73 * Sun RPC is provided with no support and without any obligation on the
74 * part of Sun Microsystems, Inc. to assist in its use, correction,
75 * modification or enhancement.
77 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
78 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
79 * OR ANY PART THEREOF.
81 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
82 * or profits or other special, indirect and consequential damages, even if
83 * Sun has been advised of the possibility of such damages.
85 * Sun Microsystems, Inc.
87 * Mountain View, California 94043
91 * Xdr operations. XDR_ENCODE causes the type to be encoded into the
92 * stream. XDR_DECODE causes the type to be extracted from the stream.
93 * XDR_FREE can be used to release the space allocated by an
97 /* We already have a boolean type in Gromacs, but the XDR library
98 * one has a slightly different name (the calls should be identical).
103 * Aninteger type that is 32 bits wide. Check if int,
104 * long or short is 32 bits and die if none of them is :-)
106 #if (INT_MAX == 2147483647)
107 typedef int xdr_int32_t;
108 typedef unsigned int xdr_uint32_t;
109 #elif (LONG_MAX == 2147483647L)
110 typedef long xdr_int32_t;
111 typedef unsigned long xdr_uint32_t;
112 #elif (SHRT_MAX == 2147483647)
113 typedef short xdr_int32_t;
114 typedef unsigned short xdr_uint32_t;
116 # error ERROR: No 32 bit wide integer type found!
134 #define BYTES_PER_XDR_UNIT (4)
135 /* Macro to round up to units of 4. */
136 #define XDR_RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1))
141 * Contains operation which is being applied to the stream,
142 * an operations vector for the particular implementation (e.g. see xdr_mem.c),
143 * and two private fields for the use of the particular implementation.
145 typedef struct XDR XDR;
148 enum xdr_op x_op; /* operation; fast additional param */
151 bool_t (*x_getbytes)(XDR* __xdrs, char* __addr, unsigned int __len);
152 /* get some bytes from " */
153 bool_t (*x_putbytes)(XDR* __xdrs, char* __addr, unsigned int __len);
154 /* put some bytes to " */
155 unsigned int (*x_getpostn)(XDR* __xdrs);
156 /* returns bytes off from beginning */
157 bool_t (*x_setpostn)(XDR* __xdrs, unsigned int __pos);
158 /* lets you reposition the stream */
159 xdr_int32_t* (*x_inline)(XDR* __xdrs, int __len);
160 /* buf quick ptr to buffered data */
161 void (*x_destroy)(XDR* __xdrs);
162 /* free privates of this xdr_stream */
163 bool_t (*x_getint32)(XDR* __xdrs, xdr_int32_t* __ip);
164 /* get a int from underlying stream */
165 bool_t (*x_putint32)(XDR* __xdrs, xdr_int32_t* __ip);
167 bool_t (*x_getuint32)(XDR* __xdrs, xdr_uint32_t* __ip);
168 /* get a unsigned int from underlying stream */
169 bool_t (*x_putuint32)(XDR* __xdrs, xdr_uint32_t* __ip);
172 char* x_public; /* users' data */
173 char* x_private; /* pointer to private data */
174 char* x_base; /* private used for position info */
175 int x_handy; /* extra private word */
179 * A xdrproc_t exists for each data type which is to be encoded or decoded.
181 * The second argument to the xdrproc_t is a pointer to an opaque pointer.
182 * The opaque pointer generally points to a structure of the data type
183 * to be decoded. If this pointer is 0, then the type routines should
184 * allocate dynamic storage of the appropriate size and return it.
187 typedef bool_t (*xdrproc_t)(XDR*, void*, ...);
190 * Operations defined on a XDR handle
193 * xdr_int32_t *int32p;
201 #define xdr_getint32(xdrs, int32p) (*(xdrs)->x_ops->x_getint32)(xdrs, int32p)
203 #define xdr_putint32(xdrs, int32p) (*(xdrs)->x_ops->x_putint32)(xdrs, int32p)
205 #define xdr_getuint32(xdrs, uint32p) (*(xdrs)->x_ops->x_getuint32)(xdrs, uint32p)
207 #define xdr_putuint32(xdrs, uint32p) (*(xdrs)->x_ops->x_putuint32)(xdrs, uint32p)
209 #define xdr_getbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
211 #define xdr_putbytes(xdrs, addr, len) (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
213 #define xdr_getpos(xdrs) (*(xdrs)->x_ops->x_getpostn)(xdrs)
215 #define xdr_setpos(xdrs, pos) (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
217 #define xdr_inline(xdrs, len) (*(xdrs)->x_ops->x_inline)(xdrs, len)
219 #define xdr_destroy(xdrs) \
222 if ((xdrs)->x_ops->x_destroy) \
224 (*(xdrs)->x_ops->x_destroy)(xdrs); \
230 bool_t xdr_int(XDR* __xdrs, int* __ip);
231 bool_t xdr_u_int(XDR* __xdrs, unsigned int* __ip);
232 bool_t xdr_short(XDR* __xdrs, short* __ip);
233 bool_t xdr_u_short(XDR* __xdrs, unsigned short* __ip);
234 bool_t xdr_bool(XDR* __xdrs, int* __bp);
235 bool_t xdr_opaque(XDR* __xdrs, char* __cp, unsigned int __cnt);
236 bool_t xdr_string(XDR* __xdrs, char** __cpp, unsigned int __maxsize);
237 bool_t xdr_char(XDR* __xdrs, char* __cp);
238 bool_t xdr_u_char(XDR* __xdrs, unsigned char* __cp);
239 bool_t xdr_vector(XDR* __xdrs, char* __basep, unsigned int __nelem, unsigned int __elemsize, xdrproc_t __xdr_elem);
240 bool_t xdr_float(XDR* __xdrs, float* __fp);
241 bool_t xdr_double(XDR* __xdrs, double* __dp);
242 void xdrstdio_create(XDR* __xdrs, FILE* __file, enum xdr_op __xop);
244 /* free memory buffers for xdr */
245 void xdr_free(xdrproc_t __proc, char* __objp);
247 #endif /* GMX_FILEIO_GMX_SYSTEM_XDR_H */