Eneboo - Documentación para desarrolladores
|
00001 /*------------------------------------------------------------------------- 00002 * 00003 * port.h 00004 * Header for src/port/ compatibility functions. 00005 * 00006 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group 00007 * Portions Copyright (c) 1994, Regents of the University of California 00008 * 00009 * $PostgreSQL: pgsql/src/include/port.h,v 1.84.2.6 2006/04/24 04:03:38 momjian Exp $ 00010 * 00011 *------------------------------------------------------------------------- 00012 */ 00013 00014 #ifndef WIN32_CLIENT_ONLY 00015 /* for thread.c */ 00016 #include <pwd.h> 00017 #include <netdb.h> 00018 #endif 00019 00020 #include <ctype.h> 00021 00022 /* non-blocking */ 00023 extern bool pg_set_noblock( int sock ); 00024 extern bool pg_set_block( int sock ); 00025 00026 /* Portable path handling for Unix/Win32 */ 00027 00028 extern char *first_dir_separator( const char *filename ); 00029 extern char *last_dir_separator( const char *filename ); 00030 extern char *first_path_separator( const char *pathlist ); 00031 extern void join_path_components( char *ret_path, 00032 const char *head, const char *tail ); 00033 extern void canonicalize_path( char *path ); 00034 extern void make_native_path( char *path ); 00035 extern bool path_contains_parent_reference( const char *path ); 00036 extern bool path_is_prefix_of_path( const char *path1, const char *path2 ); 00037 extern const char *get_progname( const char *argv0 ); 00038 extern void get_share_path( const char *my_exec_path, char *ret_path ); 00039 extern void get_etc_path( const char *my_exec_path, char *ret_path ); 00040 extern void get_include_path( const char *my_exec_path, char *ret_path ); 00041 extern void get_pkginclude_path( const char *my_exec_path, char *ret_path ); 00042 extern void get_includeserver_path( const char *my_exec_path, char *ret_path ); 00043 extern void get_lib_path( const char *my_exec_path, char *ret_path ); 00044 extern void get_pkglib_path( const char *my_exec_path, char *ret_path ); 00045 extern void get_locale_path( const char *my_exec_path, char *ret_path ); 00046 extern void get_doc_path( const char *my_exec_path, char *ret_path ); 00047 extern void get_man_path( const char *my_exec_path, char *ret_path ); 00048 extern void set_pglocale_pgservice( const char *argv0, const char *app ); 00049 extern bool get_home_path( char *ret_path ); 00050 extern void get_parent_directory( char *path ); 00051 00052 /* 00053 * is_absolute_path 00054 * 00055 * By making this a macro we prevent the need for libpq to include 00056 * path.c which uses exec.c. 00057 */ 00058 #ifndef WIN32 00059 #define is_absolute_path(filename) \ 00060 ( \ 00061 ((filename)[0] == '/') \ 00062 ) 00063 #else 00064 #define is_absolute_path(filename) \ 00065 ( \ 00066 ((filename)[0] == '/') || \ 00067 (filename)[0] == '\\' || \ 00068 (isalpha((filename)[0]) && (filename)[1] == ':' && \ 00069 ((filename)[2] == '\\' || (filename)[2] == '/')) \ 00070 ) 00071 #endif 00072 00073 00074 /* Portable way to find binaries */ 00075 extern int find_my_exec( const char *argv0, char *retpath ); 00076 extern int find_other_exec( const char *argv0, const char *target, 00077 const char *versionstr, char *retpath ); 00078 00079 #if defined(WIN32) || defined(__CYGWIN__) 00080 #define EXE ".exe" 00081 #else 00082 #define EXE "" 00083 #endif 00084 00085 #if defined(WIN32) && !defined(__CYGWIN__) 00086 #define DEVNULL "nul" 00087 /* "con" does not work from the Msys 1.0.10 console (part of MinGW). */ 00088 #define DEVTTY "con" 00089 #else 00090 #define DEVNULL "/dev/null" 00091 #define DEVTTY "/dev/tty" 00092 #endif 00093 00094 /* 00095 * Win32 needs double quotes at the beginning and end of system() 00096 * strings. If not, it gets confused with multiple quoted strings. 00097 * It also requires double-quotes around the executable name and 00098 * any files used for redirection. Other args can use single-quotes. 00099 * 00100 * See the "Notes" section about quotes at: 00101 * http://home.earthlink.net/~rlively/MANUALS/COMMANDS/C/CMD.HTM 00102 */ 00103 #if defined(WIN32) && !defined(__CYGWIN__) 00104 #define SYSTEMQUOTE "\"" 00105 #else 00106 #define SYSTEMQUOTE "" 00107 #endif 00108 00109 /* Portable delay handling */ 00110 extern void pg_usleep( long microsec ); 00111 00112 /* Portable SQL-like case-independent comparisons and conversions */ 00113 extern int pg_strcasecmp( const char *s1, const char *s2 ); 00114 extern int pg_strncasecmp( const char *s1, const char *s2, size_t n ); 00115 extern unsigned char pg_toupper( unsigned char ch ); 00116 extern unsigned char pg_tolower( unsigned char ch ); 00117 00118 #ifdef USE_REPL_SNPRINTF 00119 00120 /* 00121 * Versions of libintl >= 0.13 try to replace printf() and friends with 00122 * macros to their own versions that understand the %$ format. We do the 00123 * same, so disable their macros, if they exist. 00124 */ 00125 #ifdef vsnprintf 00126 #undef vsnprintf 00127 #endif 00128 #ifdef snprintf 00129 #undef snprintf 00130 #endif 00131 #ifdef sprintf 00132 #undef sprintf 00133 #endif 00134 #ifdef fprintf 00135 #undef fprintf 00136 #endif 00137 #ifdef printf 00138 #undef printf 00139 #endif 00140 00141 extern int pg_vsnprintf( char *str, size_t count, const char *fmt, va_list args ); 00142 extern int 00143 pg_snprintf( char *str, size_t count, const char *fmt, ... ) 00144 /* This extension allows gcc to check the format string */ 00145 __attribute__(( format( printf, 3, 4 ) ) ); 00146 extern int 00147 pg_sprintf( char *str, const char *fmt, ... ) 00148 /* This extension allows gcc to check the format string */ 00149 __attribute__(( format( printf, 2, 3 ) ) ); 00150 extern int 00151 pg_fprintf( FILE *stream, const char *fmt, ... ) 00152 /* This extension allows gcc to check the format string */ 00153 __attribute__(( format( printf, 2, 3 ) ) ); 00154 extern int 00155 pg_printf( const char *fmt, ... ) 00156 /* This extension allows gcc to check the format string */ 00157 __attribute__(( format( printf, 1, 2 ) ) ); 00158 00159 /* 00160 * The GCC-specific code below prevents the __attribute__(... 'printf') 00161 * above from being replaced, and this is required because gcc doesn't 00162 * know anything about pg_printf. 00163 */ 00164 #ifdef __GNUC__ 00165 #define vsnprintf(...) pg_vsnprintf(__VA_ARGS__) 00166 #define snprintf(...) pg_snprintf(__VA_ARGS__) 00167 #define sprintf(...) pg_sprintf(__VA_ARGS__) 00168 #define fprintf(...) pg_fprintf(__VA_ARGS__) 00169 #define printf(...) pg_printf(__VA_ARGS__) 00170 #else 00171 #define vsnprintf pg_vsnprintf 00172 #define snprintf pg_snprintf 00173 #define sprintf pg_sprintf 00174 #define fprintf pg_fprintf 00175 #define printf pg_printf 00176 #endif 00177 00178 #endif /* USE_REPL_SNPRINTF */ 00179 00180 /* Portable prompt handling */ 00181 extern char *simple_prompt( const char *prompt, int maxlen, bool echo ); 00182 00183 /* 00184 * WIN32 doesn't allow descriptors returned by pipe() to be used in select(), 00185 * so for that platform we use socket() instead of pipe(). 00186 * There is some inconsistency here because sometimes we require pg*, like 00187 * pgpipe, but in other cases we define rename to pgrename just on Win32. 00188 */ 00189 #ifndef WIN32 00190 #define pgpipe(a) pipe(a) 00191 #define piperead(a,b,c) read(a,b,c) 00192 #define pipewrite(a,b,c) write(a,b,c) 00193 #else 00194 extern int pgpipe( int handles[2] ); 00195 extern int piperead( int s, char *buf, int len ); 00196 00197 #define pipewrite(a,b,c) send(a,b,c,0) 00198 00199 #define PG_SIGNAL_COUNT 32 00200 #define kill(pid,sig) pgkill(pid,sig) 00201 extern int pgkill( int pid, int sig ); 00202 #endif 00203 00204 extern int pclose_check( FILE *stream ); 00205 00206 /* Global variable holding time zone information. */ 00207 #ifndef __CYGWIN__ 00208 #define TIMEZONE_GLOBAL timezone 00209 #define TZNAME_GLOBAL tzname 00210 #else 00211 #define TIMEZONE_GLOBAL _timezone 00212 #define TZNAME_GLOBAL _tzname 00213 #endif 00214 00215 #if defined(WIN32) || defined(__CYGWIN__) 00216 /* 00217 * Win32 doesn't have reliable rename/unlink during concurrent access, 00218 * and we need special code to do symlinks. 00219 */ 00220 extern int pgrename( const char *from, const char *to ); 00221 extern int pgunlink( const char *path ); 00222 00223 /* Include this first so later includes don't see these defines */ 00224 #ifdef WIN32_CLIENT_ONLY 00225 #include <io.h> 00226 #endif 00227 00228 #define rename(from, to) pgrename(from, to) 00229 #define unlink(path) pgunlink(path) 00230 00231 /* 00232 * Cygwin has its own symlinks which work on Win95/98/ME where 00233 * junction points don't, so use it instead. We have no way of 00234 * knowing what type of system Cygwin binaries will be run on. 00235 * Note: Some CYGWIN includes might #define WIN32. 00236 */ 00237 #if defined(WIN32) && !defined(__CYGWIN__) 00238 extern int pgsymlink( const char *oldpath, const char *newpath ); 00239 00240 #define symlink(oldpath, newpath) pgsymlink(oldpath, newpath) 00241 #endif 00242 #endif /* defined(WIN32) || defined(__CYGWIN__) */ 00243 00244 extern void copydir( char *fromdir, char *todir, bool recurse ); 00245 00246 extern bool rmtree( char *path, bool rmtopdir ); 00247 00248 #if defined(WIN32) && !defined(__CYGWIN__) 00249 00250 /* open() replacement to allow delete of held files and passing 00251 * of special options. */ 00252 #ifndef WIN32_CLIENT_ONLY 00253 extern int win32_open( const char *, int, ... ); 00254 00255 #define open(a,b,...) win32_open(a,b,##__VA_ARGS__) 00256 #endif 00257 00258 #define popen(a,b) _popen(a,b) 00259 #define pclose(a) _pclose(a) 00260 00261 /* Missing rand functions */ 00262 extern long lrand48( void ); 00263 extern void srand48( long seed ); 00264 00265 /* Last parameter not used */ 00266 //extern int gettimeofday( struct timeval * tp, struct timezone * tzp ); 00267 #else /* !WIN32 */ 00268 00269 /* 00270 * Win32 requires a special close for sockets and pipes, while on Unix 00271 * close() does them all. 00272 */ 00273 #define closesocket close 00274 #endif /* WIN32 */ 00275 00276 /* 00277 * Default "extern" declarations or macro substitutes for library routines. 00278 * When necessary, these routines are provided by files in src/port/. 00279 */ 00280 #ifndef HAVE_CRYPT 00281 extern char *crypt( const char *key, const char *setting ); 00282 #endif 00283 00284 #if defined(bsdi) || defined(netbsd) 00285 extern int fseeko( FILE *stream, off_t offset, int whence ); 00286 extern off_t ftello( FILE *stream ); 00287 #endif 00288 00289 #ifndef HAVE_FSEEKO 00290 #define fseeko(a, b, c) fseek(a, b, c) 00291 #define ftello(a) ftell(a) 00292 #endif 00293 00294 #ifndef HAVE_GETOPT 00295 extern int getopt( int nargc, char *const * nargv, const char *ostr ); 00296 #endif 00297 00298 #ifndef HAVE_ISINF 00299 extern int isinf( double x ); 00300 #endif 00301 00302 #ifndef HAVE_RINT 00303 extern double rint( double x ); 00304 #endif 00305 00306 #ifndef HAVE_INET_ATON 00307 #ifndef WIN32_CLIENT_ONLY 00308 #include <netinet/in.h> 00309 #include <arpa/inet.h> 00310 #endif 00311 extern int inet_aton( const char *cp, struct in_addr * addr ); 00312 #endif 00313 00314 #ifndef HAVE_STRDUP 00315 extern char *strdup( char const * ); 00316 #endif 00317 00318 #ifndef HAVE_RANDOM 00319 extern long random( void ); 00320 #endif 00321 00322 #ifndef HAVE_UNSETENV 00323 extern void unsetenv( const char *name ); 00324 #endif 00325 00326 #ifndef HAVE_SRANDOM 00327 extern void srandom( unsigned int seed ); 00328 #endif 00329 00330 /* thread.h */ 00331 extern char *pqStrerror( int errnum, char *strerrbuf, size_t buflen ); 00332 00333 #if !defined(WIN32) || defined(__CYGWIN__) 00334 extern int pqGetpwuid( uid_t uid, struct passwd * resultbuf, char *buffer, 00335 size_t buflen, struct passwd ** result ); 00336 #endif 00337 00338 extern int pqGethostbyname( const char *name, 00339 struct hostent * resultbuf, 00340 char *buffer, size_t buflen, 00341 struct hostent ** result, 00342 int *herrno );