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

📄 prfile.c

📁 Netscape NSPR库源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (!_pr_initialized) _PR_ImplicitInitialization();    /* Map pr open flags and mode to os specific flags */    osfd = _PR_MD_OPEN_FILE(name, flags, mode);    if (osfd != -1) {        fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);        if (!fd) {            (void) _PR_MD_CLOSE_FILE(osfd);        } else {#if !defined(XP_UNIX) /* BugZilla: 4090 */            fd->secret->appendMode = appendMode;#endif            _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);        }    }    return fd;}PRInt32 PR_GetSysfdTableMax(void){#if defined(XP_UNIX) && !defined(AIX) && !defined(NEXTSTEP) && !defined(QNX)    struct rlimit rlim;    if ( getrlimit(RLIMIT_NOFILE, &rlim) < 0) {       /* XXX need to call PR_SetError() */       return -1;    }    return rlim.rlim_max;#elif defined(AIX) || defined(NEXTSTEP) || defined(QNX)    return sysconf(_SC_OPEN_MAX);#elif defined(WIN32) || defined(OS2)    /*     * There is a systemwide limit of 65536 user handles.     * Not sure on OS/2, but sounds good.     */    return 16384;#elif defined (WIN16)    return FOPEN_MAX;#elif defined (XP_MAC) || defined(XP_BEOS)    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);   return -1;#else    write me;#endif}PRInt32 PR_SetSysfdTableSize(int table_size){#if defined(XP_UNIX) && !defined(AIX) && !defined(NEXTSTEP) && !defined(QNX)    struct rlimit rlim;    PRInt32 tableMax = PR_GetSysfdTableMax();    if (tableMax < 0)         return -1;    if (tableMax > FD_SETSIZE)        tableMax = FD_SETSIZE;    rlim.rlim_max = tableMax;    /* Grow as much as we can; even if too big */    if ( rlim.rlim_max < table_size )        rlim.rlim_cur = rlim.rlim_max;    else        rlim.rlim_cur = table_size;    if ( setrlimit(RLIMIT_NOFILE, &rlim) < 0) {        /* XXX need to call PR_SetError() */        return -1;    }    return rlim.rlim_cur;#elif defined(AIX) || defined(NEXTSTEP) || defined(QNX) \        || defined(WIN32) || defined(WIN16) || defined(OS2) \        || defined(XP_BEOS)    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);    return -1;#elif defined (XP_MAC)#pragma unused (table_size)    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);   return -1;#else    write me;#endif}PR_IMPLEMENT(PRStatus) PR_Delete(const char *name){	PRInt32 rv;	rv = _PR_MD_DELETE(name);	if (rv < 0) {		return PR_FAILURE;	} else		return PR_SUCCESS;}PR_IMPLEMENT(PRStatus) PR_GetFileInfo(const char *fn, PRFileInfo *info){	PRInt32 rv;	rv = _PR_MD_GETFILEINFO(fn, info);	if (rv < 0) {		return PR_FAILURE;	} else		return PR_SUCCESS;}PR_IMPLEMENT(PRStatus) PR_GetFileInfo64(const char *fn, PRFileInfo64 *info){#ifdef XP_MAC#pragma unused (fn, info)#endif    PRInt32 rv;    if (!_pr_initialized) _PR_ImplicitInitialization();    rv = _PR_MD_GETFILEINFO64(fn, info);    if (rv < 0) {        return PR_FAILURE;    } else {        return PR_SUCCESS;    }}PR_IMPLEMENT(PRStatus) PR_Rename(const char *from, const char *to){	PRInt32 rv;	rv = _PR_MD_RENAME(from, to);	if (rv < 0) {		return PR_FAILURE;	} else		return PR_SUCCESS;}PR_IMPLEMENT(PRStatus) PR_Access(const char *name, PRAccessHow how){PRInt32 rv;	rv = _PR_MD_ACCESS(name, how);	if (rv < 0) {		return PR_FAILURE;	} else		return PR_SUCCESS;}/*** Import an existing OS file to NSPR */PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PRInt32 osfd){    PRFileDesc *fd = NULL;    if (!_pr_initialized) _PR_ImplicitInitialization();    fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);    if( !fd ) {        (void) _PR_MD_CLOSE_FILE(osfd);    } else {        _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);    }    return fd;}/*** Import an existing OS pipe to NSPR */PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PRInt32 osfd){    PRFileDesc *fd = NULL;    if (!_pr_initialized) _PR_ImplicitInitialization();    fd = PR_AllocFileDesc(osfd, &_pr_pipeMethods);    if( !fd ) {        (void) _PR_MD_CLOSE_FILE(osfd);    } else {        _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);#ifdef WINNT        fd->secret->md.sync_file_io = PR_TRUE;#endif    }    return fd;}#ifndef NO_NSPR_10_SUPPORT/*** PR_Stat() for Win16 is defined in w16io.c** it is a hack to circumvent problems in Gromit and Java** See also: BugSplat: 98516.*/#if !defined(WIN16)/* * This function is supposed to be for backward compatibility with * nspr 1.0.  Therefore, it still uses the nspr 1.0 error-reporting * mechanism -- returns a PRInt32, which is the error code when the call * fails. *  * If we need this function in nspr 2.0, it should be changed to * return PRStatus, as follows: * * PR_IMPLEMENT(PRStatus) PR_Stat(const char *name, struct stat *buf) * { *     PRInt32 rv; * *     rv = _PR_MD_STAT(name, buf); *     if (rv < 0) *         return PR_FAILURE; *     else *         return PR_SUCCESS; * } * * -- wtc, 2/14/97. */PR_IMPLEMENT(PRInt32) PR_Stat(const char *name, struct stat *buf){    PRInt32 rv;    rv = _PR_MD_STAT(name, buf);	return rv;}#endif /* !defined(WIN16)  */#endif /* ! NO_NSPR_10_SUPPORT */PR_IMPLEMENT(PRStatus) PR_LockFile(PRFileDesc *fd){    PRStatus status = PR_SUCCESS;#ifdef WINNT    if (!fd->secret->md.io_model_committed) {        PRInt32 rv;        rv = _md_Associate((HANDLE)fd->secret->md.osfd);        PR_ASSERT(0 != rv);        fd->secret->md.io_model_committed = PR_TRUE;    }#endif    PR_Lock(_pr_flock_lock);    while (fd->secret->lockCount == -1)        PR_WaitCondVar(_pr_flock_cv, PR_INTERVAL_NO_TIMEOUT);    if (fd->secret->lockCount == 0) {        fd->secret->lockCount = -1;        PR_Unlock(_pr_flock_lock);        status = _PR_MD_LOCKFILE(fd->secret->md.osfd);        PR_Lock(_pr_flock_lock);        fd->secret->lockCount = (status == PR_SUCCESS) ? 1 : 0;        PR_NotifyAllCondVar(_pr_flock_cv);    } else {        fd->secret->lockCount++;    }    PR_Unlock(_pr_flock_lock);     return status;}PR_IMPLEMENT(PRStatus) PR_TLockFile(PRFileDesc *fd){    PRStatus status = PR_SUCCESS;#ifdef WINNT    if (!fd->secret->md.io_model_committed) {        PRInt32 rv;        rv = _md_Associate((HANDLE)fd->secret->md.osfd);        PR_ASSERT(0 != rv);        fd->secret->md.io_model_committed = PR_TRUE;    }#endif    PR_Lock(_pr_flock_lock);    if (fd->secret->lockCount == 0) {        status = _PR_MD_TLOCKFILE(fd->secret->md.osfd);        PR_ASSERT(status == PR_SUCCESS || fd->secret->lockCount == 0);        if (status == PR_SUCCESS)            fd->secret->lockCount = 1;    } else {        fd->secret->lockCount++;    }    PR_Unlock(_pr_flock_lock);    return status;}PR_IMPLEMENT(PRStatus) PR_UnlockFile(PRFileDesc *fd){    PRStatus rv = PR_SUCCESS;    PR_Lock(_pr_flock_lock);    if (fd->secret->lockCount == 1) {        rv = _PR_MD_UNLOCKFILE(fd->secret->md.osfd);        if (rv == PR_SUCCESS)             fd->secret->lockCount = 0;    } else {        fd->secret->lockCount--;    }    PR_Unlock(_pr_flock_lock);    return rv;}PR_IMPLEMENT(PRStatus) PR_CreatePipe(    PRFileDesc **readPipe,    PRFileDesc **writePipe){#if defined(XP_MAC)#pragma unused (readPipe, writePipe)#endif#ifdef WIN32    HANDLE readEnd, writeEnd;    SECURITY_ATTRIBUTES pipeAttributes;    if (!_pr_initialized) _PR_ImplicitInitialization();    ZeroMemory(&pipeAttributes, sizeof(pipeAttributes));    pipeAttributes.nLength = sizeof(pipeAttributes);    pipeAttributes.bInheritHandle = TRUE;    if (CreatePipe(&readEnd, &writeEnd, &pipeAttributes, 0) == 0) {        PR_SetError(PR_UNKNOWN_ERROR, GetLastError());        return PR_FAILURE;    }    *readPipe = PR_AllocFileDesc((PRInt32)readEnd, &_pr_pipeMethods);    if (NULL == *readPipe) {        CloseHandle(readEnd);        CloseHandle(writeEnd);        return PR_FAILURE;    }    *writePipe = PR_AllocFileDesc((PRInt32)writeEnd, &_pr_pipeMethods);    if (NULL == *writePipe) {        PR_Close(*readPipe);        CloseHandle(writeEnd);        return PR_FAILURE;    }#ifdef WINNT    (*readPipe)->secret->md.sync_file_io = PR_TRUE;    (*writePipe)->secret->md.sync_file_io = PR_TRUE;#endif    (*readPipe)->secret->inheritable = _PR_TRI_TRUE;    (*writePipe)->secret->inheritable = _PR_TRI_TRUE;    return PR_SUCCESS;#elif defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)#ifdef XP_OS2    HFILE pipefd[2];#else    int pipefd[2];#endif    if (!_pr_initialized) _PR_ImplicitInitialization();#ifdef XP_OS2    if (DosCreatePipe(&pipefd[0], &pipefd[1], 4096) != 0) {#else    if (pipe(pipefd) == -1) {#endif        /* XXX map pipe error */        PR_SetError(PR_UNKNOWN_ERROR, errno);        return PR_FAILURE;    }    *readPipe = PR_AllocFileDesc(pipefd[0], &_pr_pipeMethods);    if (NULL == *readPipe) {        close(pipefd[0]);        close(pipefd[1]);        return PR_FAILURE;    }    *writePipe = PR_AllocFileDesc(pipefd[1], &_pr_pipeMethods);    if (NULL == *writePipe) {        PR_Close(*readPipe);        close(pipefd[1]);        return PR_FAILURE;    }#ifndef XP_BEOS /* Pipes are nonblocking on BeOS */    _PR_MD_MAKE_NONBLOCK(*readPipe);#endif    _PR_MD_INIT_FD_INHERITABLE(*readPipe, PR_FALSE);#ifndef XP_BEOS /* Pipes are nonblocking on BeOS */    _PR_MD_MAKE_NONBLOCK(*writePipe);#endif    _PR_MD_INIT_FD_INHERITABLE(*writePipe, PR_FALSE);    return PR_SUCCESS;#else    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);    return PR_FAILURE;#endif}

⌨️ 快捷键说明

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