Annotation of sbbs/src/sbbs3/msdirent.c, revision 1.1

1.1     ! root        1: /* msdirent.c */
        !             2: 
        !             3: /* POSIX directory operations using Microsoft _findfirst/next functions. */
        !             4: 
        !             5: /* $Id: msdirent.c,v 1.2 2000/10/25 23:28:33 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: #include "msdirent.h"
        !            39: #include <errno.h>             /* ENOMEM & ENOENT definitions */
        !            40: #include <stdio.h>             /* sprintf prototype */
        !            41: 
        !            42: DIR* opendir(const char* dirname)
        !            43: {
        !            44:        DIR*    dir;
        !            45: 
        !            46:        if((dir=(DIR*)calloc(1,sizeof(DIR)))==NULL) {
        !            47:                errno=ENOMEM;
        !            48:                return(NULL);
        !            49:        }
        !            50:        sprintf(dir->filespec,"%.*s",sizeof(dir->filespec)-5,dirname);
        !            51:        if(*dir->filespec && dir->filespec[strlen(dir->filespec)-1]!='\\')
        !            52:                strcat(dir->filespec,"\\");
        !            53:        strcat(dir->filespec,"*.*");
        !            54:        dir->handle=_findfirst(dir->filespec,&dir->finddata);
        !            55:        if(dir->handle==-1) {
        !            56:                errno=ENOENT;
        !            57:                free(dir);
        !            58:                return(NULL);
        !            59:        }
        !            60:        return(dir);
        !            61: }
        !            62: struct dirent* readdir(DIR* dir)
        !            63: {
        !            64:        if(dir==NULL)
        !            65:                return(NULL);
        !            66:        if(dir->end==TRUE)
        !            67:                return(NULL);
        !            68:        if(dir->handle==-1)
        !            69:                return(NULL);
        !            70:        sprintf(dir->dirent.d_name,"%.*s",sizeof(struct dirent)-1,dir->finddata.name);
        !            71:        if(_findnext(dir->handle,&dir->finddata)!=0)
        !            72:                dir->end=TRUE;
        !            73:        return(&dir->dirent);
        !            74: }
        !            75: int closedir (DIR* dir)
        !            76: {
        !            77:        if(dir==NULL)
        !            78:                return(-1);
        !            79:        _findclose(dir->handle);
        !            80:        free(dir);
        !            81:        return(0);
        !            82: }
        !            83: void rewinddir(DIR* dir)
        !            84: {
        !            85:        if(dir==NULL)
        !            86:                return;
        !            87:        _findclose(dir->handle);
        !            88:        dir->end=FALSE;
        !            89:        dir->handle=_findfirst(dir->filespec,&dir->finddata);
        !            90: }

unix.superglobalmegacorp.com

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