File: tweak.h

package info (click to toggle)
fsp 2.81.b24-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,904 kB
  • ctags: 1,423
  • sloc: ansic: 9,215; sh: 3,639; makefile: 212; lex: 130; csh: 77; python: 22
file content (107 lines) | stat: -rw-r--r-- 2,477 bytes parent folder | download | duplicates (3)
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
#ifndef _FSP_TWEAK_H_
#define _FSP_TWEAK_H_ 1
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <sysexits.h>

#ifndef HAVE_FSEEKO
/* fallback to old fseek if no fseeko is available */
#define fseeko fseek
#endif

#ifndef RETSIGTYPE
#define RETSIGTYPE void
#endif

#ifdef STAT_MACROS_BROKEN
#define S_ISREG(mode) ((mode) & S_IFREG)
#define S_ISDIR(mode) ((mode) & S_IFDIR)
#endif

#define FSP_STAT stat

#define fexist(A) (!access(A,F_OK))
#define touch(A) close(open(A,O_CREAT,0600))

#ifdef min
#undef min
#endif
#define min(x,y)  ((x) < (y) ? (x) : (y))

#ifndef SECSPERDAY
#define SECSPERDAY (long)60*60*24
#endif
#ifndef DAYSPERNYEAR
#define DAYSPERNYEAR 365
#endif

#if defined(HAVE_D_INO) && !defined(HAVE_D_FILENO)
#define d_fileno d_ino
#else
#if !defined(HAVE_D_INO) && defined(HAVE_D_FILENO)
#define d_ino d_fileno
#endif
#endif

#if !defined(BYTE)
  #if SIZEOF_CHAR == 1
    #define BYTE char
  #elif SIZEOF_VOID == 1
    #define BYTE void
  #else
    #error "Need 1 byte wide type"
  #endif
#endif
/****************************************************************************
*  Macros to read and write multi-byte fields from the message header.
****************************************************************************/

#if SIZEOF_SHORT == 2
#define WORD_TYPE_2 unsigned short
#else
#if SIZEOF_UNSIGNED == 2
#define WORD_TYPE_2 unsigned
#endif
#endif

#if SIZEOF_LONG == 4
#define WORD_TYPE_4 unsigned long
#else
#if SIZEOF_UNSIGNED == 4
#define WORD_TYPE_4 unsigned
#endif
#endif

#ifdef WORD_TYPE_4
/* there is an integer type of size 4 */
#define BB_READ4(V) ntohl(*(const WORD_TYPE_4 *)(V))
#define BB_WRITE4(V,A) *(WORD_TYPE_4 *)(V) = htonl(A)
#else
/* there is no integer type of size 4 */
#define BB_READ4(V) ((((V)[0] << 24) & 0xff000000) + \
		     (((V)[1] << 16) & 0x00ff0000) + \
		     (((V)[2] <<  8) & 0x0000ff00) + \
		     (((V)[3]      ) & 0x000000ff))

#define BB_WRITE4(V,A) ((V)[0] = ((A) >> 24) & 0xff, \
			(V)[1] = ((A) >> 16) & 0xff, \
			(V)[2] = ((A) >>  8) & 0xff, \
			(V)[3] = ((A)      ) & 0xff)
#endif

#ifdef WORD_TYPE_2
/* there is an integer type of size 2 */
#define BB_READ2(V) ntohs(*(WORD_TYPE_2 *)(V))
#define BB_WRITE2(V,A) *(WORD_TYPE_2 *)(V) = htons(A)
#else
/* there is no integer type of size 2 */
#define BB_READ2(V) ((((V)[0] <<  8) & 0xff00) + \
		     (((V)[1]      ) & 0x00ff))

#define BB_WRITE2(V,A) ((V)[0] = ((A) >>  8) & 0xff, \
			(V)[1] = ((A)      ) & 0xff)
#endif

#endif /* _FSP_TWEAK_H_ */