Changeset 871


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

#697: Filehandle rewrite - first step.

Location:
trunk/src/emx
Files:
1 added
1 deleted
59 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);
  • trunk/src/emx/include/emx/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r870 r871  
    180180int __mkdir (__const__ char *name);
    181181int __newthread (int tid);
    182 int __open (__const__ char *name, int flags, off_t size);
     182struct __libc_FileHandle;
     183int __open (__const__ char *name, int flags, off_t size, unsigned fLibc, struct __libc_FileHandle **pFH);
    183184int __pause (void);
    184 int __pipe (int *two_handles, int pipe_size);
     185int __pipe(int *two_handles, int pipe_size, struct __libc_FileHandle **ppFHRead, struct __libc_FileHandle **ppFHWrite);
    185186int __profil (__const__ struct _profil *p);
    186187int __ptrace (int request, int pid, int addr, int data);
  • trunk/src/emx/include/stdio.h

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r870 r871  
    197197
    198198__BEGIN_DECLS
    199 extern FILE _streamv[];
     199extern FILE *__stdinp;
     200extern FILE *__stdoutp;
     201extern FILE *__stderrp;
    200202__END_DECLS
    201 
    202 #define __stdinp    (&_streamv[0])
    203 #define __stdoutp   (&_streamv[1])
    204 #define __stderrp   (&_streamv[2])
    205203
    206204#endif /* bird: EMX specific FILE stuff ends. */
  • trunk/src/emx/src/lib/app/stdio.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r870 r871  
    1010#include <emx/startup.h>
    1111
    12 /* See app/iodata.c. */
    1312
    14 extern int _nfiles;
    15 extern int _files[];
     13/*******************************************************************************
     14*   Global Variables                                                           *
     15*******************************************************************************/
     16/** Preallocated streams
     17 * (public since stdin,stdout,stderr references this thru #defines.) */
     18static FILE                 gaPreFiles[_NFILES] = {{0}};
    1619
    17 _rmutex _streamv_rmutex;        /* See io/_newstre.c */
     20/** Vector entry for preallocated streams. */
     21static struct streamvec     gPreStreamVec = {&gaPreFiles[0], NULL, _NFILES};
     22
     23/** More structures for preallocated streams. */
     24static struct _file2        gaPreFile2s[_NFILES];
     25
     26/** The buffer for stdin. */
     27static char                 gachStdIn[BUFSIZ];
     28
     29/** Mutex protecting the stream vector. */
     30_rmutex                     _streamv_rmutex;    /* See io/_newstre.c */
     31
     32/*
     33 * (These variables must be initialized as no extended dictionary
     34 * entries are built for COMDEF.)
     35 */
     36
     37/** Head of the stream vector. */
     38struct streamvec           *_streamvec_head = NULL;
     39
     40/** Standard input stream pointer. */
     41FILE                       *__stdinp = &gaPreFiles[0];
     42/** Standard output stream pointer. */
     43FILE                       *__stdoutp = &gaPreFiles[1];
     44/** Standard error stream pointer. */
     45FILE                       *__stderrp = &gaPreFiles[2];
    1846
    1947
    20 /* These variables must be initialized as no extended dictionary
    21    entries are built for COMDEF. */
     48/**
     49 * Initialize the streams -- this function will be called by
     50 * _CRT_init() via the __crtinit1__ set vector.
     51 */
     52void _init_streams(void);
     53void _init_streams(void)
     54{
     55    struct _FILE       *pFile;
     56    struct _file2      *pFile2;
     57    int                 i;
     58    static char         fInited = 0;
    2259
    23 FILE _streamv[_NFILES] = {{0}};
     60    /*
     61     * Paranoia!
     62     */
     63    if (fInited)
     64        return;
     65    fInited = 1;
    2466
    25 struct streamvec _streamvec_head = {_streamv, NULL, _NFILES};
     67    /*
     68     * Init the _more and _owner pointers.
     69     */
     70    pFile   = &gaPreFiles[0];
     71    pFile2  = &gaPreFile2s[0];
     72    for (i = 0; i < _NFILES; i++, pFile++, pFile2++)
     73    {
     74        pFile2->owner = pFile; /* obsolete? */
     75        pFile->_more = pFile2;
     76    }
    2677
    27 /* If we don't preallocate the first entry, _CRT_init() will call
    28    malloc() which breaks fork() because the heap object of the EXE
    29    file won't be used. */
     78    /*
     79     * Create the mutex protecting the stream list and insert the table.
     80     * ASSUME: we're ALONE at this point.
     81     */
     82    gPreStreamVec.next  = _streamvec_head;
     83    _streamvec_head     = &gPreStreamVec;
     84    _rmutex_checked_create(&_streamv_rmutex, 0);
    3085
    31 static struct _file2 _streamv2[_NFILES];
     86    /*
     87     * As far as I know there is no reason to initiate a bunch of streams
     88     * here as EM used to do. All that is required is the three standard
     89     * streams.
     90     */
     91    for (i = 0; i < 3; i++)
     92    {
     93        PLIBCFH pFH = __libc_FH(i);
     94        if (pFH)
     95        {
     96            /*
     97             * Common init - recall everything is ZERO.
     98             */
     99            gaPreFiles[i]._flags    |= _IOOPEN;
     100            gaPreFiles[i]._handle    = i;
     101            gaPreFiles[i]._flush     = _flushstream;
     102            if (_setmore(&gaPreFiles[i], 0))
     103                abort();
    32104
    33 struct streamvec2 _streamvec2_head = {_streamv2, NULL, _NFILES};
     105            /*
     106             * Specific init.
     107             */
     108            switch (i)
     109            {
     110                case 0:
     111                    /* stdin is always buffered. */
     112                    gaPreFiles[0]._flags    |= _IOREAD | _IOFBF | _IOBUFUSER;
     113                    gaPreFiles[0]._ptr       = gachStdIn;
     114                    gaPreFiles[0]._buffer    = gachStdIn;
     115                    gaPreFiles[0]._buf_size  = BUFSIZ;
     116                    break;
    34117
    35 /* The buffer for stdin. */
     118                case 1:
     119                    /* stdout is buffered unless it's connected to a device. */
     120                    gaPreFiles[1]._flags |= _IOWRT | _IOBUFNONE
     121                        | ((pFH->fFlags & F_TYPEMASK) == F_DEV ? _IONBF : _IOFBF);
     122                    break;
    36123
    37 static char ibuf[BUFSIZ];
    38 
    39 
    40 /* Initialize the streams -- this function will be called by
    41    _CRT_init() via the __crtinit1__ set vector. */
    42 
    43 void _init_streams (void);
    44 void _init_streams (void)
    45 {
    46   int i;
    47 
    48   _rmutex_checked_create (&_streamv_rmutex, 0);
    49 
    50   for (i = 0; i < _nfiles && i < _streamvec_head.n; ++i)
    51     {
    52       _streamv[i]._flags = 0;
    53       /* O_TEXT is set by init_files() for all valid handles. */
    54       if (_files[i] != 0)
    55         {
    56           _streamv[i]._flags |= _IOOPEN;
    57           _streamv[i]._ptr = NULL;
    58           _streamv[i]._buffer = NULL;
    59           _streamv[i]._rcount = 0;
    60           _streamv[i]._wcount = 0;
    61           _streamv[i]._handle = i;
    62           _streamv[i]._buf_size = 0;
    63           _streamv[i]._tmpidx = 0;
    64           _streamv[i]._pid = 0;
    65           _streamv[i]._flush = _flushstream;
    66           _streamv[i]._ungetc_count = 0;
    67           switch (i)
    68             {
    69             case 0:
    70 
    71               /* stdin is always buffered. */
    72 
    73               _streamv[0]._flags |= _IOREAD | _IOFBF | _IOBUFUSER;
    74               _streamv[0]._ptr = ibuf;
    75               _streamv[0]._buffer = ibuf;
    76               _streamv[0]._buf_size = BUFSIZ;
    77               break;
    78 
    79             case 1:
    80 
    81               /* stdout is buffered unless it's connected to a
    82                  device. */
    83 
    84               _streamv[i]._flags |= (_IOWRT | _IOBUFNONE
    85                                      | ((_files[i] & F_DEV)
    86                                         ? _IONBF : _IOFBF));
    87               break;
    88 
    89             case 2:
    90 
    91               /* stderr is always unbuffered. */
    92 
    93               _streamv[i]._flags |= _IOWRT | _IOBUFNONE | _IONBF;
    94               break;
    95 
    96             default:
    97 
    98               /* All other streams are buffered unless connected to a
    99                  device. */
    100 
    101               _streamv[i]._flags |= (_IORW | _IOBUFNONE
    102                                      | ((_files[i] & F_DEV)
    103                                         ? _IONBF : _IOFBF));
    104               break;
     124                case 2:
     125                    /* stderr is always unbuffered. */
     126                    gaPreFiles[2]._flags |= _IOWRT | _IOBUFNONE | _IONBF;
     127                    break;
    105128            }
    106           if (_setmore (&_streamv[i], 0) != 0)
    107             abort ();
    108129        }
    109     }
     130    } /* for standard handles. */
    110131}
    111132
     
    116137   print something.  (ISO 9899-1990 lets this undefined.) */
    117138
    118 void _exit_streams (void);
    119 void _exit_streams (void)
     139void _exit_streams(void);
     140void _exit_streams(void)
    120141{
    121   flushall ();
    122   _rmtmp ();
     142    flushall();
     143    _rmtmp();
    123144}
    124145
    125 _CRT_INIT1 (_init_streams)
    126 _CRT_EXIT1 (_exit_streams)
     146_CRT_INIT1(_init_streams)
     147_CRT_EXIT1(_exit_streams)
  • trunk/src/emx/src/lib/io/_fbuf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r870 r871  
    1 /* _fbuf.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
     1/* _fbuf.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
     2                     -- Copyrithg (c) 2003 by knut st. osmundsen */
    23
    34#include "libc-alias.h"
     
    56#include <stdlib.h>
    67#include <emx/io.h>
     8#include <emx/umalloc.h>
    79
    810/* Assign a buffer to a stream (which must not have a buffer) */
     
    1315    stream->_buffer = NULL;
    1416  else
    15     stream->_buffer = malloc (BUFSIZ);
     17    {
     18      PLIBCFH   pFH = __libc_FH(stream->_handle);
     19      if (pFH && (   (pFH->fFlags & F_TYPEMASK) == F_DEV
     20                  || (pFH->fFlags & F_TYPEMASK) == F_SOCKET))
     21        stream->_buffer = _lmalloc(BUFSIZ);
     22      else
     23        stream->_buffer = _hmalloc(BUFSIZ);
     24    }
    1625  if (stream->_buffer == NULL)
    1726    {
  • trunk/src/emx/src/lib/io/_fd.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r870 r871  
     1#if 0 /* dead */
     2
    13/* _fd.c (emx+gcc) -- Copyright (c) 1996 by Eberhard Mattes */
    24
     
    46#include <emx/io.h>
    57
    6 /* See app/iodata.c. */
    78
    8 extern int _nfiles;
    9 extern int _files[];
    10 extern int _lookahead[];
    11 
    12 /* Return pointer to flags word for the file descriptor HANDLE.
    13    Return NULL on error. */
    14 
    15 int *_fd_flags (int handle)
     9/**
     10 * @returns pointer to flags word for the file descriptor HANDLE.
     11 * @returns NULL on error.
     12 * @deprecated
     13 */
     14int *_fd_flags(int fh)
    1615{
    17   struct fdvec *p;
    18 
    19   if (handle < 0)
     16    PLIBCFH     pFH;
     17    pFH = __libc_FH(fh);
     18    if (!pFH)
     19        return &pFH->fFlags;
    2020    return NULL;
    21 
    22   /* We want this case to be fast.  Note that _fdvec_head.n == _nfiles
    23      and _fdvec_head.flags == _files! */
    24 
    25   if (handle < _nfiles)
    26     return &_files[handle];
    27 
    28   handle -= _nfiles;
    29   p = _fdvec_head.next;
    30   while (p != NULL && handle >= p->n)
    31     {
    32       handle -= p->n;
    33       p = p->next;
    34     }
    35   if (p == NULL)
    36     return NULL;
    37   return &p->flags[handle];
    3821}
    3922
    4023
    41 /* Return pointer to lookahead word for the file descriptor HANDLE.
    42    Return NULL on error.
     24/**
     25 * @returns pointer to lookahead word for the file descriptor HANDLE.
     26 * @returns NULL on error.
     27 * @remark  select() does this inline.
     28 * @depricated
     29 */
     30int *_fd_lookahead(int fh)
     31{
     32    PLIBCFH     pFH;
     33    pFH = __libc_FH(fh);
     34    if (!pFH)
     35        return &pFH->iLookAhead;
     36    return NULL;
     37}
    4338
    44    Note: select() does this inline. */
    45 
    46 int *_fd_lookahead (int handle)
    47 {
    48   struct fdvec *p;
    49 
    50   if (handle < 0)
    51     return NULL;
    52 
    53   /* We want this case to be fast.  Note that _fdvec_head.n == _nfiles
    54      and _fdvec_head.lookahead == _lookahead! */
    55 
    56   if (handle < _nfiles)
    57     return &_lookahead[handle];
    58 
    59   handle -= _nfiles;
    60   p = _fdvec_head.next;
    61   while (p != NULL && handle >= p->n)
    62     {
    63       handle -= p->n;
    64       p = p->next;
    65     }
    66   if (p == NULL)
    67     return NULL;
    68   return &p->lookahead[handle];
    69 }
     39#endif
  • trunk/src/emx/src/lib/io/_fdinit.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
     1#if 0 /* dead */
    12/* _fdinit.c (emx+gcc) -- Copyright (c) 1996-1997 by Eberhard Mattes */
    23
     
    119120  return &p->flags[handle];
    120121}
     122#endif
  • trunk/src/emx/src/lib/io/_flushst.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    4949          else                  /* New or flushed buffer */
    5050            {
    51               int *pflags = _fd_flags (fh);
     51              PLIBCFH   pFH = __libc_FH(fh);
    5252              w = 0;
    53               if (pflags != NULL && (*pflags & O_APPEND))
     53              if (pFH && (pFH->fFlags & O_APPEND))
    5454                lseek (fh, 0, SEEK_END);
    5555            }
  • trunk/src/emx/src/lib/io/_imphand.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    33#include "libc-alias.h"
    44#include <io.h>
    5 #include <fcntl.h>
    6 #include <errno.h>
    7 #include <sys/ioctl.h>
    8 #include <emx/io.h>
    95#include <emx/syscalls.h>
    10 
    11 extern int _fmode_bin;
    126
    137int _imphandle (int handle)
    148{
    15   int fd, rc, ht, *pflags;
    16 
    17   if (handle < 0)
    18     {
    19       errno = EBADF;
    20       return -1;
    21     }
    22 
    23   fd = __imphandle (handle);
    24   if (fd == -1)
    25     return -1;
    26   pflags = _fd_init (fd);
    27   if (pflags == NULL)
    28     {
    29       /* `fd' has been relocated and is now out of range. */
    30 
    31       __dup2 (fd, handle);
    32       __close (fd);
    33       errno = EBADF;
    34       return -1;
    35     }
    36 
    37   *pflags = O_RDWR;             /* TODO */
    38   if (_fmode_bin == 0)
    39     *pflags |= O_TEXT;
    40   rc = __ioctl1 (fd, 0);
    41   if (rc != -1 && (rc & 0x80))
    42     *pflags |= F_DEV;
    43   rc = __ioctl2 (fd, FGETHTYPE, (int)&ht);
    44   if (rc >= 0)
    45     {
    46       if (HT_ISDEV (ht))
    47         *pflags |= F_DEV;
    48       if (ht == HT_UPIPE || ht == HT_NPIPE)
    49         *pflags |= F_PIPE;
    50     }
    51   return fd;
     9    return __imphandle(handle);
    5210}
  • trunk/src/emx/src/lib/io/_isterm.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    33#include "libc-alias.h"
    44#include <io.h>
     5#include <errno.h>
     6#include <emx/io.h>
    57#include <emx/syscalls.h>
    68
    7 int _isterm (int handle)
     9int _isterm(int handle)
    810{
    9   int j;
     11    PLIBCFH pFH;
    1012
    11   if (!isatty (handle))
    12     return 0;
    13   j = __ioctl1 (handle, 0);
    14   if (j < 0)
    15     return 0;
    16   return ((j & 0x03) ? 1 : 0);
     13    /*
     14     * Get filehandle.
     15     */
     16    pFH = __libc_FH(handle);
     17    if (!pFH)
     18    {
     19        errno = EBADF;
     20        return 0;
     21    }
     22
     23    /*
     24     * Is it a atty?
     25     */
     26    if (!isatty(handle))
     27        return 0;
     28
     29    /*
     30     * If it's a device we assume is a terminal...
     31     * (Hope that's correct interpretation of the __ioctl1() call...)
     32     */
     33    return (pFH->fFlags & F_TYPEMASK) == F_DEV;
    1734}
  • trunk/src/emx/src/lib/io/_newstre.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r870 r871  
    1 /* _newstre.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
     1/* _newstre.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
     2                        -- Copyright (c) 2003 by Knut St. Osmundsen */
    23
    34#include "libc-alias.h"
     
    78#include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    89#include <sys/rmutex.h>
     10#include <emx/umalloc.h>
    911#include <emx/io.h>
    1012
    1113#define INC     32
     14#define ALIGN(p, a) (((unsigned long)(p) + (a) - 1) & ~((a) - 1))
    1215
    1316FILE *_newstream (void)
    1417{
    15   int i;
    16   struct streamvec *sv, *last = NULL;
     18    int                 i;
     19    struct streamvec   *pSV;
     20    struct streamvec   *pSVNew;
    1721
    18   STREAMV_LOCK;
    19   for (sv = &_streamvec_head; sv != NULL; sv = sv->next)
     22    /*
     23     * Search thru the list of streams.
     24     */
     25    STREAMV_LOCK;
     26    for (pSV = _streamvec_head; pSV != NULL; pSV = pSV->next)
    2027    {
    21       last = sv;
    22       for (i = 0; i < sv->n; ++i)
    23         if (!(sv->vec[i]._flags & (_IOOPEN|_IONEW)))
    24           {
    25             sv->vec[i]._flags = _IONEW;
    26 
    27             /* Initialize new members to support dynamically linked
    28                old executables with, say, -lvideo.  See also below. */
    29 
    30             sv->vec[i]._more = 0;
    31             sv->vec[i]._mbstate = 0;
    32 
    33             STREAMV_UNLOCK;
    34             return &sv->vec[i];
    35           }
    36     }
    37 
    38   /* Enlarge our tables.  As the entries must not move, we add another
    39      segment. */
    40 
    41   sv = malloc (sizeof (*sv));
    42   if (sv != NULL)
    43     {
    44       struct _FILE *fv;
    45 
    46       fv = malloc (INC * sizeof (*fv));
    47       if (fv == NULL)
    48         free (sv);
    49       else
     28        for (i = 0; i < pSV->n; ++i)
    5029        {
    51           for (i = 0; i < INC; ++i)
    52             fv[i]._flags = 0;
    53           sv->next = NULL;
    54           sv->vec = fv;
    55           sv->n = INC;
    56 
    57           /* See above. */
    58           fv[0]._flags = _IONEW;
    59           fv[0]._more = 0;
    60           fv[0]._mbstate = 0;
    61 
    62           last->next = sv;      /* Done as last step, see fflush() */
    63 
    64           STREAMV_UNLOCK;
    65           return &fv[0];
    66         }
    67     }
    68 
    69   STREAMV_UNLOCK;
    70   return NULL;
    71 }
    72 
    73 int _setmore (FILE *stream, int lock)
    74 {
    75   int i;
    76   struct _file2 *p;
    77   struct streamvec2 *sv2, *last = NULL;
    78 
    79   stream->_mbstate = 0;
    80   stream->_more = NULL;
    81   if (lock)
    82     STREAMV_LOCK;
    83   p = NULL;
    84   for (sv2 = &_streamvec2_head; sv2 != NULL; sv2 = sv2->next)
    85     {
    86       last = sv2;
    87       for (i = 0; i < sv2->n; ++i)
    88         if (sv2->vec[i].owner == NULL)
    89           {
    90             p = &sv2->vec[i];
    91             goto super_break;
    92           }
    93     }
    94 super_break:
    95   if (p == NULL)
    96     {
    97       sv2 = malloc (sizeof (*sv2));
    98       if (sv2 != NULL)
    99         {
    100           struct _file2 *fv2;
    101 
    102           fv2 = malloc (INC * sizeof (*fv2));
    103           if (fv2 == NULL)
    104             free (sv2);
    105           else
     30            if (!(pSV->vec[i]._flags & (_IOOPEN|_IONEW)))
    10631            {
    107               for (i = 0; i < INC; ++i)
    108                 fv2[i].owner = NULL;
    109               sv2->next = NULL;
    110               sv2->vec = fv2;
    111               sv2->n = INC;
    112               last->next = sv2;
    113               p = &sv2->vec[0];
     32                pSV->vec[i]._flags = _IONEW;
     33                STREAMV_UNLOCK;
     34                return &pSV->vec[i];
    11435            }
    11536        }
    11637    }
    117   if (p != NULL)
    118     p->owner = stream;
    119   if (lock)
    12038    STREAMV_UNLOCK;
    121   if (p == NULL || _rmutex_create (&p->rsem, 0) != 0)
     39
     40    /*
     41     * Enlarge our table.
     42     * (As the entries must not move, we add another segment.)
     43     */
     44    pSVNew = _hcalloc(1, sizeof(*pSV) + 15
     45                      + INC * sizeof(struct _FILE)
     46                      + 15
     47                      + INC * sizeof(struct _file2));
     48    if (pSVNew)
    12249    {
    123       /* Note that stream->_more is NULL. */
     50        struct _FILE       *pFile;
     51        struct _file2      *pFile2;
    12452
    125       _closestream (stream);
    126       if (p != NULL)
    127         p->owner = NULL;
    128       return -1;
     53        /*
     54         * Init the structures in the segment.
     55         * Remember everything is ZEROed by calloc()!
     56         */
     57        pSVNew->vec = pFile = (struct _FILE  *)ALIGN(pSVNew + 1, 16);
     58        pFile2              = (struct _file2 *)ALIGN(&pFile[INC], 16);
     59        pSVNew->vec         = pFile;
     60        pSVNew->n           = INC;
     61        for (i = 0; i < INC; i++, pFile++, pFile2++)
     62        {
     63            pFile2->owner = pFile; /* obsolete? */
     64            pFile->_more = pFile2;
     65        }
     66
     67        /*
     68         * Allocate the first one.
     69         */
     70        pFile = &pSV->vec[0];
     71        pFile->_flags = _IONEW;
     72
     73        /*
     74         * Insert the new chunk.
     75         */
     76        STREAMV_LOCK;
     77        if (_streamvec_head)
     78        {
     79            for (pSV = _streamvec_head; pSV; pSV = pSV->next)
     80                if (!pSV->next)
     81                {
     82                    pSV->next = pSVNew;
     83                    break;
     84                }
     85        }
     86        else
     87            /* Someone fopen'ed something before streams were initated. */
     88            _streamvec_head = pSVNew;
     89        STREAMV_UNLOCK;
     90        return pFile;
    12991    }
    130   stream->_more = p;
    131   return 0;
     92
     93    return NULL;
    13294}
    13395
     96/**
     97 * This used to set the _more member, but now it only create the mutex and
     98 * init _mbstate.
     99 *
     100 * @returns 0 on success.
     101 * @returns -1 on failure
     102 * @param   stream  Stream to init.
     103 * @param   lock    Ignored.
     104 */
     105int _setmore(FILE *stream, int lock)
     106{
     107    /*
     108     * Now this isn't so much work any longer, the streams are
     109     * allocated with a more buffer by default now.
     110     * All we gotta do is init _mbstate and create the mutex.
     111     */
     112    stream->_mbstate = 0;
     113    if (_rmutex_create(&stream->_more->rsem, 0) != 0)
     114    {
     115        /* free the stream */
     116        stream->_flags = 0;
     117        lock = lock;
     118        return -1;
     119    }
     120    return 0;
     121}
     122
     123/**
     124 * This is used when creating a special stream for instance in vsprintf().
     125 *
     126 * @param   stream  Special stream.
     127 * @param   more    Dummy more block
     128 */
    134129void _setdummymore (FILE *stream, struct _file2 *more)
    135130{
    136   stream->_mbstate = 0;
    137   stream->_more = more;
    138   more->owner = stream;
    139   _rmutex_dummy (&more->rsem);
     131    stream->_mbstate = 0;
     132    stream->_more = more;
     133    more->owner = stream;
     134    _rmutex_dummy(&more->rsem);
    140135}
    141136
    142 void _closestream (FILE *stream)
     137
     138/**
     139 * Closes a stream freeing the associated mutex semaphore.
     140 *
     141 * @param   stream  Stream to close.
     142 */
     143void _closestream(FILE *stream)
    143144{
    144   if (stream->_more != NULL && stream->_more->owner == stream)
    145     {
    146       _rmutex_close (&stream->_more->rsem);
    147       stream->_more->owner = NULL;
    148     }
    149   stream->_flags = 0;
     145    if (    stream->_more != NULL
     146        &&  stream->_more->owner == stream) /* paranoia */
     147        _rmutex_close(&stream->_more->rsem);
     148    stream->_flags = 0;
    150149}
  • trunk/src/emx/src/lib/io/_rmtmp.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r870 r871  
    1717
    1818  n = 0;
    19   for (sv = &_streamvec_head; sv != NULL; sv = sv->next)
     19  for (sv = _streamvec_head; sv != NULL; sv = sv->next)
    2020    for (i = 0; i < sv->n; ++i)
    2121      if ((sv->vec[i]._flags & _IOOPEN) && (sv->vec[i]._flags & _IOTMP)
  • trunk/src/emx/src/lib/io/_vsopen.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    3838     * 16 - 23  __open flags, _SO_*
    3939     */
    40     int     fFlags;
    41     int    *pfFlags;
    42     int     saved_errno;
    43     int     bits;
    44     char    chDummy;
    45     int     fCtrlZKludge = 0;
    46     off_t   cbInitial;
     40    int         fFlags;
     41    unsigned    fLibc;                  /* LIBC handle flags. */
     42    int         saved_errno;
     43    char        chDummy;
     44    int         fCtrlZKludge = 0;
     45    off_t       cbInitial;
     46    PLIBCFH     pFH;
    4747
    4848    /*
     
    5858     * Build fFlags.
    5959     */
    60     bits = fOpen & (O_ACCMODE|O_NDELAY|O_APPEND);
    61     if (fOpen & O_BINARY)
    62         /* do nothing */;
    63     else if (fOpen & O_TEXT)
    64         bits |= O_TEXT;
    65     else if (_fmode_bin == 0)          /* neither O_TEXT nor O_BINARY given */
    66         bits |= O_TEXT;
     60    fLibc = fOpen & (O_ACCMODE|O_NDELAY|O_APPEND|O_SYNC/*|O_DIRECT*/|O_NOINHERIT);
     61    if (   !(fOpen & O_BINARY)
     62        && ((fOpen & O_TEXT) || !_fmode_bin))
     63        fLibc |= O_TEXT;
    6764
    68     if ((bits & O_TEXT) && (fOpen & O_APPEND) && (fOpen & O_ACCMODE) == O_WRONLY)
     65    if ((fLibc & O_TEXT) && (fOpen & O_APPEND) && (fOpen & O_ACCMODE) == O_WRONLY)
    6966    {
    7067        /* The caller requests to open a text file for appending in
     
    113110     */
    114111    saved_errno = errno;
    115     hFile = __open(pszName, fFlags, cbInitial);
     112    hFile = __open(pszName, fFlags, cbInitial, fLibc, &pFH);
    116113    if (hFile < 0 && fCtrlZKludge && errno == EACCES)
    117114    {
     
    120117        fCtrlZKludge = 0;
    121118        fFlags = (fFlags & ~O_ACCMODE) | (fOpen & O_ACCMODE);
    122         hFile = __open(pszName, fFlags, cbInitial);
     119        hFile = __open(pszName, fFlags, cbInitial, fLibc, &pFH);
    123120    }
    124121    if (hFile < 0)
    125122        return -1;
     123    fLibc = pFH->fFlags;                /* get the updated flags. */
    126124
    127125    /*
    128126     * Check what we got a handle to.
    129127     */
    130     if (__ioctl1(hFile, 0) & 0x80)
    131     {
    132         bits |= F_DEV;
     128    if ((fLibc & F_TYPEMASK) == F_DEV)
    133129        fOpen &= ~O_APPEND;
    134     }
    135130
    136131    /*
    137132     * For text files we shall remove eventual ending Ctrl-Z.
    138133     */
    139     if (!(bits & F_DEV) && (bits & O_TEXT))
     134    if (    (fLibc & F_TYPEMASK) != F_DEV
     135        &&  (fLibc & O_TEXT))
    140136    {
    141137        off_t cbSize;
     
    163159        fFlags = (fFlags & ~O_ACCMODE) | (fOpen & O_ACCMODE);
    164160        fFlags &= ~_SO_EXCL;       /* Ignore O_EXCL */
    165         hFile = __open(pszName, fFlags, cbInitial);
     161        hFile = __open(pszName, fFlags, cbInitial, fLibc & ~F_TYPEMASK, &pFH);
    166162        if (hFile < 0)
    167163            return -1;
     
    169165
    170166    /*
    171      * Set file bits.
    172      */
    173     pfFlags = _fd_init(hFile);
    174     if (!pfFlags)
    175     {
    176         __close(hFile);
    177         errno = EMFILE;
    178         return -1;
    179     }
    180     *pfFlags = bits;
    181 
    182     /*
    183167     * When opening a file for appending, move to the end of the file.
    184168     * This is required for passing the file to a child process.
    185169     */
    186     if (!(bits & F_DEV) && (bits & O_APPEND))
     170    if (    (fLibc & F_TYPEMASK) == F_FILE
     171        &&  (fLibc & O_APPEND))
    187172        __lseek(hFile, 0L, SEEK_END);
    188173    errno = saved_errno;
  • trunk/src/emx/src/lib/io/chsize.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1010int _STD(chsize) (int handle, off_t length)
    1111{
     12  PLIBCFH   pFH;
    1213  off_t n;
    13   off_t i;
    14   int j, *pflags;
    15   char zeros[4096];
    1614
    17   if ((pflags = _fd_flags (handle)) == NULL || (*pflags & F_DEV))
     15  pFH = __libc_FH(handle);
     16  if (   !pFH
     17      || (pFH->fFlags & F_DEV)
     18      || pFH->pOps)
    1819    {
    1920      errno = EBADF;
     
    2728  if (n < length)
    2829    {
     30      off_t i;
     31      int   j;
     32      char  zeros[4096];
    2933      memset (zeros, 0, sizeof (zeros));
    3034      if (__lseek (handle, n, SEEK_SET) == -1)
  • trunk/src/emx/src/lib/io/close.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* close.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
     1/* close.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
     2                     -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
    45#include <io.h>
    5 #include <errno.h>
    66#include <emx/io.h>
    7 #include <emx/syscalls.h>
    87
    9 int _STD(close) (int handle)
     8int _STD(close)(int fh)
    109{
    11   if (_fd_flags (handle) == NULL)
    12     {
    13       errno = EBADF;
    14       return -1;
    15     }
    16   return __close (handle);
     10    int rc;
     11    rc = __libc_FHClose(fh);
     12    if (!rc)
     13        return 0;
     14    /* (it sets errno) */
     15    return -1;
    1716}
  • trunk/src/emx/src/lib/io/dup.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* dup.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* dup.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                   -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
    45#include <io.h>
    5 #include <errno.h>
    6 #include <emx/io.h>
    76#include <emx/syscalls.h>
    87
    9 int _STD(dup) (int handle)
     8int _STD(dup)(int fh)
    109{
    11   int new, *pflags1, *pflags2, *pla1, *pla2;
    12 
    13   if ((pflags1 = _fd_flags (handle)) == NULL
    14    || (pla1 = _fd_lookahead (handle)) == NULL)
    15     {
    16       errno = EBADF;
    17       return -1;
    18     }
    19   new = __dup (handle);
    20   if (new < 0)
    21     return new;
    22   if ((pflags2 = _fd_init (new)) == NULL
    23       || (pla2 = _fd_lookahead (new)) == NULL)
    24     {
    25       close (new);
    26       errno = EMFILE;
    27       return -1;
    28     }
    29   *pflags2 = *pflags1;
    30   *pla2 = *pla1;
    31   return new;
     10    return __dup(fh);
    3211}
  • trunk/src/emx/src/lib/io/dup2.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* dup2.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* dup2.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                    -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
    45#include <io.h>
    5 #include <errno.h>
    6 #include <emx/io.h>
    76#include <emx/syscalls.h>
    87
    9 int _STD(dup2) (int handle1, int handle2)
     8int _STD(dup2)(int handle1, int handle2)
    109{
    11   int *pflags1, *pflags2, *pla1, *pla2;
    12 
    13   if ((pflags1 = _fd_flags (handle1)) == NULL
    14    || (pla1 = _fd_lookahead (handle1)) == NULL
    15    || handle2 < 0)
    16     {
    17       errno = EBADF;
    18       return -1;
    19     }
    2010  /* TODO: Block signals */
    21   if (__dup2 (handle1, handle2) < 0)
     11  if (__dup2(handle1, handle2) < 0)
    2212    return -1;
    23 
    24   if ((pflags2 = _fd_init (handle2)) == NULL
    25    || (pla2 = _fd_lookahead (handle2)) == NULL)
    26     {
    27       /* TODO: Unfortunately, the original HANDLE2, if there was one,
    28          is now closed. */
    29       close (handle2);
    30       errno = EMFILE;
    31       return -1;
    32     }
    33 
    34   *pflags2 = *pflags1;
    35   *pla2 = *pla1;
    3613  return handle2;
    3714}
  • trunk/src/emx/src/lib/io/eof.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r870 r871  
    88int _STD(eof) (int handle)
    99{
    10   int *pflags;
     10  PLIBCFH   pFH;
    1111  off_t cur, len;
    1212
    13   if ((pflags = _fd_flags (handle)) == NULL)
    14     {
     13  /*
     14   * Get filehandle.
     15   */
     16  pFH = __libc_FH(handle);
     17  if (!pFH)
     18  {
    1519      errno = EBADF;
    1620      return -1;
    17     }
    18   if (*pflags & F_EOF)          /* Ctrl-Z reached */
     21  }
     22  if (pFH->fFlags & F_EOF)          /* Ctrl-Z reached */
    1923    return 1;
    2024  cur = tell (handle);
  • trunk/src/emx/src/lib/io/fcloseal.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    77int _fcloseall (void)
    88{
    9   int i, n, start;
     9  int i, n;
    1010  char ok;
    1111  struct streamvec *sv;
    1212
    1313  n = 0; ok = 1;
    14   for (sv = &_streamvec_head; sv != NULL; sv = sv->next)
     14  for (sv = _streamvec_head; sv != NULL; sv = sv->next)
    1515    {
    16       if (sv->vec == _streamv)
    17         start = 3;              /* Keep stdin, stdout, stderr */
    18       else
    19         start = 0;
    20       for (i = start; i < sv->n; ++i)
     16      for (i = sv->vec == stdin ? 3 : 0; /* Keep stdin, stdout, stderr */
     17           i < sv->n;
     18           ++i)
    2119        if (sv->vec[i]._flags & _IOOPEN)
    2220          {
     
    2624              ok = 0;
    2725          }
    28       start = 0;
    2926    }
    3027  return (ok ? n : EOF);
  • trunk/src/emx/src/lib/io/fcntl.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r870 r871  
    1 /* fcntl.c (emx+gcc) -- Copyright (c) 1992-1998 by Eberhard Mattes */
     1/* fcntl.c (emx+gcc) -- Copyright (c) 1992-1998 by Eberhard Mattes
     2                     -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    2829
    2930  /* TODO: Use sysconf()? */
     31  /** @todo Define a max handles or something */
    3032
    3133  if (handle2 < 0 || handle2 >= _POSIX_OPEN_MAX)
     
    6365{
    6466  va_list va;
    65   int ht, arg, *pflags;
     67  int arg;
     68  PLIBCFH   pFH;
    6669
    67   if ((pflags = _fd_flags (handle)) == NULL)
    68     {
     70  /*
     71   * Get filehandle.
     72   */
     73  pFH = __libc_FH(handle);
     74  if (!pFH)
     75  {
    6976      errno = EBADF;
    7077      return -1;
    71     }
     78  }
     79
     80  /** @todo Let __fcntl handle the flags. */
     81
    7282  switch (request)
    7383    {
    7484    case F_GETFL:
    75       /* Check for valid handle.  We don't call __fcntl() because
    76          emx.exe does not implement F_GETFL (emx.dll and rsx.exe
    77          do). */
    78 
    79       if (__ioctl2 (handle, FGETHTYPE, (int)&ht) != 0)
    80         return -1;
    81       return *pflags & FLAGS;
    82 
     85      return __fcntl(handle, request, 0);
    8386    case F_SETFL:
    8487      va_start (va, request);
     
    8992      if (__fcntl (handle, request, arg) == -1)
    9093        return -1;
    91       SETBITS (*pflags, FLAGS, arg);
     94      SETBITS (pFH->fFlags, FLAGS, arg);
    9295      return 0;
    9396
  • trunk/src/emx/src/lib/io/fdopen.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1919  int omode;
    2020
    21   if (_fd_flags (handle) == NULL)
     21  if (!__libc_FH(handle))
    2222    {
    2323      errno = EBADF;
  • trunk/src/emx/src/lib/io/fflush.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    7373  if (stream == NULL)
    7474    {
    75       for (sv = &_streamvec_head; sv != NULL; sv = sv->next)
     75      for (sv = _streamvec_head; sv != NULL; sv = sv->next)
    7676        for (n = 0; n < sv->n; ++n)
    7777          if ((sv->vec[n]._flags & (_IOOPEN|_IOWRT)) == (_IOOPEN|_IOWRT))
  • trunk/src/emx/src/lib/io/flushall.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1818
    1919  n = 0;
    20   for (sv = &_streamvec_head; sv != NULL; sv = sv->next)
     20  for (sv = _streamvec_head; sv != NULL; sv = sv->next)
    2121    for (i = 0; i < sv->n; ++i)
    2222      if ((sv->vec[i]._flags & _IOOPEN) && STREAM_LOCK_NOWAIT (&sv->vec[i]))
  • trunk/src/emx/src/lib/io/fseek.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1313int _fseek_nolock (FILE *stream, off_t offset, int origin)
    1414{
    15   off_t cur_pos;
    16   int fflush_result, *pflags;
     15  off_t     cur_pos;
     16  int       fflush_result;
     17  PLIBCFH   pFH;
    1718
    1819  if (!(stream->_flags & _IOOPEN) || origin < 0 || origin > 2
     
    5556          origin = SEEK_SET;
    5657        }
    57       text_mode = ((pflags = _fd_flags (stream->_handle)) != NULL
    58                    && (*pflags & F_CRLF));
     58      text_mode = (   (pFH = __libc_FH (stream->_handle)) != NULL
     59                   && (pFH->fFlags & F_CRLF));
    5960      n = stream->_ptr - stream->_buffer;
    6061      if (text_mode)
  • trunk/src/emx/src/lib/io/ftell.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1313off_t _ftell_nolock (FILE *stream)
    1414{
    15   off_t pos;
    16   int * pflags;
     15  off_t     pos;
     16  PLIBCFH   pFH;
    1717
    1818  if (stream->_flags & _IOSPECIAL)
     
    3030          pos += stream->_ptr - stream->_buffer;
    3131          if (!(stream->_flags & _IOSPECIAL)
    32               && (pflags = _fd_flags (stream->_handle)) != NULL
    33               && (*pflags & O_TEXT))
     32              && (pFH = __libc_FH (stream->_handle)) != NULL
     33              && (pFH->fFlags & O_TEXT))
    3434            {
    3535              const char *p;
     
    5858      if (!(stream->_flags & _IOSPECIAL)
    5959          && stream->_ungetc_count == 0
    60           && (pflags = _fd_flags (stream->_handle)) != NULL
    61           && (*pflags & F_CRLF))
     60          && (pFH = __libc_FH (stream->_handle)) != NULL
     61          && (pFH->fFlags & F_CRLF))
    6262        {
    6363          const char *p;
  • trunk/src/emx/src/lib/io/ftruncat.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1 /* ftruncat.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
     1/* ftruncat.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
     2                        -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    910int _STD(ftruncate) (int handle, off_t length)
    1011{
    11   int *pflags;
     12    PLIBCFH pFH;
    1213
    13   if ((pflags = _fd_flags (handle)) == NULL || (*pflags & F_DEV))
     14    /*
     15     * Get filehandle.
     16     */
     17    pFH = __libc_FH(handle);
     18    if (!pFH)
    1419    {
    15       errno = EBADF;
    16       return -1;
     20        errno = EBADF;
     21        return -1;
    1722    }
    18   return __ftruncate (handle, length);
     23/** @todo check this api with latest specs - there is a zero fill extension now IIRC. */
     24    if ((pFH->fFlags & F_TYPEMASK) != F_FILE)
     25    {
     26        errno = EBADF;
     27        return -1;
     28    }
     29    return __ftruncate (handle, length);
    1930}
  • trunk/src/emx/src/lib/io/ioctl.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r870 r871  
    1 /* ioctl.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
     1/* ioctl.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
     2                     -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    1920int _STD(ioctl) (int handle, unsigned long request, ...)
    2021{
    21   va_list va;
    22   int rc, saved_errno, arg, *int_ptr, *pflags, *pla;
    23   const struct termio *tp;
     22    va_list     va;
     23    PLIBCFH     pFH;
     24    int         rc, saved_errno, arg, *int_ptr;
     25    const struct termio *tp;
    2426
    25   if ((pflags = _fd_flags (handle)) == NULL)
     27    /*
     28     * Get filehandle.
     29     */
     30    pFH = __libc_FH(handle);
     31    if (!pFH)
    2632    {
    27       errno = EBADF;
    28       return -1;
     33        errno = EBADF;
     34        return -1;
    2935    }
    30   saved_errno = errno; errno = 0;
    31   va_start (va, request);
    32   arg = va_arg (va, int);
    33   va_end (va);
    34   rc = __ioctl2 (handle, request, arg);
    35   if (rc >= 0 && errno == 0)
    36     switch (__IOCLW(request))
    37       {
    38       case __IOCLW(TCSETAF):
    39       case __IOCLW(TCSETAW):
    40       case __IOCLW(TCSETA):
    41         va_start (va, request);
    42         tp = va_arg (va, const struct termio *);
    43         va_end (va);
    44         if (tp->c_lflag & IDEFAULT)
    45           *pflags &= ~F_TERMIO;
    46         else
    47           *pflags |= F_TERMIO;
    48         break;
    4936
    50       case __IOCLW(_TCSANOW):
    51       case __IOCLW(_TCSADRAIN):
    52       case __IOCLW(_TCSAFLUSH):
    53         *pflags |= F_TERMIO;
    54         break;
     37    /*
     38     * Make syscall.
     39     */
     40    saved_errno = errno; errno = 0;
     41    va_start (va, request);
     42    arg = va_arg(va, int);
     43    va_end (va);
     44    rc = __ioctl2(handle, request, arg);
    5545
    56       case __IOCLW(FIONREAD):
    57         if ((pla = _fd_lookahead (handle)) != NULL && *pla >= 0)
    58           {
    59             va_start (va, request);
    60             int_ptr = va_arg (va, int *);
    61             va_end (va);
    62             ++(*int_ptr);
    63           }
    64         break;
     46    /*
     47     * On success do small touches of our own.
     48     */
     49    /** @todo fFlags can be handled by the syscall just as well as here..*/
     50    if (rc >= 0 && errno == 0)
     51    {
     52        switch (__IOCLW(request))
     53        {
     54            case __IOCLW(TCSETAF):
     55            case __IOCLW(TCSETAW):
     56            case __IOCLW(TCSETA):
     57                va_start(va, request);
     58                tp = va_arg(va, const struct termio *);
     59                va_end(va);
     60                if (tp->c_lflag & IDEFAULT)
     61                    pFH->fFlags &= ~F_TERMIO;
     62                else
     63                    pFH->fFlags |= F_TERMIO;
     64                break;
    6565
    66       case __IOCLW(FIONBIO):
    67         va_start (va, request);
    68         int_ptr = va_arg (va, int *);
    69         va_end (va);
    70         if (*int_ptr)
    71           *pflags |= O_NDELAY;
    72         else
    73           *pflags &= ~O_NDELAY;
    74         break;
    75       }
    76   if (errno == 0)
    77     errno = saved_errno;
    78   return rc;
     66            case __IOCLW(_TCSANOW):
     67            case __IOCLW(_TCSADRAIN):
     68            case __IOCLW(_TCSAFLUSH):
     69                pFH->fFlags |= F_TERMIO;
     70                break;
     71
     72            case __IOCLW(FIONREAD):
     73                if (pFH->iLookAhead >= 0)
     74                {
     75                    va_start(va, request);
     76                    int_ptr = va_arg(va, int *);
     77                    va_end(va);
     78                    ++(*int_ptr);
     79                }
     80                break;
     81
     82            case __IOCLW(FIONBIO):
     83                va_start(va, request);
     84                int_ptr = va_arg(va, int *);
     85                va_end(va);
     86                if (*int_ptr)
     87                    pFH->fFlags |= O_NDELAY;
     88                else
     89                    pFH->fFlags &= ~O_NDELAY;
     90                break;
     91        } /* switch */
     92    }
     93    if (errno == 0)
     94        errno = saved_errno;
     95    return rc;
    7996}
  • trunk/src/emx/src/lib/io/isatty.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* isatty.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
     1/* isatty.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
     2                      -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    67#include <emx/io.h>
    78
    8 int _STD(isatty) (int handle)
     9int _STD(isatty)(int handle)
    910{
    10   int *pflags;
     11    PLIBCFH pFH;
    1112
    12   if ((pflags = _fd_flags (handle)) == NULL)
     13    /*
     14     * Get filehandle.
     15     */
     16    pFH = __libc_FH(handle);
     17    if (!pFH)
    1318    {
    14       errno = EBADF;
    15       return 0;
     19        errno = EBADF;
     20        return 0;
    1621    }
    17   else
    18     return ((*pflags & F_DEV) ? 1 : 0);
     22
     23    return (pFH->fFlags & F_TYPEMASK) == F_DEV;
    1924}
  • trunk/src/emx/src/lib/io/lseek.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r870 r871  
    99off_t _STD(lseek) (int handle, off_t offset, int origin)
    1010{
    11   int *pflags, *pla;
    12   off_t n, cur;
     11    PLIBCFH pFH;
     12    off_t   n;
    1313
    14   if ((pflags = _fd_flags (handle)) == NULL
    15       || (pla = _fd_lookahead (handle)) == NULL)
     14    /*
     15     * Get filehandle.
     16     */
     17    pFH = __libc_FH(handle);
     18    if (!pFH)
    1619    {
    17       errno = EBADF;
    18       return -1;
     20        errno = EBADF;
     21        return -1;
    1922    }
    20   if (origin == SEEK_CUR && (*pla >= 0 || (*pflags & F_EOF)))
    21     --offset;
    22   if (offset < 0)
     23
     24    if (    origin == SEEK_CUR
     25        && (    pFH->iLookAhead >= 0
     26            || (pFH->fFlags & F_EOF)) )
     27        --offset;
     28#if 0 /* not needed on OS/2 I think... */
     29    if (offset < 0)
    2330    {
    24       /* DOS doesn't return an error for seek before beginning of file */
    25       if (origin == SEEK_SET)
     31        off_t   cur;
     32        /* DOS doesn't return an error for seek before beginning of file */
     33        if (origin == SEEK_SET)
    2634        {
    27           errno = EINVAL;
    28           return -1;
     35            errno = EINVAL;
     36            return -1;
    2937        }
    30       cur = __lseek (handle, 0, SEEK_CUR);
    31       if (cur == -1L)
     38        cur = __lseek(handle, 0, SEEK_CUR);
     39        if (cur == -1L)
     40            return -1;
     41        n = __lseek(handle, 0, origin);
     42        if (n + offset < 0)
     43        {
     44            __lseek(handle, cur, SEEK_SET);
     45            errno = EINVAL;
     46            return -1;
     47        }
     48        offset += n;
     49        origin = SEEK_SET;
     50    }
     51#endif
     52    n = __lseek(handle, offset, origin);
     53    if (n == -1)
    3254        return -1;
    33       n = __lseek (handle, 0, origin);
    34       if (n + offset < 0)
    35         {
    36           __lseek (handle, cur, SEEK_SET);
    37           errno = EINVAL;
    38           return -1;
    39         }
    40       offset += n; origin = SEEK_SET;
    41     }
    42   n = __lseek (handle, offset, origin);
    43   if (n == -1)
    44     return -1;
    45   else
     55    else
    4656    {
    47       *pflags &= ~F_EOF;        /* Clear Ctrl-Z flag */
    48       *pla = -1;                /* Clear lookahead */
    49       return n;
     57        pFH->fFlags &= ~F_EOF;          /* Clear Ctrl-Z flag */
     58        pFH->iLookAhead = -1;           /* Clear lookahead */
     59        return n;
    5060    }
    5161}
  • trunk/src/emx/src/lib/io/pipe.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    99
    1010extern int _fmode_bin;
    11 int _pipe_size;
    1211
    13 int _STD(pipe) (int *two_handles)
     12/** The default pipe size. */
     13int     _pipe_size;
     14
     15int _STD(pipe)(int *two_handles)
    1416{
    15   int *pflags1, *pflags2;
     17    PLIBCFH pFHRead, pFHWrite;
    1618
    17   if (__pipe (two_handles, (_pipe_size != 0 ? _pipe_size : 8192)) != 0)
    18     return -1;
    19   pflags1 = _fd_init (two_handles[0]);
    20   if (pflags1 == NULL)
    21     pflags2 = NULL;
    22   else
    23     pflags2 = _fd_init (two_handles[1]);
    24   if (pflags2 == NULL)
     19    if (__pipe(two_handles, _pipe_size != 0 ? _pipe_size : 8192, &pFHRead, &pFHWrite) != 0)
     20        return -1;
     21
     22    /** @todo move _fmode_bin check to __pipe()? */
     23    if (!_fmode_bin)
    2524    {
    26       __close (two_handles[0]);
    27       __close (two_handles[1]);
    28       errno = EMFILE;
    29       return -1;
     25        pFHRead->fFlags  |= O_TEXT;
     26        pFHWrite->fFlags |= O_TEXT;
    3027    }
    31   *pflags1 = O_RDONLY | F_PIPE;
    32   *pflags2 = O_WRONLY | F_PIPE;
    33   if (_fmode_bin == 0)
    34     {
    35       *pflags1 |= O_TEXT;
    36       *pflags2 |= O_TEXT;
    37     }
    38   return 0;
     28
     29    return 0;
    3930}
  • trunk/src/emx/src/lib/io/popen.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    2929  const char *sh, *base, *opt;
    3030
    31   fcntl (pipe_local, F_SETFD, 1);
     31  fcntl (pipe_local, F_SETFD, FD_CLOEXEC);
    3232  org_private = fcntl (handle, F_GETFD, 0);
    3333  if (org_private == -1)
     
    3636  if (org_handle == -1)
    3737    return NULL;
    38   fcntl (org_handle, F_SETFD, 1);
     38  fcntl (org_handle, F_SETFD, FD_CLOEXEC);
     39
    3940  i = dup2 (pipe_remote, handle);
    4041  if (i != handle)
     
    9697  if (pipe (ph) == -1)
    9798    return NULL;
    98   if (fcntl (ph[0], F_SETFD, 1) == -1)
     99  if (fcntl (ph[0], F_SETFD, FD_CLOEXEC) == -1)
    99100    return NULL;
    100   if (fcntl (ph[1], F_SETFD, 1) == -1)
     101  if (fcntl (ph[1], F_SETFD, FD_CLOEXEC) == -1)
    101102    return NULL;
    102103  if (mode[0] == 'r')
  • trunk/src/emx/src/lib/io/read.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1313   unless O_NDELAY is in effect. */
    1414
    15 static int read_lookahead (int handle, void *buf, size_t nbyte, int *pla)
     15static int read_lookahead (int handle, void *buf, size_t nbyte, PLIBCFH pFH)
    1616{
    1717  int i, n, la, saved_errno;
     
    1919
    2020  i = 0; dst = buf; saved_errno = errno;
    21   if (nbyte > 0 && (la = __lxchg (pla, -1)) != -1)
     21  if (nbyte > 0 && (la = __lxchg (&pFH->iLookAhead, -1)) != -1)
    2222    {
    2323      *dst = (char)la;
     
    4040ssize_t _STD(read) (int handle, void *buf, size_t nbyte)
    4141{
    42   int n, *pflags, *pla;
    43   size_t j, k;
    44   char *dst, c;
     42  int       n;
     43  PLIBCFH   pFH;
     44  size_t    j, k;
     45  char     *dst, c;
    4546
    46   if ((pflags = _fd_flags (handle)) == NULL
    47       || (pla = _fd_lookahead (handle)) == NULL)
     47  /*
     48   * Get filehandle.
     49   */
     50  pFH = __libc_FH(handle);
     51  if (!pFH)
    4852    {
    4953      errno = EBADF;
     
    5155    }
    5256
    53   *pflags &= ~F_CRLF;           /* No CR/LF pair translated to newline */
    54   if (nbyte > 0 && (*pflags & F_EOF))
     57  pFH->fFlags &= ~F_CRLF;           /* No CR/LF pair translated to newline */
     58  if (nbyte > 0 && (pFH->fFlags & F_EOF))
    5559    return 0;
    5660  dst = buf;
    57   n = read_lookahead (handle, dst, nbyte, pla);
     61  n = read_lookahead (handle, dst, nbyte, pFH);
    5862  if (n == -1)
    5963    return -1;
    60   if ((*pflags & O_TEXT) && !(*pflags & F_TERMIO) && n > 0)
     64  if ((pFH->fFlags & O_TEXT) && !(pFH->fFlags & F_TERMIO) && n > 0)
    6165    {
    6266      /* special processing for text mode */
    63       if (!(*pflags & (F_PIPE|F_SOCKET|F_DEV)) && dst[n-1] == 0x1a &&
    64           eof (handle))
     67      if (  (pFH->fFlags & F_TYPEMASK) == F_FILE
     68          && dst[n-1] == 0x1a
     69          && eof (handle))
    6570        {
    6671          /* remove last Ctrl-Z in text files */
    6772          --n;
    68           *pflags |= F_EOF;
     73          pFH->fFlags |= F_EOF;
    6974          if (n == 0)
    7075            return 0;
     
    7782
    7883          int saved_errno = errno;
    79           j = read_lookahead (handle, &c, 1, pla); /* look ahead */
     84          j = read_lookahead (handle, &c, 1, pFH); /* look ahead */
    8085          if (j == -1 && errno == EAGAIN)
    8186            {
    82               *pla = '\r';
     87              pFH->iLookAhead = '\r';
    8388              return -1;
    8489            }
     
    8792            {
    8893              dst[0] = '\n';                  /* yes -> replace with LF */
    89               *pflags |= F_CRLF;
     94              pFH->fFlags |= F_CRLF;
    9095            }
    9196          else
    92             *pla = (unsigned char)c;          /* no -> save the 2nd char */
     97            pFH->iLookAhead = (unsigned char)c; /* no -> save the 2nd char */
    9398        }
    9499      else
     
    104109                 for F_CRLF logic. */
    105110
    106               *pla = '\r';
     111              pFH->iLookAhead = '\r';
    107112              --n;
    108113            }
    109114          if (k != n)
    110             *pflags |= F_CRLF;
     115            pFH->fFlags |= F_CRLF;
    111116          n = k;
    112117        }
  • trunk/src/emx/src/lib/io/readv.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1313int _STD(readv) (int handle, const struct iovec *iov, int iovcnt)
    1414{
     15/** @todo make readv a syscall so tcpip can do it's own handling. */
    1516  int i, n;
    1617  size_t total, len;
     
    3536
    3637  mp = NULL;
    37   if (total <= 0x100000)
     38  if (total <= 0x1000)
    3839    buf = alloca (total);
    3940  else
  • trunk/src/emx/src/lib/io/select.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r870 r871  
    1313                  fd_set *exceptfds, struct timeval *timeout)
    1414{
    15   struct _select args;
    16 
     15/** @todo rewrite select */
     16  struct _select args = {0,0,0,0,0};
     17#if 0
    1718  args.nfds = nfds;
    1819  args.readfds = readfds;
     
    6869        }
    6970    }
     71#endif
    7072  return __select (&args);
    7173}
  • trunk/src/emx/src/lib/io/setmode.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* setmode.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
     1/* setmode.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
     2                       -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    910int _STD(setmode) (int handle, int mode)
    1011{
    11   int old_mode, *pflags;
     12    PLIBCFH pFH;
     13    int     old_mode;
    1214
    13   if ((pflags = _fd_flags (handle)) == NULL)
     15    /*
     16     * Get filehandle.
     17     */
     18    pFH = __libc_FH(handle);
     19    if (!pFH)
    1420    {
    15       errno = EBADF;
    16       return -1;
     21        errno = EBADF;
     22        return -1;
    1723    }
    18   old_mode = ((*pflags & O_TEXT) ? O_TEXT : O_BINARY);
    19   if (mode == O_BINARY)
    20     *pflags &= ~O_TEXT;
    21   else if (mode == O_TEXT)
    22     *pflags |= O_TEXT;
    23   else
     24
     25    /*
     26     * O_BINARY isn't normally stored in the fFlags member.
     27     */
     28    old_mode = (pFH->fFlags & O_TEXT) ? O_TEXT : O_BINARY;
     29    if (mode == O_BINARY)
     30        pFH->fFlags &= ~O_TEXT;
     31    else if (mode == O_TEXT)
     32        pFH->fFlags = (pFH->fFlags & ~O_BINARY) | O_TEXT; /* paranoia */
     33    else
    2434    {
    25       errno = EINVAL;
    26       return -1;
     35        errno = EINVAL;
     36        return -1;
    2737    }
    28   return old_mode;
     38    return old_mode;
    2939}
  • trunk/src/emx/src/lib/io/tell.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    77#include <emx/syscalls.h>
    88
    9 off_t _STD(tell) (int handle)
     9off_t _STD(tell)(int handle)
    1010{
    11   int *pflags, *pla;
    12   off_t n;
     11    PLIBCFH pFH;
     12    off_t  n;
    1313
    14   if ((pflags = _fd_flags (handle)) == NULL
    15       || (pla = _fd_lookahead (handle)) == NULL)
     14    pFH = __libc_FH(handle);
     15    if (!pFH)
    1616    {
    17       errno = EBADF;
    18       return -1;
     17        errno = EBADF;
     18        return -1;
    1919    }
    20   n = __lseek (handle, 0L, SEEK_CUR);
    21   if (n == -1)
     20    n = __lseek(handle, 0L, SEEK_CUR);
     21    if (n == -1)
     22        return n;
     23    if (pFH->iLookAhead >= 0 || (pFH->fFlags & F_EOF))
     24        --n;
    2225    return n;
    23   if (*pla >= 0 || (*pflags & F_EOF))
    24     --n;
    25   return n;
    2626}
  • trunk/src/emx/src/lib/io/tmpnam.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1010char *_STD(tmpnam) (char *string)
    1111{
    12   struct _thread *tp = _thread ();
    13 
    1412  if (string == NULL)
    15     string = tp->_th_tmpnam_buf;
     13    {
     14      struct _thread *tp = _thread ();
     15      string = tp->_th_tmpnam_buf;
     16    }
    1617  if (_tmpidxnam (string) >= 0)
    1718    return string;
  • trunk/src/emx/src/lib/io/write.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    3535   Return -1 on error. */
    3636
    37 static int write_text (int handle, const char *src, size_t nbyte, int *pflags)
     37static int write_text (int handle, const char *src, size_t nbyte, PLIBCFH pFH)
    3838{
    3939  int out_cnt, lf_cnt, lf_cnt_1, buf_cnt, n;
     
    4444  out_cnt = lf_cnt = lf_cnt_1 = buf_cnt = 0;
    4545  buf_pos = 0; i = 0;
    46   if (*pflags & F_WRCRPEND)
     46  if (pFH->fFlags & F_WRCRPEND)
    4747    {
    4848      if (*src == '\n')
     
    6060             pipe. */
    6161
    62           *pflags &= ~F_WRCRPEND;
     62          pFH->fFlags &= ~F_WRCRPEND;
    6363        }
    6464    }
     
    7979    }
    8080  if (buf_cnt != 0) WRTBUF;
    81   *pflags &= ~F_WRCRPEND;
     81  pFH->fFlags &= ~F_WRCRPEND;
    8282  return out_cnt - lf_cnt;
    8383
     
    118118  if (splitp)
    119119    {
    120       if (*pflags & (F_DEV|F_SOCKET|F_PIPE))
    121         *pflags |= F_WRCRPEND;
     120      if ((pFH->fFlags & F_TYPEMASK) != F_FILE)
     121        pFH->fFlags |= F_WRCRPEND;
    122122      else
    123123        {
     
    133133    }
    134134  else
    135     *pflags &= ~F_WRCRPEND;
     135    pFH->fFlags &= ~F_WRCRPEND;
    136136  return out_cnt - lf_cnt_1;
    137137}
     
    140140int _STD(write) (int handle, const void *buf, size_t nbyte)
    141141{
    142   int n, *pflags;
     142  PLIBCFH   pFH;
     143  int       n;
    143144  const char *src;
    144145
    145   if ((pflags = _fd_flags (handle)) == NULL)
    146     {
    147       errno = EBADF; return -1;
    148     }
    149   if ((*pflags & (F_DEV|F_SOCKET|F_PIPE|O_APPEND)) == O_APPEND)
     146  /*
     147   * Get filehandle
     148   */
     149  pFH = __libc_FH(handle);
     150  if (!pFH)
     151  {
     152      errno = EBADF;
     153      return -1;
     154  }
     155
     156  if ((pFH->fFlags & (F_TYPEMASK | O_APPEND)) == (O_APPEND | F_FILE))
    150157    __lseek (handle, 0, SEEK_END);
    151158  if (nbyte == 0)                 /* Avoid truncation of file */
    152159    return 0;
    153160  src = buf;
    154   if ((*pflags & O_TEXT) && ((*pflags & F_WRCRPEND)
    155                              || memchr (src, '\n', nbyte) != NULL))
    156     n = write_text (handle, src, nbyte, pflags);
     161  if (    (pFH->fFlags & O_TEXT)
     162       && (   (pFH->fFlags & F_WRCRPEND)
     163           || memchr (src, '\n', nbyte) != NULL))
     164    n = write_text (handle, src, nbyte, pFH);
    157165  else
    158166    n = __write (handle, src, nbyte);
     
    174182         data to be written. */
    175183
    176       if ((*pflags & F_DEV) && *src == CTRL_Z)
     184      if (   (pFH->fFlags & F_TYPEMASK) == F_DEV
     185          && *src == CTRL_Z)
    177186        return 0;
    178187
     
    180189         EAGAIN. */
    181190
    182       if ((*pflags & (F_DEV|F_SOCKET|F_PIPE))
    183           && (*pflags & O_NONBLOCK))
     191      if (   (pFH->fFlags & O_NONBLOCK)
     192          && (   (pFH->fFlags & F_TYPEMASK) == F_DEV
     193              || (pFH->fFlags & F_TYPEMASK) == F_SOCKET /* ???? */
     194              || (pFH->fFlags & F_TYPEMASK) == F_PIPE) )
    184195        {
    185196          errno = EAGAIN;
  • trunk/src/emx/src/lib/io/writev.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1313int _STD(writev) (int handle, const struct iovec *iov, int iovcnt)
    1414{
     15/** @todo make syscall for this as we wanna let tcpip handle this it's own way. */
    1516  int i, n;
    1617  size_t total, len;
     
    3536
    3637  mp = NULL;
    37   if (total <= 0x100000)
     38  if (total <= 0x1000)
    3839    buf = alloca (total);
    3940  else
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.24 to 1.25
    r870 r871  
    1919EXPORTS
    2020; data
    21     "__std_daylight" @1
    22     "__fdvec_head" @2
    23     "__files" @3
    24     "__fmode_bin" @4
    25     "__io_ninherit" @5
    26     "__lookahead" @6
    27     "__mb_cur_max" @7
    28     "__org_environ" @8
    29     "__osmajor" @9
    30     "__osminor" @10
    31     "__pipe_size" @11
    32     "__std_environ" @12
    33     "__streamv" @13
    34     "__streamv_rmutex" @14
    35     "__streamvec2_head" @15
    36     "__streamvec_head" @16
    37     "__sys_clock0_ms" @17
    38     "__sys_heap_fmutex" @18
    39     "__sys_heap_obj_count" @19
    40     "__sys_heap_objs" @20
    41     "__sys_heap_size" @21
    42     "__sys_ino" @22
    43     "__sys_pid" @23
    44     "__sys_ppid" @24
    45     "__um_high_heap" @25
    46     "__sys_thread_table" @26
    47     "__sys_top_heap_obj" @27
    48     "__sys_uflags" @28
    49     "__sys_umask" @29
    50     "__sys_xreg" @30
    51     "__std_timezone" @31
    52     "__tmpidx" @32
    53     "__tzi" @33
    54     "__std_tzname" @34
    55     "__tzset_flag" @35
    56     "__um_regular_heap" @36
    57     "__um_tiled_heap" @37
    58     "_optarg" @38
    59     "_opterr" @39
    60     "_optind" @40
    61     "_optmode" @41
    62     "_optopt" @42
    63     "_optswchar" @43
    64     "__atexit_n" @44
    65     "__atexit_v" @45
    66     "__thread_tab" @46
    67     "___digits" @47
    68     "___locale" @48
    69     "___locale_C" @49
    70     "___locale_collate" @50
    71     "___locale_ctype" @51
    72     "___locale_lconv" @52
    73     "___locale_time" @53
    74     "__um_low_heap" @54
    75     "__rand48_add" @55
    76     "__rand48_mult" @56
    77     "__rand48_seed" @57
     21    "___digits" @1
     22    "___locale" @2
     23    "___locale_C" @3
     24    "___locale_collate" @4
     25    "___locale_ctype" @5
     26    "___locale_lconv" @6
     27    "___locale_time" @7
     28    "___stderrp" @8
     29    "___stdinp" @9
     30    "___stdoutp" @10
     31    "__atexit_n" @11
     32    "__atexit_v" @12
     33    "__fmode_bin" @13
     34    "__mb_cur_max" @14
     35    "__org_environ" @15
     36    "__osmajor" @16
     37    "__osminor" @17
     38    "__pipe_size" @18
     39    "__rand48_add" @19
     40    "__rand48_mult" @20
     41    "__rand48_seed" @21
     42    "__std_daylight" @22
     43    "__std_environ" @23
     44    "__std_timezone" @24
     45    "__std_tzname" @25
     46    "__streamv_rmutex" @26
     47    "__streamvec_head" @27
     48    "__thread_tab" @28
     49    "__tmpidx" @29
     50    "__tzi" @30
     51    "__tzset_flag" @31
     52    "__um_high_heap" @32
     53    "__um_low_heap" @33
     54    "__um_regular_heap" @34
     55    "__um_tiled_heap" @35
     56    "_optarg" @36
     57    "_opterr" @37
     58    "_optind" @38
     59    "_optmode" @39
     60    "_optopt" @40
     61    "_optswchar" @41
     62
    7863
    7964; code
    80     "__CRT_init" @100
    81     "__CRT_term" @101
    82     "___init" @102
    83     "___init_app" @103
    84     "___init_dll" @104
    85     "__fd_flags" @105
    86     "__fd_init" @106
    87     "__fd_lookahead" @107
    88     "__init1_fdinit" @108
    89     "__init1_tmp" @109
    90     "__std_posix_memalign" @110
    91     "__lrealloc" @111
    92     "__init_streams" @112
    93     "___initthread" @113
    94     "__emxload_connect" @114
    95     "__emxload_disconnect" @115
    96     "__emxload_do_connect" @116
    97     "__emxload_do_disconnect" @117
    98     "__emxload_do_receive" @118
    99     "__emxload_do_request" @119
    100     "__emxload_do_wait" @120
    101     "__emxload_env" @121
    102     "__emxload_list_get" @122
    103     "__emxload_list_start" @123
    104     "__emxload_prog" @124
    105     "__emxload_request" @125
    106     "__emxload_stop" @126
    107     "__emxload_this" @127
    108     "__emxload_unload" @128
    109     "__sys_init_thread" @129
    110     "__HUGE_VAL" @130
    111     "__LHUGE_VAL" @131
    112     "__abspath" @132
    113     "___alloc_thread" @133
    114     "__assert" @134
    115     "__year_day" @135
    116     "__tmalloc" @136
    117     "___atod" @137
    118     "__std_fprintf" @138
    119     "__std_printf" @139
    120     "__std_malloc" @140
    121     "__std_free" @141
    122     "__std_realloc" @142
    123     "__std_calloc" @143
    124     "__std_strdup" @144
    125     "__um_addmem_nolock" @145
    126     "__umalloc" @146
    127     "__um_alloc_no_lock" @147
    128     "__linitheap" @148
    129     "__um_crumb_free_maybe_lock" @149
    130     "__um_default_alloc" @150
    131     "__um_default_expand" @151
    132     "__um_default_release" @152
    133     "__um_default_shrink" @153
    134     "__um_find_bucket" @154
    135     "__um_free_maybe_lock" @155
    136     "__um_init_default_regular_heap" @156
    137     "__um_init_default_tiled_heap" @157
    138     "__um_lump_alloc" @158
    139     "__um_lump_coalesce_free" @159
    140     "__um_lump_free_maybe_lock" @160
    141     "__um_lump_link_heap" @161
    142     "__um_lump_make_free" @162
    143     "__um_lump_unlink_bucket" @163
    144     "__um_lump_unlink_heap" @164
    145     "__um_realloc" @165
    146     "__um_seg_addmem" @166
    147     "__um_seg_setmem" @167
    148     "__std_strcat" @168
    149     "__std_strchr" @169
    150     "__std_strcmp" @170
    151     "__std_strcoll" @171
    152     "__std_strcpy" @172
    153     "__std_strcspn" @173
    154     "__std_strerror" @174
    155     "__std_strftime" @175
    156     "__std_stricmp" @176
    157     "__std_strlen" @177
    158     "__std_strlwr" @178
    159     "__std_strncat" @179
    160     "__std_strncmp" @180
    161     "__std_strncpy" @181
    162     "__std_strnicmp" @182
    163     "__std_strnset" @183
    164     "__std_strpbrk" @184
    165     "__std_strptime" @185
    166     "__std_strrchr" @186
    167     "__std_strrev" @187
    168     "__std_strset" @188
    169     "__std_strspn" @189
    170     "__std_strstr" @190
    171     "__std_strtod" @191
    172     "__std_strtof" @192
    173     "__std_strtok" @193
    174     "__std_strtol" @194
    175     "__std_strtold" @195
    176     "__std_strtoul" @196
    177     "__std_strupr" @197
    178     "__std_strxfrm" @198
    179     "__std_abort" @199
    180     "__std_abs" @200
    181     "__std_access" @201
    182     "__std_acos" @202
    183     "__std_asctime" @203
    184     "__std_asin" @204
    185     "__std_atan" @205
    186     "__std_atan2" @206
    187     "__std_atexit" @207
    188     "__std_atof" @208
    189     "__std_atofl" @209
    190     "__std_atoi" @210
    191     "__std_atol" @211
    192     "__std_atoll" @212
    193     "__std_bcmp" @213
    194     "__std_bcopy" @214
    195     "__std_brk" @215
    196     "__std_bsearch" @216
    197     "__std_bzero" @217
    198     "__std_cbrt" @218
    199     "__std_ceil" @219
    200     "__std_chdir" @220
    201     "__std_chdrive" @221
    202     "__std_chmod" @222
    203     "__std_chsize" @223
    204     "__std_clearerr" @224
    205     "__std_clock" @225
    206     "__std_close" @226
    207     "__std_closedir" @227
    208     "__std_cos" @228
    209     "__std_cosh" @229
    210     "__std_creat" @230
    211     "__std_ctime" @231
    212     "__std_cuserid" @232
    213     "__std_difftime" @233
    214     "__std_div" @234
    215     "__std_dup" @235
    216     "__std_dup2" @236
    217     "__std_endpwent" @237
    218     "__std_eof" @238
    219     "__std_execl" @239
    220     "__std_execle" @240
    221     "__std_execlp" @241
    222     "__std_execlpe" @242
    223     "__std_execv" @243
    224     "__std_execve" @244
    225     "__std_execvp" @245
    226     "__std_execvpe" @246
    227     "__std_exit" @247
    228     "__std_exp" @248
    229     "__std_expand" @249
    230     "__std_fabs" @250
    231     "__std_fclose" @251
    232     "__std_fcntl" @252
    233     "__std_fdopen" @253
    234     "__std_feof" @254
    235     "__std_ferror" @255
    236     "__std_fflush" @256
    237     "__std_ffs" @257
    238     "__std_fgetc" @258
    239     "__std_fgetchar" @259
    240     "__std_fgetpos" @260
    241     "__std_fgets" @261
    242     "__std_filelength" @262
    243     "__std_fileno" @263
    244     "__std_flock" @264
    245     "__std_floor" @265
    246     "__std_flushall" @266
    247     "__std_fmod" @267
    248     "__std_fnmatch" @268
    249     "__std_fopen" @269
    250     "__std_fork" @270
    251     "__std_fpathconf" @271
    252     "__std_fputc" @272
    253     "__std_fputchar" @273
    254     "__std_fputs" @274
    255     "__std_fread" @275
    256     "__std_freopen" @276
    257     "__std_frexp" @277
    258     "__std_fscanf" @278
    259     "__std_fseek" @279
    260     "__std_fsetpos" @280
    261     "__std_fstat" @281
    262     "__std_fsync" @282
    263     "__std_ftell" @283
    264     "__std_ftime" @284
    265     "__std_ftruncate" @285
    266     "__std_ftw" @286
    267     "__std_fwrite" @287
    268     "__std_gcvt" @288
    269     "__std_getchar" @289
    270     "__std_getcwd" @290
    271     "__std_getenv" @291
    272     "__std_getgid" @292
    273     "__std_getgrnam" @293
    274     "__std_getgroups" @294
    275     "__std_getlogin" @295
    276     "__std_getopt" @296
    277     "__std_getpagesize" @297
    278     "__std_getpass" @298
    279     "__std_getpgrp" @299
    280     "__std_getpid" @300
    281     "__std_getppid" @301
    282     "__std_getpw" @302
    283     "__std_getpwent" @303
    284     "__std_getpwnam" @304
    285     "__std_getpwuid" @305
    286     "__std_gets" @306
    287     "__std_gettimeofday" @307
    288     "__std_getuid" @308
    289     "__std_getw" @309
    290     "__std_getwd" @310
    291     "__std_gmtime" @311
    292     "__std_index" @312
    293     "__std_ioctl" @313
    294     "__std_isatty" @314
    295     "__std_kill" @315
    296     "__std_labs" @316
    297     "__std_ldexp" @317
    298     "__std_ldiv" @318
    299     "__std_localtime" @319
    300     "__std_log" @320
    301     "__std_log10" @321
    302     "__std_longjmp" @322
    303     "__std_lseek" @323
    304     "__std_mblen" @324
    305     "__std_mbstowcs" @325
    306     "__std_mbtowc" @326
    307     "__std_memccpy" @327
    308     "__std_memchr" @328
    309     "__std_memcmp" @329
    310     "__std_memcpy" @330
    311     "__std_memicmp" @331
    312     "__std_memmove" @332
    313     "__std_memset" @333
    314     "__std_mkdir" @334
    315     "__std_mkstemp" @335
    316     "__std_mktemp" @336
    317     "__std_mktime" @337
    318     "__std_modf" @338
    319     "__std_open" @339
    320     "__std_opendir" @340
    321     "__std_pathconf" @341
    322     "__std_pause" @342
    323     "__std_pclose" @343
    324     "__std_perror" @344
    325     "__std_pipe" @345
    326     "__std_popen" @346
    327     "__std_pow" @347
    328     "__std_putchar" @348
    329     "__std_putenv" @349
    330     "__std_puts" @350
    331     "__std_putw" @351
    332     "__std_qsort" @352
    333     "__std_raise" @353
    334     "__std_rand" @354
    335     "__std_read" @355
    336     "__std_readdir" @356
    337     "__std_readv" @357
    338     "__std_remove" @358
    339     "__std_rename" @359
    340     "__std_rewind" @360
    341     "__std_rewinddir" @361
    342     "__std_rindex" @362
    343     "__std_rmdir" @363
    344     "__std_sbrk" @364
    345     "__std_scanf" @365
    346     "__std_seekdir" @366
    347     "__std_select" @367
    348     "__std_setbuf" @368
    349     "__std_setbuffer" @369
    350     "__std_setgid" @370
    351     "__std_setjmp" @371
    352     "__std_setmode" @372
    353     "__std_setpgid" @373
    354     "__std_setpwent" @374
    355     "__std_setsid" @375
    356     "__std_settimeofday" @376
    357     "__std_setuid" @377
    358     "__std_setvbuf" @378
    359     "__std_sigaction" @379
    360     "__std_sigaddset" @380
    361     "__std_sigdelset" @381
    362     "__std_sigemptyset" @382
    363     "__std_sigfillset" @383
    364     "__std_sigismember" @384
    365     "__std_signal" @385
    366     "__std_sigpending" @386
    367     "__std_sigprocmask" @387
    368     "__std_sigsuspend" @388
    369     "__std_sin" @389
    370     "__std_sinh" @390
    371     "__std_sleep" @391
    372     "__std_snprintf" @392
    373     "__std_sopen" @393
    374     "__std_spawnl" @394
    375     "__std_spawnle" @395
    376     "__std_spawnlp" @396
    377     "__std_spawnlpe" @397
    378     "__std_spawnv" @398
    379     "__std_spawnve" @399
    380     "__std_spawnvp" @400
    381     "__std_spawnvpe" @401
    382     "__std_sprintf" @402
    383     "__std_sqrt" @403
    384     "__std_srand" @404
    385     "__std_sscanf" @405
    386     "__std_stat" @406
    387     "__std_swab" @407
    388     "__std_sysconf" @408
    389     "__std_sys_errlist" @409
    390     "__std_sys_nerr" @410
    391     "__std_system" @411
    392     "__std_tan" @412
    393     "__std_tanh" @413
    394     "__std_tell" @414
    395     "__std_telldir" @415
    396     "__std_time" @416
    397     "__std_times" @417
    398     "__std_tmpfile" @418
    399     "__std_tmpnam" @419
    400     "__std_truncate" @420
    401     "__std_ttyname" @421
    402     "__std_tzset" @422
    403     "__std_ulimit" @423
    404     "__std_umask" @424
    405     "__std_uname" @425
    406     "__std_ungetc" @426
    407     "__std_unlink" @427
    408     "__std_utime" @428
    409     "__std_utimes" @429
    410     "__std_vfprintf" @430
    411     "__std_vfscanf" @431
    412     "__std_vprintf" @432
    413     "__std_vscanf" @433
    414     "__std_vsnprintf" @434
    415     "__std_vsprintf" @435
    416     "__std_vsscanf" @436
    417     "__std_wait" @437
    418     "__std_waitpid" @438
    419     "__std_wcstombs" @439
    420     "__std_wctomb" @440
    421     "__std_write" @441
    422     "__std_writev" @442
    423     "__stream_read" @443
    424     "__stream_write" @444
    425     "__strncpy" @445
    426     "__std_strtoll" @446
    427     "__std_strtoull" @447
    428     "__beginthread" @448
    429     "__bi_add_bb" @449
    430     "__bi_cmp_bb" @450
    431     "__bi_cmp_pow2" @451
    432     "__bi_div_add_back" @452
    433     "__bi_div_estimate" @453
    434     "__bi_div_rem_bb" @454
    435     "__bi_div_rem_bw" @455
    436     "__bi_div_rem_pow2" @456
    437     "__bi_div_subtract" @457
    438     "__bi_fls" @458
    439     "__bi_hdiv_rem_b" @459
    440     "__bi_mul_bb" @460
    441     "__bi_mul_bw" @461
    442     "__bi_pow5" @462
    443     "__bi_set_b" @463
    444     "__bi_set_d" @464
    445     "__bi_set_w" @465
    446     "__bi_shl_b" @466
    447     "__bi_shl_w" @467
    448     "__bi_shr_b" @468
    449     "__bi_sub_mul_bw" @469
    450     "__bi_wdiv_rem_pow2" @470
    451     "__std_cbrtl" @471
    452     "__std_cfgetispeed" @472
    453     "__std_cfgetospeed" @473
    454     "__std_cfsetispeed" @474
    455     "__std_cfsetospeed" @475
    456     "__std_cfsetspeed" @476
    457     "___chdir" @477
    458     "__chdir2" @478
    459     "___chmod" @479
    460     "___chsize" @480
    461     "__clear87" @481
    462     "___close" @482
    463     "__closestream" @483
    464     "__compute_dst_table" @484
    465     "__const_HALF" @485
    466     "__const_M_ONE" @486
    467     "__const_NAN" @487
    468     "__const_ONE" @488
    469     "__const_TWO" @489
    470     "__const_ZERO" @490
    471     "__control87" @491
    472     "__core" @492
    473     "__crlf" @493
    474     "___ctordtorInit1" @494
    475     "___ctordtorTerm1" @495
    476     "__day" @496
    477     "__defext" @497
    478     "__dt_free" @498
    479     "___dtoa" @499
    480     "__dt_read" @500
    481     "__dt_sort" @501
    482     "__dt_split" @502
    483     "___dup" @503
    484     "___dup2" @504
    485     "__endbuf1" @505
    486     "___endthread" @506
    487     "__endthread" @507
    488     "__envargs" @508
    489     "__errno" @509
    490     "__errno_fun" @510
    491     "__execname" @511
    492     "___exit" @512
    493     "__exit" @513
    494     "__exit_streams" @514
    495     "__fassign" @515
    496     "__fbuf" @516
    497     "__fcloseall" @517
    498     "___fcntl" @518
    499     "__fflush_nolock" @519
    500     "__filesys" @520
    501     "__fill" @521
    502     "___findfirst" @522
    503     "___findnext" @523
    504     "__flush" @524
    505     "__flushstream" @525
    506     "__fmutex_checked_close" @526
    507     "__fmutex_checked_create" @527
    508     "__fmutex_checked_open" @528
    509     "__fmutex_checked_release" @529
    510     "__fmutex_checked_request" @530
    511     "__fmutex_close" @531
    512     "__fmutex_create" @532
    513     "__fmutex_dummy" @533
    514     "__fmutex_open" @534
    515     "___fmutex_release_internal" @535
    516     "___fmutex_request_internal" @536
    517     "__fnexplode" @537
    518     "__fnexplodefree" @538
    519     "__fngetdrive" @539
    520     "__fnisabs" @540
    521     "__fnisrel" @541
    522     "__fnlwr" @542
    523     "__fnlwr2" @543
    524     "__fnslashify" @544
    525     "___fork" @545
    526     "___fpclassify" @546
    527     "___fpclassifyf" @547
    528     "___fpclassifyl" @548
    529     "__fpreset" @549
    530     "__fseek_hdr" @550
    531     "__fseek_nolock" @551
    532     "__fsetmode" @552
    533     "__fsopen" @553
    534     "___fstat" @554
    535     "__ftell_nolock" @555
    536     "___ftime" @556
    537     "___ftruncate" @557
    538     "__fullpath" @558
    539     "__fwrite_nolock" @559
    540     "___getcwd" @560
    541     "__getcwd1" @561
    542     "__getcwd2" @562
    543     "__getdrive" @563
    544     "__std_getegid" @564
    545     "__std_geteuid" @565
    546     "__getext" @566
    547     "__getext2" @567
    548     "__std_getgrgid" @568
    549     "__getname" @569
    550     "__getpass1" @570
    551     "__getpass2" @571
    552     "__gettid" @572
    553     "__getvol" @573
    554     "__glob" @574
    555     "__globfree" @575
    556     "__gmt2loc" @576
    557     "__gmtime" @577
    558     "__heapchk" @578
    559     "__heapmin" @579
    560     "__heapset" @580
    561     "__heap_walk" @581
    562     "___imphandle" @582
    563     "__imphandle" @583
    564     "__input" @584
    565     "__int86" @585
    566     "___ioctl1" @586
    567     "___ioctl2" @587
    568     "_isalnum" @588
    569     "_isalpha" @589
    570     "_iscntrl" @590
    571     "_isdigit" @591
    572     "___isfinite" @592
    573     "___isfinitef" @593
    574     "___isfinitel" @594
    575     "_isgraph" @595
    576     "_islower" @596
    577     "___isnan" @597
    578     "___isnanf" @598
    579     "___isnanl" @599
    580     "___isnormal" @600
    581     "___isnormalf" @601
    582     "___isnormall" @602
    583     "_isprint" @603
    584     "_ispunct" @604
    585     "_isspace" @605
    586     "__isterm" @606
    587     "_isupper" @607
    588     "_isxdigit" @608
    589     "__libc_16to32" @609
    590     "__libc_32to16" @610
    591     "__libc_thunk1" @611
    592     "__loc2gmt" @612
    593     "__localtime" @613
    594     "___lseek" @614
    595     "__makepath" @615
    596     "__memcount" @616
    597     "__memdif" @617
    598     "__memrchr" @618
    599     "__memswap" @619
    600     "__mfclose" @620
    601     "__mfopen" @621
    602     "__mheap" @622
    603     "___mkdir" @623
    604     "__mktime" @624
    605     "__month_day_leap" @625
    606     "__month_day_non_leap" @626
    607     "__msize" @627
    608     "__newstream" @628
    609     "___newthread" @629
    610     "__nfiles" @630
    611     "___open" @631
    612     "__openstream" @632
    613     "__os2_bad" @633
    614     "__output" @634
    615     "__path" @635
    616     "___pipe" @636
    617     "___read" @637
    618     "___read_kbd" @638
    619     "__read_kbd" @639
    620     "__remext" @640
    621     "___remove_zeros" @641
    622     "__response" @642
    623     "__rfnlwr" @643
    624     "___rmdir" @644
    625     "__rmtmp" @645
    626     "__rmutex_checked_close" @646
    627     "__rmutex_checked_create" @647
    628     "__rmutex_checked_open" @648
    629     "__rmutex_close" @649
    630     "__rmutex_create" @650
    631     "__rmutex_dummy" @651
    632     "__rmutex_fork" @652
    633     "__rmutex_open" @653
    634     "__wildcard" @654
    635     "__scrsize" @655
    636     "__searchenv" @656
    637     "__seek_hdr" @657
    638     "___select" @658
    639     "__setdummymore" @659
    640     "__setmore" @660
    641     "___settime" @661
    642     "__sfnlwr" @662
    643     "_sig_info" @663
    644     "__std_siglongjmp" @664
    645     "___signbit" @665
    646     "___signbitf" @666
    647     "___signbitl" @667
    648     "__std_sigsetjmp" @668
    649     "__sleep2" @669
    650     "___small_atod" @670
    651     "___small_dtoa" @671
    652     "___smutex_request_internal" @672
    653     "___spawnve" @673
    654     "__splitargs" @674
    655     "__splitpath" @675
    656     "___stat" @676
    657     "__status87" @677
    658     "___swchar" @678
    659     "__swchar" @679
    660     "__sys_deliver_pending_signals" @680
    661     "__utmalloc" @681
    662     "__sys_dump_heap_objs" @682
    663     "__sys_exception" @683
    664     "__sys_expand_heap_by" @684
    665     "__sys_expand_heap_obj_by" @685
    666     "__sys_get_clock" @686
    667     "___sys_newthread" @687
    668     "__sys_p2t" @688
    669     "__sys_set_errno" @689
    670     "__sys_shrink_heap_by" @690
    671     "__sys_shrink_heap_obj_by" @691
    672     "__sys_shrink_heap_to" @692
    673     "___wait" @693
    674     "__sys_sig_valid" @694
    675     "___waitpid" @695
    676     "__sys_thread" @696
    677     "__vsopen" @697
    678     "__tcalloc" @698
    679     "__std_tcdrain" @699
    680     "__std_tcflow" @700
    681     "__std_tcflush" @701
    682     "__std_tcgetattr" @702
    683     "__std_tcgetpgrp" @703
    684     "__std_tcsendbreak" @704
    685     "__std_tcsetattr" @705
    686     "__std_tcsetpgrp" @706
    687     "__std_tempnam" @707
    688     "__tfree" @708
    689     "__theapmin" @709
    690     "__thread" @710
    691     "___threadid" @711
    692     "__threadstore" @712
    693     "___write" @713
    694     "__tmpbuf1" @714
    695     "__tmpidx_lock" @715
    696     "__tmpidxnam" @716
    697     "__tmpidx_unlock" @717
    698     "_tolower" @718
    699     "_toupper" @719
    700     "__trealloc" @720
    701     "__trslash" @721
    702     "___ttyname" @722
    703     "__uaddmem" @723
    704     "__ucalloc" @724
    705     "__uclose" @725
    706     "__ucreate" @726
    707     "__ucreate2" @727
    708     "__udefault" @728
    709     "__udestroy" @729
    710     "__uflags" @730
    711     "__uheapchk" @731
    712     "__uheapmin" @732
    713     "__uheapset" @733
    714     "__uheap_type" @734
    715     "__uheap_walk" @735
    716     "__uheap_walk2" @736
    717     "__uldiv" @737
    718     "___ulimit" @738
    719     "__um_walk_error" @739
    720     "__um_walk_no_lock" @740
    721     "__ungetc_nolock" @741
    722     "___unwind2" @742
    723     "__uopen" @743
    724     "__ustats" @744
    725     "__utcalloc" @745
    726     "__utdefault" @746
    727     "___utimes" @747
    728     "___convert_codepage" @748
    729     "___do_Unicode" @749
    730     "___from_ucs" @750
    731     "_isascii" @751
    732     "___gnu_basename" @752
    733     "__std_basename" @753
    734     "__std_dirname" @754
    735     "__std_lltoa" @755
    736     "__std_localeconv" @756
    737     "__std_ltoa" @757
    738     "__std_setlocale" @758
    739     "__std_ulltoa" @759
    740     "__std_ultoa" @760
    741     "_toascii" @761
    742     "___to_ucs" @762
    743     "__std_acosl" @763
    744     "__std_asinl" @764
    745     "__std_atan2l" @765
    746     "__std_atanl" @766
    747     "__std_ceill" @767
    748     "__std_copysign" @768
    749     "__std_copysignf" @769
    750     "__std_copysignl" @770
    751     "__std_coshl" @771
    752     "__std_cosl" @772
    753     "__std_expl" @773
    754     "__std_fabsl" @774
    755     "__std_floorl" @775
    756     "__std_fmodl" @776
    757     "__std_frexpl" @777
    758     "__fxam" @778
    759     "__fxaml" @779
    760     "__std_hypot" @780
    761     "__std_hypotl" @781
    762     "__std_ldexpl" @782
    763     "__std_log10l" @783
    764     "__std_logl" @784
    765     "__std_modfl" @785
    766     "__std_nextafter" @786
    767     "__std_nextafterf" @787
    768     "__std_nextafterl" @788
    769     "__std_powl" @789
    770     "__std_rint" @790
    771     "__std_rintl" @791
    772     "__std_sinhl" @792
    773     "__std_sinl" @793
    774     "__std_sqrtl" @794
    775     "__std_tanhl" @795
    776     "__std_tanl" @796
    777     "__std_trunc" @797
    778     "__std_truncl" @798
    779     "__ead_add" @799
    780     "__ead_clear" @800
    781     "__ead_copy" @801
    782     "__ead_count" @802
    783     "__ead_create" @803
    784     "__ead_delete" @804
    785     "__ead_destroy" @805
    786     "__ead_enum" @806
    787     "__ead_fea2list_size" @807
    788     "__ead_fea2list_to_fealist" @808
    789     "__ead_fealist_to_fea2list" @809
    790     "__ead_find" @810
    791     "__ead_get_fea2list" @811
    792     "__ead_get_flags" @812
    793     "__ead_get_name" @813
    794     "__ead_get_value" @814
    795     "__ead_make_index" @815
    796     "__ead_name_len" @816
    797     "__ead_read" @817
    798     "__ead_replace" @818
    799     "__ead_size_buffer" @819
    800     "__ead_sort" @820
    801     "__ead_use_fea2list" @821
    802     "__ead_value_size" @822
    803     "__ead_write" @823
    804     "__ea_free" @824
    805     "__ea_get" @825
    806     "__ea_put" @826
    807     "__ea_remove" @827
    808     "__ea_set_errno" @828
    809     "__ea_write" @829
    810     "__std_setenv" @830
    811     "__std_unsetenv" @831
    812     "__std_lockf" @832
    813     "__lmalloc" @833
    814     "__std_fseeko" @834
    815     "__std_ftello" @835
    816     "__std_readdir_r" @836
    817     "__std_lstat" @837
    818     "_srandomdev" @838
    819     "_random" @839
    820     "_initstate" @840
    821     "_setstate" @841
    822     "_srandom" @842
    823     "_lchmod" @843
    824     "_stpcpy" @844
    825     "_strlcat" @845
    826     "_strlcpy" @846
    827     "_strcasestr" @847
    828     "_strnstr" @848
    829     "_strsep" @849
    830     "_heapsort" @850
    831     "_mergesort" @851
    832     "_radixsort" @852
    833     "_sradixsort" @853
    834     "__dorand48" @854
    835     "__std_srand48" @855
    836     "__std_drand48" @856
    837     "__std_erand48" @857
    838     "__std_jrand48" @858
    839     "__std_lcong48" @859
    840     "__std_lrand48" @860
    841     "__std_mrand48" @861
    842     "__std_nrand48" @862
    843     "__std_seed48" @863
    844     "__std_qsort_r" @864
    845     "__hcalloc" @865
    846     "__hinitheap" @866
    847     "__hmalloc" @867
    848     "__hrealloc" @868
    849     "__lcalloc" @869
     65    "__CRT_init" @101
     66    "__CRT_term" @102
     67    "__HUGE_VAL" @103
     68    "__LHUGE_VAL" @104
     69    "___alloc_thread" @105
     70    "___atod" @106
     71    "___chdir" @107
     72    "___chmod" @108
     73    "___chsize" @109
     74    "___close" @110
     75    "___convert_codepage" @111
     76    "___ctordtorInit1" @112
     77    "___ctordtorTerm1" @113
     78    "___do_Unicode" @114
     79    "___dtoa" @115
     80    "___dup" @116
     81    "___dup2" @117
     82    "___endthread" @118
     83    "___exit" @119
     84    "___fcntl" @120
     85    "___findfirst" @121
     86    "___findnext" @122
     87    "___fmutex_release_internal" @123
     88    "___fmutex_request_internal" @124
     89    "___fork" @125
     90    "___fpclassify" @126
     91    "___fpclassifyf" @127
     92    "___fpclassifyl" @128
     93    "___from_ucs" @129
     94    "___fstat" @130
     95    "___ftime" @131
     96    "___ftruncate" @132
     97    "___getcwd" @133
     98    "___gnu_basename" @134
     99    "___imphandle" @135
     100    "___init" @136
     101    "___init_app" @137
     102    "___init_dll" @138
     103    "___initthread" @139
     104    "___ioctl1" @140
     105    "___ioctl2" @141
     106    "___isfinite" @142
     107    "___isfinitef" @143
     108    "___isfinitel" @144
     109    "___isnan" @145
     110    "___isnanf" @146
     111    "___isnanl" @147
     112    "___isnormal" @148
     113    "___isnormalf" @149
     114    "___isnormall" @150
     115    "___libc_FH" @151
     116    "___libc_FHAllocate" @152
     117    "___libc_FHClose" @153
     118    "___libc_FHEnsureHandles" @154
     119    "___libc_HasHighMem" @155
     120    "___libc_HeapEndVoting" @156
     121    "___libc_HeapGetResult" @157
     122    "___libc_HeapVote" @158
     123    "___libc_HimemDefaultAlloc" @159
     124    "___libc_HimemDefaultRelease" @160
     125    "___lseek" @161
     126    "___mkdir" @162
     127    "___newthread" @163
     128    "___open" @164
     129    "___pipe" @165
     130    "___read" @166
     131    "___read_kbd" @167
     132    "___remove_zeros" @168
     133    "___rmdir" @169
     134    "___select" @170
     135    "___settime" @171
     136    "___signbit" @172
     137    "___signbitf" @173
     138    "___signbitl" @174
     139    "___small_atod" @175
     140    "___small_dtoa" @176
     141    "___smutex_request_internal" @177
     142    "___spawnve" @178
     143    "___stat" @179
     144    "___swchar" @180
     145    "___threadid" @181
     146    "___to_ucs" @182
     147    "___ttyname" @183
     148    "___ulimit" @184
     149    "___unwind2" @185
     150    "___utimes" @186
     151    "___wait" @187
     152    "___waitpid" @188
     153    "___write" @189
     154    "__abspath" @190
     155    "__assert" @191
     156    "__beginthread" @192
     157    "__bi_add_bb" @193
     158    "__bi_cmp_bb" @194
     159    "__bi_cmp_pow2" @195
     160    "__bi_div_add_back" @196
     161    "__bi_div_estimate" @197
     162    "__bi_div_rem_bb" @198
     163    "__bi_div_rem_bw" @199
     164    "__bi_div_rem_pow2" @200
     165    "__bi_div_subtract" @201
     166    "__bi_fls" @202
     167    "__bi_hdiv_rem_b" @203
     168    "__bi_mul_bb" @204
     169    "__bi_mul_bw" @205
     170    "__bi_pow5" @206
     171    "__bi_set_b" @207
     172    "__bi_set_d" @208
     173    "__bi_set_w" @209
     174    "__bi_shl_b" @210
     175    "__bi_shl_w" @211
     176    "__bi_shr_b" @212
     177    "__bi_sub_mul_bw" @213
     178    "__bi_wdiv_rem_pow2" @214
     179    "__chdir2" @215
     180    "__clear87" @216
     181    "__closestream" @217
     182    "__compute_dst_table" @218
     183    "__const_HALF" @219
     184    "__const_M_ONE" @220
     185    "__const_NAN" @221
     186    "__const_ONE" @222
     187    "__const_TWO" @223
     188    "__const_ZERO" @224
     189    "__control87" @225
     190    "__core" @226
     191    "__crlf" @227
     192    "__day" @228
     193    "__defext" @229
     194    "__dorand48" @230
     195    "__dt_free" @231
     196    "__dt_read" @232
     197    "__dt_sort" @233
     198    "__dt_split" @234
     199    "__ea_free" @235
     200    "__ea_get" @236
     201    "__ea_put" @237
     202    "__ea_remove" @238
     203    "__ea_set_errno" @239
     204    "__ea_write" @240
     205    "__ead_add" @241
     206    "__ead_clear" @242
     207    "__ead_copy" @243
     208    "__ead_count" @244
     209    "__ead_create" @245
     210    "__ead_delete" @246
     211    "__ead_destroy" @247
     212    "__ead_enum" @248
     213    "__ead_fea2list_size" @249
     214    "__ead_fea2list_to_fealist" @250
     215    "__ead_fealist_to_fea2list" @251
     216    "__ead_find" @252
     217    "__ead_get_fea2list" @253
     218    "__ead_get_flags" @254
     219    "__ead_get_name" @255
     220    "__ead_get_value" @256
     221    "__ead_make_index" @257
     222    "__ead_name_len" @258
     223    "__ead_read" @259
     224    "__ead_replace" @260
     225    "__ead_size_buffer" @261
     226    "__ead_sort" @262
     227    "__ead_use_fea2list" @263
     228    "__ead_value_size" @264
     229    "__ead_write" @265
     230    "__emxload_connect" @266
     231    "__emxload_disconnect" @267
     232    "__emxload_do_connect" @268
     233    "__emxload_do_disconnect" @269
     234    "__emxload_do_receive" @270
     235    "__emxload_do_request" @271
     236    "__emxload_do_wait" @272
     237    "__emxload_env" @273
     238    "__emxload_list_get" @274
     239    "__emxload_list_start" @275
     240    "__emxload_prog" @276
     241    "__emxload_request" @277
     242    "__emxload_stop" @278
     243    "__emxload_this" @279
     244    "__emxload_unload" @280
     245    "__endbuf1" @281
     246    "__endthread" @282
     247    "__envargs" @283
     248    "__errno" @284
     249    "__errno_fun" @285
     250    "__execname" @286
     251    "__exit" @287
     252    "__exit_streams" @288
     253    "__fassign" @289
     254    "__fbuf" @290
     255    "__fcloseall" @291
     256    "__fflush_nolock" @292
     257    "__filesys" @293
     258    "__fill" @294
     259    "__flush" @295
     260    "__flushstream" @296
     261    "__fmutex_checked_close" @297
     262    "__fmutex_checked_create" @298
     263    "__fmutex_checked_open" @299
     264    "__fmutex_checked_release" @300
     265    "__fmutex_checked_request" @301
     266    "__fmutex_close" @302
     267    "__fmutex_create" @303
     268    "__fmutex_dummy" @304
     269    "__fmutex_open" @305
     270    "__fnexplode" @306
     271    "__fnexplodefree" @307
     272    "__fngetdrive" @308
     273    "__fnisabs" @309
     274    "__fnisrel" @310
     275    "__fnlwr" @311
     276    "__fnlwr2" @312
     277    "__fnslashify" @313
     278    "__fpreset" @314
     279    "__fseek_hdr" @315
     280    "__fseek_nolock" @316
     281    "__fsetmode" @317
     282    "__fsopen" @318
     283    "__ftell_nolock" @319
     284    "__fullpath" @320
     285    "__fwrite_nolock" @321
     286    "__fxam" @322
     287    "__fxaml" @323
     288    "__getcwd1" @324
     289    "__getcwd2" @325
     290    "__getdrive" @326
     291    "__getext" @327
     292    "__getext2" @328
     293    "__getname" @329
     294    "__getpass1" @330
     295    "__getpass2" @331
     296    "__gettid" @332
     297    "__getvol" @333
     298    "__std_glob" @334
     299    "__std_globfree" @335
     300    "__gmt2loc" @336
     301    "__gmtime" @337
     302    "__hcalloc" @338
     303    "__heap_walk" @339
     304    "__heapchk" @340
     305    "__heapmin" @341
     306    "__heapset" @342
     307    "__hinitheap" @343
     308    "__hmalloc" @344
     309    "__hrealloc" @345
     310    "__imphandle" @346
     311    "__init1_tmp" @347
     312    "__init_streams" @348
     313    "__input" @349
     314    "__int86" @350
     315    "__isterm" @351
     316    "__lcalloc" @352
     317    "__libc_16to32" @353
     318    "__libc_32to16" @354
     319    "__libc_thunk1" @355
     320    "__linitheap" @356
     321    "__lmalloc" @357
     322    "__loc2gmt" @358
     323    "__localtime" @359
     324    "__lrealloc" @360
     325    "__makepath" @361
     326    "__memcount" @362
     327    "__memdif" @363
     328    "__memrchr" @364
     329    "__memswap" @365
     330    "__mfclose" @366
     331    "__mfopen" @367
     332    "__mheap" @368
     333    "__mktime" @369
     334    "__month_day_leap" @370
     335    "__month_day_non_leap" @371
     336    "__msize" @372
     337    "__newstream" @373
     338    "__openstream" @374
     339    "__os2_bad" @375
     340    "__output" @376
     341    "__path" @377
     342    "__read_kbd" @378
     343    "__remext" @379
     344    "__response" @380
     345    "__rfnlwr" @381
     346    "__rmtmp" @382
     347    "__rmutex_checked_close" @383
     348    "__rmutex_checked_create" @384
     349    "__rmutex_checked_open" @385
     350    "__rmutex_close" @386
     351    "__rmutex_create" @387
     352    "__rmutex_dummy" @388
     353    "__rmutex_fork" @389
     354    "__rmutex_open" @390
     355    "__scrsize" @391
     356    "__searchenv" @392
     357    "__seek_hdr" @393
     358    "__setdummymore" @394
     359    "__setmore" @395
     360    "__sfnlwr" @396
     361    "__sleep2" @397
     362    "__splitargs" @398
     363    "__splitpath" @399
     364    "__status87" @400
     365    "__std_abort" @401
     366    "__std_abs" @402
     367    "__std_access" @403
     368    "__std_acos" @404
     369    "__std_acosl" @405
     370    "__std_asctime" @406
     371    "__std_asin" @407
     372    "__std_asinl" @408
     373    "__std_atan" @409
     374    "__std_atan2" @410
     375    "__std_atan2l" @411
     376    "__std_atanl" @412
     377    "__std_atexit" @413
     378    "__std_atof" @414
     379    "__std_atofl" @415
     380    "__std_atoi" @416
     381    "__std_atol" @417
     382    "__std_atoll" @418
     383    "__std_basename" @419
     384    "__std_bcmp" @420
     385    "__std_bcopy" @421
     386    "__std_brk" @422
     387    "__std_bsearch" @423
     388    "__std_bzero" @424
     389    "__std_calloc" @425
     390    "__std_cbrt" @426
     391    "__std_cbrtl" @427
     392    "__std_ceil" @428
     393    "__std_ceill" @429
     394    "__std_cfgetispeed" @430
     395    "__std_cfgetospeed" @431
     396    "__std_cfsetispeed" @432
     397    "__std_cfsetospeed" @433
     398    "__std_cfsetspeed" @434
     399    "__std_chdir" @435
     400    "__std_chdrive" @436
     401    "__std_chmod" @437
     402    "__std_chsize" @438
     403    "__std_clearerr" @439
     404    "__std_clock" @440
     405    "__std_close" @441
     406    "__std_closedir" @442
     407    "__std_copysign" @443
     408    "__std_copysignf" @444
     409    "__std_copysignl" @445
     410    "__std_cos" @446
     411    "__std_cosh" @447
     412    "__std_coshl" @448
     413    "__std_cosl" @449
     414    "__std_creat" @450
     415    "__std_ctime" @451
     416    "__std_cuserid" @452
     417    "__std_difftime" @453
     418    "__std_dirname" @454
     419    "__std_div" @455
     420    "__std_drand48" @456
     421    "__std_dup" @457
     422    "__std_dup2" @458
     423    "__std_endpwent" @459
     424    "__std_eof" @460
     425    "__std_erand48" @461
     426    "__std_execl" @462
     427    "__std_execle" @463
     428    "__std_execlp" @464
     429    "__std_execlpe" @465
     430    "__std_execv" @466
     431    "__std_execve" @467
     432    "__std_execvp" @468
     433    "__std_execvpe" @469
     434    "__std_exit" @470
     435    "__std_exp" @471
     436    "__std_expand" @472
     437    "__std_expl" @473
     438    "__std_fabs" @474
     439    "__std_fabsl" @475
     440    "__std_fclose" @476
     441    "__std_fcntl" @477
     442    "__std_fdopen" @478
     443    "__std_feof" @479
     444    "__std_ferror" @480
     445    "__std_fflush" @481
     446    "__std_ffs" @482
     447    "__std_fgetc" @483
     448    "__std_fgetchar" @484
     449    "__std_fgetpos" @485
     450    "__std_fgets" @486
     451    "__std_filelength" @487
     452    "__std_fileno" @488
     453    "__std_flock" @489
     454    "__std_floor" @490
     455    "__std_floorl" @491
     456    "__std_flushall" @492
     457    "__std_fmod" @493
     458    "__std_fmodl" @494
     459    "__std_fnmatch" @495
     460    "__std_fopen" @496
     461    "__std_fork" @497
     462    "__std_fpathconf" @498
     463    "__std_fprintf" @499
     464    "__std_fputc" @500
     465    "__std_fputchar" @501
     466    "__std_fputs" @502
     467    "__std_fread" @503
     468    "__std_free" @504
     469    "__std_freopen" @505
     470    "__std_frexp" @506
     471    "__std_frexpl" @507
     472    "__std_fscanf" @508
     473    "__std_fseek" @509
     474    "__std_fseeko" @510
     475    "__std_fsetpos" @511
     476    "__std_fstat" @512
     477    "__std_fsync" @513
     478    "__std_ftell" @514
     479    "__std_ftello" @515
     480    "__std_ftime" @516
     481    "__std_ftruncate" @517
     482    "__std_ftw" @518
     483    "__std_fwrite" @519
     484    "__std_gcvt" @520
     485    "__std_getchar" @521
     486    "__std_getcwd" @522
     487    "__std_getegid" @523
     488    "__std_getenv" @524
     489    "__std_geteuid" @525
     490    "__std_getgid" @526
     491    "__std_getgrgid" @527
     492    "__std_getgrnam" @528
     493    "__std_getgroups" @529
     494    "__std_getlogin" @530
     495    "__std_getopt" @531
     496    "__std_getpagesize" @532
     497    "__std_getpass" @533
     498    "__std_getpgrp" @534
     499    "__std_getpid" @535
     500    "__std_getppid" @536
     501    "__std_getpw" @537
     502    "__std_getpwent" @538
     503    "__std_getpwnam" @539
     504    "__std_getpwuid" @540
     505    "__std_gets" @541
     506    "__std_gettimeofday" @542
     507    "__std_getuid" @543
     508    "__std_getw" @544
     509    "__std_getwd" @545
     510    "__std_gmtime" @546
     511    "__std_hypot" @547
     512    "__std_hypotl" @548
     513    "__std_index" @549
     514    "__std_ioctl" @550
     515    "__std_isatty" @551
     516    "__std_jrand48" @552
     517    "__std_kill" @553
     518    "__std_labs" @554
     519    "__std_lcong48" @555
     520    "__std_ldexp" @556
     521    "__std_ldexpl" @557
     522    "__std_ldiv" @558
     523    "__std_lltoa" @559
     524    "__std_localeconv" @560
     525    "__std_localtime" @561
     526    "__std_lockf" @562
     527    "__std_log" @563
     528    "__std_log10" @564
     529    "__std_log10l" @565
     530    "__std_logl" @566
     531    "__std_longjmp" @567
     532    "__std_lrand48" @568
     533    "__std_lseek" @569
     534    "__std_lstat" @570
     535    "__std_ltoa" @571
     536    "__std_malloc" @572
     537    "__std_mblen" @573
     538    "__std_mbstowcs" @574
     539    "__std_mbtowc" @575
     540    "__std_memccpy" @576
     541    "__std_memchr" @577
     542    "__std_memcmp" @578
     543    "__std_memcpy" @579
     544    "__std_memicmp" @580
     545    "__std_memmove" @581
     546    "__std_memset" @582
     547    "__std_mkdir" @583
     548    "__std_mkstemp" @584
     549    "__std_mktemp" @585
     550    "__std_mktime" @586
     551    "__std_modf" @587
     552    "__std_modfl" @588
     553    "__std_mrand48" @589
     554    "__std_nextafter" @590
     555    "__std_nextafterf" @591
     556    "__std_nextafterl" @592
     557    "__std_nrand48" @593
     558    "__std_open" @594
     559    "__std_opendir" @595
     560    "__std_pathconf" @596
     561    "__std_pause" @597
     562    "__std_pclose" @598
     563    "__std_perror" @599
     564    "__std_pipe" @600
     565    "__std_popen" @601
     566    "__std_posix_memalign" @602
     567    "__std_pow" @603
     568    "__std_powl" @604
     569    "__std_printf" @605
     570    "__std_putchar" @606
     571    "__std_putenv" @607
     572    "__std_puts" @608
     573    "__std_putw" @609
     574    "__std_qsort" @610
     575    "__std_qsort_r" @611
     576    "__std_raise" @612
     577    "__std_rand" @613
     578    "__std_read" @614
     579    "__std_readdir" @615
     580    "__std_readdir_r" @616
     581    "__std_readv" @617
     582    "__std_realloc" @618
     583    "__std_remove" @619
     584    "__std_rename" @620
     585    "__std_rewind" @621
     586    "__std_rewinddir" @622
     587    "__std_rindex" @623
     588    "__std_rint" @624
     589    "__std_rintl" @625
     590    "__std_rmdir" @626
     591    "__std_sbrk" @627
     592    "__std_scanf" @628
     593    "__std_seed48" @629
     594    "__std_seekdir" @630
     595    "__std_select" @631
     596    "__std_setbuf" @632
     597    "__std_setbuffer" @633
     598    "__std_setenv" @634
     599    "__std_setgid" @635
     600    "__std_setjmp" @636
     601    "__std_setlocale" @637
     602    "__std_setmode" @638
     603    "__std_setpgid" @639
     604    "__std_setpwent" @640
     605    "__std_setsid" @641
     606    "__std_settimeofday" @642
     607    "__std_setuid" @643
     608    "__std_setvbuf" @644
     609    "__std_sigaction" @645
     610    "__std_sigaddset" @646
     611    "__std_sigdelset" @647
     612    "__std_sigemptyset" @648
     613    "__std_sigfillset" @649
     614    "__std_sigismember" @650
     615    "__std_siglongjmp" @651
     616    "__std_signal" @652
     617    "__std_sigpending" @653
     618    "__std_sigprocmask" @654
     619    "__std_sigsetjmp" @655
     620    "__std_sigsuspend" @656
     621    "__std_sin" @657
     622    "__std_sinh" @658
     623    "__std_sinhl" @659
     624    "__std_sinl" @660
     625    "__std_sleep" @661
     626    "__std_snprintf" @662
     627    "__std_sopen" @663
     628    "__std_spawnl" @664
     629    "__std_spawnle" @665
     630    "__std_spawnlp" @666
     631    "__std_spawnlpe" @667
     632    "__std_spawnv" @668
     633    "__std_spawnve" @669
     634    "__std_spawnvp" @670
     635    "__std_spawnvpe" @671
     636    "__std_sprintf" @672
     637    "__std_sqrt" @673
     638    "__std_sqrtl" @674
     639    "__std_srand" @675
     640    "__std_srand48" @676
     641    "__std_sscanf" @677
     642    "__std_stat" @678
     643    "__std_strcat" @679
     644    "__std_strchr" @680
     645    "__std_strcmp" @681
     646    "__std_strcoll" @682
     647    "__std_strcpy" @683
     648    "__std_strcspn" @684
     649    "__std_strdup" @685
     650    "__std_strerror" @686
     651    "__std_strftime" @687
     652    "__std_stricmp" @688
     653    "__std_strlen" @689
     654    "__std_strlwr" @690
     655    "__std_strncat" @691
     656    "__std_strncmp" @692
     657    "__std_strncpy" @693
     658    "__std_strnicmp" @694
     659    "__std_strnset" @695
     660    "__std_strpbrk" @696
     661    "__std_strptime" @697
     662    "__std_strrchr" @698
     663    "__std_strrev" @699
     664    "__std_strset" @700
     665    "__std_strspn" @701
     666    "__std_strstr" @702
     667    "__std_strtod" @703
     668    "__std_strtof" @704
     669    "__std_strtok" @705
     670    "__std_strtol" @706
     671    "__std_strtold" @707
     672    "__std_strtoll" @708
     673    "__std_strtoul" @709
     674    "__std_strtoull" @710
     675    "__std_strupr" @711
     676    "__std_strxfrm" @712
     677    "__std_swab" @713
     678    "__std_sys_errlist" @714
     679    "__std_sys_nerr" @715
     680    "__std_sysconf" @716
     681    "__std_system" @717
     682    "__std_tan" @718
     683    "__std_tanh" @719
     684    "__std_tanhl" @720
     685    "__std_tanl" @721
     686    "__std_tcdrain" @722
     687    "__std_tcflow" @723
     688    "__std_tcflush" @724
     689    "__std_tcgetattr" @725
     690    "__std_tcgetpgrp" @726
     691    "__std_tcsendbreak" @727
     692    "__std_tcsetattr" @728
     693    "__std_tcsetpgrp" @729
     694    "__std_tell" @730
     695    "__std_telldir" @731
     696    "__std_tempnam" @732
     697    "__std_time" @733
     698    "__std_times" @734
     699    "__std_tmpfile" @735
     700    "__std_tmpnam" @736
     701    "__std_trunc" @737
     702    "__std_truncate" @738
     703    "__std_truncl" @739
     704    "__std_ttyname" @740
     705    "__std_tzset" @741
     706    "__std_ulimit" @742
     707    "__std_ulltoa" @743
     708    "__std_ultoa" @744
     709    "__std_umask" @745
     710    "__std_uname" @746
     711    "__std_ungetc" @747
     712    "__std_unlink" @748
     713    "__std_unsetenv" @749
     714    "__std_utime" @750
     715    "__std_utimes" @751
     716    "__std_vfprintf" @752
     717    "__std_vfscanf" @753
     718    "__std_vprintf" @754
     719    "__std_vscanf" @755
     720    "__std_vsnprintf" @756
     721    "__std_vsprintf" @757
     722    "__std_vsscanf" @758
     723    "__std_wait" @759
     724    "__std_waitpid" @760
     725    "__std_wcstombs" @761
     726    "__std_wctomb" @762
     727    "__std_write" @763
     728    "__std_writev" @764
     729    "__stream_read" @765
     730    "__stream_write" @766
     731    "__strncpy" @767
     732    "__swchar" @768
     733    "__sys_dump_heap_objs" @769
     734    "__sys_exception" @770
     735    "__tcalloc" @771
     736    "__tfree" @772
     737    "__theapmin" @773
     738    "__thread" @774
     739    "__threadstore" @775
     740    "__tmalloc" @776
     741    "__tmpbuf1" @777
     742    "__tmpidx_lock" @778
     743    "__tmpidx_unlock" @779
     744    "__tmpidxnam" @780
     745    "__trealloc" @781
     746    "__trslash" @782
     747    "__uaddmem" @783
     748    "__ucalloc" @784
     749    "__uclose" @785
     750    "__ucreate" @786
     751    "__ucreate2" @787
     752    "__udefault" @788
     753    "__udestroy" @789
     754    "__uflags" @790
     755    "__uheap_type" @791
     756    "__uheap_walk" @792
     757    "__uheap_walk2" @793
     758    "__uheapchk" @794
     759    "__uheapmin" @795
     760    "__uheapset" @796
     761    "__uldiv" @797
     762    "__um_addmem_nolock" @798
     763    "__um_alloc_no_lock" @799
     764    "__um_crumb_free_maybe_lock" @800
     765    "__um_default_alloc" @801
     766    "__um_default_expand" @802
     767    "__um_default_release" @803
     768    "__um_default_shrink" @804
     769    "__um_find_bucket" @805
     770    "__um_free_maybe_lock" @806
     771    "__um_init_default_regular_heap" @807
     772    "__um_init_default_tiled_heap" @808
     773    "__um_lump_alloc" @809
     774    "__um_lump_coalesce_free" @810
     775    "__um_lump_free_maybe_lock" @811
     776    "__um_lump_link_heap" @812
     777    "__um_lump_make_free" @813
     778    "__um_lump_unlink_bucket" @814
     779    "__um_lump_unlink_heap" @815
     780    "__um_realloc" @816
     781    "__um_seg_addmem" @817
     782    "__um_seg_setmem" @818
     783    "__um_walk_error" @819
     784    "__um_walk_no_lock" @820
     785    "__umalloc" @821
     786    "__ungetc_nolock" @822
     787    "__uopen" @823
     788    "__ustats" @824
     789    "__utcalloc" @825
     790    "__utdefault" @826
     791    "__utmalloc" @827
     792    "__vsopen" @828
     793    "__wildcard" @829
     794    "__year_day" @830
     795    "_heapsort" @831
     796    "_initstate" @832
     797    "_isalnum" @833
     798    "_isalpha" @834
     799    "_isascii" @835
     800    "_iscntrl" @836
     801    "_isdigit" @837
     802    "_isgraph" @838
     803    "_islower" @839
     804    "_isprint" @840
     805    "_ispunct" @841
     806    "_isspace" @842
     807    "_isupper" @843
     808    "_isxdigit" @844
     809    "_lchmod" @845
     810    "_mergesort" @846
     811    "_radixsort" @847
     812    "_random" @848
     813    "_setstate" @849
     814    "_sig_info" @850
     815    "_sradixsort" @851
     816    "_srandom" @852
     817    "_srandomdev" @853
     818    "_stpcpy" @854
     819    "_strcasestr" @855
     820    "_strlcat" @856
     821    "_strlcpy" @857
     822    "_strnstr" @858
     823    "_strsep" @859
     824    "_toascii" @860
     825    "_tolower" @861
     826    "_toupper" @862
     827    "___collate_range_cmp" @863
  • trunk/src/emx/src/lib/startup/startup.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r870 r871  
    1010#include <emx/startup.h>
    1111
     12#if 0 /* dead */
    1213/* See app/iodata.c. */
    1314
     
    1516extern int _files[];
    1617extern int _lookahead[];
     18#endif
    1719
    1820extern int __crtinit1__;
     
    3436  startup_flag = 1;
    3537
     38#if 0 /* moved to __init_dll() */
    3639  /* Initialize the file handles. */
    3740  init_files ();
     41#endif
    3842
    3943  /* Initialize streams etc. if required. */
     
    5155
    5256
     57#if 0 /* moved to __init_dll() */
    5358/* Initialize the file handles. */
    5459
     
    99104    }
    100105}
    101 
     106#endif
    102107
    103108
     
    121126 *                heap (or low if no high mem) when calling _hmalloc().
    122127 *          - __init_dll calls __init_environ() which initializes environ and _org_environ.
     128 *              - __init_environ() will call _hmalloc() thus initiating the high heap.
     129 *          - __init_dll calls _sys_init_largefileio() which checks for LFN APIs.
     130 *          - __init_dll calls _sys_init_filehandles() which initiates filehandle table.
     131 *              - _sys_init_filehandles() will call _hmalloc() and a number of OS/2 APIs
     132 *                to figure out what handles was inherited.
    123133 *          - __init_dll then intializes _sys_clock0_ms with the current MS count.
    124134 *      - dll0.s calls _DLL_InitTerm in startup/dllinit.c.
  • trunk/src/emx/src/lib/sys/__chsize.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    66#include "libc-alias.h"
    77#define INCL_FSMACROS
     8#define INCL_ERRORS
    89#include <os2emx.h>
    910#include <emx/syscalls.h>
     11#include <emx/io.h>
    1012#include <limits.h>
    1113#include <errno.h>
     
    1315
    1416
    15 int __chsize (int hFile, __off_t cbFile)
     17int __chsize(int fh, __off_t cbFile)
    1618{
    17     ULONG rc;
    18     FS_VAR();
     19    PLIBCFH     pFH;
     20    ULONG       rc;
    1921
    20     FS_SAVE_LOAD();
     22    /*
     23     * Get filehandle.
     24     */
     25    pFH = __libc_FH(fh);
     26    if (!pFH)
     27    {
     28        errno = EBADF;
     29        return -1;
     30    }
     31
     32    /*
     33     * Do the stuff.
     34     */
     35    if (!pFH->pOps)
     36    {
     37        FS_VAR();
     38        FS_SAVE_LOAD();
    2139#if OFF_MAX > LONG_MAX
    22     if (__pfnDosSetFileSizeL)
    23         rc = __pfnDosSetFileSizeL(hFile, cbFile);
     40        if (__pfnDosSetFileSizeL)
     41            rc = __pfnDosSetFileSizeL(fh, cbFile);
     42        else
     43        {
     44            if (cbFile > LONG_MAX)
     45            {
     46                FS_RESTORE();
     47                errno = EOVERFLOW;
     48                return -1;
     49            }
     50            rc = DosSetFileSize(fh, cbFile);
     51        }
     52#else
     53        rc = DosSetFileSize(fh, cbFile);
     54#endif
     55        FS_RESTORE();
     56    }
    2457    else
    2558    {
    26         if (cbFile > LONG_MAX)
    27         {
    28             errno = EOVERFLOW;
    29             return -1;
    30         }
    31         rc = DosSetFileSize(hFile, cbFile);
     59        /** not supported for non native filehandles. */
     60        rc = ERROR_INVALID_FUNCTION;
    3261    }
    33 #else
    34     rc = DosSetFileSize(hFile, cbFile);
    35 #endif
    36     FS_RESTORE();
    3762
     63    /*
     64     * Done.
     65     */
    3866    if (rc)
    3967    {
  • trunk/src/emx/src/lib/sys/__close.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* sys/close.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/close.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                         -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
    4 #define INCL_FSMACROS
    5 #include <os2emx.h>
     5#include <emx/io.h>
    66#include <emx/syscalls.h>
    7 #include "syscalls.h"
    87
    9 int __close (int handle)
     8int __close(int fh)
    109{
    11   ULONG rc;
    12   FS_VAR()
    13 
    14   FS_SAVE_LOAD();
    15   rc = DosClose (handle);
    16   FS_RESTORE();
    17   if (rc == 0)
    18     return 0;
    19   else
    20     {
    21       _sys_set_errno (rc);
    22       return -1;
    23     }
     10    if (!__libc_FHClose(fh))
     11        return -0;
     12    return -1;
    2413}
  • trunk/src/emx/src/lib/sys/__dup.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* sys/dup.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/dup.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                       -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
    45#define INCL_FSMACROS
    56#include <os2emx.h>
     7#include <errno.h>
     8#include <emx/io.h>
    69#include <emx/syscalls.h>
    710#include "syscalls.h"
    811
    9 int __dup (int handle)
     12int __dup(int fh)
    1013{
    11   ULONG rc;
    12   HFILE hNew;
    13   FS_VAR();
     14    PLIBCFH     pFH;
     15    int         fhNew;
     16    ULONG       rc;
    1417
    15   hNew = 0xffffffff;
    16   FS_SAVE_LOAD();
    17   rc = DosDupHandle (handle, &hNew);
    18   FS_RESTORE();
    19   if (rc != 0)
     18    /*
     19     * Get filehandle.
     20     */
     21    pFH = __libc_FH(fh);
     22    if (!pFH)
    2023    {
    21       _sys_set_errno (rc);
    22       return -1;
     24        errno = EBADF;
     25        return -1;
    2326    }
    24   return hNew;
     27
     28    /*
     29     * Choose path.
     30     */
     31    if (!pFH->pOps)
     32    {
     33        HFILE   hNew = ~0;
     34        FS_VAR();
     35        FS_SAVE_LOAD();
     36        rc = DosDupHandle(fh, &hNew);
     37        FS_RESTORE();
     38        fhNew = (int)hNew;
     39        if (!rc)
     40        {
     41            PLIBCFH pFHNew;
     42            rc = __libc_FHAllocate(hNew, pFH->fFlags, sizeof(LIBCFH), NULL, &pFHNew, NULL);
     43            if (!rc)
     44            {
     45                pFHNew->fFlags      = pFH->fFlags;
     46                pFHNew->iLookAhead  = pFH->iLookAhead;
     47            }
     48            else
     49                DosClose(hNew);
     50        }
     51    }
     52    else
     53    {
     54        fhNew = -1; /* any handle */
     55        rc = pFH->pOps->pfnDuplicate(pFH, fh, &fhNew);
     56    }
     57
     58    /*
     59     * Done.
     60     */
     61    if (rc != 0)
     62    {
     63        _sys_set_errno(rc);
     64        return -1;
     65    }
     66    return fhNew;
    2567}
  • trunk/src/emx/src/lib/sys/__dup2.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* sys/dup2.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/dup2.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                        -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
    45#define INCL_FSMACROS
    56#include <os2emx.h>
     7#include <errno.h>
    68#include <emx/syscalls.h>
     9#include <emx/io.h>
    710#include "syscalls.h"
    811
    9 int __dup2 (int handle1, int handle2)
     12int __dup2(int fh, int fhNew)
    1013{
    11   ULONG rc, state;
    12   HFILE hNew;
    13   FS_VAR();
     14    PLIBCFH     pFH;
     15    PLIBCFH     pFHNew;
     16    ULONG       rc;
    1417
    15   hNew = handle2;
    16   FS_SAVE_LOAD();
    17   if (handle1 == handle2)
    18     rc = DosQueryFHState (handle1, &state); /* Check HANDLE */
    19   else
    20     rc = DosDupHandle (handle1, &hNew);
    21   FS_RESTORE();
    22   if (rc != 0)
     18    /*
     19     * Validate the two handles.
     20     * (Specs saith fhNew must not be below zero.)
     21     */
     22    if (    fhNew < 0
     23        ||  !(pFH = __libc_FH(fh)))
    2324    {
    24       _sys_set_errno (rc);
    25       return -1;
     25        errno = EBADF;
     26        return -1;
    2627    }
    27   return hNew;
     28
     29    /*
     30     * If the two filehandles are the same, then just
     31     * check that it's still around and return accordingly.
     32     */
     33    if (fhNew == fh)
     34    {
     35        ULONG   ulState;
     36        FS_VAR();
     37        FS_SAVE_LOAD();
     38        rc = 0;
     39        if (!pFH->pOps)
     40            rc = DosQueryFHState(fh, &ulState);
     41        FS_RESTORE();
     42        if (rc)
     43        {
     44            _sys_set_errno(rc);
     45            return -1;
     46        }
     47        return fhNew;
     48    }
     49
     50    /*
     51     * Ensure the specified handle is within the bounds
     52     * of the number of filehandles this process can open.
     53     * (Specs saith so, and others say OS/2 may crash if fhNew is out of range.)
     54     */
     55    rc = __libc_FHEnsureHandles(fhNew);
     56    if (rc)
     57    {
     58        _sys_set_errno(rc);
     59        return -1;
     60    }
     61
     62    /*
     63     * If fhNew exists and is not of the OS/2 native
     64     * file handle type, we'll close it here.
     65     */
     66    pFHNew = __libc_FH(fhNew);
     67    if (pFHNew && pFHNew->pOps)
     68    {
     69        rc = __libc_FHClose(fhNew);
     70        if (rc)
     71            return -1; /* it sets errno */
     72    }
     73
     74    /*
     75     * Do the stuff.
     76     */
     77    if (!pFH->pOps)
     78    {
     79        HFILE   hNew = fhNew;
     80        FS_VAR();
     81
     82        FS_SAVE_LOAD();
     83        rc = DosDupHandle(fh, &hNew);
     84        if (!rc)
     85        {
     86            PLIBCFH pFHNew;
     87            rc = __libc_FHAllocate(hNew, pFH->fFlags, sizeof(LIBCFH), NULL, &pFHNew, NULL);
     88            if (!rc)
     89            {
     90                pFHNew->fFlags      = pFH->fFlags;
     91                pFHNew->iLookAhead  = pFH->iLookAhead;
     92            }
     93            else
     94                DosClose(hNew);
     95        }
     96        FS_RESTORE();
     97    }
     98    else
     99        rc = pFH->pOps->pfnDuplicate(pFH, fh, &fhNew);
     100
     101    /*
     102     * Done
     103     */
     104    if (rc)
     105    {
     106        _sys_set_errno(rc);
     107        return -1;
     108    }
     109    return fhNew;
    28110}
  • trunk/src/emx/src/lib/sys/__fcntl.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r870 r871  
    1 /* sys/fcntl.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/fcntl.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                         -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    910#define INCL_FSMACROS
    1011#include <os2emx.h>
     12#include <emx/io.h>
    1113#include <emx/syscalls.h>
    1214#include "syscalls.h"
     
    1416static int __fcntl_locking(int handle, int request, struct flock *pflock);
    1517
    16 int __fcntl (int handle, int request, int arg)
     18int __fcntl(int handle, int request, int arg)
    1719{
    18   ULONG rc;
    19   ULONG state, new_state;
    20   FS_VAR();
    21 
    22   switch (request)
    23     {
    24     case F_SETFL:
    25       return 0;
    26     case F_GETFD:
    27       FS_SAVE_LOAD();
    28       rc = DosQueryFHState (handle, &state);
    29       FS_RESTORE();
    30       if (rc != 0)
    31         {
    32           _sys_set_errno (rc);
    33           return -1;
    34         }
    35       return ((state & OPEN_FLAGS_NOINHERIT) ? 1 : 0);
    36     case F_SETFD:
    37       FS_SAVE_LOAD();
    38       rc = DosQueryFHState (handle, &state);
    39       FS_RESTORE();
    40       if (rc != 0)
    41         {
    42           _sys_set_errno (rc);
    43           return -1;
    44         }
    45       if (arg & 1)
    46         new_state = state | OPEN_FLAGS_NOINHERIT;
    47       else
    48         new_state = state & ~OPEN_FLAGS_NOINHERIT;
    49       if (new_state != state)
    50         {
    51           new_state &= 0x7f88;
    52           FS_SAVE_LOAD();
    53           rc = DosSetFHState (handle, new_state);
    54           FS_RESTORE();
    55           if (rc != 0)
    56             {
    57               _sys_set_errno (rc);
    58               return -1;
    59             }
    60         }
    61       return 0;
    62 
    63     case F_GETLK:   /* get record locking information */
    64     case F_SETLK:   /* set record locking information */
    65     case F_SETLKW:  /* F_SETLK; wait if blocked */
    66       return __fcntl_locking(handle, request, (struct flock*)arg);
    67 
    68     default:
    69       errno = EINVAL;
    70       return -1;
     20    ULONG     rc;
     21    ULONG     fulState;
     22    PLIBCFH   pFH;
     23    FS_VAR();
     24
     25    /*
     26     * Get the file handle data.
     27     */
     28    pFH = __libc_FH(handle);
     29    if (!pFH)
     30    {
     31        errno = EBADF;
     32        return -1;
     33    }
     34
     35    if (!pFH->pOps)
     36    {
     37        /*
     38         * Standard OS/2 File handle.
     39         */
     40        switch (request)
     41        {
     42            /*
     43             * Get file status flags and access modes.
     44             */
     45            case F_GETFL:
     46                return pFH->fFlags & (O_ACCMODE | O_APPEND | O_NONBLOCK | O_SYNC /*| O_*SYNC*/);
     47
     48            /*
     49             * Set file status flags.
     50             */
     51            case F_SETFL:
     52                /** @todo implement this properly. See FCNTLFLAGS. */
     53                return 0;
     54
     55            /*
     56             * Get file descriptor flags.
     57             * (At the moment FD_CLOEXEC is the only flag.)
     58             */
     59            case F_GETFD:
     60                FS_SAVE_LOAD();
     61                rc = DosQueryFHState(handle, &fulState);
     62                FS_RESTORE();
     63                if (rc != 0)
     64                {
     65                    _sys_set_errno(rc);
     66                    return -1;
     67                }
     68                return ((fulState & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0);
     69
     70            /*
     71             * Set file descriptor flags.
     72             * (At the moment FD_CLOEXEC is the only flag.)
     73             */
     74            case F_SETFD:
     75                FS_SAVE_LOAD();
     76                rc = DosQueryFHState(handle, &fulState);
     77                if (!rc)
     78                {
     79                    ULONG fulNewState;
     80                    if (arg & FD_CLOEXEC)
     81                        fulNewState = fulState | OPEN_FLAGS_NOINHERIT;
     82                    else
     83                        fulNewState = fulState & ~OPEN_FLAGS_NOINHERIT;
     84                    if (fulNewState != fulState)
     85                    {
     86                        fulNewState &= 0x7f88; /* Mask the flags accepted the API. */
     87                        rc = DosSetFHState(handle, fulNewState);
     88                    }
     89                }
     90                FS_RESTORE();
     91                if (rc)
     92                {
     93                    _sys_set_errno (rc);
     94                    return -1;
     95                }
     96                return 0;
     97
     98            /*
     99             * File locking.
     100             */
     101            case F_GETLK:   /* get record locking information */
     102            case F_SETLK:   /* set record locking information */
     103            case F_SETLKW:  /* F_SETLK; wait if blocked */
     104                return __fcntl_locking(handle, request, (struct flock*)arg);
     105
     106            default:
     107                errno = EINVAL;
     108                return -1;
     109        }
     110    }
     111    else
     112    {
     113        /*
     114         * Non-standard handle - call registered method.
     115         */
     116        int rcRet = 0;
     117        rc = pFH->pOps->pfnFileControl(pFH, handle, request, arg, &rcRet);
     118        if (rc)
     119        {
     120            _sys_set_errno(rc);
     121            return -1;
     122        }
     123        return rcRet;
    71124    }
    72125}
     
    78131   it's take from elsewhere. */
    79132
    80 static int __fcntl_locking (int hFile, int request, struct flock *pflock)
     133static int __fcntl_locking(int hFile, int request, struct flock *pflock)
    81134{
    82135    APIRET        rc;
     
    140193        }
    141194        if (    offStart < 0
    142             ||  cbRange + offStart < 0 )
     195            ||  cbRange + offStart < 0)
    143196        {
    144197            errno = EINVAL;
     
    195248                     && (   cbRange > LONG_MAX
    196249                         || offStart + cbRange > LONG_MAX)
    197                      )
    198                 )
    199               {
     250                    )
     251               )
     252            {
    200253                errno = EOVERFLOW;
    201254                return -1;
    202               }
     255            }
    203256#endif
    204257            memset(&aflock[(fLock + 1) & 1], 0, sizeof(aflock[0]));
  • trunk/src/emx/src/lib/sys/__fstat.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r870 r871  
    77#include <os2emx.h>
    88#include <string.h>
     9#include <errno.h>
    910#include <sys/types.h>
    1011#include <sys/stat.h>
     12#include <emx/io.h>
    1113#include <emx/syscalls.h>
    1214#include "syscalls.h"
     
    1416int __fstat(int hFile, struct stat *pStat)
    1517{
    16     ULONG rc;
    17     ULONG ulType;
    18     ULONG flFlags;
     18    ULONG   rc;
     19    ULONG   ulType;
     20    ULONG   flFlags;
     21    PLIBCFH pFH;
    1922    FS_VAR();
    2023
    2124    /*
    22      * Use query handle type to figure out the file type.
     25     * Get filehandle.
    2326     */
    24     memset(pStat, 0, sizeof(*pStat));
    25     FS_SAVE_LOAD();
    26     rc = DosQueryHType(hFile, &ulType, &flFlags);
    27     if (rc)
     27    pFH = __libc_FH(hFile);
     28    if (!pFH)
    2829    {
    29         FS_RESTORE();
    30         _sys_set_errno(rc);
     30        errno = EBADF;
    3131        return -1;
    3232    }
    33     switch (ulType & 0xff)
     33
     34    if (!pFH->pOps)
    3435    {
    35         case FHT_CHRDEV:
    36             pStat->st_mode = S_IFCHR;
    37             break;
    38         case FHT_PIPE:
    39             pStat->st_mode = S_IFSOCK;
    40             break;
    41         default:
    42             pStat->st_mode = S_IFREG;
    43             break;
    44     }
    45 
    46     if (pStat->st_mode == S_IFREG)
    47     {
    48         union
    49         {
    50             FILESTATUS3     fsts3;
    51             FILESTATUS3L    fsts3L;
    52         } info;
    53     #if OFF_MAX > LONG_MAX
    54         int     fLarge = 0;
    55     #endif
    56 
    5736        /*
    58          * Get file info.
     37         * Use query handle type to figure out the file type.
    5938         */
    60 #if OFF_MAX > LONG_MAX
    61         if (__pfnDosOpenL)
    62         {
    63             rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &info, sizeof(info.fsts3L));
    64             fLarge = 1;
    65         }
    66         else
    67 #endif
    68             rc = DosQueryFileInfo(hFile, FIL_STANDARD, &info, sizeof(info.fsts3));
     39        memset(pStat, 0, sizeof(*pStat));
     40        rc = DosQueryHType(hFile, &ulType, &flFlags);
    6941        if (rc)
    7042        {
    7143            FS_RESTORE();
    72             _sys_set_errno (rc);
     44            _sys_set_errno(rc);
    7345            return -1;
    7446        }
     47        switch (pFH->fFlags & F_TYPEMASK)
     48        {
     49            case F_DEV:     pStat->st_mode = S_IFCHR; break;
     50            case F_SOCKET:  pStat->st_mode = S_IFSOCK; break;
     51            case F_PIPE:    pStat->st_mode = S_IFSOCK/*??*/; break;
     52            default:
     53            case F_FILE:    pStat->st_mode = S_IFREG; break;
     54        }
    7555
    76         /*
    77          * Format stats struct.
    78          *      We know the info struct layouts!
    79          *      Only cbFile, cbFileAlloc and attrFile need be accessed
    80          *      using the specific structure.
    81          */
    82         /* Times: FAT might not return create and access time. */
    83         pStat->st_mtime = _sys_p2t(info.fsts3.ftimeLastWrite, info.fsts3.fdateLastWrite);
    84         if (    FTIMEZEROP(info.fsts3.ftimeCreation)
    85             &&  FDATEZEROP(info.fsts3.fdateCreation))
    86             pStat->st_ctime = pStat->st_mtime;
    87         else
    88             pStat->st_ctime = _sys_p2t(info.fsts3.ftimeCreation, info.fsts3.fdateCreation);
    89         if (    FTIMEZEROP(info.fsts3.ftimeLastAccess)
    90             &&  FDATEZEROP(info.fsts3.fdateLastAccess))
    91             pStat->st_atime = pStat->st_mtime;
    92         else
    93             pStat->st_atime = _sys_p2t(info.fsts3.ftimeLastAccess, info.fsts3.fdateLastAccess);
     56        FS_SAVE_LOAD();
     57        if (pStat->st_mode == S_IFREG)
     58        {
     59            union
     60            {
     61                FILESTATUS3     fsts3;
     62                FILESTATUS3L    fsts3L;
     63            } info;
     64        #if OFF_MAX > LONG_MAX
     65            int     fLarge = 0;
     66        #endif
     67
     68            /*
     69             * Get file info.
     70             */
     71#if OFF_MAX > LONG_MAX
     72            if (__pfnDosOpenL)
     73            {
     74                rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &info, sizeof(info.fsts3L));
     75                fLarge = 1;
     76            }
     77            else
     78#endif
     79                rc = DosQueryFileInfo(hFile, FIL_STANDARD, &info, sizeof(info.fsts3));
     80            if (rc)
     81            {
     82                FS_RESTORE();
     83                _sys_set_errno (rc);
     84                return -1;
     85            }
     86
     87            /*
     88             * Format stats struct.
     89             *      We know the info struct layouts!
     90             *      Only cbFile, cbFileAlloc and attrFile need be accessed
     91             *      using the specific structure.
     92             */
     93            /* Times: FAT might not return create and access time. */
     94            pStat->st_mtime = _sys_p2t(info.fsts3.ftimeLastWrite, info.fsts3.fdateLastWrite);
     95            if (    FTIMEZEROP(info.fsts3.ftimeCreation)
     96                &&  FDATEZEROP(info.fsts3.fdateCreation))
     97                pStat->st_ctime = pStat->st_mtime;
     98            else
     99                pStat->st_ctime = _sys_p2t(info.fsts3.ftimeCreation, info.fsts3.fdateCreation);
     100            if (    FTIMEZEROP(info.fsts3.ftimeLastAccess)
     101                &&  FDATEZEROP(info.fsts3.fdateLastAccess))
     102                pStat->st_atime = pStat->st_mtime;
     103            else
     104                pStat->st_atime = _sys_p2t(info.fsts3.ftimeLastAccess, info.fsts3.fdateLastAccess);
    94105
    95106#if OFF_MAX > LONG_MAX
    96         if (fLarge)
    97         {
    98             pStat->st_size = info.fsts3L.cbFile;
    99             pStat->st_blocks = info.fsts3L.cbFileAlloc / S_BLKSIZE;
    100             rc = info.fsts3L.attrFile;
     107            if (fLarge)
     108            {
     109                pStat->st_size = info.fsts3L.cbFile;
     110                pStat->st_blocks = info.fsts3L.cbFileAlloc / S_BLKSIZE;
     111                rc = info.fsts3L.attrFile;
     112            }
     113            else
     114#endif
     115            {
     116                pStat->st_size = info.fsts3.cbFile;
     117                pStat->st_blocks = info.fsts3.cbFileAlloc / S_BLKSIZE;
     118                rc = info.fsts3.attrFile;
     119            }
     120            pStat->st_attr = rc;
     121            if (rc & FILE_READONLY)
     122                pStat->st_mode |= (S_IREAD >> 6) * 0111;
     123            else
     124                pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
    101125        }
    102126        else
    103 #endif
    104127        {
    105             pStat->st_size = info.fsts3.cbFile;
    106             pStat->st_blocks = info.fsts3.cbFileAlloc / S_BLKSIZE;
    107             rc = info.fsts3.attrFile;
     128            pStat->st_size = 0;
     129            rc = DosQueryFHState(hFile, &flFlags);
     130            if (rc)
     131            {
     132                FS_RESTORE();
     133                _sys_set_errno (rc);
     134                return -1;
     135            }
     136            if ((flFlags & 7) == OPEN_ACCESS_READONLY)
     137                pStat->st_mode |= (S_IREAD >> 6) * 0111;
     138            else
     139                pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
    108140        }
    109         pStat->st_attr = rc;
    110         if (rc & FILE_READONLY)
    111             pStat->st_mode |= (S_IREAD >> 6) * 0111;
    112         else
    113             pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     141
     142        /* default fake stuff */
     143        pStat->st_uid = 0;
     144        pStat->st_gid = 0;
     145        pStat->st_ino = _sys_ino++;
     146        if (_sys_ino == 0)
     147            _sys_ino = 1;
     148        pStat->st_dev = 0;
     149        pStat->st_rdev = 0;
     150        pStat->st_nlink = 1;
     151        pStat->st_blksize = 4096*48;
     152        FS_RESTORE();
    114153    }
    115154    else
    116155    {
    117         pStat->st_size = 0;
    118         rc = DosQueryFHState(hFile, &flFlags);
    119         if (rc)
    120         {
    121             FS_RESTORE();
    122             _sys_set_errno (rc);
    123             return -1;
    124         }
    125         if ((flFlags & 7) == OPEN_ACCESS_READONLY)
    126             pStat->st_mode |= (S_IREAD >> 6) * 0111;
    127         else
    128             pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     156        /*
     157         * Non-standard handle - fail.
     158         */
     159        errno = EPERM;
     160        return -1;
    129161    }
    130162
    131     /* default fake stuff */
    132     pStat->st_uid = 0;
    133     pStat->st_gid = 0;
    134     pStat->st_ino = _sys_ino++;
    135     if (_sys_ino == 0)
    136         _sys_ino = 1;
    137     pStat->st_dev = 0;
    138     pStat->st_rdev = 0;
    139     pStat->st_nlink = 1;
    140     pStat->st_blksize = 4096*48;
    141     FS_RESTORE();
    142163    return 0;
    143164}
  • trunk/src/emx/src/lib/sys/__ftruncate.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    77#define INCL_FSMACROS
    88#include <os2emx.h>
    9 #include <emx/syscalls.h>
    109#include <limits.h>
    1110#include <errno.h>
     11#include <emx/io.h>
     12#include <emx/syscalls.h>
    1213#include "syscalls.h"
    1314
     
    1516{
    1617    ULONG       rc;
    17     off_t       cbCur;
    18     union
    19     {
    20         FILESTATUS3     fsts3;
    21         FILESTATUS3L    fsts3L;
    22     } info;
    23     FS_VAR();
     18    PLIBCFH     pFH;
    2419
    2520    /*
    26      * First step, figure out the current size.
     21     * Get filehandle.
    2722     */
    28     FS_SAVE_LOAD();
    29 #if OFF_MAX > LONG_MAX
    30     if (__pfnDosOpenL)
     23    pFH = __libc_FH(hFile);
     24    if (!pFH)
    3125    {
    32         rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &info, sizeof(info.fsts3L));
    33         cbCur = info.fsts3L.cbFile;
    34     }
    35     else
    36 #endif
    37     {
    38         rc = DosQueryFileInfo(hFile, FIL_STANDARD, &info, sizeof(info.fsts3));
    39         cbCur = info.fsts3.cbFile;
    40     }
    41     FS_RESTORE();
    42     if (rc)
    43     {
    44         _sys_set_errno(rc);
     26        errno = EBADF;
    4527        return -1;
    4628    }
    4729
     30    if (!pFH->pOps)
     31    {
     32        /*
     33         * Standard OS/2 file handle.
     34         */
     35        off_t       cbCur;
     36        union
     37        {
     38            FILESTATUS3     fsts3;
     39            FILESTATUS3L    fsts3L;
     40        } info;
     41        FS_VAR();
    4842
    49     /*
    50      * Is the file larger than the truncation size?
    51      * Then set the desired file size.
    52      */
    53     if (cbCur > cbFile)
    54     {
     43        /*
     44         * First step, figure out the current size.
     45         */
    5546        FS_SAVE_LOAD();
    5647#if OFF_MAX > LONG_MAX
    57         if (__pfnDosSetFileSizeL)
    58             rc = __pfnDosSetFileSizeL(hFile, cbFile);
     48        if (__pfnDosOpenL)
     49        {
     50            rc = DosQueryFileInfo(hFile, FIL_STANDARDL, &info, sizeof(info.fsts3L));
     51            cbCur = info.fsts3L.cbFile;
     52        }
    5953        else
     54#endif
    6055        {
    61             if (cbFile > __LONG_MAX)
    62             {
    63                 FS_RESTORE();
    64                 errno = EOVERFLOW;
    65                 return -1;
    66             }
    67             rc = DosSetFileSize(hFile, cbFile);
     56            rc = DosQueryFileInfo(hFile, FIL_STANDARD, &info, sizeof(info.fsts3));
     57            cbCur = info.fsts3.cbFile;
    6858        }
    69 #else
    70         rc = DosSetFileSize(hFile, cbFile);
    71 #endif
    7259        FS_RESTORE();
    73         if (rc != 0)
     60        if (rc)
    7461        {
    7562            _sys_set_errno(rc);
    7663            return -1;
    7764        }
     65
     66
     67        /*
     68         * Is the file larger than the truncation size?
     69         * Then set the desired file size.
     70         */
     71        if (cbCur > cbFile)
     72        {
     73            FS_SAVE_LOAD();
     74#if OFF_MAX > LONG_MAX
     75            if (__pfnDosSetFileSizeL)
     76                rc = __pfnDosSetFileSizeL(hFile, cbFile);
     77            else
     78            {
     79                if (cbFile > __LONG_MAX)
     80                {
     81                    FS_RESTORE();
     82                    errno = EOVERFLOW;
     83                    return -1;
     84                }
     85                rc = DosSetFileSize(hFile, cbFile);
     86            }
     87#else
     88            rc = DosSetFileSize(hFile, cbFile);
     89#endif
     90            FS_RESTORE();
     91            if (rc != 0)
     92            {
     93                _sys_set_errno(rc);
     94                return -1;
     95            }
     96        }
     97    }
     98    else
     99    {
     100        /*
     101         * Non-standard file handle - fail.
     102         */
     103        errno = EPERM;
     104        return -1;
    78105    }
    79106    return 0;
  • trunk/src/emx/src/lib/sys/__imphandle.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r870 r871  
    1 /* imphandl.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes */
     1/* imphandl.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes
     2                        -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     5#include <emx/io.h>
    46#include <emx/syscalls.h>
    57
    6 int __imphandle (int handle)
     8int __imphandle(int fh)
    79{
    8   return handle;
     10    PLIBCFH pFH = __libc_FH(fh);
     11    if (pFH)
     12        return fh;
     13    return -1;
    914}
  • trunk/src/emx/src/lib/sys/__initdll.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r870 r871  
    122122     * Init long file I/O functions.
    123123     * This is weak, so that it's only linked in when we're building with
    124      * large file suppoort enabled.
     124     * large file support enabled.
    125125     */
    126126    if (_sys_init_largefileio)
    127127        _sys_init_largefileio();
     128
     129    /*
     130     * Init file handles.
     131     */
     132    rc = _sys_init_filehandles();
     133    if (rc)
     134        return -1;
    128135
    129136    /*
  • trunk/src/emx/src/lib/sys/__ioctl1.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r870 r871  
    1 /* sys/ioctl1.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/ioctl1.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                          -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    56#define INCL_FSMACROS
    67#include <os2emx.h>
     8#include <emx/io.h>
    79#include <emx/syscalls.h>
    810#include "syscalls.h"
    911
    1012
    11 int __ioctl1 (int handle, int code)
     13/** Obsolete interface to DosQueryHType.
     14 * @deprecated Do not use this!!
     15 */
     16int __ioctl1(int handle, int code)
    1217{
    13   ULONG rc;
    14   ULONG htype, hflags;
    15   FS_VAR();
     18    PLIBCFH  pFH;
    1619
    17   if (code != 0)
     20    /*
     21     * Get filehandle.
     22     */
     23    pFH = __libc_FH(handle);
     24    if (!pFH)
    1825    {
    19       errno = EINVAL;
    20       return -1;
     26        errno = EBADF;
     27        return -1;
    2128    }
    22   FS_SAVE_LOAD();
    23   rc = DosQueryHType (handle, &htype, &hflags);
    24   FS_RESTORE();
    25   if (rc != 0)
     29    if (pFH->pOps)
    2630    {
    27       _sys_set_errno (rc);
    28       return -1;
     31        errno = EINVAL;
     32        return -1;
    2933    }
    30   if ((htype & 0xff) == 0)
    31     return 0;
    32   return (hflags & 0x0f) | 0x80;
     34
     35    /*
     36     * Check code.
     37     */
     38    switch (code)
     39    {
     40        /** @todo get rid of this hardcoded shit. */
     41        case 0:
     42        {
     43            ULONG rc;
     44            ULONG htype, hflags;
     45            FS_VAR();
     46            FS_SAVE_LOAD();
     47            rc = DosQueryHType(handle, &htype, &hflags);
     48            FS_RESTORE();
     49            if (rc)
     50            {
     51                _sys_set_errno(rc);
     52                return -1;
     53            }
     54            if ((htype & 0xff) == 0)
     55              return 0;
     56            return (hflags & 0x0f) | 0x80;
     57        }
     58    }
     59
     60    /* default */
     61    errno = EINVAL;
     62    return -1;
    3363}
  • trunk/src/emx/src/lib/sys/__ioctl2.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r870 r871  
    1 /* sys/ioctl2.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/ioctl2.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                          -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    89#define INCL_FSMACROS
    910#include <os2emx.h>
     11#include <sys/filio.h>
     12#include <emx/io.h>
    1013#include <emx/syscalls.h>
    1114#include "syscalls.h"
     
    1518 */
    1619#define __IOCLW(a) ((unsigned short)(a))
     20/** This is the syscall for ioctl(). */
     21int __ioctl2(int handle, unsigned long request, int arg)
     22{
     23    PLIBCFH pFH;
     24    ULONG   rc;
     25    ULONG   type;
     26    ULONG   flags;
     27    int *   int_ptr;
     28    FS_VAR();
    1729
    18 int __ioctl2 (int handle, unsigned long request, int arg)
    19 {
    20   ULONG rc;
    21   ULONG type, flags;
    22   int *int_ptr;
    23   FS_VAR();
    24 
    25   switch (__IOCLW(request))
     30    /*
     31     * Get filehandle.
     32     */
     33    pFH = __libc_FH(handle);
     34    if (!pFH)
    2635    {
    27     case __IOCLW(FGETHTYPE):
    28       int_ptr = (int *)arg;
    29       FS_SAVE_LOAD();
    30       rc = DosQueryHType (handle, &type, &flags);
    31       FS_RESTORE();
    32       if (rc != 0)
    33         {
    34           _sys_set_errno (rc);
    35           return -1;
    36         }
    37       switch (type & 0xff)
    38         {
    39         case 0:                 /* File */
    40           *int_ptr = HT_FILE;
    41           break;
    42         case 1:                 /* Character device */
    43           if (flags & 3)
    44             *int_ptr = HT_DEV_CON;
    45           else if (flags & 4)
    46             *int_ptr = HT_DEV_NUL;
    47           else if (flags & 8)
    48             *int_ptr = HT_DEV_CLK;
    49           else
    50             *int_ptr = HT_DEV_OTHER;
    51           break;
    52         case 2:                 /* Pipe */
    53           FS_SAVE_LOAD();
    54           rc = DosQueryNPHState (handle, &flags);
    55           FS_RESTORE();
    56           if (rc == 0 || rc == ERROR_PIPE_NOT_CONNECTED)
    57             *int_ptr = HT_NPIPE;
    58           else
    59             *int_ptr = HT_UPIPE;
    60           break;
    61         default:
    62           errno = EINVAL;
    63           return -1;
    64         }
    65       return 0;
    66     default:
    67       errno = EINVAL;
    68       return -1;
     36        errno = EBADF;
     37        return -1;
    6938    }
    7039
     40    if (!pFH->pOps)
     41    {
     42        /*
     43         * Standard OS/2 filehandle.
     44         */
     45        switch (__IOCLW(request))
     46        {
     47            case __IOCLW(FGETHTYPE):
     48                int_ptr = (int *)arg;
     49                FS_SAVE_LOAD();
     50                rc = DosQueryHType (handle, &type, &flags);
     51                FS_RESTORE();
     52                if (rc != 0)
     53                {
     54                    _sys_set_errno (rc);
     55                    return -1;
     56                }
     57                switch (type & 0xff)
     58                {
     59                    case 0:                 /* File */
     60                        *int_ptr = HT_FILE;
     61                        break;
     62                    case 1:                 /* Character device */
     63                        if (flags & 3)
     64                            *int_ptr = HT_DEV_CON;
     65                        else if (flags & 4)
     66                            *int_ptr = HT_DEV_NUL;
     67                        else if (flags & 8)
     68                            *int_ptr = HT_DEV_CLK;
     69                        else
     70                            *int_ptr = HT_DEV_OTHER;
     71                        break;
     72                    case 2:                 /* Pipe */
     73                        FS_SAVE_LOAD();
     74                        rc = DosQueryNPHState (handle, &flags);
     75                        FS_RESTORE();
     76                        if (rc == 0 || rc == ERROR_PIPE_NOT_CONNECTED)
     77                            *int_ptr = HT_NPIPE;
     78                        else
     79                            *int_ptr = HT_UPIPE;
     80                        break;
     81                    default:
     82                        errno = EINVAL;
     83                        return -1;
     84                }
     85                return 0;
     86
     87/** @todo lots of FIO* things to go!! */
     88#if 0
     89
     90#define FIOCLEX          _IO('f', 1)            /* set close on exec on fd */
     91#define FIONCLEX         _IO('f', 2)            /* remove close on exec */
     92#define FIONREAD        _IOR('f', 127, int)     /* get # bytes to read */
     93#define FIONBIO         _IOW('f', 126, int)     /* set/clear non-blocking i/o */
     94#define FIOASYNC        _IOW('f', 125, int)     /* set/clear async i/o */
     95#define FIOSETOWN       _IOW('f', 124, int)     /* set owner */
     96#define FIOGETOWN       _IOR('f', 123, int)     /* get owner */
     97#define FIODTYPE        _IOR('f', 122, int)     /* get d_flags type part */
     98#define FIOGETLBA       _IOR('f', 121, int)     /* get start blk # */
     99
     100#endif
     101
     102            default:
     103                errno = EINVAL;
     104                return -1;
     105        }
     106    }
     107    else
     108    {
     109        /*
     110         * Non-standard filehandle.
     111         */
     112        int rcRet;
     113        rc = pFH->pOps->pfnIOControl(pFH, handle, request, arg, &rcRet);
     114        if (rc)
     115        {
     116            _sys_set_errno(rc);
     117            return -1;
     118        }
     119        return rcRet;
     120    }
    71121}
  • trunk/src/emx/src/lib/sys/__lseek.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    77#define INCL_FSMACROS
    88#include <os2emx.h>
    9 #include <emx/syscalls.h>
    109#include <limits.h>
    1110#include <errno.h>
     11#include <emx/io.h>
     12#include <emx/syscalls.h>
    1213#include "syscalls.h"
    1314
     
    1516{
    1617    ULONG   rc;
     18    PLIBCFH pFH;
    1719    off_t   cbNew;
    1820    FS_VAR();
    1921
     22    /*
     23     * Get filehandle / validate input.
     24     */
     25    pFH = __libc_FH(hFile);
     26    if (!pFH)
     27    {
     28        errno = EBADF;
     29        return -1;
     30    }
    2031    if (origin == FILE_SECTOR)
    2132    {
     
    2435    }
    2536
    26     FS_SAVE_LOAD();
     37    if (!pFH->pOps)
     38    {
     39        /*
     40         * Standard OS/2 filehandle.
     41         */
     42        FS_SAVE_LOAD();
    2743#if OFF_MAX > LONG_MAX
    28     if (__pfnDosSetFilePtrL)
    29     {
    30         LONGLONG cbNewTmp;
    31         rc = __pfnDosSetFilePtrL(hFile, off, origin, &cbNewTmp);
    32         cbNew = cbNewTmp;
     44        if (__pfnDosSetFilePtrL)
     45        {
     46            LONGLONG cbNewTmp;
     47            rc = __pfnDosSetFilePtrL(hFile, off, origin, &cbNewTmp);
     48            cbNew = cbNewTmp;
     49        }
     50        else
     51        {
     52            ULONG cbNewTmp;
     53            if (off > LONG_MAX || off < LONG_MIN)
     54            {
     55                FS_RESTORE();
     56                errno = EOVERFLOW;
     57                return -1;
     58            }
     59            rc = DosSetFilePtr(hFile, off, origin, &cbNewTmp);
     60            cbNew = cbNewTmp;
     61        }
     62#else
     63        {
     64            ULONG cbNewTmp;
     65            rc = DosSetFilePtr(hFile, off, origin, &cbNewTmp);
     66            cbNew = cbNewTmp;
     67        }
     68#endif
     69        FS_RESTORE();
     70
     71        if (rc)
     72        {
     73            _sys_set_errno (rc);
     74            return -1;
     75        }
    3376    }
    3477    else
    3578    {
    36         ULONG cbNewTmp;
    37         if (off > LONG_MAX || off < LONG_MIN)
    38         {
    39             FS_RESTORE();
    40             errno = EOVERFLOW;
    41             return -1;
    42         }
    43         rc = DosSetFilePtr(hFile, off, origin, &cbNewTmp);
    44         cbNew = cbNewTmp;
    45     }
    46 #else
    47     {
    48         ULONG cbNewTmp;
    49         rc = DosSetFilePtr(hFile, off, origin, &cbNewTmp);
    50         cbNew = cbNewTmp;
    51     }
    52 #endif
    53     FS_RESTORE();
    54 
    55     if (rc)
    56     {
    57         _sys_set_errno (rc);
     79        /*
     80         * Non-standard filehandle - fail.
     81         */
     82        errno = EOPNOTSUPP;
    5883        return -1;
    5984    }
  • trunk/src/emx/src/lib/sys/__open.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r870 r871  
    1212#include <limits.h>
    1313#include <emx/syscalls.h>
     14#include <emx/io.h>
    1415#include <alloca.h>
    1516#include "syscalls.h"
    1617
    17 int __open(const char *pszFile, int flags, off_t cbInitial)
     18int __open(const char *pszFile, int flags, off_t cbInitial, unsigned fLibc, PLIBCFH *ppFH)
    1819{
    1920    ULONG   rc;
     
    119120    }
    120121#endif
     122
     123    if (!rc)
     124    {
     125        ULONG   fulType;
     126        ULONG   fulDevFlags;
     127
     128        /*
     129         * Figure the handle type.
     130         */
     131        rc = DosQueryHType(hFile, &fulType, &fulDevFlags);
     132        if (!rc)
     133        {
     134            switch (fulType & 0xff)
     135            {
     136                default: /* paranoia */
     137                case HANDTYPE_FILE:
     138                    fLibc |= F_FILE;
     139                    break;
     140                case HANDTYPE_DEVICE:
     141                    fLibc |= F_DEV;
     142                    break;
     143                case HANDTYPE_PIPE:
     144                    fLibc |= F_PIPE;
     145                    break;
     146            }
     147
     148            /*
     149             * Register the handle.
     150             */
     151            rc = __libc_FHAllocate(hFile, fLibc, sizeof(LIBCFH), NULL, ppFH, NULL);
     152        }
     153
     154        if (rc)
     155            DosClose(hFile);
     156    }
    121157    FS_RESTORE();
    122158
  • trunk/src/emx/src/lib/sys/__pipe.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1 /* sys/pipe.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/pipe.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                        -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
     
    67#include <os2safe.h>
    78#include <os2emx.h>
     9#include <sys/fcntl.h>
    810#include <emx/syscalls.h>
     11#include <emx/io.h>
    912#include "syscalls.h"
    1013
    11 int __pipe (int *two_handles, int pipe_size)
     14int __pipe(int *two_handles, int pipe_size, PLIBCFH *ppFHRead, PLIBCFH *ppFHWrite)
    1215{
    13   ULONG rc;
    14   FS_VAR();
     16    ULONG rc;
     17    FS_VAR();
    1518
    16   FS_SAVE_LOAD();
    17   rc = DosCreatePipe ((PHFILE)&two_handles[0], (PHFILE)&two_handles[1],
    18                       pipe_size);
    19   FS_RESTORE();
    20   if (rc != 0)
     19    FS_SAVE_LOAD();
     20    /*
     21     * Create the pipe
     22     */
     23    rc = DosCreatePipe((PHFILE)&two_handles[0], (PHFILE)&two_handles[1], pipe_size);
     24    if (!rc)
    2125    {
    22       _sys_set_errno (rc);
    23       return -1;
     26        /*
     27         * Register the handle.
     28         */
     29        rc = __libc_FHAllocate((HFILE)two_handles[0], F_PIPE | O_RDONLY, sizeof(LIBCFH), NULL, ppFHRead, NULL);
     30        if (!rc)
     31            rc = __libc_FHAllocate((HFILE)two_handles[1], F_PIPE | O_WRONLY, sizeof(LIBCFH), NULL, ppFHWrite, NULL);
     32        if (rc)
     33        {
     34            DosClose((HFILE)two_handles[0]);
     35            DosClose((HFILE)two_handles[1]);
     36        }
    2437    }
    25   return 0;
     38    FS_RESTORE();
     39
     40    /*
     41     * Handle error.
     42     */
     43    if (rc)
     44    {
     45        _sys_set_errno(rc);
     46        return -1;
     47    }
     48    return 0;
    2649}
  • trunk/src/emx/src/lib/sys/__read.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1 /* sys/read.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/read.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                        -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
    45#define INCL_FSMACROS
     6#define INCL_FPCWMACROS
    57#define INCL_ERRORS
    68#include <os2emx.h>
     9#include <errno.h>
    710#include <stdlib.h>
    811#include <memory.h>
    912#include <emx/umalloc.h>
     13#include <emx/io.h>
    1014#include <emx/syscalls.h>
    1115#include "syscalls.h"
    1216
    13 int __read (int handle, void *buf, size_t nbyte)
     17int __read (int handle, void *buf, size_t cbToRead)
    1418{
    15   ULONG rc;
    16   ULONG n;
    17   void *pvBuf_safe = NULL;
    18   FS_VAR();
     19    ULONG   rc;
     20    PLIBCFH pFH;
     21    ULONG   cbRead;
    1922
    20   /*
    21    * Devices doesn't like getting high addresses.
    22    */
    23   if ((unsigned)buf >= 512*1024*1024)
    24   {
    25     ULONG   ulType = 0;
    26     ULONG   ulAttr = 0;
    27     FS_SAVE_LOAD();
    28     rc = DosQueryHType(handle, &ulType, &ulAttr);
    29     FS_RESTORE();
     23    /*
     24     * Get filehandle.
     25     */
     26    pFH = __libc_FH(handle);
     27    if (!pFH)
     28    {
     29        errno = EBADF;
     30        return -1;
     31    }
    3032
    31     if (!rc && (ulType & 0xf) == HANDTYPE_DEVICE)
    32       {
    33         pvBuf_safe = _lmalloc(nbyte);
    34         if (!pvBuf_safe)
    35             return ERROR_NOT_ENOUGH_MEMORY;
    36         memcpy(pvBuf_safe, buf, nbyte);
    37       }
    38   }
     33    if (!pFH->pOps)
     34    {
     35        /*
     36         * Standard OS/2 filehandle.
     37         */
     38        void   *pvBuf_safe = NULL;
     39        FS_VAR();
     40        FSCW_VAR();
    3941
    40   FS_SAVE_LOAD();
    41   rc = DosRead (handle, pvBuf_safe ? pvBuf_safe : buf, nbyte, &n);
    42   FS_RESTORE();
    43   if (pvBuf_safe)
     42        /*
     43         * Devices doesn't like getting high addresses.
     44         *      Allocate a buffer in the low heap.
     45         */
     46        if (    (pFH->fFlags & F_TYPEMASK) == F_DEV
     47            &&  (unsigned)buf >= 512*1024*1024)
     48        {
     49            pvBuf_safe = _lmalloc(cbToRead);
     50            if (!pvBuf_safe)
     51                return ERROR_NOT_ENOUGH_MEMORY;
     52            memcpy(pvBuf_safe, buf, cbToRead);
     53        }
     54
     55        FS_SAVE_LOAD();
     56        FSCW_SAVE();
     57        rc = DosRead(handle, pvBuf_safe ? pvBuf_safe : buf, cbToRead, &cbRead);
     58        FSCW_RESTORE();
     59        FS_RESTORE();
     60        if (pvBuf_safe)
     61        {
     62            memcpy(buf, pvBuf_safe, cbToRead);
     63            free(pvBuf_safe);
     64        }
     65    }
     66    else
    4467    {
    45       memcpy(buf, pvBuf_safe, nbyte);
    46       free(pvBuf_safe);
     68        /*
     69         * Non-standard filehandle.
     70         */
     71        rc = pFH->pOps->pfnRead(pFH, handle, buf, cbToRead, &cbRead);
    4772    }
    48   if (rc == 0)
    49     return n;
    50   else
     73
     74    /*
     75     * Handle errors.
     76     */
     77    if (rc)
    5178    {
    52       _sys_set_errno (rc);
    53       return -1;
     79        _sys_set_errno(rc);
     80        return -1;
    5481    }
     82
     83    return cbRead;
    5584}
  • trunk/src/emx/src/lib/sys/__write.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r870 r871  
    1 /* sys/write.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
     1/* sys/write.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes
     2                         -- Copyright (c) 2003 by Knut St. Osmunden */
    23
    34#include "libc-alias.h"
    45#define INCL_FSMACROS
     6#define INCL_FPCWMACROS
    57#define INCL_ERRORS
    68#include <os2emx.h>
    79#include <memory.h>
    810#include <stdlib.h>
     11#include <errno.h>
     12#include <emx/io.h>
     13#include <emx/umalloc.h>
    914#include <emx/syscalls.h>
    10 #include <emx/umalloc.h>
    1115#include "syscalls.h"
    1216
    13 int __write (int handle, const void *buf, size_t nbyte)
     17int __write(int handle, const void *buf, size_t cbToWrite)
    1418{
    15   ULONG rc;
    16   ULONG n;
    17   void *pvBuf_safe = NULL;
    18   FS_VAR();
     19    PLIBCFH pFH;
     20    ULONG   rc;
     21    ULONG   cbWritten;
     22    FS_VAR();
     23    FSCW_VAR();
    1924
    20   /*
    21    * Devices doesn't like getting high addresses.
    22    */
    23   if ((unsigned)buf >= 512*1024*1024)
    24   {
    25     ULONG   ulType = 0;
    26     ULONG   ulAttr = 0;
    27     FS_SAVE_LOAD();
    28     rc = DosQueryHType(handle, &ulType, &ulAttr);
    29     FS_RESTORE();
    3025
    31     if (!rc && (ulType & 0xf) == HANDTYPE_DEVICE)
    32       {
    33         if (nbyte > 256)
    34           { /* use heap for large buffers */
    35             pvBuf_safe = _lmalloc(nbyte);
    36             if (!pvBuf_safe)
    37                 return ERROR_NOT_ENOUGH_MEMORY;
    38             memcpy(pvBuf_safe, buf, nbyte);
    39             buf = pvBuf_safe;
    40           }
    41         else
    42           { /* use stack for small buffers */
    43             pvBuf_safe = alloca(nbyte);
    44             memcpy(pvBuf_safe, buf, nbyte);
    45             buf = pvBuf_safe;
    46             pvBuf_safe = NULL;
    47           }
    48       }
    49   }
     26    /*
     27     * Get filehandle.
     28     */
     29    pFH = __libc_FH(handle);
     30    if (!pFH)
     31    {
     32        errno = EBADF;
     33        return -1;
     34    }
    5035
    51   FS_SAVE_LOAD();
    52   rc = DosWrite (handle, buf, nbyte, &n);
    53   FS_RESTORE();
     36    if (!pFH->pOps)
     37    {
     38        /*
     39         * Standard OS/2 filehandle.
     40         */
     41        void *pvBuf_safe = NULL;
    5442
    55   if (pvBuf_safe)
    56       free(pvBuf_safe);
    57   if (rc == 0)
    58     return n;
    59   else
     43        /*
     44         * Devices doesn't like getting high addresses.
     45         */
     46        if (    (pFH->fFlags & F_TYPEMASK) == F_DEV
     47            &&  (unsigned)buf >= 512*1024*1024)
     48        {
     49            if (cbToWrite > 256)
     50            {   /* use heap for large buffers */
     51                pvBuf_safe = _lmalloc(cbToWrite);
     52                if (!pvBuf_safe)
     53                    return ERROR_NOT_ENOUGH_MEMORY;
     54                memcpy(pvBuf_safe, buf, cbToWrite);
     55                buf = pvBuf_safe;
     56            }
     57            else
     58            {   /* use stack for small buffers */
     59                pvBuf_safe = alloca(cbToWrite);
     60                memcpy(pvBuf_safe, buf, cbToWrite);
     61                buf = pvBuf_safe;
     62                pvBuf_safe = NULL;
     63            }
     64        }
     65
     66        FS_SAVE_LOAD();
     67        FSCW_SAVE();
     68        rc = DosWrite(handle, buf, cbToWrite, &cbWritten);
     69        FSCW_RESTORE();
     70        FS_RESTORE();
     71
     72        if (pvBuf_safe)
     73            free(pvBuf_safe);
     74    }
     75    else
    6076    {
    61       _sys_set_errno (rc);
    62       return -1;
     77        /*
     78         * Non-standard filehandle.
     79         */
     80        rc = pFH->pOps->pfnWrite(pFH, handle, buf, cbToWrite, &cbWritten);
    6381    }
     82
     83    /*
     84     * Handle error.
     85     */
     86    if (rc)
     87    {
     88        _sys_set_errno(rc);
     89        return -1;
     90    }
     91    return cbWritten;
    6492}
     93
  • trunk/src/emx/src/lib/sys/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r870 r871  
    186186
    187187
    188 /** @group Init functions
     188/** @group Init Functions
    189189 * @{ */
    190190extern void             __init(int fDefaultHeapInHighMem);
     
    193193extern int              _sys_init_environ(const char *pszEnv);
    194194extern void             _sys_init_largefileio(void);
    195 /** @} */
     195extern int              _sys_init_filehandles(void);
     196/** @} */
     197
     198/** @group Term Functions
     199 * @{ */
     200extern int              _sys_term_filehandles(void);
     201/** @} */
     202
  • trunk/src/emx/version.smak

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r870 r871  
    44VH = 0
    55# Middle part of version number
    6 VM = 4
     6VM = 5
    77# Low part of version number
    8 VL = 1
     8VL = 0
    99
    1010# The name of this package
Note: See TracChangeset for help on using the changeset viewer.