|
|
1.1 ! root 1: /* sbbswrap.h */ ! 2: ! 3: /* Synchronet system-call wrappers */ ! 4: ! 5: /* $Id: sbbswrap.h,v 1.27 2000/12/05 03:25:45 rswindell Exp $ */ ! 6: ! 7: /**************************************************************************** ! 8: * @format.tab-size 4 (Plain Text/Source Code File Header) * ! 9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * ! 10: * * ! 11: * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * ! 12: * * ! 13: * This program is free software; you can redistribute it and/or * ! 14: * modify it under the terms of the GNU General Public License * ! 15: * as published by the Free Software Foundation; either version 2 * ! 16: * of the License, or (at your option) any later version. * ! 17: * See the GNU General Public License for more details: gpl.txt or * ! 18: * http://www.fsf.org/copyleft/gpl.html * ! 19: * * ! 20: * Anonymous FTP access to the most recent released source is available at * ! 21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * ! 22: * * ! 23: * Anonymous CVS access to the development source and modification history * ! 24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: * ! 25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login * ! 26: * (just hit return, no password is necessary) * ! 27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src * ! 28: * * ! 29: * For Synchronet coding style and modification guidelines, see * ! 30: * http://www.synchro.net/source.html * ! 31: * * ! 32: * You are encouraged to submit any modifications (preferably in Unix diff * ! 33: * format) via e-mail to [email protected] * ! 34: * * ! 35: * Note: If this box doesn't appear square, then you need to fix your tabs. * ! 36: ****************************************************************************/ ! 37: ! 38: #ifndef _SBBSWRAP_H ! 39: #define _SBBSWRAP_H ! 40: ! 41: #include "gen_defs.h" /* ulong */ ! 42: ! 43: #ifdef DLLEXPORT ! 44: #undef DLLEXPORT ! 45: #endif ! 46: #ifdef DLLCALL ! 47: #undef DLLCALL ! 48: #endif ! 49: ! 50: #ifdef _WIN32 ! 51: #ifdef WRAPPER_DLL ! 52: #define DLLEXPORT __declspec(dllexport) ! 53: #else ! 54: #define DLLEXPORT __declspec(dllimport) ! 55: #endif ! 56: #ifdef __BORLANDC__ ! 57: #define DLLCALL __stdcall ! 58: #else ! 59: #define DLLCALL ! 60: #endif ! 61: #else /* !_WIN32 */ ! 62: #define DLLEXPORT ! 63: #define DLLCALL ! 64: #endif ! 65: ! 66: #ifdef __cplusplus ! 67: extern "C" { ! 68: #endif ! 69: ! 70: ! 71: #ifdef _MSC_VER ! 72: #include "msdirent.h" ! 73: #else ! 74: #include <dirent.h> /* POSIX directory functions */ ! 75: #endif ! 76: ! 77: /***************/ ! 78: /* OS-specific */ ! 79: /***************/ ! 80: ! 81: #ifdef __unix__ ! 82: ! 83: #include <glob.h> /* POSIX.2 directory pattern matching function */ ! 84: #define ALLFILES "*" /* matches all files in a directory */ ! 85: ! 86: #else /* glob-compatible findfirst/findnext wrapper */ ! 87: ! 88: typedef struct ! 89: { ! 90: size_t gl_pathc; /* Count of paths matched so far */ ! 91: char **gl_pathv; /* List of matched pathnames. */ ! 92: size_t gl_offs; /* Slots to reserve in 'gl_pathv'. */ ! 93: } glob_t; ! 94: ! 95: /* Bits set in the FLAGS argument to `glob'. */ ! 96: #define GLOB_ERR (1 << 0) /* Return on read errors. */ ! 97: #define GLOB_MARK (1 << 1) /* Append a slash to each name. */ ! 98: #define GLOB_NOSORT (1 << 2) /* Don't sort the names. */ ! 99: #define GLOB_DOOFFS (1 << 3) /* Insert PGLOB->gl_offs NULLs. */ ! 100: #define GLOB_NOCHECK (1 << 4) /* If nothing matches, return the pattern. */ ! 101: #define GLOB_APPEND (1 << 5) /* Append to results of a previous call. */ ! 102: #define GLOB_NOESCAPE (1 << 6) /* Backslashes don't quote metacharacters. */ ! 103: #define GLOB_PERIOD (1 << 7) /* Leading `.' can be matched by metachars. */ ! 104: #define GLOB_MAGCHAR (1 << 8) /* Set in gl_flags if any metachars seen. */ ! 105: #define GLOB_ALTDIRFUNC (1 << 9) /* Use gl_opendir et al functions. */ ! 106: #define GLOB_BRACE (1 << 10) /* Expand "{a,b}" to "a" "b". */ ! 107: #define GLOB_NOMAGIC (1 << 11) /* If no magic chars, return the pattern. */ ! 108: #define GLOB_TILDE (1 << 12) /* Expand ~user and ~ to home directories. */ ! 109: #define GLOB_ONLYDIR (1 << 13) /* Match only directories. */ ! 110: #define GLOB_TILDE_CHECK (1 << 14) /* Like GLOB_TILDE but return an error ! 111: if the user name is not available. */ ! 112: /* Error returns from `glob'. */ ! 113: #define GLOB_NOSPACE 1 /* Ran out of memory. */ ! 114: #define GLOB_ABORTED 2 /* Read error. */ ! 115: #define GLOB_NOMATCH 3 /* No matches found. */ ! 116: #define GLOB_NOSYS 4 /* Not implemented. */ ! 117: ! 118: DLLEXPORT int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t*); ! 119: DLLEXPORT void DLLCALL globfree(glob_t*); ! 120: ! 121: #define ALLFILES "*.*" /* matches all files in a directory */ ! 122: ! 123: #endif ! 124: ! 125: #ifdef __unix__ ! 126: ! 127: #include <pthread.h> /* POSIX threads and mutexes */ ! 128: #include <semaphore.h> /* POSIX semaphores */ ! 129: ulong _beginthread(void( *start_address )( void * ) ! 130: ,unsigned stack_size, void *arglist); ! 131: ! 132: #elif defined(_WIN32) ! 133: ! 134: /* POIX semaphores */ ! 135: typedef HANDLE sem_t; ! 136: #define sem_init(psem,ps,v) ResetEvent(*(psem)) ! 137: #define sem_wait(psem) WaitForSingleObject(*(psem),INFINITE) ! 138: #define sem_post(psem) SetEvent(*(psem)) ! 139: #define sem_destroy(psem) CloseHandle(*(psem)) ! 140: int sem_getvalue(sem_t*, int* val); ! 141: ! 142: /* POIX mutexes */ ! 143: typedef HANDLE pthread_mutex_t; ! 144: #define PTHREAD_MUTEX_INITIALIZER CreateMutex(NULL,FALSE,NULL) ! 145: #define pthread_mutex_init(pmtx,v) *(pmtx)=CreateMutex(NULL,FALSE,NULL) ! 146: #define pthread_mutex_lock(pmtx) WaitForSingleObject(*(pmtx),INFINITE) ! 147: #define pthread_mutex_unlock(pmtx) ReleaseMutex(*(pmtx)) ! 148: #define pthread_mutex_destroy(pmtx) CloseHandle(*(pmtx)) ! 149: ! 150: #else ! 151: ! 152: #warning "Need semaphore wrappers." ! 153: ! 154: #endif ! 155: ! 156: ! 157: #if defined(_WIN32) ! 158: ! 159: #define mswait(x) Sleep(x) ! 160: #define sbbs_beep(freq,dur) Beep(freq,dur) ! 161: ! 162: #elif defined(__OS2__) ! 163: ! 164: #define mswait(x) DosSleep(x) ! 165: #define sbbs_beep(freq,dur) DosBeep(freq,dur) ! 166: ! 167: #elif defined(__unix__) ! 168: ! 169: #define mswait(x) usleep(x*1000) ! 170: #define _mkdir(dir) mkdir(dir,0777) ! 171: #define _rmdir(dir) rmdir(dir) ! 172: #define _fullpath(a,r,l) realpath(r,a) ! 173: #define tell(fd) lseek(fd,0,SEEK_CUR) ! 174: ! 175: DLLEXPORT void DLLCALL sbbs_beep(int freq, int dur); ! 176: DLLEXPORT char* DLLCALL strrev(char* str); ! 177: ! 178: #else /* Unsupported OS */ ! 179: ! 180: #warning "Unsupported Target: Need some macros of function prototypes here." ! 181: ! 182: #endif ! 183: ! 184: /*********************/ ! 185: /* Compiler-specific */ ! 186: /*********************/ ! 187: ! 188: /* Compiler Description */ ! 189: #if defined(__BORLANDC__) ! 190: ! 191: #define COMPILER_DESC(str) sprintf(str,"BCC %X.%02X" \ ! 192: ,__BORLANDC__>>8,__BORLANDC__&0xff); ! 193: ! 194: #elif defined(_MSC_VER) ! 195: ! 196: #define COMPILER_DESC(str) sprintf(str,"MSC %u", _MSC_VER); ! 197: ! 198: #elif defined(__GNUC__) && defined(__GLIBC__) ! 199: ! 200: #define COMPILER_DESC(str) sprintf(str,"GCC %u.%02u (GLIBC %u.%u)" \ ! 201: ,__GNUC__,__GNUC_MINOR__,__GLIBC__,__GLIBC_MINOR__); ! 202: ! 203: #elif defined(__GNUC__) ! 204: ! 205: #define COMPILER_DESC(str) sprintf(str,"GCC %u.%02u" \ ! 206: ,__GNUC__,__GNUC_MINOR__); ! 207: ! 208: #else /* Unknown compiler */ ! 209: ! 210: #define COMPILER_DESC(str) strcpy(str,"UNKNOWN COMPILER"); ! 211: ! 212: #endif ! 213: ! 214: /**********/ ! 215: /* Macros */ ! 216: /**********/ ! 217: ! 218: /* POSIX readdir convenience macro */ ! 219: #ifndef DIRENT ! 220: #define DIRENT struct dirent ! 221: #endif ! 222: ! 223: #if defined(__unix__) ! 224: #define BACKSLASH '/' ! 225: #else /* MS-DOS based OS */ ! 226: #define BACKSLASH '\\' ! 227: #endif ! 228: ! 229: /* Target Platform Description */ ! 230: #if defined(_WIN32) ! 231: #define PLATFORM_DESC "Win32" ! 232: #elif defined(__OS2__) ! 233: #define PLATFORM_DESC "OS/2" ! 234: #elif defined(__MSDOS__) ! 235: #define PLATFORM_DESC "DOS" ! 236: #elif defined(__linux__) ! 237: #define PLATFORM_DESC "Linux" ! 238: #elif defined(__unix__) ! 239: #define PLATFORM_DESC "Unix" ! 240: #else ! 241: #warning "Need to describe target platform" ! 242: #define PLATFORM_DESC "UNKNOWN" ! 243: #endif ! 244: ! 245: #if defined(_MSC_VER) || defined(__MINGW32__) ! 246: ! 247: #define CHMOD(s,m) _chmod(s,m) ! 248: #define PUTENV _putenv ! 249: #define GETCWD _getcwd ! 250: #define snprintf _snprintf ! 251: ! 252: #elif defined(__BORLANDC__) ! 253: ! 254: #define CHMOD(s,m) _chmod(s,1,m) ! 255: #define PUTENV putenv ! 256: #define GETCWD getcwd ! 257: ! 258: #else /* ??? */ ! 259: ! 260: #define CHMOD(s,m) chmod(s,m) ! 261: #define PUTENV putenv ! 262: #define GETCWD getcwd ! 263: ! 264: #endif ! 265: ! 266: #if defined(__BORLANDC__) ! 267: #define sbbs_random(x) random(x) ! 268: #else ! 269: DLLEXPORT int DLLCALL sbbs_random(int n); ! 270: #endif ! 271: ! 272: #if __BORLANDC__ > 0x0410 ! 273: #define _chmod(p,f,a) _rtl_chmod(p,f,a) /* _chmod obsolete in 4.x */ ! 274: #endif ! 275: ! 276: #if !defined(_MSC_VER) && !defined(__BORLANDC__) ! 277: DLLEXPORT char* DLLCALL ultoa(ulong, char*, int radix); ! 278: #endif ! 279: ! 280: ! 281: /* General file system wrappers for all platforms and compilers */ ! 282: DLLEXPORT long DLLCALL fdate(char *filename); ! 283: DLLEXPORT BOOL DLLCALL isdir(char *filename); ! 284: DLLEXPORT int DLLCALL getfattr(char* filename); ! 285: DLLEXPORT ulong DLLCALL getfreediskspace(char* path); ! 286: ! 287: #ifdef __cplusplus ! 288: } ! 289: #endif ! 290: ! 291: #endif /* Don't add anything after this line */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.