⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 w16io.c

📁 Netscape NSPR库源码
💻 C
📖 第 1 页 / 共 2 页
字号:
*/PRInt32_PR_MD_STAT(const char *fn, struct stat *info){    PRInt32     rv;        rv = _stat(fn, (struct _stat *)info);    if ( rv == -1 )    {        _PR_MD_MAP_STAT_ERROR( errno );    }    PR_Sleep( _PR_MD_WIN16_DELAY );        return( rv );}/*** _PR_MD_GETFILEINFO() - Get file attributes by filename**** Returns:*****/PRInt32_PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info){    struct _stat sb;    PRInt32 rv;     if ( (rv = _stat(fn, &sb)) == 0 ) {        if (info) {            if (S_IFREG & sb.st_mode)                info->type = PR_FILE_FILE ;            else if (S_IFDIR & sb.st_mode)                info->type = PR_FILE_DIRECTORY;            else                info->type = PR_FILE_OTHER;            info->size = sb.st_size;            LL_I2L(info->modifyTime, sb.st_mtime);            LL_I2L(info->creationTime, sb.st_ctime);        }    }    else    {        _PR_MD_MAP_STAT_ERROR( errno );    }    PR_Sleep( _PR_MD_WIN16_DELAY );        return rv;}PRInt32_PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info){    PRFileInfo info32;        PRInt32 rv = _PR_MD_GETFILEINFO(fn, &info32);    if (0 == rv)    {        info->type = info32.type;        info->modifyTime = info32.modifyTime;        info->creationTime = info32.creationTime;        LL_I2L(info->size, info32.size);    }    return(rv);}/*** _PR_MD_GETOPENFILEINFO() - Get file attributes from an open file handle**** Returns:*****/PRInt32_PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info){    struct stat statBuf;    PRInt32 rv = PR_SUCCESS;        rv = fstat( fd->secret->md.osfd, &statBuf );    if ( rv == 0)    {        if (statBuf.st_mode & S_IFREG )            info->type = PR_FILE_FILE;        else if ( statBuf.st_mode & S_IFDIR )            info->type = PR_FILE_DIRECTORY;        else            info->type = PR_FILE_OTHER;        info->size = statBuf.st_size;        LL_I2L(info->modifyTime, statBuf.st_mtime);        LL_I2L(info->creationTime, statBuf.st_ctime);            }    else    {        _PR_MD_MAP_FSTAT_ERROR( errno );    }    PR_Sleep( _PR_MD_WIN16_DELAY );        return(rv);}PRInt32_PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info){    PRFileInfo info32;        PRInt32 rv = _PR_MD_GETOPENFILEINFO(fd, &info32);    if (0 == rv)    {        info->type = info32.type;        info->modifyTime = info32.modifyTime;        info->creationTime = info32.creationTime;        LL_I2L(info->size, info32.size);    }    return(rv);}/*** _PR_MD_RENAME() - Rename a file**** Returns:*****/PRInt32_PR_MD_RENAME(const char *from, const char *to){    PRInt32 rv;        rv = rename( from, to );    if ( rv == -1 )    {        _PR_MD_MAP_RENAME_ERROR( errno );    }    PR_Sleep( _PR_MD_WIN16_DELAY );        return( rv );}/*** _PR_MD_ACCESS() - Return file acesss attribute.**** Returns:*****/PRInt32_PR_MD_ACCESS(const char *name, PRIntn how){    PRInt32     rv;    int         mode = 0;        if ( how & PR_ACCESS_WRITE_OK )        mode |= W_OK;    if ( how & PR_ACCESS_READ_OK )        mode |= R_OK;            rv = (PRInt32) access( name, mode );            if ( rv == -1 )    {        _PR_MD_MAP_ACCESS_ERROR( errno );    }    PR_Sleep( _PR_MD_WIN16_DELAY );        return(rv);}/*** _PR_MD_MKDIR() - Make a directory**** Returns:*****/PRInt32_PR_MD_MKDIR(const char *name, PRIntn mode){    PRInt32 rv;            rv = mkdir( name );    if ( rv == 0 )    {        PR_Sleep( _PR_MD_WIN16_DELAY );            return PR_SUCCESS;    }    else    {        _PR_MD_MAP_MKDIR_ERROR( errno );        PR_Sleep( _PR_MD_WIN16_DELAY );            return PR_FAILURE;    }}/*** _PR_MD_RMDIR() - Delete a directory**** Returns:*****/PRInt32_PR_MD_RMDIR(const char *name){    PRInt32 rv;        rv = (PRInt32) rmdir( name );    if ( rv == -1 )    {        _PR_MD_MAP_RMDIR_ERROR( errno );    }    PR_Sleep( _PR_MD_WIN16_DELAY );        return(rv);}/*** _PR_MD_LOCKFILE() - Lock a file.**** The _locking() call locks relative to the current file pointer.** This function is required to lock all of the file, so,** 1. Seek to the beginning of the file, preserving the original position.** 2. Lock the file, pausing if it is locked by someone else, and**    try again.** 3. Re-position to the original position in the file.**** For unlocking, a similar protocol of positioning is required.***/PRStatus_PR_MD_LOCKFILE(PRInt32 f){    PRInt32 rv = PR_SUCCESS;    /* What we return to our caller */    long    seekOrigin;         /* original position in file */    PRInt32 rc;                 /* what the system call returns to us */    /*    ** Seek to beginning of file, saving original position.    */        seekOrigin = lseek( f, 0l, SEEK_SET );    if ( rc == -1 )    {        _PR_MD_MAP_LSEEK_ERROR( errno );        return( PR_FAILURE );    }        /*    ** Attempt to lock the file.    ** If someone else has it, Sleep-a-while and try again.    */    for( rc = -1; rc != 0; )    {        rc = _locking( f, _LK_NBLCK , 0x7fffffff );        if ( rc == -1 )        {            if ( errno == EACCES )            {                PR_Sleep( 100 );                continue;            }            else            {                _PR_MD_MAP_LOCKF_ERROR( errno );                rv = PR_FAILURE;                break;            }        }    } /* end for() */        /*    ** Now that the file is locked, re-position to    ** the original file position.    **    */    rc = lseek( f, seekOrigin, SEEK_SET );    if ( rc == -1 )    {        _PR_MD_MAP_LSEEK_ERROR( errno );        rv = PR_FAILURE;    }    PR_Sleep( _PR_MD_WIN16_DELAY );        return PR_SUCCESS;} /* end _PR_MD_LOCKFILE() *//*** _PR_MD_TLOCKFILE() - Test and Lock file.**** The _locking() call locks relative to the current file pointer.** This function is required to lock all of the file, so,** 1. Seek to the beginning of the file, preserving the original position.** 2. Attempt to Lock the file.**    If the file is locked by someone else, try NO MORE.** 3. Re-position to the original position in the file.**** See the discussion of _PR_MD_LOCKFILE*****/PRStatus_PR_MD_TLOCKFILE(PRInt32 f){    PRInt32 rv = PR_SUCCESS;    /* What we return */    long    seekOrigin;         /* original position in file */    PRInt32 rc;                 /* return value from system call */    /*    ** Seek to beginning of file, saving original position.    */        seekOrigin = lseek( f, 0l, SEEK_SET );    if ( rc == -1 )    {        _PR_MD_MAP_LSEEK_ERROR( errno );        return( PR_FAILURE );    }        /*    ** Attempt to lock the file. One ping; one ping only, Vasily.    ** If someone else has it, Reposition and return failure.    */    rc = _locking( f, _LK_NBLCK , 0x7fffffff );    if ( rc == -1 )    {        if ( errno != EACCES )            _PR_MD_MAP_LOCKF_ERROR( errno );        rv = PR_FAILURE;    }        /*    ** Now that the file is locked, maybe, re-position to    ** the original file position.    */    rc = lseek( f, seekOrigin, SEEK_SET );    if ( rc == -1 )    {        _PR_MD_MAP_LSEEK_ERROR( errno );        rv = PR_FAILURE;    }        PR_Sleep( _PR_MD_WIN16_DELAY );        return rv;} /* end _PR_MD_TLOCKFILE() *//*** _PR_MD_UNLOCKFILE() - Unlock a file.**** See the discussion of _PR_MD_LOCKFILE***/PRStatus_PR_MD_UNLOCKFILE(PRInt32 f){    PRInt32 rv = PR_SUCCESS;    /* What we return */    long    seekOrigin;         /* original position in file */    PRInt32 rc;                 /* return value from system call */    /*    ** Seek to beginning of file, saving original position.    */        seekOrigin = lseek( f, 0l, SEEK_SET );    if ( rc == -1 )    {        _PR_MD_MAP_LSEEK_ERROR( errno );        return( PR_FAILURE );    }        /*    ** Unlock the file.    */    rc = _locking( f, _LK_UNLCK , 0x7fffffff );    if ( rc == -1 )    {        _PR_MD_MAP_LOCKF_ERROR( errno );        rv = PR_FAILURE;    }        /*    ** Now that the file is unlocked, re-position to    ** the original file position.    */    rc = lseek( f, seekOrigin, SEEK_SET );    if ( rc == -1 )    {        _PR_MD_MAP_LSEEK_ERROR( errno );        rv = PR_FAILURE;    }    PR_Sleep( _PR_MD_WIN16_DELAY );        return rv;} /* end _PR_MD_UNLOCKFILE() *//*** PR_Stat() -- Return status on a file**** This is a hack! ... See BugSplat: 98516 ** Basically, this hack takes a name and stat buffer as input.** The input stat buffer is presumed to be a Microsoft stat buffer.** The functions does a Watcom stat() then maps the result to** the MS stat buffer. ...***/PR_IMPLEMENT(PRInt32) PR_Stat(const char *name, struct stat *buf){    PRInt32     rv;    _MDMSStat   *mssb = (_MDMSStat*) buf; /* this is Microsoft's stat buffer */    struct stat statBuf;   /* this is Watcom's stat buffer */    /* First, get Watcom's idea of stat    ** then reformat it into a Microsoft idea of stat    */    rv = (PRInt32) _stat( name, &statBuf);    if (rv == 0l )    {        mssb->st_dev = statBuf.st_dev;        mssb->st_ino = statBuf.st_ino; /* not used, really */        mssb->st_mode = statBuf.st_mode;        mssb->st_nlink = 1; /* always 1, says MS */        mssb->st_uid = statBuf.st_uid;        mssb->st_gid = statBuf.st_gid;        mssb->st_rdev = statBuf.st_rdev; /* please Gh0d! Let these be the same */        mssb->st_size = statBuf.st_size;        mssb->st_atime = statBuf.st_atime;        mssb->st_mtime = statBuf.st_mtime;        mssb->st_ctime = statBuf.st_ctime;    }    return rv;} /* end PR_Stat() *//* $$ end W16io.c */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -