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