From 7333609f10eedbbb73690d10a6a0322077768aea Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sat, 13 Apr 2002 07:44:36 +0000 Subject: [PATCH] Eliminated in favor of xpdev versions of these wrappers. --- src/sbbs3/conwrap.c | 120 ------------ src/sbbs3/conwrap.h | 52 ----- src/sbbs3/sbbsinet.h | 129 ------------- src/sbbs3/sbbswrap.h | 289 ---------------------------- src/sbbs3/smbwrap.c | 303 ----------------------------- src/sbbs3/smbwrap.h | 143 -------------- src/sbbs3/wrappers.c | 445 ------------------------------------------- 7 files changed, 1481 deletions(-) delete mode 100644 src/sbbs3/conwrap.c delete mode 100644 src/sbbs3/conwrap.h delete mode 100644 src/sbbs3/sbbsinet.h delete mode 100644 src/sbbs3/sbbswrap.h delete mode 100644 src/sbbs3/smbwrap.c delete mode 100644 src/sbbs3/smbwrap.h delete mode 100644 src/sbbs3/wrappers.c diff --git a/src/sbbs3/conwrap.c b/src/sbbs3/conwrap.c deleted file mode 100644 index bfaeea3121..0000000000 --- a/src/sbbs3/conwrap.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - conwrap.c -- To give DOS's getch() function to Linux for use in Synchronet - Casey Martin 2000 -*/ - -/* $Id$ */ - -/* @format.tab-size 4, @format.use-tabs true */ - -#ifdef __unix__ - -#include <stdlib.h> -#include <unistd.h> -#include <termios.h> - -/* Do the correct thing under BSD */ -#ifndef __FreeBSD__ -#include <sys/kd.h> -#endif -#ifdef __FreeBSD__ -#include <sys/kbio.h> -#endif - -#include <sys/time.h> -#include <sys/types.h> -#include <signal.h> - -#include "conwrap.h" // Verify prototypes - -struct termios current; // our current term settings -struct termios original; // old termios settings -struct timeval timeout = {0, 0}; // passed in select() call -fd_set inp; // ditto -int beensetup = 0; // has _termios_setup() been called? - -/* - I'm using a variable function here simply for the sake of speed. The - termios functions must be called before a kbhit() can be successful, so - on the first call, we just set up the terminal, point to variable function - to kbhit_norm(), and then call the new function. Otherwise, testing would - be required on every call to determine if termios has already been setup. - - Maybe I'm being way too anal, though. -*/ - -/* Resets the termios to its previous state */ -void _termios_reset(void) -{ - tcsetattr(0, TCSANOW, &original); -} - -/************************************************ - This pair of functions handles Ctrl-Z presses -************************************************/ - -void _sighandler_stop(int sig) -{ - // clean up the terminal - _termios_reset(); - - // ... and stop - kill(getpid(), SIGSTOP); -} - -void _sighandler_cont(int sig) -{ - // restore terminal - tcsetattr(0, TCSANOW, ¤t); -} - - -/* Prepares termios for non-blocking action */ -void _termios_setup(void) -{ - beensetup = 1; - - tcgetattr(0, &original); - - memcpy(¤t, &original, sizeof(struct termios)); - current.c_cc[VMIN] = 1; // read() will return with one char - current.c_cc[VTIME] = 0; // read() blocks forever - current.c_lflag &= ~ICANON; // character mode - current.c_lflag &= ~ECHO; // turn off echoing - tcsetattr(0, TCSANOW, ¤t); - - // Let's install an exit function, also. This way, we can reset - // the termios silently - atexit(_termios_reset); - - // install the Ctrl-Z handler - signal(SIGSTOP, _sighandler_stop); - signal(SIGCONT, _sighandler_cont); -} - - -int kbhit(void) -{ - // set up select() args - FD_ZERO(&inp); - FD_SET(0, &inp); - - return select(1, &inp, NULL, NULL, &timeout); -} - -int getch(void) -{ - char c; - - if (!beensetup) - // I hate to test for this every time, but this shouldn't be - // called that often anyway... - _termios_setup(); - - // get a char out of stdin - read(0, &c, 1); - - return c; -} - -#endif // __unix__ diff --git a/src/sbbs3/conwrap.h b/src/sbbs3/conwrap.h deleted file mode 100644 index e1153fb7d2..0000000000 --- a/src/sbbs3/conwrap.h +++ /dev/null @@ -1,52 +0,0 @@ -/* conwrap.h */ - -/* Synchronet local console I/O wrapppers */ - -/* $Id$ */ - -/**************************************************************************** - * @format.tab-size 4 (Plain Text/Source Code File Header) * - * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * - * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * See the GNU General Public License for more details: gpl.txt or * - * http://www.fsf.org/copyleft/gpl.html * - * * - * Anonymous FTP access to the most recent released source is available at * - * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * - * * - * Anonymous CVS access to the development source and modification history * - * is available at cvs.synchro.net:/cvsroot/sbbs, example: * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login * - * (just hit return, no password is necessary) * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src * - * * - * For Synchronet coding style and modification guidelines, see * - * http://www.synchro.net/source.html * - * * - * You are encouraged to submit any modifications (preferably in Unix diff * - * format) via e-mail to mods@synchro.net * - * * - * Note: If this box doesn't appear square, then you need to fix your tabs. * - ****************************************************************************/ - -#ifndef _CONWRAP_H -#define _CONWRAP_H - -#ifdef __unix__ - - int kbhit(void); - int getch(void); - -#else /* DOS-Based */ - - #include <conio.h> - -#endif - -#endif /* _CONWRAP_H */ diff --git a/src/sbbs3/sbbsinet.h b/src/sbbs3/sbbsinet.h deleted file mode 100644 index 756594b522..0000000000 --- a/src/sbbs3/sbbsinet.h +++ /dev/null @@ -1,129 +0,0 @@ -/* sbbsinet.h */ - -/* Synchronet platform-specific Internet stuff */ - -/* $Id$ */ - -/**************************************************************************** - * @format.tab-size 4 (Plain Text/Source Code File Header) * - * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * - * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * See the GNU General Public License for more details: gpl.txt or * - * http://www.fsf.org/copyleft/gpl.html * - * * - * Anonymous FTP access to the most recent released source is available at * - * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * - * * - * Anonymous CVS access to the development source and modification history * - * is available at cvs.synchro.net:/cvsroot/sbbs, example: * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login * - * (just hit return, no password is necessary) * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src * - * * - * For Synchronet coding style and modification guidelines, see * - * http://www.synchro.net/source.html * - * * - * You are encouraged to submit any modifications (preferably in Unix diff * - * format) via e-mail to mods@synchro.net * - * * - * Note: If this box doesn't appear square, then you need to fix your tabs. * - ****************************************************************************/ - -#ifndef _SBBSINET_H -#define _SBBSINET_H - -/***************/ -/* OS-specific */ -/***************/ -#if defined _WIN32 || defined __OS2__ /* Use WinSock */ - -#include <winsock.h> /* socket/bind/etc. */ - -/* Let's agree on a standard WinSock symbol here, people */ -#ifndef _WINSOCKAPI_ -#define _WINSOCKAPI_ -#endif - -#elif defined __unix__ /* Unix-variant */ - -#include <netdb.h> /* gethostbyname */ -#ifdef __FreeBSD__ -#include <sys/types.h> /* For u_int32_t on FreeBSD */ -#endif -#include <netinet/in.h> /* IPPROTO_IP */ -#include <sys/socket.h> /* socket/bind/etc. */ -#include <sys/ioctl.h> /* FIONBIO */ -#include <sys/time.h> /* struct timeval */ -#include <arpa/inet.h> /* inet_ntoa */ -#include <unistd.h> /* close */ - -#endif - -#include <errno.h> /* errno */ - -/**********************************/ -/* Socket Implementation-specific */ -/**********************************/ -#ifdef _WINSOCKAPI_ - -#undef EINTR -#define EINTR (WSAEINTR-WSABASEERR) -#undef ENOTSOCK -#define ENOTSOCK (WSAENOTSOCK-WSABASEERR) -#undef EWOULDBLOCK -#define EWOULDBLOCK (WSAEWOULDBLOCK-WSABASEERR) -#undef ECONNRESET -#define ECONNRESET (WSAECONNRESET-WSABASEERR) -#undef ESHUTDOWN -#define ESHUTDOWN (WSAESHUTDOWN-WSABASEERR) -#undef ECONNABORTED -#define ECONNABORTED (WSAECONNABORTED-WSABASEERR) - -#define s_addr S_un.S_addr - -#define socklen_t int - -static wsa_error; -#define ERROR_VALUE ((wsa_error=WSAGetLastError())>0 ? wsa_error-WSABASEERR : wsa_error) -#define sendsocket(s,b,l) send(s,b,l,0) - -#else /* BSD sockets */ - -/* WinSock-isms */ -#define HOSTENT struct hostent -#define SOCKADDR_IN struct sockaddr_in -#define LINGER struct linger -#define SOCKET int -#define SOCKET_ERROR -1 -#define INVALID_SOCKET (SOCKET)(~0) -#define closesocket close -#define ioctlsocket ioctl -#define ERROR_VALUE errno -#define sendsocket write // FreeBSD send() is broken - -#endif /* __unix__ */ - -#ifndef SHUT_RDWR -#define SHUT_RDWR 2 /* for shutdown() */ -#endif - -#ifndef IPPORT_FTP -#define IPPORT_FTP 21 -#endif -#ifndef IPPORT_TELNET -#define IPPORT_TELNET 23 -#endif -#ifndef IPPORT_SMTP -#define IPPORT_SMTP 25 -#endif -#ifndef IPPORT_POP3 -#define IPPORT_POP3 110 -#endif - -#endif /* Don't add anything after this line */ diff --git a/src/sbbs3/sbbswrap.h b/src/sbbs3/sbbswrap.h deleted file mode 100644 index 543a44dd13..0000000000 --- a/src/sbbs3/sbbswrap.h +++ /dev/null @@ -1,289 +0,0 @@ -/* sbbswrap.h */ - -/* Synchronet system-call wrappers */ - -/* $Id$ */ - -/**************************************************************************** - * @format.tab-size 4 (Plain Text/Source Code File Header) * - * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * - * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * See the GNU General Public License for more details: gpl.txt or * - * http://www.fsf.org/copyleft/gpl.html * - * * - * Anonymous FTP access to the most recent released source is available at * - * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * - * * - * Anonymous CVS access to the development source and modification history * - * is available at cvs.synchro.net:/cvsroot/sbbs, example: * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login * - * (just hit return, no password is necessary) * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src * - * * - * For Synchronet coding style and modification guidelines, see * - * http://www.synchro.net/source.html * - * * - * You are encouraged to submit any modifications (preferably in Unix diff * - * format) via e-mail to mods@synchro.net * - * * - * Note: If this box doesn't appear square, then you need to fix your tabs. * - ****************************************************************************/ - -#ifndef _SBBSWRAP_H -#define _SBBSWRAP_H - -#include "gen_defs.h" /* ulong */ - -#ifdef DLLEXPORT -#undef DLLEXPORT -#endif -#ifdef DLLCALL -#undef DLLCALL -#endif - -#ifdef _WIN32 - #ifdef WRAPPER_DLL - #define DLLEXPORT __declspec(dllexport) - #else - #define DLLEXPORT __declspec(dllimport) - #endif - #ifdef __BORLANDC__ - #define DLLCALL __stdcall - #else - #define DLLCALL - #endif -#else /* !_WIN32 */ - #define DLLEXPORT - #define DLLCALL -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - -#ifdef _MSC_VER - #include "msdirent.h" -#else - #include <dirent.h> /* POSIX directory functions */ -#endif - -/***************/ -/* OS-specific */ -/***************/ - -#ifdef __unix__ - - #include <glob.h> /* POSIX.2 directory pattern matching function */ - #define ALLFILES "*" /* matches all files in a directory */ - -#else /* glob-compatible findfirst/findnext wrapper */ - - typedef struct - { - size_t gl_pathc; /* Count of paths matched so far */ - char **gl_pathv; /* List of matched pathnames. */ - size_t gl_offs; /* Slots to reserve in 'gl_pathv'. */ - } glob_t; - - /* Bits set in the FLAGS argument to `glob'. */ - #define GLOB_ERR (1 << 0) /* Return on read errors. */ - #define GLOB_MARK (1 << 1) /* Append a slash to each name. */ - #define GLOB_NOSORT (1 << 2) /* Don't sort the names. */ - #define GLOB_DOOFFS (1 << 3) /* Insert PGLOB->gl_offs NULLs. */ - #define GLOB_NOCHECK (1 << 4) /* If nothing matches, return the pattern. */ - #define GLOB_APPEND (1 << 5) /* Append to results of a previous call. */ - #define GLOB_NOESCAPE (1 << 6) /* Backslashes don't quote metacharacters. */ - #define GLOB_PERIOD (1 << 7) /* Leading `.' can be matched by metachars. */ - #define GLOB_MAGCHAR (1 << 8) /* Set in gl_flags if any metachars seen. */ - #define GLOB_ALTDIRFUNC (1 << 9) /* Use gl_opendir et al functions. */ - #define GLOB_BRACE (1 << 10) /* Expand "{a,b}" to "a" "b". */ - #define GLOB_NOMAGIC (1 << 11) /* If no magic chars, return the pattern. */ - #define GLOB_TILDE (1 << 12) /* Expand ~user and ~ to home directories. */ - #define GLOB_ONLYDIR (1 << 13) /* Match only directories. */ - #define GLOB_TILDE_CHECK (1 << 14) /* Like GLOB_TILDE but return an error - if the user name is not available. */ - /* Error returns from `glob'. */ - #define GLOB_NOSPACE 1 /* Ran out of memory. */ - #define GLOB_ABORTED 2 /* Read error. */ - #define GLOB_NOMATCH 3 /* No matches found. */ - #define GLOB_NOSYS 4 /* Not implemented. */ - - DLLEXPORT int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t*); - DLLEXPORT void DLLCALL globfree(glob_t*); - - #define ALLFILES "*.*" /* matches all files in a directory */ - -#endif - -#ifdef __unix__ - - #include <pthread.h> /* POSIX threads and mutexes */ - #include <semaphore.h> /* POSIX semaphores */ - ulong _beginthread(void( *start_address )( void * ) - ,unsigned stack_size, void *arglist); - -#elif defined(_WIN32) - - /* POSIX semaphores */ - typedef HANDLE sem_t; - #define sem_init(psem,ps,v) ResetEvent(*(psem)) - #define sem_wait(psem) WaitForSingleObject(*(psem),INFINITE) - #define sem_post(psem) SetEvent(*(psem)) - #define sem_destroy(psem) CloseHandle(*(psem)) - DLLEXPORT int DLLCALL sem_getvalue(sem_t*, int* val); - - /* POSIX mutexes */ - typedef HANDLE pthread_mutex_t; - #define PTHREAD_MUTEX_INITIALIZER CreateMutex(NULL,FALSE,NULL) - #define pthread_mutex_init(pmtx,v) *(pmtx)=CreateMutex(NULL,FALSE,NULL) - #define pthread_mutex_lock(pmtx) WaitForSingleObject(*(pmtx),INFINITE) - #define pthread_mutex_unlock(pmtx) ReleaseMutex(*(pmtx)) - #define pthread_mutex_destroy(pmtx) CloseHandle(*(pmtx)) - -#else - - #warning "Need semaphore wrappers." - -#endif - - -#if defined(_WIN32) - - #define sbbs_beep(freq,dur) Beep(freq,dur) - -#elif defined(__OS2__) - - #define sbbs_beep(freq,dur) DosBeep(freq,dur) - -#elif defined(__unix__) - - DLLEXPORT void DLLCALL sbbs_beep(int freq, int dur); - DLLEXPORT char* DLLCALL strrev(char* str); - -#else /* Unsupported OS */ - - #warning "Unsupported Target: Need some macros or function prototypes here." - -#endif - -/*********************/ -/* Compiler-specific */ -/*********************/ - -/* Compiler Description */ -#if defined(__BORLANDC__) - - #define COMPILER_DESC(str) sprintf(str,"BCC %X.%02X" \ - ,__BORLANDC__>>8,__BORLANDC__&0xff); - -#elif defined(_MSC_VER) - - #define COMPILER_DESC(str) sprintf(str,"MSC %u", _MSC_VER); - -/*** -#elif defined(__GNUC__) && defined(__GLIBC__) - - #define COMPILER_DESC(str) sprintf(str,"GCC %u.%02u (GLIBC %u.%u)" \ - ,__GNUC__,__GNUC_MINOR__,__GLIBC__,__GLIBC_MINOR__); -***/ - -#elif defined(__GNUC__) - - #define COMPILER_DESC(str) sprintf(str,"GCC %u.%02u" \ - ,__GNUC__,__GNUC_MINOR__); - -#else /* Unknown compiler */ - - #define COMPILER_DESC(str) strcpy(str,"UNKNOWN COMPILER"); - -#endif - -/**********/ -/* Macros */ -/**********/ - -/* POSIX readdir convenience macro */ -#ifndef DIRENT -#define DIRENT struct dirent -#endif - -#if defined(__unix__) -#define BACKSLASH '/' -#else /* MS-DOS based OS */ -#define BACKSLASH '\\' -#endif - -/* Target Platform Description */ -#if defined(_WIN64) - #define PLATFORM_DESC "Win64" -#elif defined(_WIN32) - #define PLATFORM_DESC "Win32" -#elif defined(__OS2__) - #define PLATFORM_DESC "OS/2" -#elif defined(__MSDOS__) - #define PLATFORM_DESC "DOS" -#elif defined(__linux__) - #define PLATFORM_DESC "Linux" -#elif defined(__FreeBSD__) - #define PLATFORM_DESC "FreeBSD" -#elif defined(BSD) - #define PLATFORM_DESC "BSD" -#elif defined(__unix__) - #define PLATFORM_DESC "Unix" -#else - #warning "Need to describe target platform" - #define PLATFORM_DESC "UNKNOWN" -#endif - -#if defined(_MSC_VER) || defined(__MINGW32__) - -#define CHMOD(s,m) _chmod(s,m) -#define PUTENV _putenv -#define GETCWD _getcwd -#define snprintf _snprintf - -#elif defined(__BORLANDC__) - -#define CHMOD(p,a) _rtl_chmod(p,1,a) /* _chmod obsolete in 4.x */ -#define PUTENV putenv -#define GETCWD getcwd - -#else /* ??? */ - -#define CHMOD(s,m) chmod(s,m) -#define PUTENV putenv -#define GETCWD getcwd - -#endif - -#if defined(__BORLANDC__) - #define sbbs_random(x) random(x) -#else - DLLEXPORT int DLLCALL sbbs_random(int n); -#endif - - -#if !defined(_MSC_VER) && !defined(__BORLANDC__) - DLLEXPORT char* DLLCALL ultoa(ulong, char*, int radix); -#endif - - -/* General file system wrappers for all platforms and compilers */ -DLLEXPORT time_t DLLCALL fdate(char *filename); -DLLEXPORT time_t DLLCALL filetime(int fd); -DLLEXPORT BOOL DLLCALL isdir(char *filename); -DLLEXPORT int DLLCALL getfattr(char* filename); -DLLEXPORT ulong DLLCALL getfreediskspace(char* path); - -#ifdef __cplusplus -} -#endif - -#endif /* Don't add anything after this line */ diff --git a/src/sbbs3/smbwrap.c b/src/sbbs3/smbwrap.c deleted file mode 100644 index 0180c989c7..0000000000 --- a/src/sbbs3/smbwrap.c +++ /dev/null @@ -1,303 +0,0 @@ -/* smbwrap.c */ - -/* Synchronet SMBLIB system-call wrappers */ - -/* $Id$ */ - -/**************************************************************************** - * @format.tab-size 4 (Plain Text/Source Code File Header) * - * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * - * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * See the GNU General Public License for more details: gpl.txt or * - * http://www.fsf.org/copyleft/gpl.html * - * * - * Anonymous FTP access to the most recent released source is available at * - * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * - * * - * Anonymous CVS access to the development source and modification history * - * is available at cvs.synchro.net:/cvsroot/sbbs, example: * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login * - * (just hit return, no password is necessary) * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src * - * * - * For Synchronet coding style and modification guidelines, see * - * http://www.synchro.net/source.html * - * * - * You are encouraged to submit any modifications (preferably in Unix diff * - * format) via e-mail to mods@synchro.net * - * * - * Note: If this box doesn't appear square, then you need to fix your tabs. * - ****************************************************************************/ - -/* OS-specific */ -#if defined(__unix__) - -#include <glob.h> /* glob() wildcard matching */ -#include <string.h> /* strlen() */ -#include <unistd.h> /* getpid() */ -#include <fcntl.h> /* fcntl() file/record locking */ - -#endif - -/* ANSI */ -#include <sys/types.h> /* _dev_t */ -#include <sys/stat.h> /* struct stat */ - -/* SMB-specific */ -#include "smblib.h" /* SMBCALL */ -#include "smbwrap.h" /* Verify prototypes */ - -/****************************************************************************/ -/* Convert ASCIIZ string to upper case */ -/****************************************************************************/ -#ifdef __unix__ -char* SMBCALL strupr(char* str) -{ - char* p=str; - - while(*p) { - *p=toupper(*p); - p++; - } - return(str); -} -/****************************************************************************/ -/* Convert ASCIIZ string to lower case */ -/****************************************************************************/ -char* SMBCALL strlwr(char* str) -{ - char* p=str; - - while(*p) { - *p=tolower(*p); - p++; - } - return(str); -} -#endif - -/****************************************************************************/ -/* Returns the length of the file in 'filename' */ -/****************************************************************************/ -long SMBCALL flength(char *filename) -{ -#ifdef __BORLANDC__ /* stat() doesn't work right */ - - long handle; - struct _finddata_t f; - - if(access(filename,0)==-1) - return(-1L); - - if((handle=_findfirst(filename,&f))==-1) - return(-1); - - _findclose(handle); - - return(f.size); - -#else - - struct stat st; - - if(access(filename,0)==-1) - return(-1L); - - if(stat(filename, &st)!=0) - return(-1L); - - return(st.st_size); - -#endif -} - -/****************************************************************************/ -/* Checks the file system for the existence of one or more files. */ -/* Returns TRUE if it exists, FALSE if it doesn't. */ -/* 'filespec' may contain wildcards! */ -/****************************************************************************/ -BOOL SMBCALL fexist(char *filespec) -{ -#ifdef _WIN32 - - long handle; - struct _finddata_t f; - - if(access(filespec,0)==-1 && !strchr(filespec,'*') && !strchr(filespec,'?')) - return(FALSE); - - if((handle=_findfirst(filespec,&f))==-1) - return(FALSE); - - _findclose(handle); - - if(f.attrib&_A_SUBDIR) - return(FALSE); - - return(TRUE); - -#elif defined(__unix__) /* portion by cmartin */ - - glob_t g; - int c; - int l; - - if(access(filespec,0)==-1 && !strchr(filespec,'*') && !strchr(filespec,'?')) - return(FALSE); - - // start the search - glob(filespec, GLOB_MARK | GLOB_NOSORT, NULL, &g); - - if (!g.gl_pathc) { - // no results - globfree(&g); - return FALSE; - } - - // make sure it's not a directory - c = g.gl_pathc; - while (c--) { - l = strlen(g.gl_pathv[c]); - if (l && g.gl_pathv[c][l-1] != '/') { - globfree(&g); - return TRUE; - } - } - - globfree(&g); - return FALSE; - -#else - -#warning "fexist() port needs to support wildcards!" - - return(FALSE); - -#endif -} - -#if defined(__unix__) - -/****************************************************************************/ -/* Returns the length of the file in 'fd' */ -/****************************************************************************/ -long SMBCALL filelength(int fd) -{ - struct stat st; - - if(fstat(fd, &st)!=0) - return(-1L); - - return(st.st_size); -} - -/* Sets a lock on a portion of a file */ -int SMBCALL lock(int fd, long pos, int len) -{ - int flags; - struct flock alock; - - if((flags=fcntl(fd,F_GETFL))<0) - return -1; - - if(flags==O_RDONLY) - alock.l_type = F_RDLCK; // set read lock to prevent writes - else - alock.l_type = F_WRLCK; // set write lock to prevent all access - alock.l_whence = L_SET; // SEEK_SET - alock.l_start = pos; - alock.l_len = len; - - return fcntl(fd, F_SETLK, &alock); -} - -/* Removes a lock from a file record */ -int SMBCALL unlock(int fd, long pos, int len) -{ - struct flock alock; - - alock.l_type = F_UNLCK; // remove the lock - alock.l_whence = L_SET; - alock.l_start = pos; - alock.l_len = len; - return fcntl(fd, F_SETLK, &alock); -} - -/* Opens a file in specified sharing (file-locking) mode */ -int SMBCALL sopen(char *fn, int access, int share) -{ - int fd; - struct flock alock; - - if ((fd = open(fn, access, S_IREAD|S_IWRITE)) < 0) - return -1; - - if (share == SH_DENYNO) - // no lock needed - return fd; - - alock.l_type = share; - alock.l_whence = L_SET; - alock.l_start = 0; - alock.l_len = 0; // lock to EOF - -#if 0 - /* The l_pid field is only used with F_GETLK to return the process - ID of the process holding a blocking lock. */ - alock.l_pid = getpid(); -#endif - - if (fcntl(fd, F_SETLK, &alock) < 0) { - close(fd); - return -1; - } - - return fd; -} - -#elif defined _MSC_VER || defined __MINGW32__ - -#include <io.h> /* tell */ -#include <stdio.h> /* SEEK_SET */ -#include <sys/locking.h> /* _locking */ - -/* Fix MinGW locking.h typo */ -#if defined LK_UNLOCK && !defined LK_UNLCK - #define LK_UNLCK LK_UNLOCK -#endif - -int SMBCALL lock(int file, long offset, int size) -{ - int i; - long pos; - - pos=tell(file); - if(offset!=pos) - lseek(file, offset, SEEK_SET); - i=_locking(file,LK_NBLCK,size); - if(offset!=pos) - lseek(file, pos, SEEK_SET); - return(i); -} - -int SMBCALL unlock(int file, long offset, int size) -{ - int i; - long pos; - - pos=tell(file); - if(offset!=pos) - lseek(file, offset, SEEK_SET); - i=_locking(file,LK_UNLCK,size); - if(offset!=pos) - lseek(file, pos, SEEK_SET); - return(i); -} - -#endif /* !Unix && (MSVC || MinGW) */ diff --git a/src/sbbs3/smbwrap.h b/src/sbbs3/smbwrap.h deleted file mode 100644 index d054de925b..0000000000 --- a/src/sbbs3/smbwrap.h +++ /dev/null @@ -1,143 +0,0 @@ -/* smbwrap.h */ - -/* Synchronet SMBLIB system-call wrappers */ - -/* $Id$ */ - -/**************************************************************************** - * @format.tab-size 4 (Plain Text/Source Code File Header) * - * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * - * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * See the GNU General Public License for more details: gpl.txt or * - * http://www.fsf.org/copyleft/gpl.html * - * * - * Anonymous FTP access to the most recent released source is available at * - * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * - * * - * Anonymous CVS access to the development source and modification history * - * is available at cvs.synchro.net:/cvsroot/sbbs, example: * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login * - * (just hit return, no password is necessary) * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src * - * * - * For Synchronet coding style and modification guidelines, see * - * http://www.synchro.net/source.html * - * * - * You are encouraged to submit any modifications (preferably in Unix diff * - * format) via e-mail to mods@synchro.net * - * * - * Note: If this box doesn't appear square, then you need to fix your tabs. * - ****************************************************************************/ - -#ifndef _SMBWRAP_H -#define _SMBWRAP_H - -/**********/ -/* Macros */ -/**********/ - -#if defined(_WIN32) - - #include <io.h> /* _sopen */ - #include <sys/stat.h> /* S_IREAD */ - #include <fcntl.h> /* O_BINARY */ - #include <windows.h> /* OF_SHARE_ */ - - #define sopen(f,o,s) _sopen(f,o,s,S_IREAD|S_IWRITE) - #define close(f) _close(f) - - #ifndef SH_DENYNO - #define SH_DENYNO OF_SHARE_DENY_NONE - #define SH_DENYWR OF_SHARE_DENY_WRITE - #define SH_DENYRW OF_SHARE_EXCLUSIVE - #endif - #ifndef O_DENYNONE - #define O_DENYNONE SH_DENYNO - #endif - -#elif defined(__unix__) - - #include <fcntl.h> - - #define O_TEXT 0 /* all files in binary mode on Unix */ - #define O_BINARY 0 /* all files in binary mode on Unix */ - #define O_DENYNONE (1<<31) /* req'd for Baja/nopen compatibility */ - - #define SH_DENYNO 2 // no locks - #define SH_DENYRW F_WRLCK // exclusive lock - #define SH_DENYWR F_RDLCK // shareable lock - - #if !defined(stricmp) - #define stricmp(x,y) strcasecmp(x,y) - #define strnicmp(x,y,z) strncasecmp(x,y,z) - #endif - #define chsize(fd,size) ftruncate(fd,size) - -#endif - -#if defined(_WIN32) - - #define mswait(x) Sleep(x) - -#elif defined(__OS2__) - - #define mswait(x) DosSleep(x) - -#elif defined(__unix__) - - #define mswait(x) usleep(x*1000) - #define _mkdir(dir) mkdir(dir,0777) - #define _rmdir(dir) rmdir(dir) - #define _fullpath(a,r,l) realpath(r,a) - #define tell(fd) lseek(fd,0,SEEK_CUR) - -#else /* Unsupported OS */ - - #warning "Unsupported Target: Need some macros or function prototypes here." - -#endif - -#include "smblib.h" /* SMBEXPORT/SMBCALL */ - -#ifndef BOOL -#define BOOL int -#endif -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif - -/**************/ -/* Prototypes */ -/**************/ - -#ifdef __cplusplus -extern "C" { -#endif - -#if !defined(__BORLANDC__) - SMBEXPORT int SMBCALL lock(int fd, long pos, int len); - SMBEXPORT int SMBCALL unlock(int fd, long pos, int len); -#endif - -#if defined(__unix__) - SMBEXPORT int SMBCALL sopen(char *fn, int access, int share); - SMBEXPORT long SMBCALL filelength(int fd); - SMBEXPORT char* SMBCALL strupr(char* str); - SMBEXPORT char* SMBCALL strlwr(char* str); -#endif - -SMBEXPORT BOOL SMBCALL fexist(char *filespec); -SMBEXPORT long SMBCALL flength(char *filename); - -#ifdef __cplusplus -} -#endif - -#endif /* Don't add anything after this line */ diff --git a/src/sbbs3/wrappers.c b/src/sbbs3/wrappers.c deleted file mode 100644 index 6ee8ddb65b..0000000000 --- a/src/sbbs3/wrappers.c +++ /dev/null @@ -1,445 +0,0 @@ -/* wrappers.c */ - -/* Synchronet system-call wrappers */ - -/* $Id$ */ - -/**************************************************************************** - * @format.tab-size 4 (Plain Text/Source Code File Header) * - * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * - * * - * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * - * * - * This program is free software; you can redistribute it and/or * - * modify it under the terms of the GNU General Public License * - * as published by the Free Software Foundation; either version 2 * - * of the License, or (at your option) any later version. * - * See the GNU General Public License for more details: gpl.txt or * - * http://www.fsf.org/copyleft/gpl.html * - * * - * Anonymous FTP access to the most recent released source is available at * - * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net * - * * - * Anonymous CVS access to the development source and modification history * - * is available at cvs.synchro.net:/cvsroot/sbbs, example: * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login * - * (just hit return, no password is necessary) * - * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src * - * * - * For Synchronet coding style and modification guidelines, see * - * http://www.synchro.net/source.html * - * * - * You are encouraged to submit any modifications (preferably in Unix diff * - * format) via e-mail to mods@synchro.net * - * * - * Note: If this box doesn't appear square, then you need to fix your tabs. * - ****************************************************************************/ - -#ifdef _WIN32 - -#include <windows.h> /* WINAPI, etc */ -#include <io.h> /* _findfirst */ - -#elif defined __unix__ - -#include <unistd.h> /* usleep */ -#include <fcntl.h> /* O_NOCCTY */ -#include <ctype.h> /* toupper */ - -/* FreeBSD uses kbio.h instead of kd.h */ -/* BSD also needs mount.h instead of vfs.h */ -/* param.h has needed definitions for the FreeBSD system */ -#ifndef __FreeBSD__ -#include <sys/kd.h> /* KIOCSOUND */ -#endif - -#ifdef __FreeBSD__ -#include <sys/param.h> -#include <sys/mount.h> -#include <sys/kbio.h> -#endif - -#include <sys/ioctl.h> /* ioctl */ - -#ifdef __GLIBC__ /* actually, BSD, but will work for now */ -#include <sys/vfs.h> /* statfs() */ -#endif - -#endif - -#include <sys/types.h> /* _dev_t */ -#include <sys/stat.h> /* struct stat */ - -#include <stdio.h> /* sprintf */ -#include <stdlib.h> /* rand */ -#include <errno.h> /* ENOENT definitions */ - -#include "sbbs.h" /* getfname */ - -/* Win32 (minimal) implementation of POSIX.2 glob() function */ -/* This code _may_ work on other DOS-based platforms (e.g. OS/2) */ - -#if !defined(__unix__) - -#ifdef __BORLANDC__ - #pragma argsused -#endif - -static int glob_compare( const void *arg1, const void *arg2 ) -{ - /* Compare all of both strings: */ - return stricmp( * ( char** ) arg1, * ( char** ) arg2 ); -} - -int DLLCALL glob(const char *pattern, int flags, void* unused, glob_t* glob) -{ - struct _finddata_t ff; - long ff_handle; - size_t found=0; - char path[MAX_PATH+1]; - char* p; - char** new_pathv; - - if(!(flags&GLOB_APPEND)) { - glob->gl_pathc=0; - glob->gl_pathv=NULL; - } - - ff_handle=_findfirst((char*)pattern,&ff); - while(ff_handle!=-1) { - if(!(flags&GLOB_ONLYDIR) || ff.attrib&_A_SUBDIR) { - if((new_pathv=realloc(glob->gl_pathv - ,(glob->gl_pathc+1)*sizeof(char*)))==NULL) { - globfree(glob); - return(GLOB_NOSPACE); - } - glob->gl_pathv=new_pathv; - - /* build the full pathname */ - strcpy(path,pattern); - p=getfname(path); - *p=0; - strcat(path,ff.name); - - if((glob->gl_pathv[glob->gl_pathc]=malloc(strlen(path)+2))==NULL) { - globfree(glob); - return(GLOB_NOSPACE); - } - strcpy(glob->gl_pathv[glob->gl_pathc],path); - if(flags&GLOB_MARK && ff.attrib&_A_SUBDIR) - strcat(glob->gl_pathv[glob->gl_pathc],"/"); - - glob->gl_pathc++; - found++; - } - if(_findnext(ff_handle, &ff)!=0) { - _findclose(ff_handle); - ff_handle=-1; - } - } - - if(found==0) - return(GLOB_NOMATCH); - - if(!(flags&GLOB_NOSORT)) { - qsort(glob->gl_pathv,found,sizeof(char*),glob_compare); - } - - return(0); /* success */ -} - -void DLLCALL globfree(glob_t* glob) -{ - size_t i; - - if(glob==NULL) - return; - - if(glob->gl_pathv!=NULL) { - for(i=0;i<glob->gl_pathc;i++) - if(glob->gl_pathv[i]!=NULL) - free(glob->gl_pathv[i]); - - free(glob->gl_pathv); - glob->gl_pathv=NULL; - } - glob->gl_pathc=0; -} - -#endif /* !defined(__unix__) */ - -/****************************************************************************/ -/* Returns the time/date of the file in 'filename' in time_t (unix) format */ -/****************************************************************************/ -time_t DLLCALL fdate(char *filename) -{ - struct stat st; - - if(access(filename,0)==-1) - return(-1); - - if(stat(filename, &st)!=0) - return(-1); - - return(st.st_mtime); -} - -/****************************************************************************/ -/* Returns the modification time of the file in 'fd' */ -/****************************************************************************/ -time_t DLLCALL filetime(int fd) -{ - struct stat st; - - if(fstat(fd, &st)!=0) - return(-1); - - return(st.st_mtime); -} - -/****************************************************************************/ -/* Returns TRUE if the filename specified is a directory */ -/****************************************************************************/ -BOOL DLLCALL isdir(char *filename) -{ - struct stat st; - - if(stat(filename, &st)!=0) - return(FALSE); - - return((st.st_mode&S_IFDIR) ? TRUE : FALSE); -} - -/****************************************************************************/ -/* Returns the attributes (mode) for specified 'filename' */ -/****************************************************************************/ -int DLLCALL getfattr(char* filename) -{ -#ifdef _WIN32 - long handle; - struct _finddata_t finddata; - - if((handle=_findfirst(filename,&finddata))==-1) { - errno=ENOENT; - return(-1); - } - _findclose(handle); - return(finddata.attrib); -#else - struct stat st; - - if(stat(filename, &st)!=0) { - errno=ENOENT; - return(-1L); - } - - return(st.st_mode); -#endif -} - -/****************************************************************************/ -/* Generate a tone at specified frequency for specified milliseconds */ -/* Thanks to Casey Martin for this code */ -/****************************************************************************/ -#ifdef __unix__ -void DLLCALL sbbs_beep(int freq, int dur) -{ - static int console_fd=-1; - - if(console_fd == -1) - console_fd = open("/dev/console", O_NOCTTY); - - if(console_fd != -1) { - ioctl(console_fd, KIOCSOUND, (int) (1193180 / freq)); - mswait(dur); - ioctl(console_fd, KIOCSOUND, 0); /* turn off tone */ - } -} -#endif - -/****************************************************************************/ -/* Return random number between 0 and n-1 */ -/****************************************************************************/ -#ifndef __BORLANDC__ -int DLLCALL sbbs_random(int n) -{ - float f; - - if(n<2) - return(0); - f=(float)rand()/(float)RAND_MAX; - - return((int)(n*f)); -} -#endif - -/****************************************************************************/ -/* Return ASCII string representation of ulong */ -/* There may be a native GNU C Library function to this... */ -/****************************************************************************/ -#if !defined _MSC_VER && !defined __BORLANDC__ -char* DLLCALL ultoa(ulong val, char* str, int radix) -{ - switch(radix) { - case 8: - sprintf(str,"%lo",val); - break; - case 10: - sprintf(str,"%lu",val); - break; - case 16: - sprintf(str,"%lx",val); - break; - default: - sprintf(str,"bad radix: %d",radix); - break; - } - return(str); -} -#endif - -/****************************************************************************/ -/* Reverse characters of a string (provided by amcleod) */ -/****************************************************************************/ -#ifdef __unix__ -char* strrev(char* str) -{ - char t, *i=str, *j=str+strlen(str); - - while (i<j) { - t=*i; *(i++)=*(--j); *j=t; - } - return str; -} -#endif - -/****************************************************************************/ -/* Wrapper for Win32 create/begin thread function */ -/* Uses POSIX threads */ -/****************************************************************************/ -#if defined(__unix__) && defined(SBBS) -#if defined(_POSIX_THREADS) -ulong _beginthread(void( *start_address )( void * ) - ,unsigned stack_size, void *arglist) -{ - pthread_t thread; - pthread_attr_t attr; - - pthread_attr_init(&attr); /* initialize attribute structure */ - - /* set thread attributes to PTHREAD_CREATE_DETACHED which will ensure - that thread resources are freed on exit() */ - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - if(pthread_create(&thread - ,&attr /* default attributes */ - /* POSIX defines this arg as "void *(*start_address)" */ - ,(void *) start_address - ,arglist)==0) - return((int) thread /* thread handle */); - - return(-1); /* error */ -} -#else - -#error "Need _beginthread implementation for non-POSIX thread library." - -#endif - -#endif /* __unix__ */ - -/****************************************************************************/ -/* Win32 implementation of POSIX sem_getvalue() function */ -/****************************************************************************/ -#ifdef _WIN32 -int DLLCALL sem_getvalue(sem_t* psem, int* val) -{ - if(psem==NULL || val==NULL) - return(-1); - - if(WaitForSingleObject(*(psem),0)==WAIT_OBJECT_0) - *val=1; - else - *val=0; - - return(0); -} -#endif - -#ifdef SBBS -/****************************************************************************/ -/* Return free disk space in bytes (up to a maximum of 4GB) */ -/****************************************************************************/ -#ifdef _WIN32 - typedef BOOL(WINAPI * GetDiskFreeSpaceEx_t) - (LPCTSTR,PULARGE_INTEGER,PULARGE_INTEGER,PULARGE_INTEGER); -#endif - -ulong DLLCALL getfreediskspace(char* path) -{ -#ifdef _WIN32 - char root[16]; - DWORD TotalNumberOfClusters; - DWORD NumberOfFreeClusters; - DWORD BytesPerSector; - DWORD SectorsPerCluster; - ULARGE_INTEGER avail; - ULARGE_INTEGER size; - GetDiskFreeSpaceEx_t GetDiskFreeSpaceEx; - - GetDiskFreeSpaceEx - = (GetDiskFreeSpaceEx_t)GetProcAddress(hK32,"GetDiskFreeSpaceExA"); - - if (GetDiskFreeSpaceEx!=NULL) { /* Windows 95-OSR2 or later */ - if(!GetDiskFreeSpaceEx( - path, // pointer to the directory name - &avail, // receives the number of bytes on disk avail to the caller - &size, // receives the number of bytes on disk - NULL)) // receives the free bytes on disk - return(0); -#ifdef _ANONYMOUS_STRUCT - if(avail.HighPart) -#else - if(avail.u.HighPart) -#endif - return(0xffffffff); /* 4GB max */ - -#ifdef _ANONYMOUS_STRUCT - return(avail.LowPart); -#else - return(avail.u.LowPart); -#endif - } - - /* Windows 95 (old way), limited to 2GB */ - sprintf(root,"%.3s",path); - if(!GetDiskFreeSpace( - root, // pointer to root path - &SectorsPerCluster, // pointer to sectors per cluster - &BytesPerSector, // pointer to bytes per sector - &NumberOfFreeClusters, // pointer to number of free clusters - &TotalNumberOfClusters // pointer to total number of clusters - )) - return(0); - - return(NumberOfFreeClusters*SectorsPerCluster*BytesPerSector); - - -/* statfs is also used under FreeBSD */ -#elif defined(__GLIBC__) || defined(__FreeBSD__) - - struct statfs fs; - - if (statfs(path, &fs) < 0) - return 0; - - return fs.f_bsize * fs.f_bavail; - -#else - - #warning OS-specific code needed here - return(0); - -#endif -} -#endif /* SBBS */ -- GitLab