e26ee1c89fdd83fc22fa50309939837f91bf904a
[debian/amanda] / ndmp-src / ndmos_glib.h
1 /*
2  * Copyright (c) 1998,1999,2000
3  *      Traakan, Inc., Los Altos, CA
4  *      All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice unmodified, this list of conditions, and the following
11  *    disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28
29 /*
30  * Project:  NDMJOB
31  * Ident:    $Id: $
32  *
33  * Description:
34  *      This establishes the environment and options
35  *      for the Glib "platform".   That is, it reflects all of the ndmjoblib
36  *      abstractions into the corresponding glib abstractions.  This, combined
37  *      with the O/S generic ndmos.h, are the foundation
38  *      for NDMJOBLIB.
39  *
40  *      This file is #include'd by ndmos.h when
41  *      selected by #ifdef's of NDMOS_ID.
42  *
43  *      Refer to ndmos.h for explanations of the
44  *      macros thar are or can be #define'd here.
45  */
46
47 #include "amanda.h"
48 #ifdef HAVE_RPC_RPC_H
49 #include <rpc/rpc.h>
50 #else
51 #error rpc/rpc.h is required to compile ndmp-src
52 #endif
53
54
55 /* On Solaris platforms create platform specific environment for NDMP  
56    if not we might see issues with rpc code, specifically with 64 bit 
57    mode. 
58 */
59
60 #ifdef __sun__
61 #include <stdio.h>
62 #include <stdlib.h>
63 #include <unistd.h>
64 #include <sys/types.h>
65 #include <sys/stat.h>
66 #include <sys/socket.h>
67 #include <sys/fcntl.h>
68 #include <signal.h>
69 #include <netinet/in.h>
70 #include <arpa/inet.h>
71 #include <assert.h>
72 #include <errno.h>
73 #include <strings.h>
74 #include <netdb.h>
75 #include <ctype.h>
76
77 /* On some solaris distributions INADDR_NONE is not defined 
78    hence define here.. "in_addr_t" is defined in netinet/in.h  
79 */  
80
81 #ifndef INADDR_NONE 
82 #define INADDR_NONE     ((in_addr_t)-1)
83 #endif
84
85 #endif 
86
87
88 /* this may need to be autodetected, or NDMOS_MACRO_SET_SOCKADDR may need to be
89  * rewritten in terms of Amanda's sockaddr-util.h.  According to ndmpjoblib,
90  * only FreeBDS has sin_len. */
91 #undef NDMOS_OPTION_HAVE_SIN_LEN
92
93 #define NDMOS_OPTION_TAPE_SIMULATOR
94 #define NDMOS_OPTION_ROBOT_SIMULATOR
95
96 #define NDMOS_OPTION_USE_SELECT_FOR_CHAN_POLL
97
98 #define NDMOS_API_BCOPY(S,D,N) g_memmove((void*)(D), (void*)(S), (N))
99 /* default: NDMOS_API_BZERO */
100 #define NDMOS_API_MALLOC(N) g_malloc((N))
101 #define NDMOS_API_FREE(P) g_free((void*)(P))
102 #define NDMOS_API_STRTOLL(P,PP,BASE) strtoll((P),(PP),(BASE))
103 #define NDMOS_API_STRDUP(S) g_strdup((S))
104 /* default: NDMOS_API_STREND (default: implemented in ndml_util.c) */
105
106 /* default: NDMOS_CONST_ALIGN */
107 /* default: NDMOS_CONST_EWOULDBLOCK */
108 /* default: NDMOS_CONST_TAPE_REC_MAX */
109 /* default: NDMOS_CONST_TAPE_REC_MIN */
110 /* default: NDMOS_CONST_PATH_MAX */
111 #define NDMOS_CONST_NDMOS_REVISION "Glib-2.2+"
112
113 #define NDMOS_MACRO_NEW(T) g_new(T, 1)
114 #define NDMOS_MACRO_NEWN(T,N) g_new(T, (N))
115 /* default: NDMOS_MACRO_ZEROFILL */
116 #define NDMOS_MACRO_SRAND() g_random_set_seed(time(0))
117 #define NDMOS_MACRO_RAND() g_random_int()
118 /* default: NDMOS_MACRO_OK_TAPE_REC_LEN */
119
120 /* extra */
121 #ifdef assert
122 #undef assert
123 #endif
124 #define assert g_assert