Annotation of sbbs/src/xpdev/filewrap.h, revision 1.1.1.2

1.1       root        1: /* filewrap.h */
                      2: 
                      3: /* File system-call wrappers */
                      4: 
1.1.1.2 ! root        5: /* $Id: filewrap.h,v 1.32 2011/07/13 11:24:14 rswindell Exp $ */
1.1       root        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:  *                                                                                                                                                     *
1.1.1.2 ! root       11:  * Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html         *
1.1       root       12:  *                                                                                                                                                     *
                     13:  * This library is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU Lesser 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 Lesser General Public License for more details: lgpl.txt or     *
                     18:  * http://www.fsf.org/copyleft/lesser.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 _FILEWRAP_H
                     39: #define _FILEWRAP_H
                     40: 
                     41: #include "wrapdll.h"   /* DLLEXPORT and DLLCALL */
1.1.1.2 ! root       42: #include "gen_defs.h"  /* int32_t, int64_t */
1.1       root       43: 
                     44: #include <sys/stat.h>  /* S_IREAD and S_IWRITE (for use with sopen) */
                     45: #include <stdio.h>
                     46: 
                     47: #if defined(__unix__)
                     48:        #include <unistd.h>     /* read, write, close, ftruncate, lseek, etc. */
                     49: #endif
                     50: 
                     51: #if defined(_WIN32) || defined(__BORLANDC__)
                     52:        #include <io.h>
                     53: #endif
                     54: 
                     55: #include <fcntl.h>             /* O_RDONLY, O_CREAT, etc. */
                     56: 
                     57: /**********/
                     58: /* Macros */
                     59: /**********/
                     60: 
                     61: #if defined(_WIN32)
                     62: 
                     63:        
                     64:        #include <windows.h>            /* OF_SHARE_ */
                     65:        #include <share.h>                      /* SH_DENY */
                     66: 
                     67:        #ifndef SH_DENYNO
                     68:        #define SH_DENYNO                       OF_SHARE_DENY_NONE
                     69:        #define SH_DENYWR                       OF_SHARE_DENY_WRITE
                     70:        #define SH_DENYRW                       OF_SHARE_EXCLUSIVE
                     71:        #endif
                     72: 
                     73:        #ifndef SH_COMPAT
                     74:        #define SH_COMPAT                       0
                     75:        #endif
                     76: 
1.1.1.2 ! root       77:        #if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS==64)
        !            78:                #define lseek                   _lseeki64
        !            79:                #define tell                    _telli64
        !            80:                #define filelength              _filelengthi64
        !            81:                #define stat                    _stati64
        !            82:                #define fstat                   _fstati64
        !            83:                #define fseeko                  _fseeki64
        !            84:                #define ftello                  _ftelli64
        !            85:        #else
        !            86:                #define fseeko                  fseek
        !            87:                #define ftello                  ftell
        !            88:        #endif
        !            89: 
1.1       root       90: #elif defined(__unix__)
                     91: 
                     92:        #ifdef __solaris__
                     93:                #define LOCK_NB 1
                     94:                #define LOCK_SH 2
                     95:                #define LOCK_EX 4
                     96:        #endif
                     97: 
                     98:        #ifdef __QNX__
                     99:                #include <share.h>
                    100:                #define L_SET   SEEK_SET
                    101:        #else
                    102:                #ifndef O_TEXT
                    103:                #define O_TEXT          0               /* all files in binary mode on Unix */
                    104:                #define O_BINARY        0               /* all files in binary mode on Unix */
                    105:                #endif
                    106:                #undef  O_DENYNONE
                    107:                #define O_DENYNONE  (1<<31)     /* req'd for Baja/nopen compatibility */
                    108: 
                    109:                #define SH_DENYNO       2          /* no locks */
                    110:                #ifdef F_SANEWRLCKNO
                    111:                        #define SH_DENYRW       F_SANEWRLCKNO      /* exclusive lock */
                    112:                #else
                    113:                        #define SH_DENYRW       F_WRLCK    /* exclusive lock */
                    114:                #endif
                    115:        
                    116:                #ifdef F_SANERDLCKNO
                    117:                        #define SH_DENYWR   F_SANERDLCKNO    /* shareable lock */
                    118:                #else
                    119:                        #define SH_DENYWR   F_RDLCK    /* shareable lock */
                    120:                #endif
                    121: 
                    122:                #ifndef SH_COMPAT
                    123:                        #define SH_COMPAT                       0
                    124:                #endif
                    125:        #endif
1.1.1.2 ! root      126: 
        !           127:        #ifndef DEFFILEMODE
        !           128:        #define DELFILEMODE                     (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
        !           129:        #endif
        !           130: 
1.1       root      131:        #define chsize(fd,size)         ftruncate(fd,size)
                    132:        #define tell(fd)                        lseek(fd,0,SEEK_CUR)
                    133:        #define eof(fd)                         (tell(fd)==filelength(fd))
                    134: 
                    135: #elif defined(__OS2__)
                    136: 
                    137:        #include <share.h>                      /* SH_DENY */
                    138: 
                    139: #endif
                    140: 
1.1.1.2 ! root      141: #ifndef DEFFILEMODE
        !           142: #define DEFFILEMODE                    (S_IREAD|S_IWRITE)
        !           143: #endif
        !           144: 
1.1       root      145: /* Standard file descriptors.  */
                    146: #ifndef STDIN_FILENO
                    147: #define STDIN_FILENO    0       /* Standard input */
                    148: #define STDOUT_FILENO   1       /* Standard output */
                    149: #define STDERR_FILENO   2       /* Standard error output */
                    150: #endif
                    151: 
                    152: #ifndef O_DENYNONE
                    153: #define O_DENYNONE             SH_DENYNO
                    154: #endif
                    155: 
                    156: /**************/
                    157: /* Prototypes */
                    158: /**************/
                    159: 
                    160: #if defined(__cplusplus)
                    161: extern "C" {
                    162: #endif
                    163: 
                    164: #if !defined(__BORLANDC__) && !defined(__WATCOMC__)
1.1.1.2 ! root      165:        DLLEXPORT int   DLLCALL lock(int fd, off_t pos, off_t len);
        !           166:        DLLEXPORT int   DLLCALL unlock(int fd, off_t pos, off_t len);
1.1       root      167: #endif
                    168: 
                    169: #if !defined(__BORLANDC__) && defined(__unix__)
1.1.1.2 ! root      170:        DLLEXPORT int           DLLCALL sopen(const char* fn, int sh_access, int share, ...);
        !           171:        DLLEXPORT off_t         DLLCALL filelength(int fd);
1.1       root      172: #endif
                    173: 
                    174: #if defined(__unix__)
                    175:        DLLEXPORT FILE * DLLCALL _fsopen(char *pszFilename, char *pszMode, int shmode);
                    176: #endif
                    177: 
1.1.1.2 ! root      178: #if defined(_MSC_VER) && (_MSC_VER < 1300)     /* missing prototypes */
        !           179:        DLLEXPORT int           DLLCALL _fseeki64(FILE*, int64_t, int origin);
        !           180:        DLLEXPORT int64_t       DLLCALL _ftelli64(FILE*);
        !           181: #endif
        !           182: 
1.1       root      183: DLLEXPORT time_t       DLLCALL filetime(int fd);
                    184: 
                    185: #if defined(__cplusplus)
                    186: }
                    187: #endif
                    188: 
                    189: #endif /* Don't add anything after this line */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.