Annotation of sbbs/xpdev/dirwrap.h, revision 1.1.1.1

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