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