00001 /* 00002 ** Copyright (C) 1993/1994, OFFIS, Oldenburg University and CERIUM 00003 ** 00004 ** This software and supporting documentation were 00005 ** developed by 00006 ** 00007 ** Institut OFFIS 00008 ** Bereich Kommunikationssysteme 00009 ** Westerstr. 10-12 00010 ** 26121 Oldenburg, Germany 00011 ** 00012 ** Fachbereich Informatik 00013 ** Abteilung Prozessinformatik 00014 ** Carl von Ossietzky Universitaet Oldenburg 00015 ** Ammerlaender Heerstr. 114-118 00016 ** 26111 Oldenburg, Germany 00017 ** 00018 ** CERIUM 00019 ** Laboratoire SIM 00020 ** Faculte de Medecine 00021 ** 2 Avenue du Pr. Leon Bernard 00022 ** 35043 Rennes Cedex, France 00023 ** 00024 ** for CEN/TC251/WG4 as a contribution to the Radiological 00025 ** Society of North America (RSNA) 1993 Digital Imaging and 00026 ** Communications in Medicine (DICOM) Demonstration. 00027 ** 00028 ** THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND NEITHER OFFIS, 00029 ** OLDENBURG UNIVERSITY NOR CERIUM MAKE ANY WARRANTY REGARDING 00030 ** THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 00031 ** FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER 00032 ** DISEASES OR ITS CONFORMITY TO ANY SPECIFICATION. THE 00033 ** ENTIRE RISK AS TO QUALITY AND PERFORMANCE OF THE SOFTWARE 00034 ** IS WITH THE USER. 00035 ** 00036 ** Copyright of the software and supporting documentation 00037 ** is, unless otherwise stated, jointly owned by OFFIS, 00038 ** Oldenburg University and CERIUM and free access is hereby 00039 ** granted as a license to use this software, copy this 00040 ** software and prepare derivative works based upon this 00041 ** software. However, any distribution of this software 00042 ** source code or supporting documentation or derivative 00043 ** works (source code and supporting documentation) must 00044 ** include the three paragraphs of this copyright notice. 00045 ** 00046 */ 00047 /* 00048 ** 00049 ** Author:Andrew Hewett Created: 11-08-93 00050 ** Oldenburg University 00051 ** Germany 00052 ** 00053 ** Module: dcompat.h 00054 ** 00055 ** Purpose: 00056 ** This is the place to declare compatability routines 00057 ** which can be missing on some systems. 00058 ** 00059 ** This include file is automatically included by dicom.h 00060 ** 00061 ** Module Prefix: none 00062 ** 00063 ** 00064 ** Last Update: $Author: meichel $ 00065 ** Update Date: $Date: 2005/12/08 16:02:19 $ 00066 ** Source File: $Source: /share/dicom/cvs-depot/dcmtk/dcmnet/include/dcmtk/dcmnet/dcompat.h,v $ 00067 ** CVS/RCS Revision: $Revision: 1.23 $ 00068 ** Status: $State: Exp $ 00069 ** 00070 ** CVS/RCS Log at end of file 00071 ** 00072 */ 00073 00074 #ifndef DCOMPAT_H 00075 #define DCOMPAT_H 00076 00077 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00078 #include "dcmtk/ofstd/ofbmanip.h" /* for bzero workaround */ 00079 00080 #define INCLUDE_CSTDLIB 00081 #define INCLUDE_CTIME 00082 #define INCLUDE_CSTRING 00083 #define INCLUDE_CERRNO 00084 #define INCLUDE_LIBC 00085 #define INCLUDE_UNISTD 00086 #include "dcmtk/ofstd/ofstdinc.h" 00087 00088 #ifdef HAVE_GUSI_H 00089 /* Use the Grand Unified Sockets Interface (GUSI) on Macintosh */ 00090 #include <GUSI.h> 00091 #endif 00092 00093 #ifdef HAVE_WINDOWS_H 00094 #include <windows.h> /* this includes either winsock.h or winsock2.h */ 00095 #else 00096 #ifdef HAVE_WINSOCK_H 00097 #include <winsock.h> /* include winsock.h directly i.e. on MacOS */ 00098 #ifdef macintosh 00099 /* 00100 ** The WinSock header on Macintosh does not declare the WORD type nor the MAKEWORD 00101 ** macro need to initialize the WinSock library. 00102 */ 00103 typedef u_short WORD; 00104 #define MAKEWORD(a,b) ((WORD) (((a)&0xff)<<8) | ((b)&0xff) ) 00105 #endif 00106 #endif 00107 #endif 00108 00109 BEGIN_EXTERN_C 00110 #ifdef HAVE_SYS_TIME_H 00111 #include <sys/time.h> 00112 #endif 00113 #ifdef HAVE_SYS_TYPES_H 00114 #include <sys/types.h> 00115 #endif 00116 #ifdef HAVE_SYS_SOCKET_H 00117 #ifndef DCOMPAT_SYS_SOCKET_H_ 00118 #define DCOMPAT_SYS_SOCKET_H_ 00119 /* some systems don't protect sys/socket.h (e.g. DEC Ultrix) */ 00120 #include <sys/socket.h> 00121 #endif 00122 #endif 00123 #ifdef HAVE_NETINET_IN_H 00124 #include <netinet/in.h> 00125 #endif 00126 #ifdef HAVE_ARPA_INET_H 00127 #include <arpa/inet.h> 00128 #endif 00129 #ifdef HAVE_NETDB_H 00130 #include <netdb.h> 00131 #endif 00132 #ifdef HAVE_SYS_WAIT_H 00133 #include <sys/wait.h> 00134 #endif 00135 #ifdef HAVE_SYS_RESOURCE_H 00136 #include <sys/resource.h> 00137 #endif 00138 #ifdef HAVE_SYS_PARAM_H 00139 #include <sys/param.h> 00140 #endif 00141 #ifdef HAVE_SYS_SELECT_H 00142 #include <sys/select.h> 00143 #endif 00144 #ifdef HAVE_SYS_FILE_H 00145 #include <sys/file.h> 00146 #endif 00147 END_EXTERN_C 00148 00149 #ifdef _WIN32 00150 #include <process.h> 00151 #include <io.h> 00152 #ifndef __CYGWIN__ 00153 #include <sys/locking.h> 00154 #endif 00155 #endif 00156 00157 #ifndef EINTR 00158 /* The WinSock header on Macintosh does not define an EINTR error code */ 00159 #ifdef HAVE_WINSOCK_H 00160 #define EINTR WSAEINTR 00161 #endif 00162 #endif 00163 00164 #ifdef HAVE_PROTOTYPE_FLOCK 00165 #define dcmtk_flock flock 00166 #define dcmtk_plockerr perror 00167 #endif 00168 00169 #ifndef HAVE_PROTOTYPE_FLOCK 00170 #ifdef HAVE_FLOCK 00171 BEGIN_EXTERN_C 00172 int flock(int fd, int operation); 00173 END_EXTERN_C 00174 #define dcmtk_flock flock 00175 #define dcmtk_plockerr perror 00176 #else 00177 /* 00178 * Simulate the flock function calls 00179 * using the facilities of fcntl(2) 00180 */ 00181 00182 #define LOCK_SH 1 /* shared lock */ 00183 #define LOCK_EX 2 /* exclusive lock */ 00184 #define LOCK_NB 4 /* don't block when locking */ 00185 #define LOCK_UN 8 /* unlock */ 00186 00187 int dcmtk_flock(int fd, int operation); 00188 void dcmtk_plockerr(const char *s); 00189 00190 #endif /* !HAVE_FLOCK */ 00191 #endif 00192 00193 #ifndef HAVE_BZERO 00194 #ifndef bzero 00195 #define bzero(p,len) memset((void*)(p), 0, (len)); 00196 #endif 00197 #endif 00198 00199 #ifndef HAVE_PROTOTYPE_GETHOSTNAME 00200 #ifdef HAVE_GETHOSTNAME 00201 /* gethostname is in the libraries but we have no prototype */ 00202 BEGIN_EXTERN_C 00203 int gethostname(char* name, int namelen); 00204 END_EXTERN_C 00205 #else 00206 /* define gethostname ourselves */ 00207 int gethostname(char* name, int namelen); 00208 #endif 00209 #endif 00210 00211 #ifndef HAVE_PROTOTYPE_GETHOSTBYNAME 00212 #ifdef HAVE_GETHOSTBYNAME 00213 /* it is in the libraries but we have no prototype */ 00214 BEGIN_EXTERN_C 00215 struct hostent *gethostbyname(const char* name); 00216 END_EXTERN_C 00217 #else 00218 /* don't know how to emulate */ 00219 #endif 00220 #endif 00221 00222 #ifndef HAVE_PROTOTYPE_GETSOCKOPT 00223 #ifdef HAVE_GETSOCKOPT 00224 /* it is in the libraries but we have no prototype */ 00225 BEGIN_EXTERN_C 00226 int getsockopt(int s, int level, int optname, char *optval, int *optlen); 00227 END_EXTERN_C 00228 #else 00229 /* don't know how to emulate */ 00230 #endif 00231 #endif 00232 00233 #ifndef HAVE_PROTOTYPE_SETSOCKOPT 00234 #ifdef HAVE_SETSOCKOPT 00235 /* it is in the libraries but we have no prototype */ 00236 BEGIN_EXTERN_C 00237 int setsockopt(int s, int level, int optname, const char *optval, int optlen); 00238 END_EXTERN_C 00239 #else 00240 /* don't know how to emulate */ 00241 #endif 00242 #endif 00243 00244 #ifndef HAVE_PROTOTYPE_LISTEN 00245 #ifdef HAVE_LISTEN 00246 /* it is in the libraries but we have no prototype */ 00247 BEGIN_EXTERN_C 00248 int listen(int s, int backlog); 00249 END_EXTERN_C 00250 #else 00251 /* don't know how to emulate */ 00252 #endif 00253 #endif 00254 00255 #ifndef HAVE_PROTOTYPE_SOCKET 00256 #ifdef HAVE_SOCKET 00257 /* it is in the libraries but we have no prototype */ 00258 BEGIN_EXTERN_C 00259 int socket(int domain, int type, int protocol); 00260 END_EXTERN_C 00261 #else 00262 /* don't know how to emulate */ 00263 #endif 00264 #endif 00265 00266 #ifndef HAVE_PROTOTYPE_CONNECT 00267 #ifdef HAVE_CONNECT 00268 /* it is in the libraries but we have no prototype */ 00269 BEGIN_EXTERN_C 00270 int connect(int s, struct sockaddr *name, int namelen); 00271 END_EXTERN_C 00272 #else 00273 /* don't know how to emulate */ 00274 #endif 00275 #endif 00276 00277 #ifndef HAVE_PROTOTYPE_SELECT 00278 #ifdef HAVE_SELECT 00279 /* it is in the libraries but we have no prototype */ 00280 BEGIN_EXTERN_C 00281 int select(int nfds, fd_set *readfds, fd_set *writefds, 00282 fd_set *exceptfds, struct timeval *timeout); 00283 END_EXTERN_C 00284 #else 00285 /* don't know how to emulate */ 00286 #endif 00287 #endif 00288 00289 #ifndef HAVE_PROTOTYPE_BIND 00290 #ifdef HAVE_BIND 00291 /* it is in the libraries but we have no prototype */ 00292 BEGIN_EXTERN_C 00293 int bind(int s, const struct sockaddr *name, int namelen); 00294 END_EXTERN_C 00295 #else 00296 /* don't know how to emulate */ 00297 #endif 00298 #endif 00299 00300 #ifndef HAVE_PROTOTYPE_ACCEPT 00301 #ifdef HAVE_ACCEPT 00302 /* it is in the libraries but we have no prototype */ 00303 BEGIN_EXTERN_C 00304 int accept(int s, struct sockaddr *addr, int *addrlen); 00305 END_EXTERN_C 00306 #else 00307 /* don't know how to emulate */ 00308 #endif 00309 #endif 00310 00311 #ifndef HAVE_PROTOTYPE_GETSOCKNAME 00312 #ifdef HAVE_GETSOCKNAME 00313 /* it is in the libraries but we have no prototype */ 00314 BEGIN_EXTERN_C 00315 int getsockname(int s, struct sockaddr *name, int *namelen); 00316 END_EXTERN_C 00317 #else 00318 /* don't know how to emulate */ 00319 #endif 00320 #endif 00321 00322 #ifndef HAVE_PROTOTYPE_WAITPID 00323 #ifdef HAVE_WAITPID 00324 /* it is in the libraries but we have no prototype */ 00325 BEGIN_EXTERN_C 00326 int waitpid(pid_t pid, int *statusp, int options); 00327 END_EXTERN_C 00328 #else 00329 /* don't know how to emulate */ 00330 #endif 00331 #endif 00332 00333 #ifndef HAVE_PROTOTYPE_WAIT3 00334 #ifdef HAVE_WAIT3 00335 /* it is in the libraries but we have no prototype */ 00336 BEGIN_EXTERN_C 00337 int wait3(int *statusp, int options, struct rusage *rusage); 00338 END_EXTERN_C 00339 #else 00340 /* don't know how to emulate */ 00341 #endif 00342 #endif 00343 00344 #ifndef HAVE_GETPID 00345 #ifndef getpid 00346 #ifdef _WIN32 00347 #define getpid() (_getpid()) 00348 #else 00349 #define getpid() ((int) 9000) 00350 #endif 00351 #endif 00352 #endif 00353 00354 #ifndef HAVE_ACCESS 00355 00356 #ifndef R_OK 00357 #define R_OK 0x01 00358 #define W_OK 0x02 00359 #define X_OK 0x04 00360 #define F_OK 0x08 00361 #endif 00362 00363 int access(const char* path, int amode); 00364 #else /* HAVE_ACCESS */ 00365 00366 #ifdef _WIN32 00367 /* windows defines access but not the constants */ 00368 #ifndef R_OK 00369 #define W_OK 02 /* Write permission */ 00370 #define R_OK 04 /* Read permission */ 00371 #define F_OK 00 /* Existance only */ 00372 #define X_OK 00 /* execute permission has no meaning under windows, treat as existance */ 00373 #endif /* R_OK */ 00374 #endif /* _WIN32 */ 00375 00376 #endif /* HAVE_ACCESS */ 00377 00378 #ifndef HAVE_STRERROR 00379 char *strerror(int e); 00380 #endif 00381 00382 #ifndef HAVE_TEMPNAM 00383 char *tempnam(char *dir, char *pfx); 00384 #endif 00385 00386 #ifdef _WIN32 00387 #define NULL_DEVICE_NAME "nul" 00388 #else 00389 #define NULL_DEVICE_NAME "/dev/null" 00390 #endif 00391 00392 00393 #endif /* DCOMPAT_H */ 00394 00395 /* 00396 ** CVS Log 00397 ** $Log: dcompat.h,v $ 00398 ** Revision 1.23 2005/12/08 16:02:19 meichel 00399 ** Changed include path schema for all DCMTK header files 00400 ** 00401 ** Revision 1.22 2004/08/03 11:42:43 meichel 00402 ** Headers libc.h and unistd.h are now included via ofstdinc.h 00403 ** 00404 ** Revision 1.21 2003/12/17 16:33:26 meichel 00405 ** Removed unused macros 00406 ** 00407 ** Revision 1.20 2003/06/06 09:44:56 meichel 00408 ** Added static sleep function in class OFStandard. This replaces the various 00409 ** calls to sleep(), Sleep() and usleep() throughout the toolkit. 00410 ** 00411 ** Revision 1.19 2002/11/27 13:04:35 meichel 00412 ** Adapted module dcmnet to use of new header file ofstdinc.h 00413 ** 00414 ** Revision 1.18 2000/11/10 16:25:01 meichel 00415 ** Fixed problem with DIMSE routines which attempted to delete /dev/null 00416 ** under certain circumstances, which could lead to disastrous results if 00417 ** tools were run with root permissions (what they shouldn't). 00418 ** 00419 ** Revision 1.17 2000/02/23 15:12:24 meichel 00420 ** Corrected macro for Borland C++ Builder 4 workaround. 00421 ** 00422 ** Revision 1.16 2000/02/01 10:24:06 meichel 00423 ** Avoiding to include <stdlib.h> as extern "C" on Borland C++ Builder 4, 00424 ** workaround for bug in compiler header files. 00425 ** 00426 ** Revision 1.15 1999/11/12 16:51:02 meichel 00427 ** Corrected file locking code that did not work correctly under Win95/98. 00428 ** 00429 ** Revision 1.14 1999/05/04 12:18:04 joergr 00430 ** Minor changes to support Cygwin B20.1 (check __CYGWIN__ to distinguish from 00431 ** MSVC which also defines _WIN32). 00432 ** 00433 ** Revision 1.13 1999/04/30 16:36:32 meichel 00434 ** Renamed all flock calls to dcmtk_flock to avoid name clash between flock() 00435 ** emulation based on fcntl() and a constructor for struct flock. 00436 ** 00437 ** Revision 1.12 1999/04/21 13:02:56 meichel 00438 ** Now always including <windows.h> instead of <winsock.h> on Win32 platforms. 00439 ** This makes sure that <winsock2.h> is used if available. 00440 ** 00441 ** Revision 1.11 1999/04/19 08:42:35 meichel 00442 ** Added constants for access() on Win32. 00443 ** 00444 ** Revision 1.10 1997/09/11 16:02:15 hewett 00445 ** Conditionally included more standard header files into the 00446 ** the dcmnet compatibility header file to allow appropriate 00447 ** declarations to be picked up. For Signus GnuWin32. 00448 ** 00449 ** Revision 1.9 1997/04/18 08:37:30 andreas 00450 ** - Removed double include of sys/select 00451 ** 00452 ** Revision 1.8 1997/02/06 12:14:42 hewett 00453 ** Updated preliminary Apple Macintosh support for the Metrowerks CodeWarrior 00454 ** version 11 compiler and environment. 00455 ** 00456 ** Revision 1.7 1996/09/27 14:03:03 hewett 00457 ** Added emulation of sleep() for Win32. 00458 ** 00459 ** Revision 1.6 1996/09/27 08:27:59 hewett 00460 ** Move the defines for BEGIN_EXTERN_C/END_EXTERN_C to config/include/osconfig.h 00461 ** Added support for Win32 by conditionally including <WINSOCK.h>. 00462 ** 00463 ** Revision 1.5 1996/09/24 16:22:36 hewett 00464 ** Added preliminary support for the Macintosh environment (GUSI library). 00465 ** 00466 ** Revision 1.4 1996/06/20 07:31:09 hewett 00467 ** Corrected compilation problem when including <sys/socket.h> on 00468 ** DEC Alpha OSF/1. 00469 ** 00470 ** Revision 1.3 1996/05/03 10:30:41 hewett 00471 ** Added some common include files. 00472 ** 00473 ** Revision 1.2 1996/04/25 16:05:44 hewett 00474 ** Added prototypes for some network functions if not available on system. 00475 ** 00476 ** Revision 1.1.1.1 1996/03/26 18:38:45 hewett 00477 ** Initial Release. 00478 ** 00479 ** 00480 */