/usr/include/dpm/marshall.h is in libdpm-dev 1.8.7-3.1+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | /*
* $Id: marshall.h,v 1.1.1.1 2004/01/21 09:19:34 baud Exp $
*/
/*
* @(#)$RCSfile: marshall.h,v $ $Revision: 1.1.1.1 $ $Date: 2004/01/21 09:19:34 $ CERN IT-PDP/DM Fabrizio Cane
*/
/*
* Copyright (C) 1990-2002 by CERN/IT/PDP/DM
* All rights reserved
*/
/* marshall.h - marshalling/unmarshalling definitions */
#ifndef _MARSHALL_H_INCLUDED_
#define _MARSHALL_H_INCLUDED_
#include <osdep.h> /* Operating system dependencies */
#include <memory.h> /* memory operations definition */
#define SHORT WORD
/* #define U_SHORT U_WORD */
#define SHORTSIZE WORDSIZE
#define SHORTADDR WORDADDR
#define marshall_WORD marshall_SHORT
#define unmarshall_WORD unmarshall_SHORT
#define INC_PTR(ptr,n) (ptr) = (char*)(ptr) + (n)
#define DIFF_PTR(ptr,base) (char*)(ptr) - (char*)(base)
/*
* BIT manipulation
*/
#define BITSOFBYTE 8 /* number of bits in a byte */
#define bitsof(t) sizeof(t)*BITSOFBYTE /* number of bits in a type*/
typedef char* bitvct; /* bit vector type definition */
/*
* Allocate enough memory for a 'bitvct' type variable containing
* 'size' bits
*/
#define bitalloc(size) (bitvct)malloc(size/BITSOFBYTE + \
((size%BITSOFBYTE) ? 1 : 0))
/*
* Set the bit 'bit-th' starting from the byte pointed to by 'ptr'
*/
#define BIT_SET(ptr,bit) { char *p = (char*)(ptr) + (bit)/8; \
*p = *p | (1 << (7-(bit)%8)) ; \
}
/*
* Clear the bit 'bit-th' starting from the byte pointed to by 'ptr'
*/
#define BIT_CLR(ptr,bit) { char *p = (char*)(ptr) + (bit)/8; \
*p = *p & ~(1 << (7-(bit)%8)); \
}
/*
* Test the bit 'bit-th' starting from the byte pointed to by 'ptr'
*/
#define BIT_ISSET(ptr,bit) (*(char*)((char*)(ptr)+(bit)/8) & (1 << (7-(bit)%8)))
/*
* B Y T E
*/
#define marshall_BYTE(ptr,n) { BYTE n_ = n; \
(void) memcpy((ptr),BYTEADDR(n_),BYTESIZE); \
INC_PTR(ptr,BYTESIZE); \
}
#define unmarshall_BYTE(ptr,n) { BYTE n_; \
(void) memcpy(BYTEADDR(n_),(ptr),BYTESIZE); \
n = n_; \
INC_PTR(ptr,BYTESIZE); \
}
/*
* S H O R T
*/
#define marshall_SHORT(ptr,n) { SHORT n_ = htons((unsigned short)(n)); \
(void) memcpy((ptr),SHORTADDR(n_),SHORTSIZE); \
INC_PTR(ptr,SHORTSIZE); \
}
#define unmarshall_SHORT(ptr,n) { SHORT n_ = 0; \
(void) memcpy(SHORTADDR(n_),(ptr),SHORTSIZE); \
n = ntohs((unsigned short)(n_)); \
if ( BIT_ISSET(ptr,0) && sizeof(SHORT)-SHORTSIZE > 0 ) \
(void) memset((char *)&n,255,sizeof(SHORT)-SHORTSIZE); \
INC_PTR(ptr,SHORTSIZE); \
}
/*
* L O N G
*/
#define marshall_LONG(ptr,n) { LONG n_ = htonl((unsigned long)(n)); \
(void) memcpy((ptr),LONGADDR(n_),LONGSIZE); \
INC_PTR(ptr,LONGSIZE); \
}
#define unmarshall_LONG(ptr,n) { LONG n_ = 0; \
(void) memcpy(LONGADDR(n_),(ptr),LONGSIZE); \
n = ntohl((unsigned long)(n_)); \
if ( BIT_ISSET(ptr,0) && sizeof(LONG)-LONGSIZE > 0 ) \
(void) memset((char *)&n,255,sizeof(LONG)-LONGSIZE); \
INC_PTR(ptr,LONGSIZE); \
}
/*
* S T R I N G
*/
#define marshall_STRING(ptr,str) { (void) strcpy((char*)(ptr),(char*)(str)); \
INC_PTR(ptr,strlen(str)+1); \
}
#define unmarshall_STRING(ptr,str) { (void) strcpy((char*)(str),(char*)(ptr)); \
INC_PTR(ptr,strlen(str)+1); \
}
EXTERN_C int DLL_DECL _unmarshall_STRINGN _PROTO((char **, char*, int));
#define unmarshall_STRINGN(ptr,str,n) _unmarshall_STRINGN(&ptr, str, n)
/*
* H Y P E R ( 6 4 B I T S )
*/
#if !defined(__alpha) && !defined(i386) && !defined(_WIN32) && !defined(__ia64__) && !defined(__x86_64)
#define marshall_HYPER(ptr,n) { U_HYPER u_ = n; \
LONG n_ = htonl(*((unsigned long *)&(u_))); \
(void) memcpy((ptr),LONGADDR(n_),LONGSIZE); \
INC_PTR(ptr,LONGSIZE); \
n_ = htonl(*((unsigned long *)((char *)&(u_)+LONGSIZE))); \
(void) memcpy((ptr),LONGADDR(n_),LONGSIZE); \
INC_PTR(ptr,LONGSIZE); \
}
#define unmarshall_HYPER(ptr,n) { U_HYPER u_; \
LONG n_ = 0; \
(void) memcpy(LONGADDR(n_),(ptr),LONGSIZE); \
*((LONG *)&(u_)) = ntohl((unsigned long)(n_)); \
INC_PTR(ptr,LONGSIZE); \
n_ = 0; \
(void) memcpy(LONGADDR(n_),(ptr),LONGSIZE); \
*((LONG *)((char *)&(u_)+LONGSIZE)) = \
ntohl((unsigned long)(n_)); \
INC_PTR(ptr,LONGSIZE); \
n = u_; \
}
#else
#define marshall_HYPER(ptr,n) { U_HYPER u_ = n; \
LONG n_ = htonl(*((U_LONG *)((char *)&(u_)+LONGSIZE))); \
(void) memcpy((ptr),LONGADDR(n_),LONGSIZE); \
INC_PTR(ptr,LONGSIZE); \
n_ = htonl(*((U_LONG *)&(u_))); \
(void) memcpy((ptr),LONGADDR(n_),LONGSIZE); \
INC_PTR(ptr,LONGSIZE); \
}
#define unmarshall_HYPER(ptr,n) { U_HYPER u_; \
LONG n_ = 0; \
(void) memcpy(LONGADDR(n_),(ptr),LONGSIZE); \
*((LONG *)((char *)&(u_)+LONGSIZE)) = \
ntohl((U_LONG)(n_)); \
INC_PTR(ptr,LONGSIZE); \
n_ = 0; \
(void) memcpy(LONGADDR(n_),(ptr),LONGSIZE); \
*((LONG *)&(u_)) = ntohl((U_LONG)(n_)); \
INC_PTR(ptr,LONGSIZE); \
n = u_; \
}
#endif
/*
* O P A Q U E
*/
#define marshall_OPAQUE(ptr,raw,n) { (void) memcpy((ptr),(raw),(n)); \
INC_PTR(ptr,(n)); \
}
#define unmarshall_OPAQUE(ptr,raw,n) { (void) memcpy((raw),(ptr),(n)); \
INC_PTR(ptr,(n)); \
}
/*
* T I M E
*/
#define marshall_TIME_T(ptr,n) { \
TIME_T _marshall_time_dummy = (TIME_T) n; \
marshall_HYPER(ptr,_marshall_time_dummy); \
}
#define unmarshall_TIME_T(ptr,n) { \
TIME_T _unmarshall_time_dummy; \
unmarshall_HYPER(ptr,_unmarshall_time_dummy); \
n = (time_t) _unmarshall_time_dummy; \
}
#endif /* _MARSHALL_H_INCLUDED_ */
|