Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
stdio.cpp File Reference
#include "mozce_internal.h"
#include <stdarg.h>

Go to the source code of this file.

Classes

struct  _fdtab_block

Defines

#define MAXFDS   100

Typedefs

typedef struct _fdtab_block _fdtab_block

Functions

void _initfds ()
int _getnewfd ()
MOZCE_SHUNT_API int mozce_access (const char *path, int mode)
MOZCE_SHUNT_API void mozce_rewind (FILE *inStream)
MOZCE_SHUNT_API FILEmozce_fdopen (int fd, const char *inMode)
MOZCE_SHUNT_API void mozce_perror (const char *inString)
MOZCE_SHUNT_API int mozce_remove (const char *inPath)
MOZCE_SHUNT_API char * mozce_getcwd (char *buff, size_t size)
MOZCE_SHUNT_API int mozce_printf (const char *format,...)
static void mode2binstr (int mode, char *buffer)
MOZCE_SHUNT_API int mozce_open (const char *pathname, int flags, int mode)
MOZCE_SHUNT_API int mozce_close (int fd)
MOZCE_SHUNT_API size_t mozce_read (int fd, void *buffer, size_t count)
MOZCE_SHUNT_API size_t mozce_write (int fd, const void *buffer, size_t count)
MOZCE_SHUNT_API int mozce_unlink (const char *pathname)
MOZCE_SHUNT_API int mozce_lseek (int fd, int offset, int whence)
MOZCE_SHUNT_API int mozce_fileno (FILE *f)

Variables

_fdtab_block _fdtab [MAXFDS]

Class Documentation

struct _fdtab_block

Definition at line 53 of file stdio.cpp.

Collaboration diagram for _fdtab_block:
Class Members
int fd
FILE * file

Define Documentation

#define MAXFDS   100

Definition at line 51 of file stdio.cpp.


Typedef Documentation

typedef struct _fdtab_block _fdtab_block

Function Documentation

Definition at line 82 of file stdio.cpp.

{
    int i;
    
    for(i = 0; i < MAXFDS; i++)
    {
        if(_fdtab[i].fd == -1)
            return i;
    }
    
    return -1;
}

Here is the caller graph for this function:

Definition at line 68 of file stdio.cpp.

{
    static int fdsinitialized = 0;
    
    if(fdsinitialized)
        return;
    
    for (int i = 0; i < MAXFDS; i++)
        _fdtab[i].fd = -1;
    
    fdsinitialized = 1;
}

Here is the caller graph for this function:

static void mode2binstr ( int  mode,
char *  buffer 
) [static]

Definition at line 216 of file stdio.cpp.

{
    if (mode | O_RDWR || (mode | O_WRONLY))  // write only == read|write
    {
        if (mode | O_CREAT)
        {
            strcpy(buffer, "wb+");
        }
        else if (mode | O_APPEND)
        {
            strcpy(buffer, "ab+");
        }
        else if (mode | O_TRUNC)
        {
            strcpy(buffer, "wb+");
        }
        
        else if (mode == O_RDWR)
        {
            strcpy(buffer, "rb+");
        }
    }
    else if (mode | O_RDONLY)
    {
        strcpy(buffer, "rb");
    }
}

Here is the caller graph for this function:

MOZCE_SHUNT_API int mozce_access ( const char *  path,
int  mode 
)

Definition at line 98 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("-- mozce_access called\n");
#endif
    
    return 0;
}

Here is the call graph for this function:

Definition at line 282 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_close called\n");
#endif
    
    
    
    
    if(fd < 0 || fd >= MAXFDS || _fdtab[fd].fd == -1)
        return -1;
    
    
    fclose(_fdtab[fd].file);
    _fdtab[fd].fd = -1;
    
    return 0;
}

Here is the call graph for this function:

MOZCE_SHUNT_API FILE* mozce_fdopen ( int  fd,
const char *  inMode 
)

Definition at line 121 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("-- mozce_fdopen called (mode is ignored!) \n");
#endif
    
    
    if(fd < 0 || fd >= MAXFDS || _fdtab[fd].fd == -1)
        return 0;
    
    return _fdtab[fd].file;
}

Here is the call graph for this function:

Definition at line 375 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_fileno called\n");
#endif
    
    // Windows SDK is broken.  _fileno should return an int, but for whatever god forsaken reason, CE returns void*.
    int fd;
    
    for(fd = 0; fd < MAXFDS; fd++)
    {
        if(_fdtab[fd].file == f)
        {
            return _fdtab[fd].fd;
        }
    }
    return (int) fileno(f);
    
}

Here is the call graph for this function:

