The R Project SVN R

Rev

Rev 56420 | Rev 84681 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 56420 Rev 56474
Line 1... Line 1...
1
#ifdef HAVE_CONFIG_H
1
#ifdef HAVE_CONFIG_H
2
#include <config.h>
2
#include <config.h>
3
#endif
3
#endif
4
 
4
 
5
#if SIZEOF_LONG > 4
5
#include <stdint.h>
6
#error This XDR implementation assumes 4-byte longs
-
 
7
#endif
-
 
8
 
6
 
9
/* Local mod: assumes WIN32 is i386 and little-endian generic is 32-bit */
7
/* Local mod: assumes WIN32 is i386 and little-endian generic is 32-bit */
10
#if defined(WIN32) || defined(__CYGWIN__)
8
#if defined(WIN32) || defined(__CYGWIN__)
11
static unsigned long int
9
static uint32_t ntohl(uint32_t x)
12
ntohl(unsigned long int x)
-
 
13
{ /* could write VC++ inline assembler, but not worth it for now */
10
{ /* could write VC++ inline assembler, but not worth it for now */
14
#ifdef _MSC_VER
11
#ifdef _MSC_VER
15
  return((x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24));
12
  return((x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24));
16
#else
13
#else
17
  __asm__("xchgb %b0,%h0\n\t"	/* swap lower bytes	*/
14
  __asm__("xchgb %b0,%h0\n\t"	/* swap lower bytes	*/
Line 23... Line 20...
23
#endif 
20
#endif 
24
}
21
}
25
#else /* net is big-endian: little-endian hosts need byte-swap code */
22
#else /* net is big-endian: little-endian hosts need byte-swap code */
26
#ifndef WORDS_BIGENDIAN
23
#ifndef WORDS_BIGENDIAN
27
/* #ifdef LITTLE_ENDIAN */
24
/* #ifdef LITTLE_ENDIAN */
28
static unsigned long int 
25
static uint32_t ntohl (uint32_t x)
29
ntohl (unsigned long int x)
-
 
30
{
26
{
31
  return((x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24));
27
  return((x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24));
32
}
28
}
33
#else
29
#else
34
#define ntohl(x) (x)
30
#define ntohl(x) (x)
Line 147... Line 143...
147
	if (xdrs->x_op == XDR_ENCODE) fflush((FILE *)xdrs->x_private);
143
	if (xdrs->x_op == XDR_ENCODE) fflush((FILE *)xdrs->x_private);
148
	/* xx should we close the file ?? */
144
	/* xx should we close the file ?? */
149
}
145
}
150
 
146
 
151
static bool_t
147
static bool_t
152
xdrstdio_getlong(xdrs, lp)
148
xdrstdio_getlong(XDR *xdrs, int32_t *lp)
153
	XDR *xdrs;
-
 
154
	register long *lp;
-
 
155
{
149
{
156
	if (fread((caddr_t)lp, 4, 1, (FILE *)xdrs->x_private) != 1)
150
	if (fread((caddr_t)lp, 4, 1, (FILE *)xdrs->x_private) != 1)
157
		return (FALSE);
151
		return (FALSE);
158
	*lp = ntohl(*lp);
152
	*lp = ntohl(*lp);
159
	return (TRUE);
153
	return (TRUE);
160
}
154
}
161
 
155
 
162
static bool_t
156
static bool_t
163
xdrstdio_putlong(xdrs, lp)
157
xdrstdio_putlong(XDR *xdrs, int32_t *lp)
164
	XDR *xdrs;
-
 
165
	long *lp;
-
 
166
{
158
{
167
	long mycopy = htonl(*lp);
159
	int32_t mycopy = htonl(*lp);
168
	lp = &mycopy;
160
	lp = &mycopy;
169
	if (fwrite((caddr_t)lp, 4, 1, (FILE *)xdrs->x_private) != 1)
161
	if (fwrite((caddr_t)lp, 4, 1, (FILE *)xdrs->x_private) != 1)
170
		return (FALSE);
162
		return (FALSE);
171
	return (TRUE);
163
	return (TRUE);
172
}
164
}