Annotation of sbbs/src/xpdev/dirwrap.h, revision 1.1

1.1     ! root        1: /* dirwrap.h */
        !             2: 
        !             3: /* Directory system-call wrappers */
        !             4: 
        !             5: /* $Id: dirwrap.h,v 1.38 2006/08/23 23:48:45 deuce 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 2006 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            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 _DIRWRAP_H
        !            39: #define _DIRWRAP_H
        !            40: 
        !            41: #include <stdlib.h>            /* _fullpath() on Win32 */
        !            42: 
        !            43: #if defined(__unix__)
        !            44:        #include <sys/param.h>  /* PATH_MAX */
        !            45: #endif
        !            46: 
        !            47: #if defined(INCLUDE_PATHS_H)
        !            48:        #include <paths.h>              /* _PATHS_* macros */
        !            49: #endif
        !            50: 
        !            51: #include "gen_defs.h"  /* ulong */
        !            52: #include "wrapdll.h"   /* DLLEXPORT and DLLCALL */
        !            53: 
        !            54: #if defined(__cplusplus)
        !            55: extern "C" {
        !            56: #endif
        !            57: 
        !            58: /****************/
        !            59: /* RTL-specific */
        !            60: /****************/
        !            61: 
        !            62: #if defined(__unix__)
        !            63: 
        !            64:        #define ALLFILES "*"    /* matches all files in a directory */
        !            65:        #include <sys/types.h>
        !            66:        #include <sys/stat.h>
        !            67:        #include <glob.h>               /* POSIX.2 directory pattern matching function */
        !            68:        #define MKDIR(dir)              mkdir(dir,0777)
        !            69: 
        !            70:        #if defined(__CYGWIN__)
        !            71:                #define DLLEXPORT       /* CygWin's glob.h #undef's DLLEXPORT */
        !            72:        #endif
        !            73: 
        !            74: #else
        !            75: 
        !            76:        /* Values for the second argument to access.
        !            77:           These may be OR'd together.  */
        !            78:        #define R_OK    4               /* Test for read permission.  */
        !            79:        #define W_OK    2               /* Test for write permission.  */
        !            80:        #define X_OK    1               /* Test for execute permission.  */
        !            81:        #define F_OK    0               /* Test for existence.  */
        !            82: 
        !            83:        #include <direct.h>             /* mkdir() */
        !            84: 
        !            85:        #define ALLFILES "*.*"  /* matches all files in a directory */
        !            86:        #ifdef __WATCOMC__
        !            87:                #define MKDIR(dir)              mkdir(dir)
        !            88:        #else
        !            89:                #define MKDIR(dir)              _mkdir(dir)
        !            90:        #endif
        !            91: 
        !            92:        /* glob-compatible findfirst/findnext wrapper */
        !            93: 
        !            94:        typedef struct 
        !            95:        {
        !            96:                        size_t gl_pathc;                        /* Count of paths matched so far */
        !            97:                        char **gl_pathv;                        /* List of matched pathnames. */
        !            98:                        size_t gl_offs;                         /* Slots to reserve in 'gl_pathv'. */
        !            99:        } glob_t;
        !           100: 
        !           101:        /* Bits set in the FLAGS argument to `glob'.  */
        !           102:        #define GLOB_ERR        (1 << 0)        /* Return on read errors.  */
        !           103:        #define GLOB_MARK       (1 << 1)        /* Append a slash to each name.  */
        !           104:        #define GLOB_NOSORT     (1 << 2)        /* Don't sort the names.  */
        !           105:        #define GLOB_DOOFFS     (1 << 3)        /* Insert PGLOB->gl_offs NULLs.  */
        !           106:        #define GLOB_NOCHECK    (1 << 4)        /* If nothing matches, return the pattern.  */
        !           107:        #define GLOB_APPEND     (1 << 5)        /* Append to results of a previous call.  */
        !           108:        #define GLOB_NOESCAPE   (1 << 6)        /* Backslashes don't quote metacharacters.  */
        !           109:        #define GLOB_PERIOD     (1 << 7)        /* Leading `.' can be matched by metachars.  */
        !           110:        #define GLOB_MAGCHAR    (1 << 8)        /* Set in gl_flags if any metachars seen.  */
        !           111:        #define GLOB_ALTDIRFUNC (1 << 9)        /* Use gl_opendir et al functions.  */
        !           112:        #define GLOB_BRACE      (1 << 10)       /* Expand "{a,b}" to "a" "b".  */
        !           113:        #define GLOB_NOMAGIC    (1 << 11)       /* If no magic chars, return the pattern.  */
        !           114:        #define GLOB_TILDE      (1 << 12)       /* Expand ~user and ~ to home directories. */
        !           115:        #define GLOB_ONLYDIR    (1 << 13)       /* Match only directories.  */
        !           116:        #define GLOB_TILDE_CHECK (1 << 14)      /* Like GLOB_TILDE but return an error
        !           117:                                                                                  if the user name is not available.  */
        !           118:        /* Error returns from `glob'.  */
        !           119:        #define GLOB_NOSPACE    1       /* Ran out of memory.  */
        !           120:        #define GLOB_ABORTED    2       /* Read error.  */
        !           121:        #define GLOB_NOMATCH    3       /* No matches found.  */
        !           122:        #define GLOB_NOSYS      4       /* Not implemented.  */
        !           123: 
        !           124:        DLLEXPORT int   DLLCALL glob(const char *pattern, int flags, void* unused, glob_t*);
        !           125:        DLLEXPORT void  DLLCALL globfree(glob_t*);
        !           126: 
        !           127: #endif
        !           128: 
        !           129: #define FULLPATH(a,r,l)                _fullpath(a,r,l)
        !           130: 
        !           131: /*****************************/
        !           132: /* POSIX Directory Functions */
        !           133: /*****************************/
        !           134: #if defined(_MSC_VER) || defined(__DMC__)
        !           135:        #include <io.h>         /* _finddata_t */
        !           136: 
        !           137:        /* dirent structure returned by readdir().
        !           138:         */
        !           139:        struct dirent
        !           140:        {       
        !           141:                char        d_name[260];        /* filename */
        !           142:        };
        !           143: 
        !           144:        /* DIR type returned by opendir().  The members of this structure
        !           145:         * must not be accessed by application programs.
        !           146:         */
        !           147:        typedef struct
        !           148:        {
        !           149:                char                            filespec[260];
        !           150:                struct dirent           dirent;
        !           151:                long                            handle;
        !           152:                struct _finddata_t      finddata;
        !           153:                BOOL                            end;            /* End of directory flag */
        !           154:        } DIR;
        !           155: 
        !           156: 
        !           157:        /* Prototypes.
        !           158:         */
        !           159:        DIR            *        opendir  (const char *__dirname);
        !           160:        struct dirent  *        readdir  (DIR *__dir);
        !           161:        int                 closedir (DIR *__dir);
        !           162:        void                rewinddir(DIR *__dir);
        !           163: #elif !defined(__WATCOMC__)
        !           164:        #include <dirent.h>     /* POSIX directory functions */
        !           165: #endif
        !           166: 
        !           167: 
        !           168: /**********/
        !           169: /* Macros */
        !           170: /**********/
        !           171: 
        !           172: /* POSIX readdir convenience macro */
        !           173: #ifndef DIRENT
        !           174: #define DIRENT struct dirent   
        !           175: #endif
        !           176: 
        !           177: #if defined(__unix__)
        !           178:        #define PATH_DELIM                      '/'
        !           179:        #define IS_PATH_DELIM(x)        (x=='/')
        !           180: 
        !           181:        /* These may be pre-defined in paths.h (BSD) */
        !           182:        #ifndef _PATH_TMP
        !           183:        #define _PATH_TMP                       "/tmp/"
        !           184:        #endif
        !           185:        #ifndef _PATH_DEVNULL
        !           186:        #define _PATH_DEVNULL           "/dev/null"
        !           187:        #endif
        !           188: 
        !           189: #else /* MS-DOS based OS */
        !           190: 
        !           191:        #define PATH_DELIM                      '\\'
        !           192:        #define IS_PATH_DELIM(x)        ((x)=='/' || (x)=='\\')
        !           193:        #define _PATH_TMP                       getenv("TEMP")
        !           194:        #define _PATH_DEVNULL           "NUL"
        !           195: 
        !           196: #endif
        !           197: 
        !           198: #if !defined(MAX_PATH) /* maximum path length */
        !           199:        #if defined MAXPATHLEN
        !           200:                #define MAX_PATH MAXPATHLEN     /* clib.h */
        !           201:        #elif defined PATH_MAX
        !           202:                #define MAX_PATH PATH_MAX
        !           203:        #elif defined _MAX_PATH
        !           204:                #define MAX_PATH _MAX_PATH
        !           205:        #else
        !           206:                #define MAX_PATH 260            
        !           207:        #endif
        !           208: #endif
        !           209: 
        !           210: #if defined(_MSC_VER) || defined(__MINGW32__)
        !           211:        #define CHMOD(s,m)              _chmod(s,m)
        !           212: #elif defined(__BORLANDC__) && !defined(__unix__)
        !           213:        #define CHMOD(p,a)              _rtl_chmod(p,1,a)       /* _chmod obsolete in 4.x */
        !           214: #else  
        !           215:        #define CHMOD(s,m)              chmod(s,m)
        !           216: #endif
        !           217: 
        !           218: /* General file system wrappers for all platforms and compilers */
        !           219: DLLEXPORT BOOL         DLLCALL fexist(const char *filespec);
        !           220: DLLEXPORT BOOL         DLLCALL fexistcase(char *filespec);     /* fixes upr/lwr case fname */
        !           221: DLLEXPORT long         DLLCALL flength(const char *filename);
        !           222: DLLEXPORT time_t       DLLCALL fdate(const char *filename);
        !           223: DLLEXPORT int          DLLCALL setfdate(const char* filename, time_t t);
        !           224: DLLEXPORT BOOL         DLLCALL isdir(const char *filename);
        !           225: DLLEXPORT BOOL         DLLCALL isabspath(const char *filename);
        !           226: DLLEXPORT BOOL         DLLCALL isfullpath(const char* filename);
        !           227: DLLEXPORT char*                DLLCALL getfname(const char* path);
        !           228: DLLEXPORT char*                DLLCALL getfext(const char* path);
        !           229: DLLEXPORT int          DLLCALL getfattr(const char* filename);
        !           230: DLLEXPORT ulong                DLLCALL getdisksize(const char* path, ulong unit);
        !           231: DLLEXPORT ulong                DLLCALL getfreediskspace(const char* path, ulong unit);
        !           232: DLLEXPORT ulong                DLLCALL delfiles(char *inpath, char *spec);
        !           233: DLLEXPORT char*                DLLCALL backslash(char* path);
        !           234: DLLEXPORT BOOL                 DLLCALL wildmatch(const char *fname, const char *spec, BOOL path);
        !           235: DLLEXPORT BOOL                 DLLCALL wildmatchi(const char *fname, const char *spec, BOOL path);
        !           236: DLLEXPORT int          DLLCALL mkdirs(const char* path);
        !           237: 
        !           238: 
        !           239: #if defined(__unix__)
        !           240: DLLEXPORT void DLLCALL _splitpath(const char *path, char *drive, char *dir, 
        !           241:                                                                  char *fname, char *ext);
        !           242: DLLEXPORT char * DLLCALL _fullpath(char *target, const char *path, size_t size);
        !           243: DLLEXPORT int DLLCALL removecase(char *path);
        !           244: #else
        !           245:        #define removecase(x)   remove(x)
        !           246: #endif
        !           247: 
        !           248: #if defined(__cplusplus)
        !           249: }
        !           250: #endif
        !           251: 
        !           252: #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.