MOZCE_SHUNT_API char* mozce_getcwd ( char *  buff,
size_t  size 
)

Definition at line 176 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_getcwd called.\n");
#endif
    int i;
    unsigned short dir[MAX_PATH];
    GetModuleFileName(GetModuleHandle (NULL), dir, MAX_PATH);
    for (i = _tcslen(dir); i && dir[i] != TEXT('\\'); i--) {}
    dir[i + 1] = TCHAR('\0');
    
    w2a_buffer(dir, -1, buff, size);
    
    return buff;
}

Here is the call graph for this function:

MOZCE_SHUNT_API int mozce_lseek ( int  fd,
int  offset,
int  whence 
)

Definition at line 353 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_lseek called\n");
#endif
    
    
    if(fd < 0 || fd >= MAXFDS || _fdtab[fd].fd == -1)
        return -1;
    
    int newpos = -1;
    int error = fseek(_fdtab[fd].file, offset, whence);
    
    if (!error)
        newpos = ftell(_fdtab[fd].file);
    return newpos;
}

Here is the call graph for this function:

MOZCE_SHUNT_API int mozce_open ( const char *  pathname,
int  flags,
int  mode 
)

Definition at line 244 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_open called\n");
#endif
    
    _initfds();
    
    
    char modestr[10];
    *modestr = '\0';
    
    mode2binstr(mode, modestr);
    if (*modestr == '\0')
        return -1;
    
    
    FILE* file = fopen(pathname, modestr);
    
    int fd = -1;
    
    if (file)
    {
        fd = _getnewfd();
        
        _fdtab[fd].fd = fd;
        _fdtab[fd].file = file;
        
        fflush(file);
        fread(NULL, 0, 0, file);
    }
    
    return fd;
}

Here is the call graph for this function:

MOZCE_SHUNT_API void mozce_perror ( const char *  inString)

Definition at line 137 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_perror called\n");
#endif
    
    fprintf(stderr, "%s", inString);
}

Here is the call graph for this function:

MOZCE_SHUNT_API int mozce_printf ( const char *  format,
  ... 
)

Definition at line 194 of file stdio.cpp.

{
#ifdef DEBUG
#define MAX_CHARS_IN_VARIABLE_STRING 1024
    
    char buf[MAX_CHARS_IN_VARIABLE_STRING];
    
    TCHAR tBuf[MAX_CHARS_IN_VARIABLE_STRING];
    
    va_list ptr;
    va_start(ptr,format);
    vsprintf(buf,format,ptr);
    
    mbstowcs(tBuf, buf, MAX_CHARS_IN_VARIABLE_STRING);
    
    OutputDebugString(tBuf);
    
    return 1;
#endif
    return 0;
}

Here is the call graph for this function:

MOZCE_SHUNT_API size_t mozce_read ( int  fd,
void buffer,
size_t  count 
)

Definition at line 303 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_read called\n");
#endif
    
    if(fd < 0 || fd >= MAXFDS || _fdtab[fd].fd == -1)
        return -1;
    
    size_t num = fread(buffer, 1, count, _fdtab[fd].file);
    
    if (ferror(_fdtab[fd].file))
        return -1;
    
    return num;
}

Here is the call graph for this function:

MOZCE_SHUNT_API int mozce_remove ( const char *  inPath)

Definition at line 149 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_remove called on %s\n", inPath);
#endif
    
    int retval = -1;
    
    if(NULL != inPath)
    {
        unsigned short wPath[MAX_PATH];
        
        if(0 != a2w_buffer(inPath, -1, wPath, sizeof(wPath) / sizeof(unsigned short)))
        {
            if(FALSE != DeleteFileW(wPath))
            {
                retval = 0;
                
            }
        }
    }
    
    return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 109 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_rewind called\n");
#endif
    
    fseek(inStream, 0, SEEK_SET);
}

Here is the call graph for this function:

MOZCE_SHUNT_API int mozce_unlink ( const char *  pathname)

Definition at line 342 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_unlink called\n");
#endif
    return mozce_remove(pathname);
}

Here is the call graph for this function:

MOZCE_SHUNT_API size_t mozce_write ( int  fd,
const void buffer,
size_t  count 
)

Definition at line 323 of file stdio.cpp.

{
    MOZCE_PRECHECK
        
#ifdef DEBUG
        mozce_printf("mozce_write called\n");
#endif
    
    if(fd < 0 || fd >= MAXFDS || _fdtab[fd].fd == -1)
        return -1;
    
    size_t num = fwrite(buffer, 1, count, _fdtab[fd].file);
    if (ferror(_fdtab[fd].file))
        return -1;
    
    return num;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 61 of file stdio.cpp.