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

📄 os2io.c

📁 Netscape NSPR库源码
💻 C
📖 第 1 页 / 共 2 页
字号:
_PR_MD_OPEN_DIR(_MDDir *d, const char *name){    char filename[ CCHMAXPATH ];    PRUword numEntries, rc;    numEntries = 1;    PR_snprintf(filename, CCHMAXPATH, "%s%s%s",                name, PR_DIRECTORY_SEPARATOR_STR, "*.*");    FlipSlashes( filename, strlen(filename) );    d->d_hdl = HDIR_CREATE;    rc = DosFindFirst( filename,                       &d->d_hdl,                       FILE_DIRECTORY | FILE_HIDDEN,                       &(d->d_entry),                       sizeof(d->d_entry),                       &numEntries,                       FIL_STANDARD);    if ( rc != NO_ERROR ) {		_PR_MD_MAP_OPENDIR_ERROR(rc);        return PR_FAILURE;    }    d->firstEntry = PR_TRUE;    d->magic = _MD_MAGIC_DIR;    return PR_SUCCESS;}char *_PR_MD_READ_DIR(_MDDir *d, PRIntn flags){    PRUword numFiles = 1;    BOOL rv;    char *fileName;    USHORT fileAttr;    if ( d ) {       while (1) {           if (d->firstEntry) {               d->firstEntry = PR_FALSE;               rv = NO_ERROR;           } else {               rv = DosFindNext(d->d_hdl,                                &(d->d_entry),                                sizeof(d->d_entry),                                &numFiles);           }           if (rv != NO_ERROR) {               break;           }           fileName = GetFileFromDIR(d);           fileAttr = GetFileAttr(d);           if ( (flags & PR_SKIP_DOT) &&                (fileName[0] == '.') && (fileName[1] == '\0'))                continue;           if ( (flags & PR_SKIP_DOT_DOT) &&                (fileName[0] == '.') && (fileName[1] == '.') &&                (fileName[2] == '\0'))                continue;			/*			 * XXX			 * Is this the correct definition of a hidden file on OS/2?			 */           if ((flags & PR_SKIP_NONE) && (fileAttr & FILE_HIDDEN))                return fileName;           else if ((flags & PR_SKIP_HIDDEN) && (fileAttr & FILE_HIDDEN))                continue;           return fileName;        }        PR_ASSERT(NO_ERROR != rv);			_PR_MD_MAP_READDIR_ERROR(rv);        return NULL;		}    PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);    return NULL;}PRInt32_PR_MD_DELETE(const char *name){    PRInt32 rc = DosDelete((char*)name);    if(rc == NO_ERROR) {        return 0;    } else {		_PR_MD_MAP_DELETE_ERROR(rc);        return -1;    }}PRInt32_PR_MD_STAT(const char *fn, struct stat *info){    PRInt32 rv;    char filename[CCHMAXPATH];    PR_snprintf(filename, CCHMAXPATH, "%s", fn);    FlipSlashes(filename, strlen(filename));    rv = _stat((char*)filename, info);    if (-1 == rv) {        /*         * Check for MSVC runtime library _stat() bug.         * (It's really a bug in FindFirstFile().)         * If a pathname ends in a backslash or slash,         * e.g., c:\temp\ or c:/temp/, _stat() will fail.         * Note: a pathname ending in a slash (e.g., c:/temp/)         * can be handled by _stat() on NT but not on Win95.         *         * We remove the backslash or slash at the end and         * try again.           *         * Not sure if this happens on OS/2 or not,         * but it doesn't hurt to be careful.         */        int len = strlen(fn);        if (len > 0 && len <= _MAX_PATH                && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {            char newfn[_MAX_PATH + 1];            strcpy(newfn, fn);            newfn[len - 1] = '\0';            rv = _stat(newfn, info);        }    }    if (-1 == rv) {        _PR_MD_MAP_STAT_ERROR(errno);    }    return rv;}PRInt32_PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info){    struct stat sb;    PRInt32 rv;    PRInt64 s, s2us;     if ( (rv = _PR_MD_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(s2us, PR_USEC_PER_SEC);            LL_I2L(s, sb.st_mtime);            LL_MUL(s, s, s2us);            info->modifyTime = s;            LL_I2L(s, sb.st_ctime);            LL_MUL(s, s, s2us);            info->creationTime = s;        }    }    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;        LL_UI2L(info->size,info32.size);        info->modifyTime = info32.modifyTime;        info->creationTime = info32.creationTime;    }    return rv;}PRInt32_PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info){   /* For once, the VAC compiler/library did a nice thing.    * The file handle used by the C runtime is the same one    * returned by the OS when you call DosOpen().  This means    * that you can take an OS HFILE and use it with C file    * functions.  The only caveat is that you have to call    * _setmode() first to initialize some junk.  This is    * immensely useful because I did not have a clue how to    * implement this function otherwise.  The windows folks    * took the source from the Microsoft C library source, but    * IBM wasn't kind enough to ship the source with VAC.    * On second thought, the needed function could probably    * be gotten from the OS/2 GNU library source, but the    * point is now moot.    */   struct stat hinfo;    PRInt64 s, s2us;    _setmode(fd->secret->md.osfd, O_BINARY);    if(fstat((int)fd->secret->md.osfd, &hinfo) != NO_ERROR) {		_PR_MD_MAP_FSTAT_ERROR(errno);        return -1;	}    if (hinfo.st_mode & S_IFDIR)        info->type = PR_FILE_DIRECTORY;    else        info->type = PR_FILE_FILE;    info->size = hinfo.st_size;    LL_I2L(s2us, PR_USEC_PER_SEC);    LL_I2L(s, hinfo.st_mtime);    LL_MUL(s, s, s2us);    info->modifyTime = s;    LL_I2L(s, hinfo.st_ctime);    LL_MUL(s, s, s2us);    info->creationTime = s;    return 0;}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;       LL_UI2L(info->size,info32.size);       info->modifyTime = info32.modifyTime;       info->creationTime = info32.creationTime;   }   return rv;}PRInt32_PR_MD_RENAME(const char *from, const char *to){   PRInt32 rc;    /* Does this work with dot-relative pathnames? */    if ( (rc = DosMove((char *)from, (char *)to)) == NO_ERROR) {        return 0;    } else {		_PR_MD_MAP_RENAME_ERROR(rc);        return -1;    }}PRInt32_PR_MD_ACCESS(const char *name, PRAccessHow how){  PRInt32 rv;    switch (how) {      case PR_ACCESS_WRITE_OK:        rv = access(name, 02);		break;      case PR_ACCESS_READ_OK:        rv = access(name, 04);		break;      case PR_ACCESS_EXISTS:        return access(name, 00);	  	break;      default:		PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);		return -1;    }	if (rv < 0)		_PR_MD_MAP_ACCESS_ERROR(errno);    return rv;}PRInt32_PR_MD_MKDIR(const char *name, PRIntn mode){   PRInt32 rc;    /* XXXMB - how to translate the "mode"??? */    if ((rc = DosCreateDir((char *)name, NULL))== NO_ERROR) {        return 0;    } else {		_PR_MD_MAP_MKDIR_ERROR(rc);        return -1;    }}PRInt32_PR_MD_RMDIR(const char *name){   PRInt32 rc;    if ( (rc = DosDeleteDir((char *)name)) == NO_ERROR) {        return 0;    } else {		_PR_MD_MAP_RMDIR_ERROR(rc);        return -1;    }}PRStatus_PR_MD_LOCKFILE(PRInt32 f){	PRInt32   rv;   FILELOCK lock, unlock;   lock.lOffset = 0;   lock.lRange = 0xffffffff;   unlock.lOffset = 0;   unlock.lRange = 0;	/*     * loop trying to DosSetFileLocks(),     * pause for a few miliseconds when can't get the lock     * and try again     */    for( rv = FALSE; rv == FALSE; /* do nothing */ )    {    	    rv = DosSetFileLocks( (HFILE) f,			                    &unlock, &lock,			                    0, 0); 		if ( rv != NO_ERROR )        {            DosSleep( 50 );  /* Sleep() a few milisecs and try again. */        }                } /* end for() */    return PR_SUCCESS;} /* end _PR_MD_LOCKFILE() */PRStatus_PR_MD_TLOCKFILE(PRInt32 f){    return _PR_MD_LOCKFILE(f);} /* end _PR_MD_TLOCKFILE() */PRStatus_PR_MD_UNLOCKFILE(PRInt32 f){	PRInt32   rv;   FILELOCK lock, unlock;   lock.lOffset = 0;   lock.lRange = 0;   unlock.lOffset = 0;   unlock.lRange = 0xffffffff;       rv = DosSetFileLocks( (HFILE) f,                          &unlock, &lock,                          0, 0);                 if ( rv != NO_ERROR )    {    	return PR_SUCCESS;    }    else    {		return PR_FAILURE;    }} /* end _PR_MD_UNLOCKFILE() */PRStatus_PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable){    int rv = 0;    ULONG flags;    rv = DosQueryFHState((HFILE)fd->secret->md.osfd, &flags);    if (rv != 0) {        PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO());        return PR_FAILURE;    }    if (inheritable)      flags &= ~OPEN_FLAGS_NOINHERIT;    else      flags |= OPEN_FLAGS_NOINHERIT;    rv = DosSetFHState((HFILE)fd->secret->md.osfd, flags);    if (rv != 0) {        PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO());        return PR_FAILURE;    }    return PR_SUCCESS;}void_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported){    /* XXX this function needs to be implemented */    fd->secret->inheritable = _PR_TRI_UNKNOWN;}void_PR_MD_QUERY_FD_INHERITABLE(PRFileDesc *fd){    /* XXX this function needs to be reviewed */    ULONG flags;    PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);    if (DosQueryFHState((HFILE)fd->secret->md.osfd, &flags) == 0) {        if (flags & OPEN_FLAGS_NOINHERIT) {            fd->secret->inheritable = _PR_TRI_FALSE;        } else {            fd->secret->inheritable = _PR_TRI_TRUE;        }    }}

⌨️ 快捷键说明

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