Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
w16io.c File Reference
#include "primpl.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <share.h>
#include <sys/locking.h>

Go to the source code of this file.

Defines

#define _PR_MD_WIN16_DELAY   1
#define GetFileFromDIR(d)   (d)->d_entry.cFileName

Functions

PRStatus PR_MD_RegisterW16StdioCallbacks (PRStdinRead inReadf, PRStdoutWrite outWritef, PRStderrWrite errWritef)
PRInt32 _PR_MD_OPEN (const char *name, PRIntn osflags, int mode)
PRInt32 _PR_MD_READ (PRFileDesc *fd, void *buf, PRInt32 len)
PRInt32 _PR_MD_WRITE (PRFileDesc *fd, const void *buf, PRInt32 len)
PRInt32 _PR_MD_LSEEK (PRFileDesc *fd, PRInt32 offset, int whence)
PRInt64 _PR_MD_LSEEK64 (PRFileDesc *fd, PRInt64 offset, int whence)
PRInt32 _PR_MD_FSYNC (PRFileDesc *fd)
PRInt32 _PR_MD_CLOSE_FILE (PRInt32 osfd)
void FlipSlashes (char *cp, int len)
PRStatus _PR_MD_OPEN_DIR (_MDDir *d, const char *name)
char * _PR_MD_READ_DIR (_MDDir *d, PRIntn flags)
PRInt32 _PR_MD_CLOSE_DIR (_MDDir *d)
PRInt32 _PR_MD_DELETE (const char *name)
PRInt32 _PR_MD_STAT (const char *fn, struct stat *info)
PRInt32 _PR_MD_GETFILEINFO (const char *fn, PRFileInfo *info)
PRInt32 _PR_MD_GETFILEINFO64 (const char *fn, PRFileInfo64 *info)
PRInt32 _PR_MD_GETOPENFILEINFO (const PRFileDesc *fd, PRFileInfo *info)
PRInt32 _PR_MD_GETOPENFILEINFO64 (const PRFileDesc *fd, PRFileInfo64 *info)
PRInt32 _PR_MD_RENAME (const char *from, const char *to)
PRInt32 _PR_MD_ACCESS (const char *name, PRIntn how)
PRInt32 _PR_MD_MKDIR (const char *name, PRIntn mode)
PRInt32 _PR_MD_RMDIR (const char *name)
PRStatus _PR_MD_LOCKFILE (PRInt32 f)
PRStatus _PR_MD_TLOCKFILE (PRInt32 f)
PRStatus _PR_MD_UNLOCKFILE (PRInt32 f)
 PR_IMPLEMENT (PRInt32)

Variables

PRStdinRead _pr_md_read_stdin = 0
PRStdoutWrite _pr_md_write_stdout = 0
PRStderrWrite _pr_md_write_stderr = 0

Define Documentation

Definition at line 49 of file w16io.c.

#define GetFileFromDIR (   d)    (d)->d_entry.cFileName

Definition at line 307 of file w16io.c.


Function Documentation

PRInt32 _PR_MD_ACCESS ( const char *  name,
PRIntn  how 
)

Definition at line 576 of file w16io.c.

{
    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);
}

Here is the call graph for this function:

Definition at line 386 of file w16io.c.

