Ignore:
Timestamp:
Nov 23, 2003, 12:31:59 AM (22 years ago)
Author:
bird
Message:

#697: Filehandle rewrite - first step.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/emx/io.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1818#endif
    1919
    20 /* Low-level i/o */
    21 
     20/** @defgroup   libc_ioflags    Low Level I/O Flags
     21 * These low level I/O flags are kept in the fFlags member of the LIBCFH
     22 * structure. The O_* flags are defined in sys/fcntl.h, the F_* flags are
     23 * internal to LIBC and defined in emx/io.h.
     24 * @{
     25 */
     26/*      O_RDONLY    0x00000000 */
     27/*      O_WRONLY    0x00000001 */
     28/*      O_RDWR      0x00000002 */
    2229/*      O_ACCMODE   0x00000003 */
    23 /*      O_NDELAY    0x00000004 */
     30/*      O_NONBLOCK  0x00000004 */
    2431/*      O_APPEND    0x00000008 */
    25 /*      O_TEXT      0x00000010 */
    26 #define F_EOF       0x00000020
    27 #define F_TERMIO    0x00000040
    28 #define F_DEV       0x00000080
    29 /*      O_BINARY    0x00000100 */
     32/* emx  O_TEXT      0x00000010 */
     33/* emx  O_SIZE      0x00000020 */
     34/*      free        0x00000040 */
     35/*      O_(F)SYNC   0x00000080 */
     36/*      O_SYNC      0x00000080 */
     37/* emx  O_BINARY    0x00000100 */
    3038/*      O_CREAT     0x00000200 */
    3139/*      O_TRUNC     0x00000400 */
    3240/*      O_EXCL      0x00000800 */
    33 /*      O_NOINHERIT 0x00001000 */
    34 /*      O_SYNC      0x00002000 */
    35 /*      O_NOCTTY    0x00004000 */
    36 /*      O_SIZE      0x00008000 */
    37 #define F_SOCKET    0x10000000
    38 #define F_PIPE      0x20000000
    39 #define F_WRCRPEND  0x40000000
    40 #define F_CRLF      0x80000000
     41/* emx  O_NOINHERIT 0x00001000 */
     42/*      free        0x00002000 */
     43/*      free        0x00004000 */
     44/*      O_NOCTTY    0x00008000 */
     45#define F_EOF       0x01000000
     46#define F_TERMIO    0x02000000
     47#define F_WRCRPEND  0x04000000
     48#define F_CRLF      0x08000000
     49/** Filetype mask. */
     50#define F_TYPEMASK  0xf0000000
     51/** Type - Regular file. */
     52#define F_FILE      0x10000000
     53/** Type - Characater device. */
     54#define F_DEV       0x20000000
     55/** Type - Pipe. */
     56#define F_PIPE      0x30000000
     57/** Type - Socket. */
     58#define F_SOCKET    0x40000000
     59/** @} */
    4160
    4261/* stdio */
     
    157176};
    158177
    159 extern struct streamvec _streamvec_head;
    160 
    161 extern int _io_ninherit;
    162 extern struct fdvec _fdvec_head;
    163 
    164 /* This is currently used only in the multi-thread libraries.  We
    165    can't use and reallocate a single array because rmutex semaphores
    166    cannot be moved. */
    167 
    168 struct streamvec2
    169 {
    170   struct _file2 *vec;
    171   struct streamvec2 *next;
    172   int n;
    173 };
    174 
    175 extern struct streamvec2 _streamvec2_head;
     178extern struct streamvec    *_streamvec_head;
     179extern int                  _io_ninherit;
     180extern struct fdvec         _fdvec_head;
    176181
    177182#if defined (_SYS_RMUTEX_H)
     
    203208#endif /* defined (_SYS_RMUTEX_H) */
    204209
     210struct __libc_FileHandle;
     211
     212/**
     213 * File handle Operations.
     214 * (for non standard handles (like sockets))
     215 */
     216typedef struct __libc_FileHandleOperations
     217{
     218    /** Handle type. */
     219    enum
     220    {
     221        /** Anything which is supported by the OS/2 file API.
     222         * (not used at present as those handles doesn't need special ops). */
     223        enmFH_File,
     224        /** Socket handle. */
     225        enmFH_Socket
     226    }   enmType;
     227
     228    /** Close operation.
     229     * @returns 0 on success.
     230     * @returns OS/2 error code on failure.
     231     * @param   pFH         Pointer to the handle structure to operate on.
     232     * @param   fh          It's associated filehandle.
     233     */
     234    int (*pfnClose)(struct __libc_FileHandle *pFH, int fh);
     235    /** Read operation.
     236     * @returns 0 on success.
     237     * @returns OS/2 error code on failure.
     238     * @param   pFH         Pointer to the handle structure to operate on.
     239     * @param   fh          It's associated filehandle.
     240     * @param   pvBuf       Pointer to the buffer to read into.
     241     * @param   cbRead      Number of bytes to read.
     242     * @param   pcbRead     Where to store the count of bytes actually read.
     243     */
     244    int (*pfnRead)(struct __libc_FileHandle *pFH, int fh, void *pvBuf, size_t cbRead, size_t *pcbRead);
     245    /** Write operation.
     246     * @returns 0 on success.
     247     * @returns OS/2 error code on failure.
     248     * @param   pFH         Pointer to the handle structure to operate on.
     249     * @param   fh          It's associated filehandle.
     250     * @param   pvBuf       Pointer to the buffer which contains the data to write.
     251     * @param   cbWrite     Number of bytes to write.
     252     * @param   pcbWritten  Where to store the count of bytes actually written.
     253     */
     254    int (*pfnWrite)(struct __libc_FileHandle *pFH, int fh, const void *pvBuf, size_t cbWrite, size_t *pcbWritten);
     255    /** Duplicate handle operation.
     256     * @returns 0 on success, OS/2 error code on failure.
     257     * @param   pFH         Pointer to the handle structure to operate on.
     258     * @param   fh          It's associated filehandle.
     259     * @param   pfhNew      Where to store the duplicate filehandle.
     260     *                      The input value describe how the handle is to be
     261     *                      duplicated. If it's -1 a new handle is allocated.
     262     *                      Any other value will result in that value to be
     263     *                      used as handle. Any existing handle with that
     264     *                      value will be closed.
     265     */
     266    int (*pfnDuplicate)(struct __libc_FileHandle *pFH, int fh, int *pfhNew);
     267    /** File Control operation.
     268     * @returns 0 on success, OS/2 error code on failure.
     269     * @param   pFH         Pointer to the handle structure to operate on.
     270     * @param   fh          It's associated filehandle.
     271     * @param   iIOControl  Which file file control operation to perform.
     272     * @param   iArg        Argument which content is specific to each
     273     *                      iIOControl operation.
     274     * @param   prc         Where to store the value which upon success is
     275     *                      returned to the caller.
     276     */
     277    int (*pfnFileControl)(struct __libc_FileHandle *pFH, int fh, int iIOControl, int iArg, int *prc);
     278    /** I/O Control operation.
     279     * @returns 0 on success, OS/2 error code on failure.
     280     * @param   pFH         Pointer to the handle structure to operate on.
     281     * @param   fh          It's associated filehandle.
     282     * @param   iIOControl  Which I/O control operation to perform.
     283     * @param   iArg        Argument which content is specific to each
     284     *                      iIOControl operation.
     285     * @param   prc         Where to store the value which upon success is
     286     *                      returned to the caller.
     287     */
     288    int (*pfnIOControl)(struct __libc_FileHandle *pFH, int fh, int iIOControl, int iArg, int *prc);
     289
     290} LIBCFHOPS, *PLIBCFHOPS/*, const * PCLIBCFHOPS*/;
     291
     292
     293/**
     294 * Common part of a per 'file' handle structure.
     295 */
     296typedef struct __libc_FileHandle
     297{
     298    /** Handle flags.
     299     * Previously represented by _files / *fd_vec->flags.
     300     * @remark For thread safety update this atomically. */
     301    unsigned int    fFlags;
     302
     303    /** Lookahead. (whoever uses that?)
     304     * Previously represented by _files / *fd_vec->flags.
     305     * @remark For thread safety update this atomically. */
     306    int             iLookAhead;
     307
     308    /** Pointer to the operations one can perform on the handle.
     309     * Only for special handles not supported by the OS/2 file API. */
     310    PLIBCFHOPS      pOps;
     311
     312} LIBCFH, *PLIBCFH;
     313
     314int     __libc_FHEnsureHandles(int fh);
     315int     __libc_FHAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh);
     316int     __libc_FHClose(int fh);
     317PLIBCFH __libc_FH(int fh);
     318
    205319
    206320int _endbuf1 (struct _FILE *);
    207321void _fbuf (struct _FILE *);
    208 int *_fd_flags (int);
    209 int *_fd_init (int);
    210 int *_fd_lookahead (int);
     322#define _fd_flags(a)        please do not use this use this! ##a
     323#define _fd_init(a)         please do not use this use this! ##a
     324#define _fd_lookahead(a)    please do not use this use this! ##a
    211325struct _FILE *_openstream (struct _FILE *, __const__ char *, __const__ char *,
    212326    int, int);
Note: See TracChangeset for help on using the changeset viewer.