Back to index

lightning-sunbird  0.9+nobinonly
Functions | Variables
prfile.c File Reference
#include "primpl.h"
#include <string.h>
#include <fcntl.h>

Go to the source code of this file.

Functions

static PRInt32 PR_CALLBACK FileRead (PRFileDesc *fd, void *buf, PRInt32 amount)
static PRInt32 PR_CALLBACK FileWrite (PRFileDesc *fd, const void *buf, PRInt32 amount)
static PROffset32 PR_CALLBACK FileSeek (PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence)
static PROffset64 PR_CALLBACK FileSeek64 (PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
static PRInt32 PR_CALLBACK FileAvailable (PRFileDesc *fd)
static PRInt64 PR_CALLBACK FileAvailable64 (PRFileDesc *fd)
static PRInt32 PR_CALLBACK PipeAvailable (PRFileDesc *fd)
static PRInt64 PR_CALLBACK PipeAvailable64 (PRFileDesc *fd)
static PRStatus PR_CALLBACK PipeSync (PRFileDesc *fd)
static PRStatus PR_CALLBACK FileGetInfo (PRFileDesc *fd, PRFileInfo *info)
static PRStatus PR_CALLBACK FileGetInfo64 (PRFileDesc *fd, PRFileInfo64 *info)
static PRStatus PR_CALLBACK FileSync (PRFileDesc *fd)
static PRStatus PR_CALLBACK FileClose (PRFileDesc *fd)
static PRInt16 PR_CALLBACK FilePoll (PRFileDesc *fd, PRInt16 in_flags, PRInt16 *out_flags)
 PR_IMPLEMENT (const PRIOMethods *)
 PR_IMPLEMENT (PRFileDesc *)
 PR_IMPLEMENT (PRInt32)
 PR_IMPLEMENT (PRStatus)

Variables

PRLock_pr_flock_lock
PRCondVar_pr_flock_cv
static PRIOMethods _pr_fileMethods
static PRIOMethods _pr_pipeMethods

Function Documentation

static PRInt32 PR_CALLBACK FileAvailable ( PRFileDesc fd) [static]

Definition at line 144 of file prfile.c.

{
    PRInt32 result, cur, end;

    cur = _PR_MD_LSEEK(fd, 0, PR_SEEK_CUR);

       if (cur >= 0)
       end = _PR_MD_LSEEK(fd, 0, PR_SEEK_END);

    if ((cur < 0) || (end < 0)) {
        return -1;
    }

    result = end - cur;
    _PR_MD_LSEEK(fd, cur, PR_SEEK_SET);

    return result;
}
static PRInt64 PR_CALLBACK FileAvailable64 ( PRFileDesc fd) [static]

Definition at line 163 of file prfile.c.

{
#ifdef XP_MAC
#pragma unused( fd )
#endif
    PRInt64 result, cur, end;
    PRInt64 minus_one;

    LL_I2L(minus_one, -1);
    cur = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_CUR);

    if (LL_GE_ZERO(cur))
       end = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_END);

    if (!LL_GE_ZERO(cur) || !LL_GE_ZERO(end)) return minus_one;

    LL_SUB(result, end, cur);
    (void)_PR_MD_LSEEK64(fd, cur, PR_SEEK_SET);

    return result;
}
static PRStatus PR_CALLBACK FileClose ( PRFileDesc fd) [static]

Definition at line 242 of file prfile.c.

{
    if (!fd || !fd->secret
            || (fd->secret->state != _PR_FILEDESC_OPEN
            && fd->secret->state != _PR_FILEDESC_CLOSED)) {
        PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
        return PR_FAILURE;
    }

    if (fd->secret->state == _PR_FILEDESC_OPEN) {
        if (_PR_MD_CLOSE_FILE(fd->secret->md.osfd) < 0) {
            return PR_FAILURE;
        }
        fd->secret->state = _PR_FILEDESC_CLOSED;
    }
    PR_FreeFileDesc(fd);
    return PR_SUCCESS;
}
static PRStatus PR_CALLBACK FileGetInfo ( PRFileDesc fd,
PRFileInfo info 
) [static]

Definition at line 208 of file prfile.c.

{
       PRInt32 rv;

    rv = _PR_MD_GETOPENFILEINFO(fd, info);
    if (rv < 0) {
       return PR_FAILURE;
    } else
       return PR_SUCCESS;
}
static PRStatus PR_CALLBACK FileGetInfo64 ( PRFileDesc fd,
PRFileInfo64 info 
) [static]

Definition at line 219 of file prfile.c.

{
#ifdef XP_MAC
#pragma unused( fd, info )
#endif
    /* $$$$ NOT YET IMPLEMENTED */
       PRInt32 rv;

    rv = _PR_MD_GETOPENFILEINFO64(fd, info);
    if (rv < 0) return PR_FAILURE;
    else return PR_SUCCESS;
}
static PRInt16 PR_CALLBACK FilePoll ( PRFileDesc fd,
PRInt16  in_flags,
PRInt16 out_flags 
) [static]

Definition at line 261 of file prfile.c.

{
#ifdef XP_MAC
#pragma unused( fd, in_flags )
#endif
    *out_flags = 0;
    return in_flags;
}  /* FilePoll */
static PRInt32 PR_CALLBACK FileRead ( PRFileDesc fd,
void buf,
PRInt32  amount 
) [static]

Definition at line 57 of file prfile.c.