{
    PRInt32     rv;
    
    if ( d->dir ) 
    {
        rv = closedir( d->dir );
        if (rv != 0) 
        {
            _PR_MD_MAP_CLOSEDIR_ERROR( errno );
        }
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return rv;
}

Here is the call graph for this function:

Definition at line 292 of file w16io.c.

{
    PRInt32     rv;
    
    rv = (PRInt32) close( osfd );
    if ( rv == -1 )
    {
        _PR_MD_MAP_CLOSE_ERROR( errno );
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return(rv);
} /* --- end _MD_CloseFile() --- */

Here is the call graph for this function:

PRInt32 _PR_MD_DELETE ( const char *  name)

Definition at line 411 of file w16io.c.

{
    PRInt32     rv;
    
    rv = (PRInt32) remove( name );
    if ( rv != 0 )
    {
        _PR_MD_MAP_DELETE_ERROR( errno );
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return(rv);
}

Here is the call graph for this function:

Definition at line 271 of file w16io.c.

{
    PRInt32     rv;
    
    rv = (PRInt32) fsync( fd->secret->md.osfd );
    if ( rv == -1 )
    {
        _PR_MD_MAP_FSYNC_ERROR( errno );
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return(rv);
}

Here is the call graph for this function:

PRInt32 _PR_MD_GETFILEINFO ( const char *  fn,
PRFileInfo info 
)

Definition at line 454 of file w16io.c.

{
    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;
}

Here is the call graph for this function:

PRInt32 _PR_MD_GETFILEINFO64 ( const char *  fn,
PRFileInfo64 info 
)

Definition at line 481 of file w16io.c.

{
    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);
}

Definition at line 504 of file w16io.c.

{
    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);
}

Here is the call graph for this function:

Definition at line 532 of file w16io.c.

{
    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);
}

Definition at line 656 of file w16io.c.

{
    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() */

Here is the call graph for this function:

PRInt32 _PR_MD_LSEEK ( PRFileDesc fd,
PRInt32  offset,
int  whence 
)

Definition at line 227 of file w16io.c.

{
    PRInt32     rv;
    
    rv = lseek( fd->secret->md.osfd, offset, whence );
    if ( rv == -1 )
    {
        _PR_MD_MAP_LSEEK_ERROR( errno );
        
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return( rv );
}

Here is the call graph for this function:

PRInt64 _PR_MD_LSEEK64 ( PRFileDesc fd,
PRInt64  offset,
int  whence 
)

Definition at line 246 of file w16io.c.

{
    PRInt64 test;
    PRInt32 rv, off;
    LL_SHR(test, offset, 32);
    if (!LL_IS_ZERO(test))
    {
        PR_SetError(PR_FILE_TOO_BIG_ERROR, 0);
        LL_I2L(test, -1);
        return test;
    }
    LL_L2I(off, offset);
    rv = _PR_MD_LSEEK(fd, off, whence);
    LL_I2L(test, rv);
    return test;
} /* end _PR_MD_LSEEK64() */
PRInt32 _PR_MD_MKDIR ( const char *  name,
PRIntn  mode 
)

Definition at line 603 of file w16io.c.

{
    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;
    }
}

Here is the call graph for this function:

PRInt32 _PR_MD_OPEN ( const char *  name,
PRIntn  osflags,
int  mode 
)

Definition at line 92 of file w16io.c.

{
    PRInt32 file;
    int     access = O_BINARY;
    int     rights = 0;
    
    
    /*
    ** Map NSPR open flags to os open flags
    */
    if (osflags & PR_RDONLY )
        access |= O_RDONLY;
    if (osflags & PR_WRONLY )
        access |= O_WRONLY;
    if (osflags & PR_RDWR )
        access |= O_RDWR;
    if (osflags & PR_CREATE_FILE )
    {
        access |= O_CREAT;
        rights |= S_IRWXU;
    }
    if (osflags & PR_TRUNCATE)
        access |= O_TRUNC;
    if (osflags & PR_APPEND)
        access |= O_APPEND;
    else
        access |= O_RDONLY;
        
    /*
    ** Open the file
    */        
    file = (PRInt32) sopen( name, access, SH_DENYNO, rights );
    if ( -1 == (PRInt32)file )
    {
        _PR_MD_MAP_OPEN_ERROR( errno );
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return file;
}

Here is the call graph for this function:

PRStatus _PR_MD_OPEN_DIR ( _MDDir d,
const char *  name 
)

Definition at line 335 of file w16io.c.

{
    d->dir = opendir( name );
    
    if ( d->dir == NULL )
    {
        _PR_MD_MAP_OPENDIR_ERROR( errno );
        return( PR_FAILURE );
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return( PR_SUCCESS );
}

Here is the call graph for this function:

PRInt32 _PR_MD_READ ( PRFileDesc fd,
void buf,
PRInt32  len 
)

Definition at line 139 of file w16io.c.

{
    PRInt32     rv;
    
    if ( (PR_GetDescType(fd) == PR_DESC_FILE) &&
         ( fd->secret->md.osfd == PR_StandardInput ) &&
         ( _pr_md_write_stdout ))
    {
        rv = (*_pr_md_read_stdin)( buf, len);    
    }
    else
    {
        rv = read( fd->secret->md.osfd, buf, len );
    }
    
    if ( rv == -1)
    {
        _PR_MD_MAP_READ_ERROR( errno );
    }
    
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return rv;
}

Here is the call graph for this function:

char* _PR_MD_READ_DIR ( _MDDir d,
PRIntn  flags 
)

Definition at line 355 of file w16io.c.

{
    struct dirent *de;
    int err;

       for (;;) 
    {
              de = readdir( d->dir );
              if ( de == NULL ) {
                     _PR_MD_MAP_READDIR_ERROR( errno);
                     return 0;
              }             
              if ((flags & PR_SKIP_DOT) &&
                  (de->d_name[0] == '.') && (de->d_name[1] == 0))
                     continue;
              if ((flags & PR_SKIP_DOT_DOT) &&
                  (de->d_name[0] == '.') && (de->d_name[1] == '.') &&
                  (de->d_name[2] == 0))
                     continue;
              break;
       }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
       return de->d_name;
}

Here is the call graph for this function:

PRInt32 _PR_MD_RENAME ( const char *  from,
const char *  to 
)

Definition at line 555 of file w16io.c.

{
    PRInt32 rv;
    
    rv = rename( from, to );
    if ( rv == -1 )
    {
        _PR_MD_MAP_RENAME_ERROR( errno );
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return( rv );
}

Here is the call graph for this function:

PRInt32 _PR_MD_RMDIR ( const char *  name)

Definition at line 629 of file w16io.c.

{
    PRInt32 rv;
    
    rv = (PRInt32) rmdir( name );
    if ( rv == -1 )
    {
        _PR_MD_MAP_RMDIR_ERROR( errno );
    }
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return(rv);
}

Here is the call graph for this function:

PRInt32 _PR_MD_STAT ( const char *  fn,
struct stat info 
)

Definition at line 433 of file w16io.c.

{
    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 );
}

Here is the call graph for this function:

Definition at line 725 of file w16io.c.

{
    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() */

Here is the call graph for this function:

Definition at line 776 of file w16io.c.

{
    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() */

Here is the call graph for this function:

PRInt32 _PR_MD_WRITE ( PRFileDesc fd,
const void buf,
PRInt32  len 
)

Definition at line 174 of file w16io.c.

{
    PRInt32     rv;

    if ( (PR_GetDescType(fd) == PR_DESC_FILE))
    {
        switch ( fd->secret->md.osfd )
        {
            case  PR_StandardOutput :
                if ( _pr_md_write_stdout )
                    rv = (*_pr_md_write_stdout)( (void *)buf, len);
                else
                    rv = len; /* fake success */
                break;
                
            case  PR_StandardError  :
                if ( _pr_md_write_stderr )
                    rv = (*_pr_md_write_stderr)( (void *)buf, len);    
                else
                    rv = len; /* fake success */
                break;
                
            default:
                rv = write( fd->secret->md.osfd, buf, len );
                if ( rv == -1 )
                {
                    _PR_MD_MAP_WRITE_ERROR( errno );
                }
                break;
        }
    }
    else
    {
        rv = write( fd->secret->md.osfd, buf, len );
        if ( rv == -1 )
        {
            _PR_MD_MAP_WRITE_ERROR( errno );
        }
    }
    
    PR_Sleep( _PR_MD_WIN16_DELAY );    
    return rv;
} /* --- end _PR_MD_WRITE() --- */

Here is the call graph for this function:

void FlipSlashes ( char *  cp,
int  len 
)

Definition at line 316 of file w16io.c.

{
    while (--len >= 0) {
    if (cp[0] == '/') {
        cp[0] = PR_DIRECTORY_SEPARATOR;
    }
    cp++;
    }
}

Definition at line 826 of file w16io.c.

{
    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() */
PRStatus PR_MD_RegisterW16StdioCallbacks ( PRStdinRead  inReadf,
PRStdoutWrite  outWritef,
PRStderrWrite  errWritef 
)

Definition at line 74 of file w16io.c.

{
    _pr_md_write_stdout = outWritef;
    _pr_md_write_stderr = errWritef;
    _pr_md_read_stdin   = inReadf;
    
    return(PR_SUCCESS);
} /* end PR_MD_RegisterW16StdioCallbacks() */

Variable Documentation

PRStdinRead _pr_md_read_stdin = 0

Definition at line 69 of file w16io.c.

PRStderrWrite _pr_md_write_stderr = 0

Definition at line 71 of file w16io.c.

PRStdoutWrite _pr_md_write_stdout = 0

Definition at line 70 of file w16io.c.