/* Copyright (C) 1990 Transarc Corporation - All rights reserved */

/* $Header: /afs/transarc.com/project/fs/dev/afs/rcs/config/RCS/stds.h,v 2.15 1993/12/14 15:43:41 dws Exp $ */

#ifndef TRANSARC_AFS_CONFIG_STDS_H
#define TRANSARC_AFS_CONFIG_STDS_H

/* The following two groups are from /afs/tr/kansas/src/stds/transarc_stds.h
 * entered by Erik Brown.  900301 -ota */

#define IN              /* indicates a parameter is read in */
#define OUT             /* indicates a parameter is sent out (a ptr) */
#define INOUT           /* indicates a parameter is read in and
                         * sent out (a ptr) */

#define EXPORT          /* available to everyone */
#define HIDDEN		/* used in a PUBLIC macro, but not exported */
#define SHARED          /* shared between module source files */ 
#define PRIVATE static  /* private to a source (.c) file */
#define IMPORT extern	/* this is new -ota */


#ifndef	MACRO_BEGIN
#define MACRO_BEGIN	do {
#endif
#ifndef	MACRO_END
#define MACRO_END	} while (0)
#endif

/*
 * The following are provided for ANSI C compatibility
 */

#ifdef __STDC__
typedef void *opaque;
#else /* __STDC__ */
#define const
typedef char *opaque;
#endif /* __STDC__ */

/* Use _TAKES with double parentheses around an ANSI C param list */
/* MIPS compilers understand ANSI prototypes (and check 'em too!) */

#ifndef _TAKES
#if defined(__STDC__) || defined(mips)
#define _TAKES(x) x
#else /* __STDC__ */
#define _TAKES(x) ()
#endif /* __STDC__ */
#endif /* _TAKES */

#if defined(__HIGHC__)
/*
 * keep HC from complaining about the use of "old-style" function definitions
 * with prototypes
 */
pragma Off(Prototype_override_warnings);
#endif /* defined(__HIGHC__) */

/*
 * This makes including the RCS id in object files less painful.  Put this near
 * the beginning of .c files (not .h files).  Do NOT follow it with a
 * semi-colon.  The argument should be a double quoted string containing the
 * standard RCS Header keyword.
 */

#ifndef lint

/* Believe it or not this seems to supress all warnings from all compilers I've
 * checked.  I've tried the HC compile with normal, -g and -o switched.  Also
 * gcc on the pmax with "-O -Wall" and so far so good. -ota 900426 */

#define RCSID(x) \
  static const char *rcsid = x; \
  static int (*__rcsid)(); \
  static int _rcsid () \
  { static int a; \
    a = (int)rcsid; __rcsid = _rcsid; a = (int)__rcsid; return a; }

/* #define RCSID(x) static const char *rcsid() { return x;} */

#else
#define RCSID(x)
#endif

/* Now some types to enhance portability.  Always use these on the wire or when
 * laying out shared structures on disk. */

/* Imagine that this worked...
#if (sizeof(long) != 4) || (sizeof(short) != 2)
#error We require size of long and pointers to be equal
#endif */

typedef short	         int16;
typedef unsigned short u_int16;
typedef long	         int32;

/* The Sun RPC include files define this with a typedef and this caused
 * problems for the NFS Translator.  Users of those include files should just
 * #undef this. */

#define u_int32 unsigned long
/* typedef unsigned long	u_int32; */

/* you still have to include <netinet/in.h> to make these work */

#define hton32 htonl
#define hton16 htons
#define ntoh32 ntohl
#define ntoh16 ntohs


/* Since there is going to be considerable use of 64 bit integers we provide
 * some assistence in this matter.  The hyper type is supposed to be compatible
 * with the afsHyper type: the same macros will work on both. */

typedef struct hyper { /* unsigned 64 bit integers */
    unsigned long high;
    unsigned long low;
} hyper;

#define hcmp(a,b) ((a).high<(b).high? -1 : ((a).high > (b).high? 1 : \
    ((a).low <(b).low? -1 : ((a).low > (b).low? 1 : 0))))
#define hsame(a,b) ((a).low == (b).low && (a).high == (b).high)
#define hiszero(a) ((a).low == 0 && (a).high == 0)
#define hfitsin32(a) ((a).high == 0)
#define hset(a,b) ((a) = (b))
#define hzero(a) ((a).low = 0, (a).high = 0)
#define hones(a) ((a).low = 0xffffffff, (a).high = 0xffffffff)
#define hget32(i,a) ((i) = (a).low)
#define hget64(hi,lo,a) ((lo) = (a).low, (hi) = (a).high)
#define hset32(a,i) ((a).high = 0, (a).low = (i))
#define hset64(a,hi,lo) ((a).high = (hi), (a).low = (lo))

/* The algorithm here is to check for two cases that cause a carry.  If the top
 * two bits are different then if the sum has the top bit off then there must
 * have been a carry.  If the top bits are both one then there is always a
 * carry.  We assume 32 bit longs and twos complement arithmetic. */

#define SIGN 0x80000000
#define hadd32(a,i) \
    (((((a).low ^ (long)(i)) & SIGN) \
      ? (((((a).low + (long)(i)) & SIGN) == 0) && (a).high++) \
      : (((a).low & (long)(i) & SIGN) && (a).high++)), \
     (a).low += (long)(i))

#define hadd(a,b) (hadd32(a,(b).low), (a).high += (b).high)


#endif /* TRANSARC_CONFIG_AFS_STDS_H */