{
    PRInt32 rv = 0;
    PRThread *me = _PR_MD_CURRENT_THREAD();

    if (_PR_PENDING_INTERRUPT(me)) {
              me->flags &= ~_PR_INTERRUPT;
              PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
              rv = -1;
    }
    if (_PR_IO_PENDING(me)) {
        PR_SetError(PR_IO_PENDING_ERROR, 0);
       rv = -1;
    }
    if (rv == -1)
       return rv;

       rv = _PR_MD_READ(fd, buf, amount);
       if (rv < 0) {
              PR_ASSERT(rv == -1);
       }
    PR_LOG(_pr_io_lm, PR_LOG_MAX, ("read -> %d", rv));
    return rv;
}
static PROffset32 PR_CALLBACK FileSeek ( PRFileDesc fd,
PROffset32  offset,
PRSeekWhence  whence 
) [static]

Definition at line 125 of file prfile.c.

{
    PROffset32 result;

    result = _PR_MD_LSEEK(fd, offset, whence);
    return result;
}
static PROffset64 PR_CALLBACK FileSeek64 ( PRFileDesc fd,
PROffset64  offset,
PRSeekWhence  whence 
) [static]

Definition at line 133 of file prfile.c.

{
#ifdef XP_MAC
#pragma unused( fd, offset, whence )
#endif
    PROffset64 result;

    result = _PR_MD_LSEEK64(fd, offset, whence);
    return result;
}
static PRStatus PR_CALLBACK FileSync ( PRFileDesc fd) [static]

Definition at line 232 of file prfile.c.

{
    PRInt32 result;
    result = _PR_MD_FSYNC(fd);
    if (result < 0) {
              return PR_FAILURE;
    }
    return PR_SUCCESS;
}
static PRInt32 PR_CALLBACK FileWrite ( PRFileDesc fd,
const void buf,
PRInt32  amount 
) [static]

Definition at line 82 of file prfile.c.

{
    PRInt32 rv = 0;
    PRInt32 temp, count;
    PRThread *me = _PR_MD_CURRENT_THREAD();

    if (_PR_PENDING_INTERRUPT(me)) {
        me->flags &= ~_PR_INTERRUPT;
        PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
           rv = -1;
    }
    if (_PR_IO_PENDING(me)) {
        PR_SetError(PR_IO_PENDING_ERROR, 0);
           rv = -1;
    }
    if (rv != 0)
       return rv;

    count = 0;
#if !defined(_PR_HAVE_O_APPEND)  /* Bugzilla: 4090, 276330 */
    if (fd->secret->appendMode) {
        if (PR_Seek64(fd, 0, PR_SEEK_END) == -1) {
            return -1;
        }
    } /* if (fd->secret->appendMode...) */
#endif /* _PR_HAVE_O_APPEND */
    while (amount > 0) {
              temp = _PR_MD_WRITE(fd, buf, amount);
              if (temp < 0) {
                     count = -1;
                     break;
              }
              count += temp;
              if (fd->secret->nonblocking) {
                     break;
              }
              buf = (const void*) ((const char*)buf + temp);
              amount -= temp;
    }
    PR_LOG(_pr_io_lm, PR_LOG_MAX, ("write -> %d", count));
    return count;
}
static PRInt32 PR_CALLBACK PipeAvailable ( PRFileDesc fd) [static]

Definition at line 185 of file prfile.c.

{
       PRInt32 rv;
       rv =  _PR_MD_PIPEAVAILABLE(fd);
       return rv;           
}
static PRInt64 PR_CALLBACK PipeAvailable64 ( PRFileDesc fd) [static]

Definition at line 192 of file prfile.c.

{
    PRInt64 rv;
    LL_I2L(rv, _PR_MD_PIPEAVAILABLE(fd));
       return rv;           
}
static PRStatus PR_CALLBACK PipeSync ( PRFileDesc fd) [static]

Definition at line 199 of file prfile.c.

{
#if defined(XP_MAC)
#pragma unused (fd)
#endif

       return PR_SUCCESS;
}

Definition at line 310 of file prfile.c.

{
    return &_pr_fileMethods;
}

Definition at line 359 of file prfile.c.

{
    PRInt32 osfd;
    PRFileDesc *fd = 0;
#if !defined(_PR_HAVE_O_APPEND)
    PRBool  appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
#endif

    if (!_pr_initialized) _PR_ImplicitInitialization();

    /* Map pr open flags and mode to os specific flags */

    osfd = _PR_MD_OPEN(name, flags, mode);
    if (osfd != -1) {
        fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
        if (!fd) {
            (void) _PR_MD_CLOSE_FILE(osfd);
        } else {
#if !defined(_PR_HAVE_O_APPEND)
            fd->secret->appendMode = appendMode;
#endif
            _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
        }
    }
    return fd;
}

Here is the call graph for this function:

Definition at line 414 of file prfile.c.

{
#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)
    /*
     * There is a systemwide limit of 65536 user handles.
     */
    return 16384;
#elif defined (WIN16)
    return FOPEN_MAX;
#elif defined(XP_OS2)
    ULONG ulReqCount = 0;
    ULONG ulCurMaxFH = 0;
    DosSetRelMaxFH(&ulReqCount, &ulCurMaxFH);
    return ulCurMaxFH;
#elif defined (XP_MAC) || defined(XP_BEOS)
    PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
   return -1;
#else
    write me;
#endif
}

Definition at line 497 of file prfile.c.

{
       PRInt32 rv;

       rv = _PR_MD_DELETE(name);
       if (rv < 0) {
              return PR_FAILURE;
       } else
              return PR_SUCCESS;
}

Variable Documentation

Definition at line 271 of file prfile.c.

Definition at line 46 of file prio.c.

Definition at line 45 of file prio.c.

Definition at line 315 of file prfile.c.