Changeset 1454


Ignore:
Timestamp:
Sep 4, 2004, 8:22:38 AM (21 years ago)
Author:
bird
Message:

Joined with the fork() tree from netlabs.cvs.

Location:
trunk/src/emx
Files:
32 added
4 deleted
211 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/Makefile

    • Property cvs2svn:cvs-rev changed from 1.47 to 1.48
    r1453 r1454  
    9191
    9292# The C compiler
    93 CC = gcc -c -Zmt -fmessage-length=150
     93CC = gcc -c -Zmt -fmessage-length=0
    9494# The C compiler flags
    9595ifndef NO_LOCAL_HEADERS
     
    118118# Linker flags
    119119LDFLAGS     = $(LDFLAGS.$(MODE)) $(LDFLAGS.KIND) -Zmap -Zstack 1024 -Zhigh-mem $(LIBS)
    120 LDFLAGS.DLL = $(LDFLAGS) -Zdll
     120LDFLAGS.DLL = $(LDFLAGS) -Zdll -Zfork
    121121# Linker flags for different build modes
    122122LDFLAGS.opt = -g -Zcrtdll=c_dll
     
    329329
    330330dep depend:
    331         @$(MAKE) --no-print-directory BUILD_DEPS=1 depdone
     331        @$(MAKE) -f $(MAKEFILE) --no-print-directory BUILD_DEPS=1 depdone
    332332
    333333depdone:
  • trunk/src/emx/include/386/builtin.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    77#define _I386_BUILTIN_H
    88
    9 #if defined (__cplusplus)
    10 extern "C" {
    11 #endif
     9#include <sys/cdefs.h>
     10#include <stdint.h>
     11
     12__BEGIN_DECLS
     13
    1214
    1315static __inline__ signed char __cxchg (__volatile__ signed char *p,
     
    4042}
    4143
     44
     45/**
     46 * Performs an atomical xchg on an unsigned int.
     47 * @returns old value.
     48 * @param   pu      Pointer to the value to update.
     49 * @param   u       The new value.
     50 */
     51static __inline__ unsigned __atomic_xchg(__volatile__ unsigned *pu, unsigned u)
     52{
     53    __asm__ __volatile__ ("xchgl %0, %1" : "=m" (*pu), "=r" (u) : "1" (u));
     54    return u;
     55}
     56
     57/**
     58 * Performs an atomical xchg on an 16-bit unsigned integer.
     59 *
     60 * @returns old value.
     61 * @param   pu16    Pointer to the value to update.
     62 * @param   u16     The new value.
     63 */
     64static inline uint16_t __atomic_xchg_word(volatile uint16_t *pu16, uint16_t u16)
     65{
     66    __asm__ __volatile__ ("xchgw %0, %1" : "=m" (*pu16), "=r" (u16) : "1" (u16));
     67    return u16;
     68}
     69
    4270/**
    4371 * Atomically sets a bit and return the old one.
    4472 *
    45  * @returns 1 if the bit was set, 0 if it was clear.
     73 * @returns 1 if the bwit was set, 0 if it was clear.
    4674 * @param   pv      Pointer to base of bitmap.
    4775 * @param   uBit    Bit in question.
     
    89117                           "0"  (uBit));
    90118    return uBit;
     119}
     120
     121
     122/**
     123 * Atomically add a 32-bit unsigned value to another.
     124 *
     125 * @param   pu      Pointer to the value to add to.
     126 * @param   uAdd    The value to add to *pu.
     127 */
     128static __inline__ void __atomic_add(__volatile__ unsigned *pu, unsigned uAdd)
     129{
     130    __asm__ __volatile__("lock addl %1, %0"
     131                         : "=m" (*pu)
     132                         : "r" (uAdd));
     133}
     134
     135/**
     136 * Atomically subtract a 32-bit unsigned value from another.
     137 *
     138 * @param   pu      Pointer to the value to subtract from.
     139 * @param   uAdd    The value to subtract from *pu.
     140 */
     141static __inline__ void __atomic_sub(__volatile__ unsigned *pu, unsigned uSub)
     142{
     143    __asm__ __volatile__("lock subl %1, %0"
     144                         : "=m" (*pu)
     145                         : "r" (uSub));
    91146}
    92147
     
    148203
    149204/**
     205 * Atomically increments a 16-bit unsigned value if less than max.
     206 *
     207 * @returns New value.
     208 * @returns Current value | 0xffff0000 if current value is less or equal to u16Min.
     209 * @param   pu16    Pointer to the value to increment.
     210 * @param   u16Max  *pu16 must not be above this value after the incrementation.
     211 */
     212static inline unsigned __atomic_increment_word_max(volatile uint16_t *pu16, uint16_t u16Max)
     213{
     214    unsigned rc;
     215    __asm__ __volatile__("movw  (%1), %%ax\n\t"
     216                         "1:\n\t"
     217                         "movw  %%ax, %%bx\n\t"
     218                         "cmpw  %%dx, %%ax\n\t"
     219                         "jb    2f\n\t"
     220                         "orl   $0xffff0000, %%ebx\n\t"
     221                         "jmp   3f\n"
     222                         "2:\n\t"
     223                         "incw  %%bx\n\t"
     224                         "lock  cmpxchgw %%bx, (%1)\n\t"
     225                         "jz    3f\n\t"
     226                         "jmp   1b\n\t"
     227                         "3:"
     228                         : "=b" (rc)
     229                         : "r"  (pu16),
     230                           "d"  (u16Max)
     231                         : "%eax");
     232    return rc;
     233}
     234
     235
     236/**
    150237 * Atomically decrements a 32-bit unsigned value if greater than a min.
    151238 *
     
    180267
    181268
     269/**
     270 * Atomically decrements a 16-bit unsigned value if greater than a min.
     271 *
     272 * @returns New value.
     273 * @returns Current value | 0xffff0000 if current value is less or equal to u16Min.
     274 * @param   pu16    Pointer to the  value to decrement.
     275 * @param   u16Min  *pu16 must not be below this value after the decrementation.
     276 */
     277static inline unsigned __atomic_decrement_word_min(volatile uint16_t *pu16, uint16_t u16Min)
     278{
     279    unsigned rc;
     280    __asm__ __volatile__("movw  (%1), %%ax\n"
     281                         "1:\n\t"
     282                         "movw  %%ax, %%bx\n\t"
     283                         "cmpw  %%dx, %%ax\n\t"
     284                         "ja    2f\n\t"
     285                         "orl   $0xffff0000, %%ebx\n\t"
     286                         "jmp   3f\n"
     287                         "2:\n\t"
     288                         "decw  %%bx\n\t"
     289                         "lock  cmpxchgw %%bx, (%1)\n\t"
     290                         "jz    3f\n\t"
     291                         "jmp   1b\n"
     292                         "3:"
     293                         : "=b" (rc)
     294                         : "r"  (pu16),
     295                           "d"  (u16Min)
     296                         : "%eax");
     297    return rc;
     298}
     299
     300
    182301#define __ROTATE_FUN(F,I,T) \
    183302  static __inline__ T F (T value, int shift) \
     
    356475}
    357476
    358 #if defined (__cplusplus)
    359 }
    360 #endif
    361 
     477__END_DECLS
    362478#endif /* not _I386_BUILTIN_H */
  • trunk/src/emx/include/InnoTekLIBC/logstrict.h

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    179179#define __LIBC_LOG_GRP_ENV          15
    180180
     181/** Shared Process Database and LIBC Shared Memory APIs. */
     182#define __LIBC_LOG_GRP_SPM          24
     183/** Fork APIs. */
     184#define __LIBC_LOG_GRP_FORK         25
    181185/** Backend IO APIs. */
    182186#define __LIBC_LOG_GRP_BACK_IO      26
    183 
    184187/** Init/Term APIs and Events. */
    185188#define __LIBC_LOG_GRP_INITTERM     27
     
    204207/** Posix thread APIs. */
    205208#define __LIBC_LOG_GRP_PTHREAD      36
     209/** Posix thread APIs. */
     210#define __LIBC_LOG_GRP_DOSEX        37
    206211
    207212/** @todo complete this */
    208 #define __LIBC_LOG_GRP_MAX          36
     213#define __LIBC_LOG_GRP_MAX          37
    209214/** @} */
    210215
  • trunk/src/emx/include/ctype.h

    • Property cvs2svn:cvs-rev changed from 1.13 to 1.14
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
    4 
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Character type querying.
    8 */
     1/* ctype.h,v 1.14 2004/09/04 06:22:16 bird Exp */
     2/** @file
     3 *
     4 * InnoTek LIBC - Character type querying.
     5 *
     6 * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
     7 *
     8 *
     9 * This program is free software; you can redistribute it and/or modify
     10 * it under the terms of the GNU General Public License as published by
     11 * the Free Software Foundation; either version 2 of the License, or
     12 * (at your option) any later version.
     13 *
     14 * This program is distributed in the hope that it will be useful,
     15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 * GNU General Public License for more details.
     18 *
     19 * You should have received a copy of the GNU General Public License
     20 * along with This program; if not, write to the Free Software
     21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     22 *
     23 */
    924
    1025#ifndef _CTYPE_H_
     
    1227
    1328#include <sys/cdefs.h>
    14 #include <sys/locale.h>
     29
     30#if !defined(__InnoTekLIBC_locale_h__)
     31__BEGIN_DECLS
     32/**
     33 * Simplified Ctype structure for inline functions.
     34 */
     35extern struct
     36{
     37    /** All uppercased characters. */
     38    unsigned char   auchUpper[256];
     39    /** All lowercased characters. */
     40    unsigned char   auchLower[256];
     41    /** Bit flags for every character (for isXXX() function series). */
     42    unsigned short  ausfType[256];
     43} __libc_GLocaleCtype;
     44
     45/**
     46 * Simplified Default Ctype structure for inline functions.
     47 */
     48extern const struct
     49{
     50    /** Bit flags for every character (for isXXX() function series). */
     51    unsigned short  ausfType[256];
     52} __libc_GLocaleCtypeDefault;
     53__END_DECLS
     54#endif /* !__InnoTekLIBC_locale_h__ */
     55
     56
     57/** Bit masks for the ausfType member of __libc_GLocaleCtype
     58 *  and __libc_GLocaleCtypeDefault
     59 *
     60 * @remark These have identical values to the CT_* to speed up setlocale().
     61 * @{
     62 */
     63#define __UPPER     0x0001      /** Upper case alphabetic character. */
     64#define __LOWER     0x0002      /** Lower case alphabetic character. */
     65#define __DIGIT     0x0004      /** Digits 0-9. */
     66#define __SPACE     0x0008      /** White space and line ends. */
     67#define __PUNCT     0x0010      /** Punctuation marks. */
     68#define __CNTRL     0x0020      /** Control and format characters. */
     69#define __BLANK     0x0040      /** Space and tab. */
     70#define __XDIGIT    0x0080      /** Hex digits. */
     71#define __ALPHA     0x0100      /** Letters and linguistic marks. */
     72#define __ALNUM     0x0200      /** Alphanumeric. */
     73#define __GRAPH     0x0400      /** All except controls and space. */
     74#define __PRINT     0x0800      /** Everything except controls. */
     75#define __NUMBER    0x1000      /** Integral number. */
     76#define __SYMBOL    0x2000      /** Symbol. */
     77#define __ASCII     0x8000      /** In standard ASCII set. */
     78/** @} */
     79
    1580
    1681__BEGIN_DECLS
     
    51116#define isalpha(c)  __istype((c), (__UPPER)|(__LOWER))
    52117#define iscntrl(c)  __istype((c), (__CNTRL))
    53 #define isdigit(c)  __istype((c), (__DIGIT))
    54118#define isgraph(c)  __istype((c), (__PUNCT)|(__UPPER)|(__LOWER)|(__DIGIT))
    55119#define islower(c)  __istype((c), (__LOWER))
     
    58122#define isspace(c)  __istype((c), (__SPACE))
    59123#define isupper(c)  __istype((c), (__UPPER))
    60 #define isxdigit(c) __istype((c), (__XDIGIT))
     124#ifdef __UNIX_CHAR_CLASS__
     125/* BSD and some other UNIXes have non-standard definitions of these two at least. */
     126#define isdigit(c)  __isctype((c),(__DIGIT))
     127#define isxdigit(c) __isctype((c),(__XDIGIT))
     128#else
     129#define isdigit(c)  __istype((c),(__DIGIT))
     130#define isxdigit(c) __istype((c),(__XDIGIT))
     131#endif
     132#define tolower(c)  __tolower(c)
    61133#define toupper(c)  __toupper(c)
    62 #define tolower(c)  __tolower(c)
    63134
    64135#if __XSI_VISIBLE
     
    81152__BEGIN_DECLS
    82153static inline int __istype(int _c, unsigned _f)
    83 { return __locale_ctype.cflags [_c & 0xff] & (_f); }
     154{ return (__libc_GLocaleCtype.ausfType[_c & 0xff] & (_f)) != 0; }
     155static inline int __isctype(int _c, unsigned _f)
     156{ return (__libc_GLocaleCtypeDefault.ausfType[_c & 0xff] & (_f)) != 0; }
    84157static inline int __toupper(int _c)
    85 { return __locale_ctype.upcase [_c & 0xff]; }
     158{ return __libc_GLocaleCtype.auchUpper[_c & 0xff]; }
    86159static inline int __tolower(int _c)
    87 { return __locale_ctype.locase [_c & 0xff]; }
     160{ return __libc_GLocaleCtype.auchLower[_c & 0xff]; }
    88161__END_DECLS
    89162
     
    92165__BEGIN_DECLS
    93166int __istype(int, unsigned);
     167int __isctype(int, unsigned);
    94168int __toupper(int);
    95169int __tolower(int);
  • trunk/src/emx/include/emx/asm386.h

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1453 r1454  
    3939#define LABEL(name)     LABEL0(name)
    4040
    41 #define ALIGN   .align  2, 0x90
     41#define ALIGN   .align  4, 0x90
    4242
    4343#define SET_ERRNO_CONST(x) \
  • trunk/src/emx/include/emx/io.h

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1453 r1454  
    44#define _EMX_IO_H
    55
    6 #if defined (__cplusplus)
    7 extern "C" {
    8 #endif
    9 
     6#include <sys/cdefs.h>
    107#include <sys/types.h>
     8#include <InnoTekLIBC/fork.h>
     9
     10__BEGIN_DECLS
    1111
    1212#if !defined (NULL)
     
    1919
    2020/** @defgroup   libc_ioflags    Low Level I/O Flags
     21 *
    2122 * These low level I/O flags are kept in the fFlags member of the LIBCFH
    2223 * 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 * internal to LIBC and defined in emx/io.h (they should've been decorated
     25 * with the usual prefix but it's already EMX legacy), and the FD_* flag(s)
     26 * is(/are) defined
     27 *
    2428 * @{
    2529 */
     
    4347/*      free        0x00004000 */
    4448/*      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
     49#define F_EOF       0x00100000
     50#define F_TERMIO    0x00200000
     51#define F_WRCRPEND  0x00400000
     52#define F_CRLF      0x00800000
    5153/** Type - Regular file. */
    52 #define F_FILE      0x10000000
     54#define F_FILE      0x01000000
    5355/** Type - Characater device. */
    54 #define F_DEV       0x20000000
     56#define F_DEV       0x02000000
    5557/** Type - Pipe. */
    56 #define F_PIPE      0x30000000
     58#define F_PIPE      0x03000000
    5759/** Type - Socket. */
    58 #define F_SOCKET    0x40000000
     60#define F_SOCKET    0x04000000
     61/*      FD_CLOEXEC  0x10000000 (when shifted) */
     62/** The shift for the file descriptor part of __LIBC_FH::fFlags. */
     63#define __LIBC_FH_FDFLAGS_SHIFT     28
     64
     65/** File status/open flag mask. */
     66#define __LIBC_FH_OFLAGS_MASK       0x00ffffff
     67/** File handle type mask. */
     68#define __LIBC_FH_TYPEMASK          0x0f000000
     69/** File descriptor flags mask. */
     70#define __LIBC_FH_FDFLAGS_MASK      0xf0000000
     71
    5972/** @} */
    6073
     
    179192extern struct fdvec         _fdvec_head;
    180193
    181 #if defined (_SYS_RMUTEX_H)
     194#if defined (_SYS_FMUTEX_H)
    182195
    183196/* This semaphore (defined in app/stdio.c) protects _streamv[].  Only
     
    188201   _newstream(), _setmore(), and freopen(). */
    189202
    190 extern _rmutex _streamv_rmutex;
    191 
    192 #define STREAMV_LOCK    _rmutex_checked_request (&_streamv_rmutex, _FMR_IGNINT)
    193 #define STREAMV_UNLOCK  _rmutex_checked_release (&_streamv_rmutex)
     203extern _fmutex _streamv_fmutex;
     204
     205#define STREAMV_LOCK    _fmutex_checked_request(&_streamv_fmutex, _FMR_IGNINT)
     206#define STREAMV_UNLOCK  _fmutex_checked_release(&_streamv_fmutex)
    194207
    195208#define STREAM_LOCK(f) \
    196   (_rmutex_request (&(f)->__u.__rsem, _FMR_IGNINT) != 0 \
     209  (_fmutex_request(&(f)->__u.__fsem, _FMR_IGNINT) != 0 \
    197210   ? abort () : (void)0)
    198211
    199212#define STREAM_UNLOCK(f) \
    200   (_rmutex_release (&(f)->__u.__rsem) != 0 ? abort () : (void)0)
     213  (_fmutex_release(&(f)->__u.__fsem) != 0 ? abort() : (void)0)
    201214
    202215#define STREAM_LOCK_NOWAIT(f) \
    203   (_rmutex_request (&(f)->__u.__rsem, _FMR_NOWAIT) == 0)
    204 
    205 #define STREAM_UNLOCKED(f) _rmutex_available (&(f)->__u.__rsem)
    206 
    207 #endif /* defined (_SYS_RMUTEX_H) */
     216  (_fmutex_request(&(f)->__u.__fsem, _FMR_NOWAIT) == 0)
     217
     218#define STREAM_UNLOCKED(f) _fmutex_available(&(f)->__u.__fsem)
     219
     220#endif /* defined (_SYS_FMUTEX_H) */
    208221
    209222struct __libc_FileHandle;
     223
     224/**
     225 * Filehandle type.
     226 */
     227typedef enum __libc_FileHandleType
     228{
     229    /** Anything which is supported by the OS/2 file API.
     230     * (not used at present as those handles doesn't need special ops). */
     231    enmFH_File,
     232    /** Socket handle (BSD 4.3 stack). */
     233    enmFH_Socket43,
     234    /** Socket handle (BSD 4.4 stack). */
     235    enmFH_Socket44
     236} __LIBC_FHTYPE;
    210237
    211238/**
     
    216243{
    217244    /** Handle type. */
    218     enum
    219     {
    220         /** Anything which is supported by the OS/2 file API.
    221          * (not used at present as those handles doesn't need special ops). */
    222         enmFH_File,
    223         /** Socket handle. */
    224         enmFH_Socket
    225     }   enmType;
    226 
     245    __LIBC_FHTYPE       enmType;
    227246    /** Close operation.
    228247     * @returns 0 on success.
     
    269288     * @param   pFH         Pointer to the handle structure to operate on.
    270289     * @param   fh          It's associated filehandle.
    271      * @param   iIOControl  Which file file control operation to perform.
     290     * @param   iRequest    Which file file descriptior request to perform.
    272291     * @param   iArg        Argument which content is specific to each
    273      *                      iIOControl operation.
     292     *                      iRequest operation.
    274293     * @param   prc         Where to store the value which upon success is
    275294     *                      returned to the caller.
    276295     */
    277     int (*pfnFileControl)(struct __libc_FileHandle *pFH, int fh, int iIOControl, int iArg, int *prc);
     296    int (*pfnFileControl)(struct __libc_FileHandle *pFH, int fh, int iRequest, int iArg, int *prc);
    278297    /** I/O Control operation.
    279298     * @returns 0 on success.
     
    303322     */
    304323    int (*pfnSelect)(int cFHs, struct fd_set *pRead, struct fd_set *pWrite, struct fd_set *pExcept, struct timeval *tv, int *prc);
    305 
    306 } LIBCFHOPS, *PLIBCFHOPS/*, const * PCLIBCFHOPS*/;
    307 
     324    /** Fork notification - parent context.
     325     * If NULL it's assumed that no notifiction is needed.
     326     *
     327     * @returns 0 on success.
     328     * @returns OS/2 error code or negated errno on failure.
     329     * @param   pFH             Pointer to the handle structure to operate on.
     330     * @param   fh              It's associated filehandle.
     331     * @param   pForkHandle     The fork handle.
     332     * @param   enmOperation    The fork operation.
     333     */
     334    int (*pfnForkParent)(struct __libc_FileHandle *pFH, int fh, __LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     335    /** Fork notification - child context.
     336     * Only the __LIBC_FORK_OP_FORK_CHILD operation is forwarded atm.
     337     * If NULL it's assumed that no notifiction is needed.
     338     *
     339     * @returns 0 on success.
     340     * @returns OS/2 error code or negated errno on failure.
     341     * @param   pFH             Pointer to the handle structure to operate on.
     342     * @param   fh              It's associated filehandle.
     343     * @param   pForkHandle     The fork handle.
     344     * @param   enmOperation    The fork operation.
     345     */
     346    int (*pfnForkChild)(struct __libc_FileHandle *pFH, int fh, __LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     347
     348} __LIBC_FHOPS;
     349/** Pointer to file handle operations. */
     350typedef __LIBC_FHOPS *__LIBC_PFHOPS;
     351/** Pointer to const file handle operations. */
     352typedef const __LIBC_FHOPS *__LIBC_PCFHOPS;
    308353
    309354/**
     
    313358{
    314359    /** Handle flags.
    315      * Previously represented by _files / *fd_vec->flags.
     360     * See group @ref libc_ioflags in include/emx.h.
    316361     * @remark For thread safety update this atomically. */
    317     unsigned int    fFlags;
     362    volatile unsigned int   fFlags;
    318363
    319364    /** Lookahead. (whoever uses that?)
    320365     * Previously represented by _files / *fd_vec->flags.
    321366     * @remark For thread safety update this atomically. */
    322     int             iLookAhead;
     367    volatile int            iLookAhead;
    323368
    324369    /** Pointer to the operations one can perform on the handle.
    325370     * Only for special handles not supported by the OS/2 file API. */
    326     PLIBCFHOPS      pOps;
    327 
    328 } LIBCFH, *PLIBCFH;
     371    __LIBC_PCFHOPS          pOps;
     372
     373} __LIBC_FH;
     374/** Pointer to filehandle. */
     375typedef __LIBC_FH *__LIBC_PFH;
     376/* fixme!! */
     377#define LIBCFH __LIBC_FH
     378#define PLIBCFH __LIBC_PFH
     379
    329380
    330381int     __libc_FHEnsureHandles(int fh);
    331382int     __libc_FHMoreHandles(void);
    332 int     __libc_FHAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh);
     383int     __libc_FHAllocate(int fh, unsigned fFlags, int cb, __LIBC_PCFHOPS pOps, PLIBCFH *ppFH, int *pfh);
    333384int     __libc_FHClose(int fh);
    334385PLIBCFH __libc_FH(int fh);
     
    359410
    360411
    361 #if defined (__cplusplus)
    362 }
    363 #endif
     412__END_DECLS
    364413
    365414#endif /* not _EMX_IO_H */
  • trunk/src/emx/include/emx/locale.h

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
    4 
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Internal header file.
    8 */
    9 
    10 #ifndef _local_private_h_
    11 #define _local_private_h_
    12 
    13 #include <sys/types.h>
    14 #include <uconv.h>
    15 
    16 int __to_ucs (UconvObject uconv_obj, const unsigned char *sbcs, size_t len,
    17   UniChar *ucs);
    18 int __from_ucs (UconvObject uconv_obj, UniChar c, unsigned char *sbcs,
    19   size_t len);
    20 void __convert_codepage (const char *cp, UniChar *ucp);
    21 void __do_Unicode (UconvObject *uconv, char *s, void *arg,
    22    int (*xform) (UniChar *, void *));
    23 
    24 #endif
    25 
     1/* dead */
  • trunk/src/emx/include/emx/umalloc.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    1313#include <sys/builtin.h>
    1414#include <sys/fmutex.h>
    15 #include <sys/rmutex.h>
    1615#include <sys/uflags.h>
    1716
     
    688687     because the heap is probably not in a consistent state. */
    689688
    690   _rmutex rsem;
     689  _fmutex fsem;
    691690
    692691  /* This member is used for various purposes by _uheapchk():
     
    756755void *  __libc_HimemDefaultAlloc(Heap_t Heap, size_t *pcb, int *pfClean);
    757756void    __libc_HimemDefaultRelease(Heap_t Heap, void *pv, size_t cb);
     757#if 0
     758int     __libc_HimemDefaultExpand(Heap_t Heap, void *pvBase, size_t cbOld, size_t *pcbNew, int *pfClean);
     759void    __libc_HimemDefaultShrink(Heap_t Heap, void *pvBase, size_t cbOld, size_t *pcbNew);
     760#endif
    758761int     __libc_HasHighMem(void);
    759762/** @} */
     
    773776static __inline__ void _um_heap_lock (Heap_t h)
    774777{
    775   _rmutex_checked_request (&h->rsem, _FMR_IGNINT);
     778  _fmutex_checked_request (&h->fsem, _FMR_IGNINT);
    776779}
    777780
     
    779782static __inline__ void _um_heap_unlock (Heap_t h)
    780783{
    781   _rmutex_checked_release (&h->rsem);
     784  _fmutex_checked_release (&h->fsem);
    782785}
    783786
  • trunk/src/emx/include/locale.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    11/*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
     2 * Copyright (c) 1991, 1993
     3 *      The Regents of the University of California.  All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
     13 * 3. All advertising materials mentioning features or use of this software
     14 *    must display the following acknowledgement:
     15 *      This product includes software developed by the University of
     16 *      California, Berkeley and its contributors.
     17 * 4. Neither the name of the University nor the names of its contributors
     18 *    may be used to endorse or promote products derived from this software
     19 *    without specific prior written permission.
     20 *
     21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31 * SUCH DAMAGE.
     32 *
     33 *      @(#)locale.h    8.1 (Berkeley) 6/2/93
     34 * $FreeBSD: src/include/locale.h,v 1.7 2002/10/09 09:19:27 tjr Exp $
     35 */
    436
    5     For conditions of distribution and use, see the file COPYING.
     37/** @file
     38 * FreeBSD 5.1
     39 * @changed bird: removed unsupported values and added comments to lconv.
     40 * @changed bird: Changed the LC_* values to match those unidef.h sets.
     41 */
    642
    7     POSIX locale implementation.
    8 */
     43#ifndef _LOCALE_H_
     44#define _LOCALE_H_
    945
    10 #ifndef _LOCALE_H
    11 #define _LOCALE_H
     46struct lconv {
     47        char    *decimal_point;         /** non-monetary decimal point */
     48        char    *thousands_sep;         /** non-monetary thousands separator */
     49        char    *grouping;              /** non-monetary size of grouping */
     50        char    *int_curr_symbol;       /** international currency symbol and separator */
     51        char    *currency_symbol;       /** local currency symbol */
     52        char    *mon_decimal_point;     /** monetary decimal point */
     53        char    *mon_thousands_sep;     /** monetary thousands separator */
     54        char    *mon_grouping;          /** monetary size of grouping */
     55        char    *positive_sign;         /** non-negative values sign */
     56        char    *negative_sign;         /** negative values sign */
     57        char    int_frac_digits;        /** number of fractional digits - int currency */
     58        char    frac_digits;            /** number of fractional digits - local currency */
     59        char    p_cs_precedes;          /** (non-neg curr sym) 1-precedes, 0-succeeds */
     60        char    p_sep_by_space;         /** (non-neg curr sym) 1-space, 0-no space */
     61        char    n_cs_precedes;          /** (neg curr sym) 1-precedes, 0-succeeds */
     62        char    n_sep_by_space;         /** (neg curr sym) 1-space, 0-no space */
     63        char    p_sign_posn;            /** positioning of non-negative monetary sign */
     64        char    n_sign_posn;            /** positioning of negative monetary sign */
     65#if 0 /* bird: we don't have this information (it's C99 stuff btw). */
     66        char    int_p_cs_precedes;
     67        char    int_n_cs_precedes;
     68        char    int_p_sep_by_space;
     69        char    int_n_sep_by_space;
     70        char    int_p_sign_posn;
     71        char    int_n_sign_posn;
     72#endif
     73};
    1274
    13 #if defined (__cplusplus)
    14 extern "C" {
     75#ifndef NULL
     76#define NULL    0
    1577#endif
    1678
    17 /* lconv and categories */
    18 #include <sys/locale.h>
     79#define LC_ALL          (-1) /* bird: was 0 */
     80#define LC_COLLATE      0    /* bird: was 1 */
     81#define LC_CTYPE        1    /* bird: was 2 */
     82#define LC_MONETARY     2    /* bird: was 3 */
     83#define LC_NUMERIC      3    /* bird: was 4 */
     84#define LC_TIME         4    /* bird: was 5 */
     85#define LC_MESSAGES     5    /* bird: was 6 */
    1986
    20 /* Set current locale, if __locale is not NULL. Returns previous locale. */
    21 extern char *setlocale (int category, __const__ char *locale);
    22 /* Get information about current locale. */
    23 extern struct lconv *localeconv (void);
     87#define _LC_LAST        6    /* bird: was 7 */          /* marks end */
    2488
    25 #if defined (__cplusplus)
    26 }
    27 #endif
     89#include <sys/cdefs.h>
    2890
    29 #endif /* not _LOCALE_H */
     91__BEGIN_DECLS
     92struct lconv    *localeconv(void);
     93char            *setlocale(int, const char *);
     94__END_DECLS
     95
     96#endif /* _LOCALE_H_ */
  • trunk/src/emx/include/os2emx.h

    • Property cvs2svn:cvs-rev changed from 1.17 to 1.18
    r1453 r1454  
    14161416
    14171417
     1418#if 0 /* -pedantic generates annoying warnings here */
    14181419typedef struct _FTIME
    14191420{
     
    14221423  USHORT hours   : 5;
    14231424} FTIME;
     1425#else
     1426typedef struct _FTIME
     1427{
     1428  unsigned twosecs : 5;
     1429  unsigned minutes : 6;
     1430  unsigned hours   : 5;
     1431} FTIME;
     1432#endif
    14241433typedef FTIME *PFTIME;
    14251434
     1435#if 0 /* -pedantic generates annoying warnings here */
    14261436typedef struct _FDATE
    14271437{
     
    14301440  USHORT year  : 7;
    14311441} FDATE;
     1442#else
     1443typedef struct _FDATE
     1444{
     1445  unsigned day   : 5;
     1446  unsigned month : 4;
     1447  unsigned year  : 7;
     1448} FDATE;
     1449#endif
    14321450typedef FDATE *PFDATE;
    14331451
     
    80688086#define MLE_RGB                         1
    80698087
     8088#define MLE_INDEX                       0
     8089#define MLE_RGB                         1
     8090
    80708091#define MLS_WORDWRAP                    0x0001
    80718092#define MLS_BORDER                      0x0002
     
    1331513336
    1331613337
     13338#ifdef INCL_EXAPIS
     13339
     13340/** Allocate memory at given location. */
     13341#define OBJ_LOCATION    0x01000000
     13342/** The allocated memory object should be duplicated/opened in forked process. */
     13343#define OBJ_FORK        0x02000000
     13344
     13345/**
     13346 * Extended DosAllocMem().
     13347 *
     13348 * @returns See DosAllocMem().
     13349 * @param   ppv     Where to store the address of the allocated memory.
     13350 *                  If OBJ_LOCATION is specified in the flFlags *ppv will be the
     13351 *                  address the object must be allocated at.
     13352 * @param   cb      Number of bytes to allocate.
     13353 * @param   flFlags Allocation flags. This API supports the same flags as DosAllocMem()
     13354 *                  but adds OBJ_FORK and OBJ_LOCATION.
     13355 *                  If OBJ_FORK is specified the object will be automatically
     13356 *                  duplicated in the new process.
     13357 *                  If OBJ_LOCATION is specified the object will be allocated
     13358 *                  at the address specified by *ppv.
     13359 * @remark  The memory must be freed with DosFreeMemEx()!
     13360 */
     13361APIRET APIENTRY DosAllocMemEx(PPVOID ppv, ULONG cb, ULONG flFlags);
     13362
     13363/**
     13364 * Extended DosAllocSharedMem().
     13365 *
     13366 * @returns See DosAllocSharedMem().
     13367 * @param   ppv     Where to store the address of the allocated memory.
     13368 * @param   pszName Name of the shared memory. (optional)
     13369 * @param   cb      Number of bytes to allocate.
     13370 * @param   flFlags Allocation flags. This API supports the same flags as DosAllocSharedMem()
     13371 *                  but adds OBJ_FORK.
     13372 *                  If OBJ_FORK is specified the object will be automatically
     13373 *                  be opened in a forked() process.
     13374 * @remark  The memory must be freed with DosFreeMemEx()!
     13375 */
     13376APIRET APIENTRY DosAllocSharedMemEx(PPVOID ppv, PCSZ pszName, ULONG cb, ULONG flFlags);
     13377
     13378/**
     13379 * Extended DosGetSharedMem().
     13380 *
     13381 * @returns See DosGetSharedMem().
     13382 * @param   pv      The address of the shared memory.
     13383 * @param   flFlags Allocation flags. This API supports the same flags as DosGetSharedMem()
     13384 *                  but adds OBJ_FORK. If OBJ_FORK is specified the object will
     13385 *                  be automatically be opened in a forked() process.
     13386 * @remark  The memory must be freed with DosFreeMemEx()!
     13387 */
     13388APIRET APIENTRY DosGetSharedMemEx(PVOID pv, ULONG flFlags);
     13389
     13390/**
     13391 * Extended DosGetNamedSharedMem().
     13392 *
     13393 * @returns See DosGetNamedSharedMem().
     13394 * @param   pv      The address of the shared memory.
     13395 * @param   flFlags Allocation flags. This API supports the same flags as DosGetNamedSharedMem()
     13396 *                  but adds OBJ_FORK. If OBJ_FORK is specified the object will
     13397 *                  be automatically be opened in a forked() process.
     13398 * @remark  The memory must be freed with DosFreeMemEx()!
     13399 */
     13400APIRET APIENTRY DosGetNamedSharedMemEx(PPVOID ppv, PCSZ pszName, ULONG flFlags);
     13401
     13402/**
     13403 * Free memory allocated by DosAllocMemEx.
     13404 *
     13405 * @returns See DosFreeMem().
     13406 * @param   pv  Address of the memory to free.
     13407 */
     13408APIRET APIENTRY DosFreeMemEx(PVOID pv);
     13409
     13410/**
     13411 * Extended DosCreateEventSem() which will make sure the created semaphore is
     13412 * opened in a forked process with the same handle.
     13413 */
     13414APIRET APIENTRY DosCreateEventSemEx(PSZ pszName, PHEV phev, ULONG flAttr, BOOL32 fState);
     13415/**
     13416 * Extended DosCreateMutexSem() which will make sure the created semaphore is
     13417 * opened in a forked process with the same handle.
     13418 */
     13419APIRET APIENTRY DosCreateMutexSemEx(PSZ pszName, PHMTX phmtx, ULONG flAttr, BOOL32 fState);
     13420/**
     13421 * Extended DosOpenEventSem() which will make sure the opened semaphore is
     13422 * opened in a forked process with the same handle.
     13423 */
     13424APIRET APIENTRY DosOpenEventSemEx(PSZ pszName, PHEV phev);
     13425/**
     13426 * Extended DosOpenMutexSem() which will make sure the opened semaphore is
     13427 * opened in a forked process with the same handle.
     13428 */
     13429APIRET APIENTRY DosOpenMutexSemEx(PSZ pszName, PHMTX phmtx);
     13430/**
     13431 * Close semaphore opened or created using the extended APIs.
     13432 * @returns see DosCloseMutexSem().
     13433 * @param   hmtx    Handle to the mutex semaphore which is to be closed.
     13434 */
     13435APIRET APIENTRY DosCloseMutexSemEx(HMTX hmtx);
     13436/**
     13437 * Close semaphore opened or created using the extended APIs.
     13438 * @returns see DosCloseEventSem().
     13439 * @param   hev     Handle to the event semaphore which is to be closed.
     13440 */
     13441APIRET APIENTRY DosCloseEventSemEx(HEV hev);
     13442
     13443#ifdef INCL_EXAPIS_MAPPINGS
     13444
     13445#define DosAllocMem(a, b, c)       DosAllocMemEx((a),(b),(c) | OBJ_FORK)
     13446#define DosAllocSharedMem(a,b,c,d) DosAllocSharedMemEx((a),(b),(c),(d) | OBJ_FORK)
     13447#define DosFreeMem(a)              DosFreeMemEx((a))
     13448
     13449#define DosCreateMutexSem(a,b,c,d) DosCreateMutexSemEx((a),(b),(c),(d))
     13450#define DosCreateEventSem(a,b,c,d) DosCreateEventSemEx((a),(b),(c),(d))
     13451#define DosOpenMutexSem(a,b)       DosOpenMutexSemEx((a),(b))
     13452#define DosOpenEventSem(a,b)       DosOpenEventSemEx((a),(b))
     13453#define DosCloseMutexSem(a)        DosCloseMutexSemEx((a))
     13454#define DosCloseEventSem(a)        DosCloseEventSemEx((a))
     13455
     13456#endif /* INCL_EXAPIS_MAPPINGS */
     13457
     13458
     13459#endif /* INCL_EXAPIS */
     13460
     13461
    1331713462/* ------------------------------ THE END --------------------------------- */
    1331813463
  • trunk/src/emx/include/stdio.h

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1453 r1454  
    197197    union
    198198    {
    199 #if defined (_SYS_RMUTEX_H)
    200         _rmutex   __rsem;
    201 #endif
    202         char      __rsem_ersatz[16];
     199#if defined (_SYS_FMUTEX_H)
     200        _fmutex   __fsem;
     201#endif
     202        char      __rsem_ersatz[8];
    203203    } __u;
    204204    /** Pointer to the stream vector which thie FILE belongs to.
  • trunk/src/emx/include/sys/fcntl.h

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    274274/* Open flags.
    275275   As stated in the FreeBSD part, there is supposidly a limited number of bits
    276    available. We'll try keep in suitable for 16bit just in case (don't care to
    277    check what we use right now).
     276   available. We'll try keep it suitable for 16bit just in case (don't care to
     277   check what we use right now) because that'll enable us to share a 32-bit flag
     278   variable per handle to both status (O_*) flags and descriptor (FD_*) flags.
     279
    278280   When we've disabled a few BSD flags and leave out KERNEL stuff the following
    279281   bits are available:
  • trunk/src/emx/include/sys/locale.h

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
    4 
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Private header file for locale support.
    8 */
    9 
    10 #ifndef __SYS_LOCALE_H__
    11 #define __SYS_LOCALE_H__
    12 
    13 /* To avoid conflicts with unidef.h we should use same values as there. */
    14 #define LC_ALL                  (-1)
    15 #define LC_COLLATE              0
    16 #define LC_CTYPE                1
    17 #define LC_NUMERIC              2
    18 #define LC_MONETARY             3
    19 #define LC_TIME                 4
    20 #define LC_MESSAGES             5
    21 #define __LC_COUNT 6
    22 
    23 /* Bit masks for __locale_global.ctype -
    24    !NOTE! - these have identical values to the CT_* to speed up setlocale(). */
    25 #define __UPPER     0x0001      /* Upper case alphabetic character. */
    26 #define __LOWER     0x0002      /* Lower case alphabetic character. */
    27 #define __DIGIT     0x0004      /* Digits 0-9. */
    28 #define __SPACE     0x0008      /* White space and line ends. */
    29 #define __PUNCT     0x0010      /* Punctuation marks. */
    30 #define __CNTRL     0x0020      /* Control and format characters. */
    31 #define __BLANK     0x0040      /* Space and tab. */
    32 #define __XDIGIT    0x0080      /* Hex digits. */
    33 #define __ALPHA     0x0100      /* Letters and linguistic marks. */
    34 #define __ALNUM     0x0200      /* Alphanumeric. */
    35 #define __GRAPH     0x0400      /* All except controls and space. */
    36 #define __PRINT     0x0800      /* Everything except controls. */
    37 #define __NUMBER    0x1000      /* Integral number. */
    38 #define __SYMBOL    0x2000      /* Symbol. */
    39 #define __ASCII     0x8000      /* In standard ASCII set. */
    40 
    41 /* Locale information structure. */
    42 struct lconv
    43 {
    44   char *decimal_point;          /* non-monetary decimal point */
    45   char *thousands_sep;          /* non-monetary thousands separator */
    46   char *grouping;               /* non-monetary size of grouping */
    47   char *int_curr_symbol;        /* international currency symbol and separator */
    48   char *currency_symbol;        /* local currency symbol */
    49   char *mon_decimal_point;      /* monetary decimal point */
    50   char *mon_thousands_sep;      /* monetary thousands separator */
    51   char *mon_grouping;           /* monetary size of grouping */
    52   char *positive_sign;          /* non-negative values sign */
    53   char *negative_sign;          /* negative values sign */
    54   char int_frac_digits;         /* number of fractional digits - int currency */
    55   char frac_digits;             /* number of fractional digits - local currency */
    56   char p_cs_precedes;           /* (non-neg curr sym) 1-precedes, 0-succeeds */
    57   char p_sep_by_space;          /* (non-neg curr sym) 1-space, 0-no space */
    58   char n_cs_precedes;           /* (neg curr sym) 1-precedes, 0-succeeds */
    59   char n_sep_by_space;          /* (neg curr sym) 1-space, 0-no space */
    60   char p_sign_posn;             /* positioning of non-negative monetary sign */
    61   char n_sign_posn;             /* positioning of negative monetary sign */
    62   /** @todo C99
    63 char     int_n_cs_precedes
    64 char     int_n_sep_by_space
    65 char     int_n_sign_posn
    66 char     int_p_cs_precedes
    67 char     int_p_sep_by_space
    68 char     int_p_sign_posn
    69   */
    70 };
    71 
    72 
    73 #ifdef __INTERNAL_DEFS
    74 
    75 #include <uconv.h>
    76 
    77 /* This structure keeps the time formatting rules. */
    78 struct __locale_time
    79 {
    80   char *smonths [12];           /* Short month names */
    81   char *lmonths [12];           /* Long month names */
    82   char *swdays [7];             /* Short weekday names */
    83   char *lwdays [7];             /* Long weekday names */
    84   char *date_time_fmt;          /* Date and time format */
    85   char *date_fmt;               /* Date format */
    86   char *time_fmt;               /* Time format */
    87   char *am, *pm;                /* AM and PM strings */
    88 };
    89 
    90 /* There is one global object of this type that contains integral
    91    information about last selected (with setlocale()) locale.
    92    The locale information itself is split into parts to avoid linking
    93    unused data into programs that use just the "C" locale and just
    94    a few functions that use locale data (such as strdate()). */
    95 struct __locale_global
    96 {
    97   /* Lock for multi-threaded operations. */
    98   signed char /* _smutex */ lock; /* Avoid including builtin.h & smutex.h */
    99   /* Category names. */
    100   char *name [__LC_COUNT + 1];
    101 };
    102 
    103 /* This structure contains the uppercase/lowercase tables. */
    104 struct __locale_ctype
    105 {
    106   /* Bit flags for every character (for isXXX() function series) */
    107   unsigned short cflags [256];
    108   /* All uppercased characters */
    109   unsigned char upcase [256];
    110   /* All lowercased characters */
    111   unsigned char locase [256];
    112   /* MBCS prefixes. Two bits per character. */
    113   unsigned char mbcsprefix [256/4];
    114   /* The converter object to convert to and from selected codepage
    115      (used with MBCS codepages only) */
    116   UconvObject uconv;
    117   /* The locale object. */
    118   LocaleObject locale;
    119   /* Non-zero if there are any MBCS prefix characters in codepage */
    120   char mbcs;
    121 };
    122 
    123 struct __locale_collate
    124 {
    125   /* Character weight for SBCS codepages */
    126   unsigned char weight [256];
    127   /* MBCS prefixes. Two bits per character. */
    128   unsigned char mbcsprefix [256/4];
    129   /* The converter object to convert to and from selected codepage
    130      (used with MBCS codepages only) */
    131   UconvObject uconv;
    132   /* The locale object. */
    133   LocaleObject locale;
    134   /* Non-zero if there are any MBCS prefix characters in codepage */
    135   char mbcs;
    136 };
    137 
    138 /* Handy macros for working with (__locale_ctype|__locale_collate).mbcsprefix */
    139 #define SET_MBCS_PREFIX(s,c,v) \
    140   s [((unsigned char)c) >> 2] |= (v) << (2 * ((c) & 3))
    141 #define LEN_MBCS_PREFIX(s,c) \
    142   ((s [((unsigned char)c) >> 2] >> (2 * ((c & 3) ^ 3))) & 3)
    143 #define IS_MBCS_PREFIX(s,c) \
    144   (LEN_MBCS_PREFIX(s.mbcsprefix,c) != 1)
    145 #define CHK_MBCS_PREFIX(s,c,v) \
    146   ((v = LEN_MBCS_PREFIX(s.mbcsprefix,c)) > 1)
    147 
    148 /* A static constant string denoting the "C" locale. */
    149 extern const char __locale_C[2];
    150 
    151 /* Global locale information. */
    152 extern struct __locale_global __locale;
    153 /* String collation information. */
    154 extern struct __locale_collate __locale_collate;
    155 /* Character case conversion tables. */
    156 extern struct __locale_ctype __locale_ctype;
    157 /* Locale information structure. */
    158 extern struct lconv __locale_lconv;
    159 /* Date / time formatting rules. */
    160 extern struct __locale_time __locale_time;
    161 
    162 /* Convert a string to Unicode, apply some transform and convert back. */
    163 extern void __do_Unicode (UconvObject *uconv, char *s, void *arg,
    164   int (*xform) (UniChar *, void *));
    165 /* Convert a MBCS character to Unicode; returns number of bytes in MBCS char. */
    166 extern int __to_ucs (UconvObject, const unsigned char *, size_t, UniChar *);
    167 /* Convert a Unicode character to MBCS */
    168 extern int __from_ucs (UconvObject, UniChar, unsigned char *, size_t);
    169 
    170 #else
    171 
    172 /* Simplified extern definitions for inline functions usage */
    173 
    174 /* Character case conversion tables. */
    175 extern struct
    176 {
    177   unsigned short cflags [256];
    178   unsigned char upcase [256];
    179   unsigned char locase [256];
    180 } __locale_ctype;
    181 
    182 #endif /* __INTERNAL_DEFS */
    183 
    184 #endif /* __SYS_LOCALE_H__ */
     1/* dead */
  • trunk/src/emx/include/sys/resource.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1453 r1454  
    1 /* sys/resource.h (emx+gcc) */
     1/*
     2 * Copyright (c) 1982, 1986, 1993
     3 *      The Regents of the University of California.  All rights reserved.
     4 *
     5 * Redistribution and use in source and binary forms, with or without
     6 * modification, are permitted provided that the following conditions
     7 * are met:
     8 * 1. Redistributions of source code must retain the above copyright
     9 *    notice, this list of conditions and the following disclaimer.
     10 * 2. Redistributions in binary form must reproduce the above copyright
     11 *    notice, this list of conditions and the following disclaimer in the
     12 *    documentation and/or other materials provided with the distribution.
     13 * 3. All advertising materials mentioning features or use of this software
     14 *    must display the following acknowledgement:
     15 *      This product includes software developed by the University of
     16 *      California, Berkeley and its contributors.
     17 * 4. Neither the name of the University nor the names of its contributors
     18 *    may be used to endorse or promote products derived from this software
     19 *    without specific prior written permission.
     20 *
     21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31 * SUCH DAMAGE.
     32 *
     33 *      @(#)resource.h  8.4 (Berkeley) 1/9/95
     34 * $FreeBSD: src/sys/sys/resource.h,v 1.19 2003/02/16 13:30:29 phk Exp $
     35 */
     36
     37/** @file
     38 * FreeBSD 5.1
     39 */
     40
     41#ifndef _SYS_RESOURCE_H_
     42#define _SYS_RESOURCE_H_
     43
     44/*
     45 * Process priority specifications to get/setpriority.
     46 */
     47#define PRIO_MIN        -20
     48#define PRIO_MAX        20
     49#ifdef _KERNEL
     50#define PRIO_TOTAL      (PRIO_MAX - PRIO_MIN)
     51#endif /* _KERNEL */
     52
     53#define PRIO_PROCESS    0
     54#define PRIO_PGRP       1
     55#define PRIO_USER       2
     56
     57/*
     58 * Resource utilization information.
     59 */
     60
     61#define RUSAGE_SELF     0
     62#define RUSAGE_CHILDREN -1
     63
     64struct rusage {
     65        struct timeval ru_utime;        /* user time used */
     66        struct timeval ru_stime;        /* system time used */
     67        long    ru_maxrss;              /* max resident set size */
     68#define ru_first        ru_ixrss
     69        long    ru_ixrss;               /* integral shared memory size */
     70        long    ru_idrss;               /* integral unshared data " */
     71        long    ru_isrss;               /* integral unshared stack " */
     72        long    ru_minflt;              /* page reclaims */
     73        long    ru_majflt;              /* page faults */
     74        long    ru_nswap;               /* swaps */
     75        long    ru_inblock;             /* block input operations */
     76        long    ru_oublock;             /* block output operations */
     77        long    ru_msgsnd;              /* messages sent */
     78        long    ru_msgrcv;              /* messages received */
     79        long    ru_nsignals;            /* signals received */
     80        long    ru_nvcsw;               /* voluntary context switches */
     81        long    ru_nivcsw;              /* involuntary " */
     82#define ru_last         ru_nivcsw
     83};
     84
     85/*
     86 * Resource limits
     87 */
     88#define RLIMIT_CPU      0               /* cpu time in milliseconds */
     89#define RLIMIT_FSIZE    1               /* maximum file size */
     90#define RLIMIT_DATA     2               /* data size */
     91#define RLIMIT_STACK    3               /* stack size */
     92#define RLIMIT_CORE     4               /* core file size */
     93#define RLIMIT_RSS      5               /* resident set size */
     94#define RLIMIT_MEMLOCK  6               /* locked-in-memory address space */
     95#define RLIMIT_NPROC    7               /* number of processes */
     96#define RLIMIT_NOFILE   8               /* number of open files */
     97#define RLIMIT_SBSIZE   9               /* maximum size of all socket buffers */
     98#define RLIMIT_VMEM     10              /* virtual process size (inclusive of mmap) */
     99
     100#define RLIM_NLIMITS    11              /* number of resource limits */
     101
     102#define RLIM_INFINITY   ((rlim_t)(((u_quad_t)1 << 63) - 1))
     103
     104
     105/*
     106 * Resource limit string identifiers
     107 */
     108
     109#ifdef _RLIMIT_IDENT
     110static char *rlimit_ident[] = {
     111        "cpu",
     112        "fsize",
     113        "data",
     114        "stack",
     115        "core",
     116        "rss",
     117        "memlock",
     118        "nproc",
     119        "nofile",
     120        "sbsize",
     121        "vmem",
     122};
     123#endif
     124
     125struct orlimit {
     126        int32_t rlim_cur;               /* current (soft) limit */
     127        int32_t rlim_max;               /* maximum value for rlim_cur */
     128};
     129
     130struct rlimit {
     131        rlim_t  rlim_cur;               /* current (soft) limit */
     132        rlim_t  rlim_max;               /* maximum value for rlim_cur */
     133};
     134
     135/* Load average structure. */
     136struct loadavg {
     137        fixpt_t ldavg[3];
     138        long    fscale;
     139};
     140
     141#define CP_USER         0
     142#define CP_NICE         1
     143#define CP_SYS          2
     144#define CP_INTR         3
     145#define CP_IDLE         4
     146#define CPUSTATES       5
     147
     148#ifdef _KERNEL
     149extern struct loadavg averunnable;
     150extern long cp_time[CPUSTATES];
     151
     152int     dosetrlimit(struct thread *, u_int, struct rlimit *);
     153
     154#else
     155#include <sys/cdefs.h>
     156
     157__BEGIN_DECLS
     158int     getpriority(int, int);
     159int     getrlimit(int, struct rlimit *);
     160int     getrusage(int, struct rusage *);
     161int     setpriority(int, int, int);
     162int     setrlimit(int, const struct rlimit *);
     163__END_DECLS
     164
     165#endif  /* _KERNEL */
     166#endif  /* !_SYS_RESOURCE_H_ */
  • trunk/src/emx/include/sys/rmutex.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1453 r1454  
    11/* sys/rmutex.h (emx+gcc) */
    2 
    3 /* _rmutex semaphores are registered _fmutex semaphores.  They are a
    4    bit bigger than _fmutex metaphores but they are inherited by child
    5    processes created with fork().  Shared _rmutex semaphores behave
    6    like _fmutex semaphores, ie, they are not registered and therefore
    7    not inherited by child processes created with fork().  (As malloc()
    8    uses _rmutex semaphores, we have to support shared semaphores
    9    anyway.) */
    102
    113/* This header requires <sys/builtin.h> and <sys/fmutex.h>. */
     
    146#define _SYS_RMUTEX_H
    157
    16 #if defined (__cplusplus)
    17 extern "C" {
    18 #endif
     8#warning "_rmutex is obsoleted. use _fmutex!"
    199
    20 /* See also <emx/io.h> and /emx/test/internal.c. */
    21 typedef struct __rmutex
    22 {
    23   struct __rmutex *next;
    24   struct __rmutex *prev;
    25   _fmutex fm;
    26   unsigned char flags;
    27   unsigned short count;
    28 } _rmutex;
     10#define _rmutex             _fmutex
     11#define _rmutex_request     _fmutex_request
     12#define _rmutex_release     _fmutex_release
     13#define _rmutex_close       _fmutex_close
     14#define _rmutex_create      _fmutex_create
     15#define _rmutex_open        _fmutex_open
     16#define _rmutex_available   _fmutex_available
     17#define _rmutex_dummy       _fmutex_dummy
     18#define _rmutex_checked_request _fmutex_checked_request
     19#define _rmutex_checked_release _fmutex_checked_release
     20#define _rmutex_checked_close   _fmutex_checked_close
     21#define _rmutex_checked_create  _fmutex_checked_create
     22#define _rmutex_checked_open    _fmutex_checked_open
    2923
    3024
    31 static __inline__ unsigned _rmutex_request (_rmutex *sem, unsigned flags)
    32 {
    33   return _fmutex_request (&sem->fm, flags);
    34 }
    35 
    36 
    37 static __inline__ unsigned _rmutex_release (_rmutex *sem)
    38 {
    39   return _fmutex_release (&sem->fm);
    40 }
    41 
    42 
    43 static __inline__ int _rmutex_available (_rmutex *sem)
    44 {
    45   return _fmutex_available (&sem->fm);
    46 }
    47 
    48 
    49 unsigned _rmutex_close (_rmutex *);
    50 unsigned _rmutex_create (_rmutex *, unsigned);
    51 unsigned _rmutex_open (_rmutex *);
    52 void _rmutex_dummy (_rmutex *);
    53 
    54 
    55 static __inline__ void _rmutex_checked_release (_rmutex *sem)
    56 {
    57   _fmutex_checked_release (&sem->fm);
    58 }
    59 
    60 
    61 static __inline__ void _rmutex_checked_request (_rmutex *sem, unsigned flags)
    62 {
    63   _fmutex_checked_request (&sem->fm, flags);
    64 }
    65 
    66 
    67 void _rmutex_checked_close (_rmutex *);
    68 void _rmutex_checked_create (_rmutex *, unsigned);
    69 void _rmutex_checked_open (_rmutex *);
    70 
    71 #if defined (__cplusplus)
    72 }
    73 #endif
    74 
    7525#endif /* not _SYS_RMUTEX_H */
  • trunk/src/emx/include/unistd.h

    • Property cvs2svn:cvs-rev changed from 1.15 to 1.16
    r1453 r1454  
    183183int      dup(int);
    184184int      dup2(int, int);
    185 /** @todo int    eaccess(const char *, int); */
     185int      eaccess(const char *, int);
    186186int      execl(const char *, const char *, ...);
    187187int      execle(const char *, const char *, ...);
  • trunk/src/emx/libonly.gmk

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    33MAKEFILE := libonly.gmk
    44GENRULES  = $.genrules-libonly.smak
    5 SUBMAK   := version.smak $(wildcard src/lib*/*.smak) include/include.smak \
    6   $(wildcard bsd/*/*.smak) $(wildcard gnu/*/*.smak)
     5SUBMAK   := version.smak $(wildcard src/lib*/*.smak) include/include.smak
    76
    87include Makefile
  • trunk/src/emx/src/emxload/emxload.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1453 r1454  
    1919Boston, MA 02111-1307, USA.  */
    2020
    21 
     21#define NO_EXAPIS
    2222#include <stdio.h>
    2323#include <stdlib.h>
  • trunk/src/emx/src/emxomf/emxomf.c

    • Property cvs2svn:cvs-rev changed from 1.38 to 1.39
    r1453 r1454  
    9090  int seg_name[3];              /* Name indices of the three segments */
    9191  int seg_index[3];             /* Segment indices of the three segments */
    92   int group_name;               /* Name index of the group */
    93   int group_index;              /* Group index of the group */
    9492  int def;                      /* Non-zero if head element encountered */
    9593  int count;                    /* Number of non-head non-tail elements */
     
    245243static struct set *sets;
    246244static struct set **set_add;
    247 
    248 /* For compatibility with emxomf 0.8h and older, generation of GRPDEF
    249    records for sets can be enabled by using the -g option.  That
    250    option sets this variable to TRUE.  By default, GRPDEF records are
    251    not generated. */
    252 static int do_set_groups = FALSE;
    253245
    254246/* If this variable is TRUE, an a.out archive is split into several
     
    22492241                  set_ptr->seg_index[j] = -1;
    22502242                }
    2251               set_ptr->group_name = -1;
    22522243              set_ptr->count = 0;
    22532244              set_ptr->data = NULL;
     
    22942285
    22952286
    2296 /* Create the group name with group name index for each set. */
    2297 
    2298 static void define_set_groups (void)
    2299 {
    2300   struct set *set_ptr;
    2301   char tmp[512];
    2302 
    2303   for (set_ptr = sets; set_ptr != NULL; set_ptr = set_ptr->next)
    2304     {
    2305       strcpy (tmp, "GROUP");
    2306       strcat (tmp, set_ptr->name);
    2307       set_ptr->group_name = find_lname (tmp);
    2308     }
    2309 }
    2310 
    2311 
    23122287/* Define three segments for each set.  The segment names have already
    23132288   been defined, now write the SEGDEF records. */
     
    23212296    for (j = 0; j < 3; ++j)
    23222297      set_ptr->seg_index[j] =
    2323         seg_def (set_ptr->seg_name[j], code_class_name,
     2298        seg_def (set_ptr->seg_name[j], data_class_name,
    23242299                 4 * (j == 1 ? set_ptr->count : set_ptr->def), FALSE, TRUE);
    2325 }
    2326 
    2327 
    2328 /* Write the GRPDEF records for all the sets.  One group consisting of
    2329    three segments is defined for each set.
    2330 
    2331    GRPDEF record:
    2332     1/2 Group name index
    2333    Ú
    2334    ³1   0xff (use segment index)
    2335    ³1/2 Segment index
    2336    À
    2337 
    2338    Group indices are assigned sequentially. */
    2339 
    2340 static void write_set_groups (void)
    2341 {
    2342   int j;
    2343   struct set *set_ptr;
    2344 
    2345   for (set_ptr = sets; set_ptr != NULL; set_ptr = set_ptr->next)
    2346     {
    2347       set_ptr->group_index = group_index++;
    2348       init_rec (GRPDEF);
    2349       put_idx (set_ptr->group_name);
    2350       for (j = 0; j < 3; ++j)
    2351         {
    2352           put_8 (0xff); put_idx (set_ptr->seg_index[j]);
    2353         }
    2354       write_rec ();
    2355     }
    23562300}
    23572301
     
    34783422  byte *t;
    34793423  const struct nlist *entry_symbol;
     3424  struct set *set_ptr;
     3425  int j;
    34803426
    34813427  /* Simplify things by reading the complete a.out module into
     
    35883534  flat_group_name = find_lname ("FLAT");
    35893535  dgroup_group_name = find_lname ("DGROUP");
    3590   if (do_set_groups)
    3591     define_set_groups ();
    35923536
    35933537  /* Write the THREADR record. */
     
    36243568  text_index = seg_def (text_seg_name, code_class_name, text_size,
    36253569                        FALSE, FALSE);
    3626   write_set_segs ();
    3627 
    36283570  if (udat_seg_string != NULL)
    36293571    udat_index = seg_def (udat_seg_name, data_class_name, data_size,
     
    36353577    udat_index = data_index;
    36363578
     3579  write_set_segs ();
     3580
    36373581  bss_index = seg_def (bss_seg_name, bss_class_name, a_out_h->a_bss,
    36383582                       FALSE, FALSE);
     
    36513595
    36523596  /* Define groups (GRPDEF records).  This must be done after defining
    3653      segments. */
     3597     segments.
     3598     We lazily assumes that the number of sets will not make the GRPDEF
     3599     record too big. Rather safe unless a hundred setvectors are used... */
    36543600
    36553601  flat_index = group_index++;
     
    36633609  put_8 (0xff); put_idx (bss_index);
    36643610  put_8 (0xff); put_idx (data_index);
     3611  for (set_ptr = sets; set_ptr != NULL; set_ptr = set_ptr->next)
     3612      for (j = 0; j < 3; ++j)
     3613        {
     3614          put_8 (0xff); put_idx (set_ptr->seg_index[j]);
     3615        }
    36653616  write_rec ();
    3666 
    3667   if (do_set_groups)
    3668     write_set_groups ();
    36693617
    36703618  /* Process weak symbols */
     
    37543702  puts ("\nOptions:");
    37553703  puts ("  -d                 Delete input files except for archives");
    3756   puts ("  -g                 Create groups for sets");
    37573704  puts ("  -i <default_lib>   Add default library request");
    37583705  puts ("  -l[<symbol>]       Convert library modules, with optional entrypoint");
     
    41904137  /* Parse the command line options. */
    41914138
    4192   while ((c = getopt (argc, argv, "bdD:gh:i:jI:m:l::o:P:p:qO:r:R:tsuxwz")) != EOF)
     4139  while ((c = getopt (argc, argv, "bdD:h:i:jI:m:l::o:P:p:qO:r:R:tsuxwz")) != EOF)
    41934140    switch (c)
    41944141      {
     
    42014148      case 'D':
    42024149        udat_seg_string = optarg;
    4203         break;
    4204       case 'g':
    4205         do_set_groups = TRUE;
    42064150        break;
    42074151      case 'h':
  • trunk/src/emx/src/lib/app/stdio.c

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r1453 r1454  
    44#include "libc-alias.h"
    55#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    6 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    7 #include <sys/rmutex.h>
     6#include <sys/fmutex.h>
    87#include <stdio.h>
    98#include <stdlib.h>
     
    2827
    2928/** Mutex protecting the stream vector. */
    30 _rmutex                     _streamv_rmutex;    /* See io/_newstre.c */
     29_fmutex                     _streamv_fmutex;    /* See io/_newstre.c */
    3130
    3231/*
     
    6968
    7069    /*
    71      * Init the _more and _owner pointers.
     70     * Init the stream vector back pointer.
    7271     */
    7372    pFile   = &gaPreFiles[0];
     
    8180    _streamvec_head     = &gPreStreamVec;
    8281    _streamvec_tail     = &gPreStreamVec;
    83     _rmutex_checked_create(&_streamv_rmutex, 0);
     82    _fmutex_checked_create(&_streamv_fmutex, 0);
    8483
    8584    /*
     
    10099            gaPreFiles[i]._handle    = i;
    101100            gaPreFiles[i]._flush     = _flushstream;
    102             if (_rmutex_create (&gaPreFiles[i].__u.__rsem, 0) != 0)
     101            if (_fmutex_create(&gaPreFiles[i].__u.__fsem, 0) != 0)
    103102            {
    104103                LIBC_ASSERTM_FAILED("_setmore failed for i=%d\n", i);
     
    117116                    gaPreFiles[0]._buffer    = gachStdIn;
    118117                    gaPreFiles[0]._buf_size  = BUFSIZ;
    119                     LIBCLOG_MSG("__stdinp=%p\n", __stdinp);
     118                    LIBCLOG_MSG("__stdinp=%p\n", (void *)__stdinp);
    120119                    break;
    121120
     
    123122                    /* stdout is buffered unless it's connected to a device. */
    124123                    gaPreFiles[1]._flags |= _IOWRT | _IOBUFNONE
    125                         | ((pFH->fFlags & F_TYPEMASK) == F_DEV ? _IONBF : _IOFBF);
    126                     LIBCLOG_MSG("__stdoutp=%p flags=%#x (%s)\n", __stdoutp, gaPreFiles[1]._flags,
    127                                 (pFH->fFlags & F_TYPEMASK) == F_DEV ? "dev" : "none-dev");
     124                        | ((pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV ? _IONBF : _IOFBF);
     125                    LIBCLOG_MSG("__stdoutp=%p flags=%#x (%s)\n", (void *)__stdoutp, gaPreFiles[1]._flags,
     126                                (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV ? "dev" : "none-dev");
    128127                    break;
    129128
     
    131130                    /* stderr is always unbuffered. */
    132131                    gaPreFiles[2]._flags |= _IOWRT | _IOBUFNONE | _IONBF;
    133                     LIBCLOG_MSG("__stderrp=%p\n", __stderrp);
     132                    LIBCLOG_MSG("__stderrp=%p\n", (void *)__stderrp);
    134133                    break;
    135134            }
  • trunk/src/emx/src/lib/conv/atod.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    11/* atod.c (emx+gcc) -- Copyright (c) 1996-1998 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdlib.h>
    6 #include <ctype.h>
    75#include <math.h>
    86#include <float.h>
     
    1210#include <emx/bigint.h>
    1311#include <emx/float.h>
    14 #include <sys/locale.h>
     12#include <InnoTekLIBC/locale.h>
     13#include <ctype.h>
     14
    1515
    1616#define BBITS           (LDBL_MAX_EXP + LDBL_MANT_DIG - LDBL_MAX_10_EXP \
     
    2222#define MAX2    (_BI_WORDMAX - 10 * MAX1)
    2323
    24 #define DOT     (unsigned char)__locale_lconv.decimal_point[0]
     24#define DOT     (unsigned char)__libc_gLocaleLconv.s.decimal_point[0]
    2525
    2626const char * __atod (long double *p_result, const char *string,
  • trunk/src/emx/src/lib/conv/conv.smak

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    3434.TCF.src/lib/conv/bipow5.c := -I$.
    3535$(call .MVER,conv/bipow5.o): $.bipow5.tab
     36src/lib/conv/bipow5.c: $.bipow5.tab
    3637$.bipow5.tab: $.makepow5.exe
    3738        $< -o $@ -s -m325 4951
  • trunk/src/emx/src/lib/conv/gcvt.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    11/* gcvt.c (emx+gcc) -- Copyright (c) 1994-1996 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdlib.h>
     
    98#include <locale.h>
    109#include <emx/float.h>
    11 #include <sys/locale.h>
     10#include <InnoTekLIBC/locale.h>
    1211
    1312char *_STD(gcvt) (double x, int digits, char *buffer)
     
    8281      *dst++ = str[0];
    8382      if (str[1] != 0)
    84         *dst++ = __locale_lconv.decimal_point[0];
     83        *dst++ = __libc_gLocaleLconv.s.decimal_point[0];
    8584      for (src = str+1; *src != 0; ++src)
    8685        *dst++ = *src;
     
    112111        {
    113112          if (i == xp + 1)
    114             *dst++ = __locale_lconv.decimal_point[0];
     113            *dst++ = __libc_gLocaleLconv.s.decimal_point[0];
    115114          *dst++ = str[i];
    116115        }
  • trunk/src/emx/src/lib/conv/smalatod.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    11/* smalatod.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdlib.h>
     
    76#include <float.h>
    87#include <locale.h>
    9 #include <ctype.h>
    108#include <errno.h>
    119#define __atod  __small_atod /* bird: let's get a prototype. */
    1210#include <emx/float.h>
    13 #include <sys/locale.h>
     11#include <InnoTekLIBC/locale.h>
     12#include <ctype.h>
    1413
    1514
     
    3433  } z;
    3534
    36   s = end = string;
     35  s = end = (unsigned char *)string;
    3736
    3837  switch (mant_dig)
     
    4948    default:
    5049      *p_result = NAN;
    51       return string;
     50      return (const char *)string;
    5251    }
    5352
     
    7473        s += 5;
    7574      *p_result = neg ? -INFINITY : INFINITY;
    76       return s;
     75      return (const char *)s;
    7776    }
    7877  else if ((s[0] == 'n' || s[0] == 'N')
     
    9594        }
    9695      *p_result = NAN;
    97       return end;
     96      return (const char *)end;
    9897    }
    9998
     
    104103  for (;;)
    105104    {
    106       if (*s == (unsigned char)__locale_lconv.decimal_point[0] && !dot)
     105      if (*s == (unsigned char)__libc_gLocaleLconv.s.decimal_point[0] && !dot)
    107106        {
    108107          dot = 1;
     
    127126    {
    128127      *p_result = 0.0;
    129       return string;
     128      return (const char *)string;
    130129    }
    131130
     
    151150
    152151          saved_errno = errno; errno = 0;
    153           exp = strtol (s, (char **)&q, 10);
     152          exp = strtol ((const char *)s, (char **)&q, 10);
    154153          if (errno == ERANGE)
    155154            {
     
    215214
    216215  *p_result = neg ? -z.ld : z.ld;
    217   return end;
     216  return (const char *)end;
    218217
    219218overflow:
    220219  *p_result = neg ? -HUGE_VALL : HUGE_VALL;
    221220  errno = ERANGE;
    222   return end;
     221  return (const char *)end;
    223222
    224223underflow:
    225224  *p_result = neg ? -0.0 : 0.0;
    226225  errno = ERANGE;
    227   return end;
     226  return (const char *)end;
    228227}
  • trunk/src/emx/src/lib/io/_fbuf.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    1717    {
    1818      PLIBCFH   pFH = __libc_FH(stream->_handle);
    19       if (pFH && (   (pFH->fFlags & F_TYPEMASK) == F_DEV
    20                   || (pFH->fFlags & F_TYPEMASK) == F_SOCKET))
     19      if (pFH && (   (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV
     20                  || (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_SOCKET))
    2121        stream->_buffer = _lmalloc(BUFSIZ);
    2222      else
  • trunk/src/emx/src/lib/io/_fdinit.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    66#include <emx/io.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/startup.h>
    1110
     
    1817/* This semaphore protects a critical region in _fd_init(). */
    1918
    20 static _rmutex _fdinit_rmutex;
     19static _fmutex _fdinit_fmutex;
    2120
    2221
     
    2726void _init1_fdinit (void)
    2827{
    29   _rmutex_checked_create (&_fdinit_rmutex, 0);
     28  _fmutex_checked_create (&_fdinit_fmutex, 0);
    3029}
    3130
     
    8281      /* Prevent other threads from updating last->next. */
    8382
    84       _rmutex_checked_request (&_fdinit_rmutex, _FMR_IGNINT);
     83      _fmutex_checked_request (&_fdinit_fmutex, _FMR_IGNINT);
    8584
    8685      /* Now that we have locked other threads out of this critical
     
    9493         and therefore won't be changed by other threads. */
    9594
    96       _rmutex_checked_release (&_fdinit_rmutex);
     95      _fmutex_checked_release (&_fdinit_fmutex);
    9796
    9897      /* If another thread updated last->next, back out and retry,
  • trunk/src/emx/src/lib/io/_fopen.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    66#include <errno.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <stdio.h>
    1110#include <emx/io.h>
     
    8079  dst->_flags |= _IOOPEN | _IOBUFNONE;
    8180  dst->_flush = _flushstream;
    82   if (_rmutex_create (&dst->__u.__rsem, 0) != 0)
     81  if (_fmutex_create (&dst->__u.__fsem, 0) != 0)
    8382    {
    8483      _closestream (dst);
  • trunk/src/emx/src/lib/io/_input.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    11/* _input.c (emx+gcc) -- Copyright (c) 1990-2000 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdio.h>
     
    76#include <stdarg.h>
    87#include <string.h>
    9 #include <ctype.h>
    108#include <limits.h>
    119#include <locale.h>
    12 #include <sys/locale.h>
    1310#include <emx/io.h>
     11#include <InnoTekLIBC/locale.h>
     12#include <ctype.h>
    1413#include "getputc.h"
    1514
     
    477476          c = get (v);
    478477        }
    479       if (c == (unsigned char)__locale_lconv.decimal_point[0])
     478      if (c == (unsigned char)__libc_gLocaleLconv.s.decimal_point[0])
    480479        {
    481480          COLLECT (c);
     
    597596             unread." */
    598597
    599           if (!CHK_MBCS_PREFIX (__locale_ctype, f, mbn))
     598          if (!CHK_MBCS_PREFIX (&__libc_GLocaleCtype, f, mbn))
    600599            mbn = 1;
    601600          for (mbi = 0; mbi < mbn; ++mbi)
  • trunk/src/emx/src/lib/io/_isterm.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    3131     * (Hope that's correct interpretation of the __ioctl1() call...)
    3232     */
    33     return (pFH->fFlags & F_TYPEMASK) == F_DEV;
     33    return (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV;
    3434}
  • trunk/src/emx/src/lib/io/_mfopen.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    55#include <errno.h>
    66#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    7 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    8 #include <sys/rmutex.h>
     7#include <sys/fmutex.h>
    98#include <stdio.h>
    109#include <emx/io.h>
     
    8988  stream->_tmpidx = inc;
    9089  stream->_ungetc_count = 0;
    91   if (_rmutex_create (&stream->__u.__rsem, 0) != 0)
     90  if (_fmutex_create (&stream->__u.__fsem, 0) != 0)
    9291    {
    9392      if (abuf != NULL) free (abuf);
  • trunk/src/emx/src/lib/io/_newstre.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    55#include <stdlib.h>
    66#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    7 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    8 #include <sys/rmutex.h>
     7#include <sys/fmutex.h>
    98#include <stdio.h>
    109#include <emx/io.h>
     
    105104    stream->_flags = 0;
    106105    /* Assumption hare made about how the dummy stuff is made. */
    107     if (stream->__u.__rsem.fm.hev)
    108         _rmutex_close(&stream->__u.__rsem);
     106    if (stream->__u.__fsem.hev)
     107        _fmutex_close(&stream->__u.__fsem);
    109108
    110109    if (stream->__pSV)
  • trunk/src/emx/src/lib/io/_output.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    11/* _output.c (emx+gcc) -- Copyright (c) 1990-2000 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdio.h>
     
    1312#include <emx/io.h>
    1413#include <emx/float.h>
    15 #include <sys/locale.h>
     14#include <InnoTekLIBC/locale.h>
    1615#include "getputc.h"
    1716
     
    704703  v.stream = stream;
    705704  v.count = 0;
    706   zdot[1] = __locale_lconv.decimal_point[0];
     705  zdot[1] = __libc_gLocaleLconv.s.decimal_point[0];
    707706
    708707  /* ANSI X3.159-1989, 4.9.6.1: "The format shall be a multibyte
     
    723722           Avoid the overhead of calling mblen(). */
    724723
    725         if (!CHK_MBCS_PREFIX (__locale_ctype, c, mbn))
     724        if (!CHK_MBCS_PREFIX (&__libc_GLocaleCtype, c, mbn))
    726725          mbn = 1;
    727726        while (mbn > 0)
  • trunk/src/emx/src/lib/io/_rmtmp.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <emx/io.h>
  • trunk/src/emx/src/lib/io/_tempnam.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    33
    44#include "libc-alias.h"
    5 #define __USE_GNU
    65#include <stdio.h>
    76#include <stdlib.h>
     7#ifndef __USE_GNU /* __strnlen */
     8# define __USE_GNU
     9#endif
    810#include <string.h>
    911#include <io.h>
     
    7577      _itoa (_tmpidx, p, 10);
    7678      strcat (p, ".tmp");
    77       memmove (p, prefix, strnlen (prefix, 5));
     79      memmove (p, prefix, __strnlen (prefix, 5));
    7880      errno = 0;
    7981      if (access (tmpname, 0) != 0)
  • trunk/src/emx/src/lib/io/_tmp.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <emx/startup.h>
    87#include "_tmp.h"
    98
     9
     10/*******************************************************************************
     11*   Global Variables                                                           *
     12*******************************************************************************/
    1013int _tmpidx = IDX_LO;
    1114
     15/** This semaphore protects _tmpidx. */
     16static _fmutex _tmpidx_fmutex;
    1217
    13 /* This semaphore protects _tmpidx. */
    14 
    15 static _rmutex _tmpidx_rmutex;
     18/*******************************************************************************
     19*   Internal Functions                                                         *
     20*******************************************************************************/
     21static void _init1_tmp(void);
    1622
    1723
    18 /* Initialize the semaphore -- this function will be called by
     24_CRT_INIT1(_init1_tmp)
     25
     26/** Initialize the semaphore -- this function will be called by
    1927   _CRT_init() via the __crtinit1__ set vector. */
    20 
    21 void _init1_tmp (void);
    22 void _init1_tmp (void)
     28static void _init1_tmp(void)
    2329{
    24   _rmutex_checked_create (&_tmpidx_rmutex, 0);
     30    static void *hack = (void *)_init1_tmp;
     31    hack = hack;
     32    _fmutex_checked_create(&_tmpidx_fmutex, 0);
    2533}
    2634
    27 _CRT_INIT1 (_init1_tmp)
    2835
    29 
    30 void _tmpidx_lock (void)
     36void _tmpidx_lock(void)
    3137{
    32   _rmutex_checked_request (&_tmpidx_rmutex, _FMR_IGNINT);
     38    _fmutex_checked_request(&_tmpidx_fmutex, _FMR_IGNINT);
    3339}
    3440
    35 void _tmpidx_unlock (void)
     41void _tmpidx_unlock(void)
    3642{
    37   _rmutex_checked_release (&_tmpidx_rmutex);
     43    _fmutex_checked_release(&_tmpidx_fmutex);
    3844}
  • trunk/src/emx/src/lib/io/_trslash.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    11/* _trslash.c (emx+gcc) -- Copyright (c) 1996 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <emx/io.h>
    6 #include <sys/locale.h>
     5#include <InnoTekLIBC/locale.h>
    76
    87/* Detect trailing slash or backslash for stat(), access(), and
     
    6059  for (;;)
    6160    {
    62       if (CHK_MBCS_PREFIX (__locale_ctype, name[i], mbcl))
     61      if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, name[i], mbcl))
    6362        {
    6463          if (i == len - 1 - mbcl)
  • trunk/src/emx/src/lib/io/_vsopen.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    126126     * Check what we got a handle to.
    127127     */
    128     if ((fLibc & F_TYPEMASK) == F_DEV)
     128    if ((fLibc & __LIBC_FH_TYPEMASK) == F_DEV)
    129129        fOpen &= ~O_APPEND;
    130130
     
    132132     * For text files we shall remove eventual ending Ctrl-Z.
    133133     */
    134     if (    (fLibc & F_TYPEMASK) != F_DEV
     134    if (    (fLibc & __LIBC_FH_TYPEMASK) != F_DEV
    135135        &&  (fLibc & O_TEXT))
    136136    {
     
    159159        fFlags = (fFlags & ~O_ACCMODE) | (fOpen & O_ACCMODE);
    160160        fFlags &= ~_SO_EXCL;       /* Ignore O_EXCL */
    161         hFile = __open(pszName, fFlags, cbInitial, fLibc & ~F_TYPEMASK, &pFH);
     161        hFile = __open(pszName, fFlags, cbInitial, fLibc & ~__LIBC_FH_TYPEMASK, &pFH);
    162162        if (hFile < 0)
    163163            return -1;
     
    168168     * This is required for passing the file to a child process.
    169169     */
    170     if (    (fLibc & F_TYPEMASK) == F_FILE
     170    if (    (fLibc & __LIBC_FH_TYPEMASK) == F_FILE
    171171        &&  (fLibc & O_APPEND))
    172172        __lseek(hFile, 0L, SEEK_END);
  • trunk/src/emx/src/lib/io/fdopen.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    66#include <errno.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <stdio.h>
    1110#include <stdio.h>
     
    3130  if (!dst)
    3231    return NULL;
    33   if (_rmutex_create (&dst->__u.__rsem, 0) != 0)
     32  if (_fmutex_create (&dst->__u.__fsem, 0) != 0)
    3433    {
    3534      _closestream (dst);
  • trunk/src/emx/src/lib/io/fflush.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/fgetc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/fgets.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/flushall.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/fprintf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/fputc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/fread.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <sys/param.h>
    87#include <stdio.h>
  • trunk/src/emx/src/lib/io/freopen.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    55#include <share.h>
    66#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    7 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    8 #include <sys/rmutex.h>
     7#include <sys/fmutex.h>
    98#include <emx/io.h>
    109
  • trunk/src/emx/src/lib/io/fscanf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/fseek.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/ftell.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/ftruncat.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    2222    }
    2323/** @todo check this api with latest specs - there is a zero fill extension now IIRC. */
    24     if ((pFH->fFlags & F_TYPEMASK) != F_FILE)
     24    if ((pFH->fFlags & __LIBC_FH_TYPEMASK) != F_FILE)
    2525    {
    2626        errno = EBADF;
  • trunk/src/emx/src/lib/io/fwrite.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/gets.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/isatty.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    2121    }
    2222
    23     return (pFH->fFlags & F_TYPEMASK) == F_DEV;
     23    return (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV;
    2424}
  • trunk/src/emx/src/lib/io/printf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/puts.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/read.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    6565    {
    6666      /* special processing for text mode */
    67       if (  (pFH->fFlags & F_TYPEMASK) == F_FILE
     67      if (  (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_FILE
    6868          && dst[n-1] == 0x1a
    6969          && eof (handle))
  • trunk/src/emx/src/lib/io/rewind.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/scanf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/setvbuf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/snprintf.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdio.h>
     
    3029  trick._ungetc_count = 0;
    3130  trick._mbstate = 0;
    32   _rmutex_dummy(&trick.__u.__rsem);
     31  _fmutex_dummy(&trick.__u.__fsem);
    3332  result = _output (&trick, format, arg_ptr);
    3433  if (n != 0)
  • trunk/src/emx/src/lib/io/sprintf.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdio.h>
     
    2827  trick._ungetc_count = 0;
    2928  trick._mbstate = 0;
    30   _rmutex_dummy(&trick.__u.__rsem);
     29  _fmutex_dummy(&trick.__u.__fsem);
    3130  result = _output (&trick, format, arg_ptr);
    3231  putc (0, &trick);
  • trunk/src/emx/src/lib/io/sscanf.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdio.h>
     
    2928  trick._ungetc_count = 0;
    3029  trick._mbstate = 0;
    31   _rmutex_dummy(&trick.__u.__rsem);
     30  _fmutex_dummy(&trick.__u.__fsem);
    3231  result = _input (&trick, format, arg_ptr);
    3332  va_end (arg_ptr);
  • trunk/src/emx/src/lib/io/ungetc.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/vfprintf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/vfscanf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/vprintf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/vscanf.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdlib.h>
  • trunk/src/emx/src/lib/io/vsnprint.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdio.h>
     
    2726  trick._ungetc_count = 0;
    2827  trick._mbstate = 0;
    29   _rmutex_dummy(&trick.__u.__rsem);
     28  _fmutex_dummy(&trick.__u.__fsem);
    3029  result = _output (&trick, format, arg_ptr);
    3130  if (n != 0)
  • trunk/src/emx/src/lib/io/vsprintf.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdio.h>
     
    2524  trick._ungetc_count = 0;
    2625  trick._mbstate = 0;
    27   _rmutex_dummy(&trick.__u.__rsem);
     26  _fmutex_dummy(&trick.__u.__fsem);
    2827  result = _output (&trick, format, arg_ptr);
    2928  putc (0, &trick);
  • trunk/src/emx/src/lib/io/vsscanf.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    33#include "libc-alias.h"
    44#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    5 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    6 #include <sys/rmutex.h>
     5#include <sys/fmutex.h>
    76#include <stdio.h>
    87#include <stdio.h>
     
    2726  trick._ungetc_count = 0;
    2827  trick._mbstate = 0;
    29   _rmutex_dummy(&trick.__u.__rsem);
     28  _fmutex_dummy(&trick.__u.__fsem);
    3029  result = _input (&trick, format, arg_ptr);
    3130  return result;
  • trunk/src/emx/src/lib/io/write.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    118118  if (splitp)
    119119    {
    120       if ((pFH->fFlags & F_TYPEMASK) != F_FILE)
     120      if ((pFH->fFlags & __LIBC_FH_TYPEMASK) != F_FILE)
    121121        pFH->fFlags |= F_WRCRPEND;
    122122      else
     
    154154  }
    155155
    156   if ((pFH->fFlags & (F_TYPEMASK | O_APPEND)) == (O_APPEND | F_FILE))
     156  if ((pFH->fFlags & (__LIBC_FH_TYPEMASK | O_APPEND)) == (O_APPEND | F_FILE))
    157157    __lseek (handle, 0, SEEK_END);
    158158  if (nbyte == 0)                 /* Avoid truncation of file */
     
    182182         data to be written. */
    183183
    184       if (   (pFH->fFlags & F_TYPEMASK) == F_DEV
     184      if (   (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV
    185185          && *src == CTRL_Z)
    186186        return 0;
     
    190190
    191191      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) )
     192          && (   (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV
     193              || (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_SOCKET /* ???? */
     194              || (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_PIPE) )
    195195        {
    196196          errno = EAGAIN;
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.58 to 1.59
    r1453 r1454  
    2323    "___default_hash" @1
    2424    "___digits" @2
    25     "___locale" @3
    26     "___locale_collate" @4
    27     "___locale_ctype" @5
    28     "___locale_lconv" @6
    29     "___locale_time" @7
     25    "___libc_GLocaleCtype" @3
     26    "___libc_GLocaleCtypeDefault" @4
     27    ;fixme "___locale_collate" @4
     28    ;fixme "___locale_ctype" @5
     29    ;fixme "___locale_lconv" @6
     30    ;fixme "___locale_time" @7
    3031    "___progname" @8
    3132    "___stderrp" @9
     
    5354    "__std_timezone" @31
    5455    "__std_tzname" @32
    55     "__streamv_rmutex" @33
     56    "__streamv_fmutex" @33
    5657    "__streamvec_head" @34
    5758    "__tmpidx" @35
     
    138139    "__alloca" @161
    139140; LIBGCCEND
    140        
     141
    141142; LIBC code - and const
    142143    "__CRT_init" @162
     
    195196    "___close" @215
    196197    "___collate_range_cmp" @216
    197     "___convert_codepage" @217
     198    ;fixme "___convert_codepage" @217
    198199    "___ctordtorInit1" @218
    199200    "___ctordtorTerm1" @219
    200201    "___dbpanic" @220
    201202    "___delpair" @221
    202     "___do_Unicode" @222
     203    ;fixme "___do_Unicode" @222
    203204    "___dtoa" @223
    204205    "___dup" @224
     
    220221    "___fpclassifyl" @240
    221222    "___free_ovflpage" @241
    222     "___from_ucs" @242
     223    ;fixme "___from_ucs" @242
    223224    "___fstat" @243
    224225    "___ftime" @244
     
    274275    "___libc_TLSGet" @294
    275276    "___libc_TLSSet" @295
    276     "___locale_C" @296
     277    ;fixme "___locale_C" @296
    277278    "___log2" @297
    278279    "___lseek" @298
     
    323324    "___swchar" @343
    324325    "___threadid" @344
    325     "___to_ucs" @345
     326    ;fixme "___to_ucs" @345
    326327    "___tolower" @346
    327328    "___toupper" @347
     
    488489    "__hrealloc" @508
    489490    "__imphandle" @509
    490     "__init1_tmp" @510
     491    ; fixme!! "__init1_tmp" @510
    491492    "__init_streams" @511
    492493    "__input" @512
     
    523524    "__rfnlwr" @543
    524525    "__rmtmp" @544
    525     "__rmutex_checked_close" @545
    526     "__rmutex_checked_create" @546
    527     "__rmutex_checked_open" @547
    528     "__rmutex_close" @548
    529     "__rmutex_create" @549
    530     "__rmutex_dummy" @550
    531     "__rmutex_fork" @551
    532     "__rmutex_open" @552
     526    ; fixme!! "__rmutex_checked_close" @545
     527    ; fixme!! "__rmutex_checked_create" @546
     528    ; fixme!! "__rmutex_checked_open" @547
     529    ; fixme!! "__rmutex_close" @548
     530    ; fixme!! "__rmutex_create" @549
     531    ; fixme!! "__rmutex_dummy" @550
     532    ; fixme!! "__rmutex_fork" @551
     533    ; fixme!! "__rmutex_open" @552
    533534    "__scrsize" @553
    534535    "__searchenv" @554
     
    11001101    "___libc_ThreadRegisterTermCallback" @1120
    11011102    "___libc_TLSGetDestructor" @1121
    1102    
     1103
    11031104; LIBGCCSTART
    11041105; GCC333.DLL - move this!!!
     
    11091110    "___gcc_personality_v0" @1126  ; (this is a bug in the gcc 3.2.2 config, it should've been there too.)
    11101111; LIBGCCEND
    1111    
     1112
    11121113    "__std_strtok_r" @1127
     1114    "___libc_LogDumpHex" @1128
     1115    "DosAllocMemEx" @1129
     1116    "DosAllocSharedMemEx" @1130
     1117    "DosCloseEventSemEx" @1131
     1118    "DosCloseMutexSemEx" @1132
     1119    "DosCreateEventSemEx" @1133
     1120    "DosCreateMutexSemEx" @1134
     1121    "DosFreeMemEx" @1135
     1122    "DosGetNamedSharedMemEx" @1136
     1123    "DosGetSharedMemEx" @1137
     1124    "DosOpenEventSemEx" @1138
     1125    "DosOpenMutexSemEx" @1139
     1126    "__atfork_callback" @1140
     1127    "__std_getrlimit" @1141
     1128    "__std_setrlimit" @1142
     1129    "___libc_ForkDefaultModuleCallback" @1143
     1130    "___libc_ForkRegisterModule" @1144
     1131    "___isctype" @1145
     1132    "___libc_TranslateCodepage" @1146
     1133    "__std_eaccess" @1147
     1134    "___libc_TcpipAllocFH43" @1148
     1135    "___libc_TcpipAllocFH44" @1149
     1136    "___libc_TcpipAllocFHEx43" @1150
     1137    "___libc_TcpipAllocFHEx44" @1151
     1138    "___libc_Tcpipbsdselect43" @1152
     1139    "___libc_Tcpipbsdselect44" @1153
  • trunk/src/emx/src/lib/libc.smak

    • Property cvs2svn:cvs-rev changed from 1.41 to 1.42
    r1453 r1454  
    2929.TSRC   := $(libc.TSRC.$(CPU)) $(libc.TSRC)
    3030.TDEP   := $(libc.TDEP.$(CPU)) $(libc.TDEP)
    31 .TCF    := -I$. -D__DBINTERFACE_PRIVATE -D__NETBSD_SYSCALLS -DPOSIX_MISTAKE -DHAVE_CONFIG_H -Isrc/lib/bsd/locale -Isrc/lib/lgpl/include
     31.TCF    := -I$. -DIN_INNOTEK_LIBC -D__DBINTERFACE_PRIVATE -D__NETBSD_SYSCALLS -DPOSIX_MISTAKE -DHAVE_CONFIG_H -Isrc/lib/bsd/locale -Isrc/lib/lgpl/include
    3232.INSDIR = lib/
    3333.TKEEP  := 1
    3434include mklib.smak
    3535
    36 .TARGET := libc_l_s.a
     36
     37.TARGET := libc_l_s.a
    3738.TKIND  := aout log
    3839.TKEEP  := 1
     
    5657LIBC.IMPLIB     := $.omf/libc_dll.lib $.aout/libc_dll.a
    5758LIBC.DEF        := $.omf/libc.def
    58 LIBC.OBJS       := $.omf/src/lib/startup/dll0hi.obj $.omf/src/lib/startup/dllinit.obj
     59LIBC.OBJS       := $.omf/src/lib/startup/dll0hifork.obj $.omf/src/lib/startup/dllinit.obj
    5960LIBC.LIBS       := $.omf/libc_s.lib $.omf/libc_app.lib
    6061LIBC.DEPS       := $(LIBC.STUB) $.omf/libc_alias.lib
     
    6465LIBC.PRF.DLL    := $(LIBC.DLL:.dll=.prf)
    6566LIBC.PRF.DEF    := $.omf/libc.prf.def
    66 LIBC.PRF.OBJS   := $.omf/src/lib/startup/dll0hi.obj $.omf-prof/src/lib/startup/dllinit.obj
     67LIBC.PRF.OBJS   := $.omf/src/lib/startup/dll0hifork.obj $.omf-prof/src/lib/startup/dllinit.obj
    6768LIBC.PRF.LIBS   := $.omf-prof/libc_p_s.lib $.omf-prof/libc_app_p.lib
    6869LIBC.PRF.DEPS   := $(LIBC.DEPS)
     
    7879LIBC.LOG.DLL    := $(LIBC.DLL:.dll=.logchk)
    7980LIBC.LOG.DEF    := $(LIBC.DEF)
    80 LIBC.LOG.OBJS   := $.omf/src/lib/startup/dll0hi.obj $.omf/src/lib/startup/dllinit.obj
     81LIBC.LOG.OBJS   := $.omf/src/lib/startup/dll0hifork.obj $.omf/src/lib/startup/dllinit.obj
    8182LIBC.LOG.LIBS   := $.omf-log/libc_l_s.lib $.omf-log/libc_app_l.lib
    8283LIBC.LOG.DEPS   := $(LIBC.DEPS)
     
    248249  $(addprefix $(INS)lib/,$(notdir $(LIBC.IMPLIB))) \
    249250  $(INS)lib/$(notdir $(LIBC.LOG.DLL)) \
     251  $(INS)lib/$(notdir $(LIBC.LOG.DLL).map) \
    250252  $(INS)lib/$(notdir $(LIBC.PRF.DLL)) \
    251   $(INS)lib/$(notdir $(LIBC.ELH.DLL))
     253  $(INS)lib/$(notdir $(LIBC.PRF.DLL).map) \
     254  $(INS)lib/$(notdir $(LIBC.ELH.DLL)) \
     255  $(INS)lib/$(notdir $(LIBC.ELH.DLL).map)
    252256
    253257$(INS)lib/$(notdir $(LIBC.DLL)): $(LIBC.DLL)
     
    258262$(INS)lib/$(notdir $(LIBC.LOG.DLL)): $(LIBC.LOG.DLL)
    259263        $(call CP,$<,$@)
     264$(INS)lib/$(notdir $(LIBC.LOG.DLL).map): $(LIBC.LOG.DLL).map
     265        $(call CP,$<,$@)
    260266                                               
    261267$(INS)lib/$(notdir $(LIBC.PRF.DLL)): $(LIBC.PRF.DLL)
    262268        $(call CP,$<,$@)
     269$(INS)lib/$(notdir $(LIBC.PRF.DLL).map): $(LIBC.PRF.DLL).map
     270        $(call CP,$<,$@)
    263271
    264272$(INS)lib/$(notdir $(LIBC.ELH.DLL)): $(LIBC.ELH.DLL)
     273        $(call CP,$<,$@)
     274$(INS)lib/$(notdir $(LIBC.ELH.DLL).map): $(LIBC.ELH.DLL).map
    265275        $(call CP,$<,$@)
    266276
  • trunk/src/emx/src/lib/locale/__convcp.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale - code page translation.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    426
    5     For conditions of distribution and use, see the file COPYING.
     27#include <InnotekLIBC/locale.h>
     28#include <string.h>
    629
    7     Convert an ASCIIZ codepage to UCS-2 form and convert POSIX codepage
    8     names to names understood by OS/2 Unicode API.
    9 */
     30/**
     31 * Convert an ASCIIZ codepage to UCS-2 form and convert POSIX codepage
     32 * names to names understood by OS/2 Unicode API.
     33 */
     34extern void __libc_TranslateCodepage(const char *cp, UniChar *ucp)
     35{
     36    static const struct _cp_aliases
     37    {
     38        const char *pszAlias;
     39        const char *pszIBM;
     40    } aAliases[] =
     41    {   /* pszAlias   ->      pszIBM */
     42        { "SYSTEM",           ""},
     43        { "ASCII",            "IBM-367"},
     44        { "UTF-8",            "IBM-1208"},
     45        { "UCS-2",            "IBM-1200"},
     46        { "UCS-2BE",          "IBM-1200@endian=big"},
     47        { "UCS-2LE",          "IBM-1200@endian=little"},
     48        { "EUC-JP",           "IBM-954"},
     49        { "EUC-KR",           "IBM-970"},
     50        { "EUC-TW",           "IBM-964"},
     51        { "EUC-CN",           "IBM-1383"},
     52        { "BIG5",             "IBM-950"},
     53    };
     54    unsigned    i;
     55    size_t      sl;
    1056
    11 #include <string.h>
    12 #include <uconv.h>
    13 #include <emx/locale.h>
    14 
    15 /* Convert an encoding name to te form understood by UniCreateUconvObject.  */
    16 void __convert_codepage (const char *cp, UniChar *ucp)
    17 {
    18   static const struct _cp_aliases
    19   {
    20       const char *pszAlias;
    21       const char *pszIBM;
    22   } aAliases[] =
    23   {   /* pszAlias   ->      pszIBM */
    24       { "SYSTEM",           ""         },
    25       { "ASCII",            "IBM-367"  },
    26       { "UTF-8",            "IBM-1208" },
    27       { "UCS-2",            "IBM-1200" },
    28       { "UCS-2BE",          "IBM-1200@endian=big" },
    29       { "UCS-2LE",          "IBM-1200@endian=little" },
    30       { "EUC-JP",           "IBM-954"  },
    31       { "EUC-KR",           "IBM-970"  },
    32       { "EUC-TW",           "IBM-964"  },
    33       { "EUC-CN",           "IBM-1383" },
    34       { "BIG5",             "IBM-950"  },
    35   };
    36   int       i;
    37   size_t    sl;
    38 
    39   /*
    40    * Try aliases.
    41    */
    42   for (i = 0; i < sizeof(aAliases) / sizeof(aAliases[0]); i++ )
     57    /*
     58     * Try aliases.
     59     */
     60    for (i = 0; i < sizeof(aAliases) / sizeof(aAliases[0]); i++)
    4361    {
    44       if (!strcmp(cp, aAliases[i].pszAlias))
     62        if (!strcmp(cp, aAliases[i].pszAlias))
    4563        {
    46           cp = aAliases[i].pszIBM;
    47           while ((*ucp++ = *cp++) != 0)
    48               /* nada */;
    49           return;
     64            cp = aAliases[i].pszIBM;
     65            while ((*ucp++ = *cp++) != '\0')
     66                /* nada */;
     67            return;
    5068        }
    5169    }
    5270
    53   /*
    54    * Generic transformations:
    55    *    CPxxxx     -> IBM-xxxx
    56    *    ISO-xxxx-x -> ISOxxxx-x
    57    */
    58   sl = 0;
    59   /* Transform CPXXX naming style to IBM-XXX style */
    60   if ((cp[0] == 'C' || cp[0] == 'c')
    61    && (cp[1] == 'P' || cp[1] == 'p'))
     71    /*
     72     * Generic transformations:
     73     *    CPxxxx     -> IBM-xxxx
     74     *    ISO-xxxx-x -> ISOxxxx-x
     75     */
     76    sl = 0;
     77    /* Transform CPXXX naming style to IBM-XXX style */
     78    if (   (cp[0] == 'C' || cp[0] == 'c')
     79        && (cp[1] == 'P' || cp[1] == 'p'))
    6280    {
    63       ucp[sl++] = 'I';
    64       ucp[sl++] = 'B';
    65       ucp[sl++] = 'M';
    66       ucp[sl++] = '-';
    67       cp += 2;
     81        ucp[sl++] = 'I';
     82        ucp[sl++] = 'B';
     83        ucp[sl++] = 'M';
     84        ucp[sl++] = '-';
     85        cp += 2;
    6886    }
    69   /* Transform ISO-XXXX-X naming style to ISOXXXX-X style */
    70   else if ((cp[0] == 'I' || cp[0] == 'i')
    71         && (cp[1] == 'S' || cp[1] == 's')
    72         && (cp[2] == 'O' || cp[2] == 'o')
    73         && (cp[3] == '-'))
    74   {
    75       ucp[sl++] = 'I';
    76       ucp[sl++] = 'S';
    77       ucp[sl++] = 'O';
    78       cp += 4;
    79   }
     87    /* Transform ISO-XXXX-X naming style to ISOXXXX-X style */
     88    else if (   (cp[0] == 'I' || cp[0] == 'i')
     89             && (cp[1] == 'S' || cp[1] == 's')
     90             && (cp[2] == 'O' || cp[2] == 'o')
     91             && (cp[3] == '-'))
     92    {
     93        ucp[sl++] = 'I';
     94        ucp[sl++] = 'S';
     95        ucp[sl++] = 'O';
     96        cp += 4;
     97    }
    8098
    81   /* copy the rest of the string. */
    82   while (*cp != '\0')
    83     ucp[sl++] = *cp++;
    84   ucp[sl] = 0;
     99    /* copy the rest of the string. */
     100    while (*cp != '\0')
     101        ucp[sl++] = *cp++;
     102    ucp[sl] = '\0';
    85103}
  • trunk/src/emx/src/lib/locale/__do_uni.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale - String processor.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    426
    5     For conditions of distribution and use, see the file COPYING.
    627
    7     Utility routine that converts a string to Unicode, calls some
    8     function and then converts the string back. Used to handle
    9     MBCS encodings.
    10 */
    11 
    12 #define INCL_FSMACROS
    13 #include <os2emx.h>
    14 #include <uconv.h>
     28#include <InnoTekLIBC/locale.h>
    1529#include <alloca.h>
    1630#include <malloc.h>
    1731#include <string.h>
    18 #include <emx/locale.h>
     32#define INCL_FSMACROS
     33#include <os2emx.h>
    1934
    20 void __do_Unicode (UconvObject *uconv, char *s, void *arg,
    21   int (*xform) (UniChar *, void *))
     35/**
     36 * Utility routine that converts a string to Unicode, calls some
     37 * function and then converts the string back.
     38 * Used to handle MBCS encodings
     39 */
     40extern void __libc_ucs2Do(UconvObject *uconv, char *s, void *arg, int (*xform)(UniChar *, void *))
    2241{
    23   /* We'll get maximum that much UniChar's */
    24   size_t sl = strlen (s) + 1;
    25   char free_ucs = 0;
    26   UniChar *ucs;
    27   void *mbcsbuf;
    28   UniChar *ucsbuf;
    29   size_t in_left, out_left, nonid;
    30   FS_VAR();
    31   FS_SAVE_LOAD();
     42    /* We'll get maximum that much UniChar's */
     43    size_t sl = strlen(s) + 1;
     44    char free_ucs = 0;
     45    UniChar *ucs;
     46    void *mbcsbuf;
     47    UniChar *ucsbuf;
     48    size_t in_left, out_left, nonid;
     49    FS_VAR();
     50    FS_SAVE_LOAD();
    3251
    33   /* Allocate strings up to 2000 characters on the stack */
    34   if (sl < 4096 / sizeof (UniChar))
    35     ucs = alloca (sl * sizeof (UniChar));
    36   else
    37   {
    38     free_ucs = 1;
    39     ucs = malloc (sl * sizeof (UniChar));
    40   }
     52    /* Allocate strings up to 2000 characters on the stack */
     53    if (sl < 4096 / sizeof(UniChar))
     54        ucs = alloca(sl * sizeof(UniChar));
     55    else
     56    {
     57        free_ucs = 1;
     58        ucs = malloc(sl * sizeof(UniChar));
     59    }
    4160
    42   /* Translate the string to Unicode */
    43   mbcsbuf = s; in_left = sl;
    44   ucsbuf = ucs; out_left = sl;
    45   if (UniUconvToUcs (uconv, &mbcsbuf, &in_left, &ucsbuf, &out_left, &nonid))
    46     goto out;
     61    /* Translate the string to Unicode */
     62    mbcsbuf = s; in_left = sl;
     63    ucsbuf = ucs; out_left = sl;
     64    if (UniUconvToUcs(uconv, &mbcsbuf, &in_left, &ucsbuf, &out_left, &nonid))
     65        goto out;
    4766
    48   /* Apply the transform function */
    49   if (xform (ucs, arg))
    50   {
    51     /* Now convert back to MBCS */
    52     ucsbuf = ucs; in_left = sl - out_left;
    53     mbcsbuf = s; out_left = sl;
    54     UniUconvFromUcs (uconv, &ucsbuf, &in_left, &mbcsbuf, &out_left, &nonid);
    55   }
     67    /* Apply the transform function */
     68    if (xform(ucs, arg))
     69    {
     70        /* Now convert back to MBCS */
     71        ucsbuf = ucs; in_left = sl - out_left;
     72        mbcsbuf = s; out_left = sl;
     73        UniUconvFromUcs(uconv, &ucsbuf, &in_left, &mbcsbuf, &out_left, &nonid);
     74    }
    5675
    5776out:
    58   if (free_ucs)
    59     free (ucs);
    60   FS_RESTORE();
     77    if (free_ucs)
     78        free(ucs);
     79    FS_RESTORE();
    6180}
  • trunk/src/emx/src/lib/locale/__from_ucs.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale - Convert a char from unicode to mbcs.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    426
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Helper function: Convert a character from Unicode.
    8     Returns number of bytes in the MBCS character.
    9 */
    10 
     27#include <InnoTekLIBC/locale.h>
    1128#define INCL_FSMACROS
    1229#include <os2emx.h>
    13 #include <uconv.h>
    14 #include <emx/locale.h>
    1530
    16 int __from_ucs (UconvObject uconv_obj, UniChar c, unsigned char *sbcs,
    17   size_t len)
     31/** Convert a Unicode character to MBCS. */
     32extern int  __libc_ucs2From(UconvObject uobj, UniChar c, unsigned char *sbcs, size_t len)
    1833{
    19   UniChar *inbuf = &c;
    20   void *outbuf = sbcs;
    21   size_t nonid, in_left = 1, out_left = len;
    22   int rc;
    23   FS_VAR();
     34    UniChar *inbuf = &c;
     35    void *outbuf = sbcs;
     36    size_t nonid, in_left = 1, out_left = len;
     37    int rc;
     38    FS_VAR();
    2439
    25   FS_SAVE_LOAD();
    26   rc = UniUconvFromUcs (uconv_obj, &inbuf, &in_left, &outbuf, &out_left, &nonid);
    27   FS_RESTORE();
    28   if (rc || nonid || in_left)
    29     return 0;
     40    FS_SAVE_LOAD();
     41    rc = UniUconvFromUcs(uobj, &inbuf, &in_left, &outbuf, &out_left, &nonid);
     42    FS_RESTORE();
     43    if (rc || nonid || in_left)
     44        return 0;
    3045
    31   return len - out_left;
     46    return len - out_left;
    3247}
  • trunk/src/emx/src/lib/locale/__to_ucs.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale - Confer from MBCS to Unicode.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    426
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Helper function: convert a MBCS character to a Unicode character.
    8     Returns 0 or the length of the MBCS character in bytes.
    9 */
    10 
     27#include <InnoTekLIBC/locale.h>
    1128#define INCL_FSMACROS
    1229#include <os2emx.h>
    13 #include <uconv.h>
    14 #include <emx/locale.h>
    1530
    16 int __to_ucs (UconvObject uconv_obj, const unsigned char *sbcs, size_t len,
    17   UniChar *ucs)
     31
     32/** Convert a MBCS character to Unicode; returns number of bytes in MBCS char. */
     33int  __libc_ucs2To(UconvObject uobj, const unsigned char *sbcs, size_t len, UniChar *ucs)
    1834{
    19   void *inbuf = (void *)sbcs;
    20   UniChar *outbuf = ucs;
    21   size_t nonid, in_left = len, out_left = 1;
    22   int ret;
    23   FS_VAR();
     35    void *inbuf = (void *)sbcs;
     36    UniChar *outbuf = ucs;
     37    size_t nonid, in_left = len, out_left = 1;
     38    int ret;
     39    FS_VAR();
    2440
    25   FS_SAVE_LOAD();
    26   ret = UniUconvToUcs (uconv_obj, &inbuf, &in_left, &outbuf, &out_left,
    27     &nonid);
    28   FS_RESTORE();
     41    FS_SAVE_LOAD();
     42    ret = UniUconvToUcs(uobj, &inbuf, &in_left, &outbuf, &out_left, &nonid);
     43    FS_RESTORE();
    2944
    30   if ((ret && (ret != ULS_BUFFERFULL)) || nonid || out_left)
    31     return 0;
     45    if ((ret && (ret != ULS_BUFFERFULL)) || nonid || out_left)
     46        return 0;
    3247
    33   return len - in_left;
     48    return len - in_left;
    3449}
  • trunk/src/emx/src/lib/locale/isxxx.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
    4 
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Usually these routines are not needed (they are inline), but
    8     for cases when a program instead of including ctype.h blindly
    9     declares them with "extern", they will be linked in.
    10 */
     1/* $Id$ */
     2/** @file
     3 *
     4 * ctype functions.
     5 *
     6 * Usually these routines are not needed (they are inline), but
     7 * for cases when a program instead of including ctype.h blindly
     8 * declares them with "extern", they will be linked in.
     9 *
     10 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     11 * Copyright (c) 2003-2004 knut st. osmundsen <bird-srcspam@anduin.net>
     12 *
     13 *
     14 * This file is part of InnoTek LIBC.
     15 *
     16 * InnoTek LIBC is free software; you can redistribute it and/or modify
     17 * it under the terms of the GNU General Public License as published by
     18 * the Free Software Foundation; either version 2 of the License, or
     19 * (at your option) any later version.
     20 *
     21 * InnoTek LIBC is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with InnoTek LIBC; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     29 *
     30 */
    1131
    1232#define _DONT_USE_CTYPE_INLINE_
    1333#include "libc-alias.h"
    14 #include <sys/locale.h>
    1534#include <ctype.h>
    1635
    1736#undef isalnum
    1837int isalnum(int _c)
    19 { return __locale_ctype.cflags [_c & 0xff] & (__UPPER|__LOWER|__DIGIT); }
     38{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__UPPER|__LOWER|__DIGIT); }
    2039
    2140#undef isalpha
    2241int isalpha(int _c)
    23 { return __locale_ctype.cflags [_c & 0xff] & (__UPPER|__LOWER); }
     42{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__UPPER|__LOWER); }
    2443
    2544#undef iscntrl
    2645int iscntrl(int _c)
    27 { return __locale_ctype.cflags [_c & 0xff] & (__CNTRL); }
     46{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__CNTRL); }
    2847
    2948#undef isdigit
    3049int isdigit(int _c)
    31 { return __locale_ctype.cflags [_c & 0xff] & (__DIGIT); }
     50{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__DIGIT); }
    3251
    3352#undef isgraph
    3453int isgraph(int _c)
    35 { return __locale_ctype.cflags [_c & 0xff] & (__PUNCT|__UPPER|__LOWER|__DIGIT); }
     54{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__PUNCT|__UPPER|__LOWER|__DIGIT); }
    3655
    3756#undef islower
    3857int islower(int _c)
    39 { return __locale_ctype.cflags [_c & 0xff] & (__LOWER); }
     58{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__LOWER); }
    4059
    4160#undef isprint
    4261int isprint(int _c)
    43 { return __locale_ctype.cflags [_c & 0xff] & (__PRINT); }
     62{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__PRINT); }
    4463
    4564#undef ispunct
    4665int ispunct(int _c)
    47 { return __locale_ctype.cflags [_c & 0xff] & (__PUNCT); }
     66{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__PUNCT); }
    4867
    4968#undef isspace
    5069int isspace(int _c)
    51 { return __locale_ctype.cflags [_c & 0xff] & (__SPACE); }
     70{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__SPACE); }
    5271
    5372#undef isupper
    5473int isupper(int _c)
    55 { return __locale_ctype.cflags [_c & 0xff] & (__UPPER); }
     74{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__UPPER); }
    5675
    5776#undef isxdigit
    5877int isxdigit(int _c)
    59 { return __locale_ctype.cflags [_c & 0xff] & (__XDIGIT); }
     78{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__XDIGIT); }
    6079
    6180#undef isblank
    6281int isblank(int _c)
    63 { return __locale_ctype.cflags [_c & 0xff] & (__BLANK); }
     82{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__BLANK); }
    6483
    6584#undef ishexnumber
    6685int ishexnumber(int _c)
    67 { return __locale_ctype.cflags [_c & 0xff] & (__XDIGIT); }
     86{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__XDIGIT); }
    6887
    6988#undef isnumber
    7089int isnumber(int _c)
    71 { return __locale_ctype.cflags [_c & 0xff] & (__DIGIT); }
     90{ return __libc_GLocaleCtype.ausfType[_c & 0xff] & (__DIGIT); }
    7291
    7392#undef toascii
     
    7998{ return (_c & 0x80) != 0; }
    8099
    81 
  • trunk/src/emx/src/lib/locale/locale_collate.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale - String collation information array.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    426
    5     For conditions of distribution and use, see the file COPYING.
     27#include <InnoTekLIBC/locale.h>
    628
    7     String collation information array.
    8 */
    9 
    10 #define __INTERNAL_DEFS
    11 #include <sys/locale.h>
    12 #include <string.h>
    13 
    14 struct __locale_collate __locale_collate =
     29/** String collation information. */
     30__LIBC_LOCALECOLLATE     __libc_gLocaleCollate =
    1531{
    16   weight:
    17   {
    18   0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
    19   10, 11, 13, 12, 14, 15, 16, 17, 18, 19,
    20   20, 21, 23, 22, 24, 25, 26, 27, 28, 29,
    21   30, 31, 33, 32, 34, 35, 36, 37, 38, 39,
    22   40, 41, 43, 42, 44, 45, 46, 47, 48, 49,
    23   50, 51, 53, 52, 54, 55, 56, 57, 58, 59,
    24   60, 61, 63, 62, 64, 65, 66, 67, 68, 69,
    25   70, 71, 73, 72, 74, 75, 76, 77, 78, 79,
    26   80, 81, 83, 82, 84, 85, 86, 87, 88, 89,
    27   90, 91, 93, 92, 94, 95, 96, 97, 98, 99,
    28   100, 101, 103, 102, 104, 105, 106, 107, 108, 109,
    29   110, 111, 113, 112, 114, 115, 116, 117, 118, 119,
    30   120, 121, 123, 122, 124, 125, 126, 127, 128, 129,
    31   130, 131, 133, 132, 134, 135, 136, 137, 138, 139,
    32   140, 141, 143, 142, 144, 145, 146, 147, 148, 149,
    33   150, 151, 153, 152, 154, 155, 156, 157, 158, 159,
    34   160, 161, 163, 162, 164, 165, 166, 167, 168, 169,
    35   170, 171, 173, 172, 174, 175, 176, 177, 178, 179,
    36   180, 181, 183, 182, 184, 185, 186, 187, 188, 189,
    37   190, 191, 193, 192, 194, 195, 196, 197, 198, 199,
    38   200, 201, 203, 202, 204, 205, 206, 207, 208, 209,
    39   210, 211, 213, 212, 214, 215, 216, 217, 218, 219,
    40   220, 221, 223, 222, 224, 225, 226, 227, 228, 229,
    41   230, 231, 233, 232, 234, 235, 236, 237, 238, 239,
    42   240, 241, 243, 242, 244, 245, 246, 247, 248, 249,
    43   250, 251, 253, 252, 254, 255
    44   },
    45   mbcsprefix:
    46   {
    47     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    48     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    49     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    50     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    51     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    52     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    53     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    54     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    55   },
    56   uconv: 0,
    57   locale: 0,
    58   mbcs: 0
     32    .auchWeight =
     33    {
     34          0,   1,   2,   3,   4,   5,   6,   7,   8,  9,
     35         10,  11,  13,  12,  14,  15,  16,  17,  18, 19,
     36         20,  21,  23,  22,  24,  25,  26,  27,  28, 29,
     37         30,  31,  33,  32,  34,  35,  36,  37,  38, 39,
     38         40,  41,  43,  42,  44,  45,  46,  47,  48, 49,
     39         50,  51,  53,  52,  54,  55,  56,  57,  58, 59,
     40         60,  61,  63,  62,  64,  65,  66,  67,  68, 69,
     41         70,  71,  73,  72,  74,  75,  76,  77,  78, 79,
     42         80,  81,  83,  82,  84,  85,  86,  87,  88, 89,
     43         90,  91,  93,  92,  94,  95,  96,  97,  98, 99,
     44        100, 101, 103, 102, 104, 105, 106, 107, 108, 109,
     45        110, 111, 113, 112, 114, 115, 116, 117, 118, 119,
     46        120, 121, 123, 122, 124, 125, 126, 127, 128, 129,
     47        130, 131, 133, 132, 134, 135, 136, 137, 138, 139,
     48        140, 141, 143, 142, 144, 145, 146, 147, 148, 149,
     49        150, 151, 153, 152, 154, 155, 156, 157, 158, 159,
     50        160, 161, 163, 162, 164, 165, 166, 167, 168, 169,
     51        170, 171, 173, 172, 174, 175, 176, 177, 178, 179,
     52        180, 181, 183, 182, 184, 185, 186, 187, 188, 189,
     53        190, 191, 193, 192, 194, 195, 196, 197, 198, 199,
     54        200, 201, 203, 202, 204, 205, 206, 207, 208, 209,
     55        210, 211, 213, 212, 214, 215, 216, 217, 218, 219,
     56        220, 221, 223, 222, 224, 225, 226, 227, 228, 229,
     57        230, 231, 233, 232, 234, 235, 236, 237, 238, 239,
     58        240, 241, 243, 242, 244, 245, 246, 247, 248, 249,
     59        250, 251, 253, 252, 254, 255
     60    },
     61    .au2MBCSPrefixs =
     62    {   /* 01 */
     63        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     64        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     65        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     66        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     67        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     68        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     69        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     70        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     71    },
     72    .uobj = 0,
     73    .lobj = 0,
     74    .mbcs = 0
    5975};
    6076
  • trunk/src/emx/src/lib/locale/locale_ctype.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
    4 
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Default character type bits for "C" locale.
    8 */
    9 
    10 #define __INTERNAL_DEFS
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale - ctype data.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 * Copyright (c) 2003-2004 knut st. osmundsen <bird-srcspam@anduin.net>
     8 *
     9 *
     10 * This file is part of InnoTek LIBC.
     11 *
     12 * InnoTek LIBC is free software; you can redistribute it and/or modify
     13 * it under the terms of the GNU General Public License as published by
     14 * the Free Software Foundation; either version 2 of the License, or
     15 * (at your option) any later version.
     16 *
     17 * InnoTek LIBC is distributed in the hope that it will be useful,
     18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20 * GNU General Public License for more details.
     21 *
     22 * You should have received a copy of the GNU General Public License
     23 * along with InnoTek LIBC; if not, write to the Free Software
     24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     25 *
     26 */
     27
    1128#define _DONT_USE_CTYPE_INLINE_
    1229#include "libc-alias.h"
    13 #include <sys/locale.h>
     30#include <InnoTekLIBC/locale.h>
    1431#include <ctype.h>
    1532
    1633
    17 struct __locale_ctype __locale_ctype =
    18 {
    19   cflags:
    20   {
    21     0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020,
    22     0x8020, 0x8068, 0x8028, 0x8028, 0x8028, 0x8028, 0x8020, 0x8020,
    23     0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020,
    24     0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020,
    25     0x8848, 0x8c10, 0x8c10, 0x8c10, 0xac10, 0x8c10, 0x8c10, 0x8c10,
    26     0x8c10, 0x8c10, 0x8c10, 0xac10, 0x8c10, 0x8c10, 0x8c10, 0x8c10,
    27     0x9e84, 0x9e84, 0x9e84, 0x9e84, 0x9e84, 0x9e84, 0x9e84, 0x9e84,
    28     0x9e84, 0x9e84, 0x8c10, 0x8c10, 0xac10, 0xac10, 0xac10, 0x8c10,
    29     0x8c10, 0x8f81, 0x8f81, 0x8f81, 0x8f81, 0x8f81, 0x8f81, 0x8f01,
    30     0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01,
    31     0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01,
    32     0x8f01, 0x8f01, 0x8f01, 0x8c10, 0x8c10, 0x8c10, 0xac10, 0x8c10,
    33     0xac10, 0x8f82, 0x8f82, 0x8f82, 0x8f82, 0x8f82, 0x8f82, 0x8f02,
    34     0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02,
    35     0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02,
    36     0x8f02, 0x8f02, 0x8f02, 0x8c10, 0xac10, 0x8c10, 0xac10, 0x8020,
    37   },
    38   upcase:
    39   {
    40     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    41     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
    42     0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
    43     0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
    44     0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
    45     0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
    46     0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
    47     0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
    48     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
    49     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
    50     0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
    51     0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
    52     0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
    53     0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
    54     0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
    55     0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
    56   },
    57   locase:
    58   {
    59     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
    60     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
    61     0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
    62     0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
    63     0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
    64     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
    65     0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
    66     0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
    67     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
    68     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
    69     0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
    70     0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
    71     0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
    72     0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
    73     0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
    74     0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
    75   },
    76   mbcsprefix:
    77   {
    78     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    79     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    80     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    81     0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
    82   },
    83   uconv: 0,
    84   locale: 0,
    85   mbcs: 0x0
     34/* Character case conversion tables. */
     35__LIBC_LOCALECTYPE       __libc_GLocaleCtype =
     36{
     37    .auchUpper =
     38    {
     39        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
     40        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
     41        0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
     42        0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
     43        0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
     44        0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
     45        0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
     46        0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
     47        0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
     48        0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
     49        0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
     50        0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
     51        0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
     52        0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
     53        0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
     54        0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
     55    },
     56    .auchLower =
     57    {
     58        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
     59        0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
     60        0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
     61        0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
     62        0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
     63        0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
     64        0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
     65        0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
     66        0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
     67        0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
     68        0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
     69        0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
     70        0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
     71        0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
     72        0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
     73        0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
     74    },
     75    .ausfType =
     76    {
     77        0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020,
     78        0x8020, 0x8068, 0x8028, 0x8028, 0x8028, 0x8028, 0x8020, 0x8020,
     79        0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020,
     80        0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020, 0x8020,
     81        0x8848, 0x8c10, 0x8c10, 0x8c10, 0xac10, 0x8c10, 0x8c10, 0x8c10,
     82        0x8c10, 0x8c10, 0x8c10, 0xac10, 0x8c10, 0x8c10, 0x8c10, 0x8c10,
     83        0x9e84, 0x9e84, 0x9e84, 0x9e84, 0x9e84, 0x9e84, 0x9e84, 0x9e84,
     84        0x9e84, 0x9e84, 0x8c10, 0x8c10, 0xac10, 0xac10, 0xac10, 0x8c10,
     85        0x8c10, 0x8f81, 0x8f81, 0x8f81, 0x8f81, 0x8f81, 0x8f81, 0x8f01,
     86        0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01,
     87        0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01, 0x8f01,
     88        0x8f01, 0x8f01, 0x8f01, 0x8c10, 0x8c10, 0x8c10, 0xac10, 0x8c10,
     89        0xac10, 0x8f82, 0x8f82, 0x8f82, 0x8f82, 0x8f82, 0x8f82, 0x8f02,
     90        0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02,
     91        0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02, 0x8f02,
     92        0x8f02, 0x8f02, 0x8f02, 0x8c10, 0xac10, 0x8c10, 0xac10, 0x8020,
     93    },
     94    .au2MBCSPrefixs =
     95    {
     96        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     97        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     98        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     99        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     100    },
     101    .uobj = 0,
     102    .lobj = 0,
     103    .mbcs = 0
    86104};
     105
    87106
    88107
    89108#undef tolower
    90109int tolower(int _c)
    91 { return __locale_ctype.locase [_c & 0xff]; }
     110{
     111    return __libc_GLocaleCtype.auchLower[_c & 0xff];
     112}
     113#undef __tolower
    92114int __tolower(int _c)
    93 { return __locale_ctype.locase [_c & 0xff]; }
     115{
     116    return __libc_GLocaleCtype.auchLower[_c & 0xff];
     117}
    94118
    95119#undef toupper
    96120int toupper(int _c)
    97 { return __locale_ctype.upcase [_c & 0xff]; }
     121{
     122    return __libc_GLocaleCtype.auchUpper[_c & 0xff];
     123}
     124#undef __toupper
    98125int __toupper(int _c)
    99 { return __locale_ctype.upcase [_c & 0xff]; }
    100 
     126{
     127    return __libc_GLocaleCtype.auchUpper[_c & 0xff];
     128}
     129
     130#undef __istype
    101131int __istype(int _c, unsigned _f)
    102 { return __locale_ctype.cflags [_c & 0xff] & (_f); }
    103 
    104 
    105 
    106 
    107 #if 0 /* code for regenerating that table. */
    108 
    109 #define __INTERNAL_DEFS
    110 #include <locale.h>
    111 #include <ctype.h>
     132{
     133    return (__libc_GLocaleCtype.ausfType[_c & 0xff] & (_f)) != 0;
     134}
     135
     136
     137
     138
     139
     140#if 0 /* code for regenerating that table - link staticly! */
     141
     142#include <InnoTekLIBC/locale.h>
    112143#include <stdio.h>
    113144
     
    117148    setlocale(LC_CTYPE, "en_US");
    118149    setlocale(LC_CTYPE, "C");
    119     printf("/*\n"
    120            "    Locale support implementation through OS/2 Unicode API.\n"
    121            "    Copyright (c) 2003 InnoTek Systemberatung GmbH\n"
    122            "\n"
    123            "    For conditions of distribution and use, see the file COPYING.\n"
    124            "\n"
    125            "    Default character type bits for \"C\" locale.\n"
    126            "*/\n"
    127            "\n"
    128            "#define __INTERNAL_DEFS\n"
    129            "#define _DONT_USE_CTYPE_INLINE_\n"
    130            "#include \"libc-alias.h\"\n"
    131            "#include <sys/locale.h>\n"
    132            "#include <ctype.h>\n"
    133            "\n"
    134            "\n"
    135            "struct __locale_ctype __locale_ctype =\n"
    136            "{\n"
    137            "  cflags:\n"
    138            "  {");
    139     for (i = 0; i < /*sizeof(__locale_ctype.cflags) / sizeof(__locale_ctype.cflags[0])*/ 128; i++)
     150    printf("{\n"
     151           "    .auchUpper =\n"
     152           "    {");
     153    for (i = 0; i < sizeof(__libc_GLocaleCtype.auchUpper) / sizeof(__libc_GLocaleCtype.auchUpper[0]); i++)
     154    {
     155        if (i % 16)
     156            printf("0x%02x, ", (int)__libc_GLocaleCtype.auchUpper[i]);
     157        else
     158            printf("\n        0x%02x, ", (int)__libc_GLocaleCtype.auchUpper[i]);
     159    }
     160    printf("\n"
     161           "    },\n"
     162           "    .auchLower =\n"
     163           "    {");
     164    for (i = 0; i < sizeof(__libc_GLocaleCtype.auchLower) / sizeof(__libc_GLocaleCtype.auchLower[0]); i++)
     165    {
     166        if (i % 16)
     167            printf("0x%02x, ", (int)__libc_GLocaleCtype.auchLower[i]);
     168        else
     169            printf("\n        0x%02x, ", (int)__libc_GLocaleCtype.auchLower[i]);
     170    }
     171    printf("\n"
     172           "    },\n"
     173           "    .ausfType = \n"
     174           "    {");
     175    for (i = 0; i < 128; i++)
    140176    {
    141177        if (i % 8)
    142             printf("0x%04x, ", (int)__locale_ctype.cflags[i]);
    143         else
    144             printf("\n    0x%04x, ", (int)__locale_ctype.cflags[i]);
    145     }
    146     printf("\n  },\n"
    147            "  upcase:\n"
    148            "  {");
    149     for (i = 0; i < sizeof(__locale_ctype.upcase) / sizeof(__locale_ctype.upcase[0]); i++)
     178            printf("0x%04x, ", (int)__libc_GLocaleCtype.ausfType[i]);
     179        else
     180            printf("\n        0x%04x, ", (int)__libc_GLocaleCtype.ausfType[i]);
     181    }
     182    printf("\n"
     183           "    },\n"
     184           "    .au2MBCSPrefixs =\n"
     185           "    {");
     186    for (i = 0; i < sizeof(__libc_GLocaleCtype.au2MBCSPrefixs) / sizeof(__libc_GLocaleCtype.au2MBCSPrefixs[0]); i++)
    150187    {
    151188        if (i % 16)
    152             printf("0x%02x, ", (int)__locale_ctype.upcase[i]);
    153         else
    154             printf("\n    0x%02x, ", (int)__locale_ctype.upcase[i]);
    155     }
    156     printf("\n  },\n"
    157            "  locase:\n"
    158            "  {");
    159     for (i = 0; i < sizeof(__locale_ctype.locase) / sizeof(__locale_ctype.locase[0]); i++)
    160     {
    161         if (i % 16)
    162             printf("0x%02x, ", (int)__locale_ctype.locase[i]);
    163         else
    164             printf("\n    0x%02x, ", (int)__locale_ctype.locase[i]);
    165     }
    166     printf("\n  },\n"
    167            "  mbcsprefix:\n"
    168            "  {");
    169     for (i = 0; i < sizeof(__locale_ctype.mbcsprefix) / sizeof(__locale_ctype.mbcsprefix[0]); i++)
    170     {
    171         if (i % 16)
    172             printf("0x%02x, ", (int)__locale_ctype.mbcsprefix[i]);
    173         else
    174             printf("\n    0x%02x, ", (int)__locale_ctype.mbcsprefix[i]);
    175     }
    176     printf("\n  },\n"
    177            "  uconv: 0,\n"
    178            "  locale: 0,\n"
    179            "  mbcs: 0x%x\n"
     189            printf("0x%02x, ", (int)__libc_GLocaleCtype.au2MBCSPrefixs[i]);
     190        else
     191            printf("\n    0x%02x, ", (int)__libc_GLocaleCtype.au2MBCSPrefixs[i]);
     192    }
     193    printf("\n"
     194           "    },\n"
     195           "    .uobj = 0,\n"
     196           "    .lobj = 0,\n"
     197           "    .mbcs = %d\n"
    180198           "};\n",
    181            (int)__locale_ctype.mbcs);
     199           (int)__libc_GLocaleCtype.mbcs);
    182200
    183201    return 0;
  • trunk/src/emx/src/lib/locale/locale_lconv.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale - lconv data.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    426
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Global locale information structure.
    8 */
    9 
    10 #define __INTERNAL_DEFS
    11 #include <sys/locale.h>
     27#include <InnoTekLIBC/locale.h>
    1228#include <limits.h>
    1329
    14 struct lconv __locale_lconv =
     30/* Locale information structure. */
     31__LIBC_LOCALELCONV       __libc_gLocaleLconv =
    1532{
    16   ".", "", "",
    17   "", "", "", "", "", "", "-",
    18   CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX,
    19   CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX
     33    .s =
     34    {
     35        ".",                            //*decimal_point;         /** non-monetary decimal point */
     36        "",                             //*thousands_sep;         /** non-monetary thousands separator */
     37        "",                             //*grouping;              /** non-monetary size of grouping */
     38        "",                             //*int_curr_symbol;       /** international currency symbol and separator */
     39        "",                             //*currency_symbol;       /** local currency symbol */
     40        "",                             //*mon_decimal_point;     /** monetary decimal point */
     41        "",                             //*mon_thousands_sep;     /** monetary thousands separator */
     42        "",                             //*mon_grouping;          /** monetary size of grouping */
     43        "",                             //*positive_sign;         /** non-negative values sign */
     44        "-",                            //*negative_sign;         /** negative values sign */
     45        CHAR_MAX,                       //int_frac_digits;        /** number of fractional digits - int currency */
     46        CHAR_MAX,                       //frac_digits;            /** number of fractional digits - local currency */
     47        CHAR_MAX,                       //p_cs_precedes;          /** (non-neg curr sym) 1-precedes, 0-succeeds */
     48        CHAR_MAX,                       //p_sep_by_space;         /** (non-neg curr sym) 1-space, 0-no space */
     49        CHAR_MAX,                       //n_cs_precedes;          /** (neg curr sym) 1-precedes, 0-succeeds */
     50        CHAR_MAX,                       //n_sep_by_space;         /** (neg curr sym) 1-space, 0-no space */
     51        CHAR_MAX,                       //p_sign_posn;            /** positioning of non-negative monetary sign */
     52        CHAR_MAX                        //n_sign_posn;            /** positioning of negative monetary sign */
     53    },
     54
     55    .fNumericConsts = 1,
     56    .fMonetaryConsts = 1
    2057};
     58
  • trunk/src/emx/src/lib/locale/locale_time.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale - time data.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    426
    5     For conditions of distribution and use, see the file COPYING.
     27#include <InnoTekLIBC/locale.h>
    628
    7     Locale-dependent time formatting strings.
    8 */
    9 
    10 #define __INTERNAL_DEFS
    11 #include <sys/locale.h>
    12 
    13 struct __locale_time __locale_time =
     29/** Date / time formatting rules. */
     30__LIBC_LOCALETIME        __libc_gLocaleTime =
    1431{
    15   smonths: { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"},
    16   lmonths: { "January","February","March","April","May","June","July","August","September","October","November","December" },
    17   swdays:  { "Sun","Mon","Tue","Wed","Thu","Fri","Sat" },
    18   lwdays:  { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" },
    19   date_time_fmt: "%a %b %d %H:%M:%S %Y",
    20   date_fmt: "%m/%d/%y",
    21   time_fmt: "%H:%M:%S",
    22   am:       "AM",
    23   pm:       "PM"
     32  .smonths = { "Jan",    "Feb",     "Mar",  "Apr",  "May","Jun", "Jul", "Aug",   "Sep",      "Oct",    "Nov",     "Dec"},
     33  .lmonths = { "January","February","March","April","May","June","July","August","September","October","November","December" },
     34  .swdays =  { "Sun",   "Mon",   "Tue",    "Wed",      "Thu",     "Fri",   "Sat" },
     35  .lwdays =  { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" },
     36  .date_time_fmt = "%a %b %d %H:%M:%S %Y",
     37  .date_fmt = "%m/%d/%y",
     38  .time_fmt = "%H:%M:%S",
     39  .am =       "AM",
     40  .pm =       "PM",
     41  .fConsts = 1
    2442};
    2543
  • trunk/src/emx/src/lib/locale/localeconv.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
    4 
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Return the address of the (static) locale information structure.
    8 */
     1/* $Id$ */
     2/** @file
     3 *
     4 * localeconv().
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    926
    1027#define __INTERNAL_DEFS
    1128#include "libc-alias.h"
    1229#include <locale.h>
    13 #include <sys/locale.h>
     30#include <InnoTekLIBC/locale.h>
    1431
    15 struct lconv *_STD(localeconv) (void)
     32/**
     33 * Return the address of the (static) locale information structure.
     34 */
     35struct lconv *_STD(localeconv)(void)
    1636{
    17   return &__locale_lconv;
     37    return &__libc_gLocaleLconv.s;
    1838}
     39
  • trunk/src/emx/src/lib/locale/setlocale.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    1 /*
    2     Locale support implementation through OS/2 Unicode API.
    3     Copyright (c) 2003 InnoTek Systemberatung GmbH
    4 
    5     For conditions of distribution and use, see the file COPYING.
    6 
    7     Implementation of the setlocale() function.
    8 */
    9 
    10 #define __INTERNAL_DEFS
     1/* $Id$ */
     2/** @file
     3 *
     4 * Locale support implementation through OS/2 Unicode API.
     5 *
     6 * Implementation of the setlocale() function.
     7 *
     8 *
     9 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     10 * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
     11 *
     12 *
     13 * This file is part of InnoTek LIBC.
     14 *
     15 * InnoTek LIBC is free software; you can redistribute it and/or modify
     16 * it under the terms of the GNU General Public License as published by
     17 * the Free Software Foundation; either version 2 of the License, or
     18 * (at your option) any later version.
     19 *
     20 * InnoTek LIBC is distributed in the hope that it will be useful,
     21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     23 * GNU General Public License for more details.
     24 *
     25 * You should have received a copy of the GNU General Public License
     26 * along with InnoTek LIBC; if not, write to the Free Software
     27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     28 *
     29 */
     30
     31
     32/*******************************************************************************
     33*   Header Files                                                               *
     34*******************************************************************************/
    1135#include "libc-alias.h"
    12 #include <locale.h>
    13 #include <sys/locale.h>
     36#include <InnoTekLIBC/locale.h>         /* must be included before ctype. */
     37#include <ctype.h>
     38
    1439#include <stdlib.h>
     40
    1541#include <alloca.h>
    1642#include <string.h>
    1743#include <errno.h>
    18 #include <ctype.h>
    1944#include <386/builtin.h>
    2045#include <sys/param.h>
    2146#include <sys/smutex.h>
     47#include <InnoTekLIBC/errno.h>
     48#include <InnoTekLIBC/fork.h>
    2249
    2350#define INCL_DOS
     
    2754#include <uconv.h>
    2855
    29 /* Instead of strcmp since it's faster */
    30 #define IS_C_LOCALE(s) (((s) [0] == 'C') && (!(s) [1]))
    31 
    32 /* The order of locale categories must equal those in <locale.h> */
    33 static char *locale_cat =
    34   "LC_COLLATE\0LC_CTYPE\0LC_MONETARY\0LC_NUMERIC\0LC_TIME\0LC_MESSAGES\0";
    35 
    36 extern void __convert_codepage (const char *cp, UniChar *ucp);
    37 
    38 /* Structure used while sorting codepage characters by their weights. */
     56#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_LOCALE
     57#include <InnoTekLIBC/logstrict.h>
     58
     59
     60/*******************************************************************************
     61*   Defined Constants And Macros                                               *
     62*******************************************************************************/
     63/** Instead of strcmp since it's faster. */
     64#define IS_C_LOCALE(s)      (((s)[0] == 'C') && (!(s)[1]))
     65/** For simplisity. */
     66#define IS_POSIX_LOCALE(s)  (   (s)[0] == 'P' \
     67                             && (s)[1] == 'O' \
     68                             && (s)[2] == 'S' \
     69                             && (s)[3] == 'I' \
     70                             && (s)[4] == 'X' \
     71                             && (s)[5] == '\0' )
     72/** Max lenght we anticipate of a codepage name. */
     73#define CODEPAGE_MAX_LENGTH     64
     74
     75/*******************************************************************************
     76*   Structures and Typedefs                                                    *
     77*******************************************************************************/
     78/** Structure used while sorting codepage characters by their weights. */
    3979struct __collate_weight
    4080{
    41   /* Character code. */
    42   unsigned char code;
    43   /* Actual weight length. */
    44   unsigned char len;
    45   /* The weight itself. */
    46   UniChar weight [7];
     81    /* Character code. */
     82    unsigned char code;
     83    /* Actual weight length. */
     84    unsigned char len;
     85    /* The weight itself. */
     86    UniChar       ucsWeight[7];
    4787};
    4888
    49 static int convert_ucs (UconvObject uconv_obj, UniChar *in, char **out)
    50 {
    51   size_t usl = UniStrlen (in) + 1;
    52   /* Allocate twice as much as we need - just in case every character is DBCS
    53      or desired encoding is UCS-2. */
    54   size_t osl = usl * 2;
    55   size_t in_left = usl;
    56   size_t nonid, out_left = osl;
    57   char *tmp = malloc (osl);
    58   UniChar *inbuf = in;
    59   void *outbuf = tmp;
    60   int try_count = 0;
    61   FS_VAR();
    62 
    63   FS_SAVE_LOAD();
    64 try_again:
    65 
    66   if (try_count > 10)
    67     {
    68       /* Well... nobody will say we gave it no chance ... */
    69       free(tmp);
    70       FS_RESTORE();
    71       return -1;
    72     }
    73 
    74   switch (UniUconvFromUcs (uconv_obj, &inbuf, &in_left, &outbuf, &out_left, &nonid))
    75   {
    76     case 0:
    77       break;
    78 
    79     case UCONV_E2BIG:
    80       /* Out buffer too small, make one larger */
    81       inbuf = in; in_left = usl;
    82       out_left = (osl *= 2);
    83       outbuf = tmp = realloc (tmp, osl);
    84       try_count++;
    85       goto try_again;
    86 
    87     default:
    88       /* Unexpected error. */
    89       free (tmp);
    90       FS_RESTORE();
    91       return -1;
    92   }
    93 
    94   usl = (char *)outbuf - (char *)tmp;
    95   (*out) = (char *)malloc (usl);
    96   memcpy (*out, tmp, usl);
    97   free (tmp);
    98   FS_RESTORE();
    99 
    100   return 0;
    101 }
    102 
    103 static void setname (int category, const char *value, int noalloc)
    104 {
    105   /* LC_ALL is -1. */
    106   category++;
    107   if (__locale.name [category] && (__locale.name [category] != __locale_C))
    108     free (__locale.name [category]);
    109   __locale.name [category] = noalloc ? (char *)value : strdup (value);
    110 }
    111 
    112 static int query_array (LocaleObject locale_obj, UconvObject uconv_obj,
    113   int count, LocaleItem first, char **out)
    114 {
    115   UniChar *item;
    116   int idx;
    117 
    118   for (idx = 0; idx < count; idx++)
    119     if (UniQueryLocaleItem (locale_obj, first + idx, &item)
    120      || convert_ucs (uconv_obj, item, &out [idx]))
    121       return -1;
    122 
    123   return 0;
    124 }
    125 
    126 #define FREE(x) { if (x) free (x); }
    127 
    128 static void free_time (struct __locale_time *loc_time)
    129 {
    130   int i;
    131 
    132   for (i = 0; i < 12; i++)
    133   {
    134     FREE (__locale_time.smonths [i]);
    135     FREE (__locale_time.lmonths [i]);
    136   }
    137 
    138   for (i = 0; i < 7; i++)
    139   {
    140     FREE (__locale_time.swdays [i]);
    141     FREE (__locale_time.lwdays [i]);
    142   }
    143 
    144   FREE (__locale_time.date_time_fmt);
    145   FREE (__locale_time.date_fmt);
    146   FREE (__locale_time.time_fmt);
    147   FREE (__locale_time.am);
    148   FREE (__locale_time.pm);
    149 }
    150 
    151 static void free_numeric (struct lconv *lconv)
    152 {
    153   FREE (lconv->decimal_point);
    154   FREE (lconv->thousands_sep);
    155   FREE (lconv->grouping);
    156 }
    157 
    158 static void free_monetary (struct lconv *lconv)
    159 {
    160   FREE (lconv->int_curr_symbol);
    161   FREE (lconv->currency_symbol);
    162   FREE (lconv->mon_decimal_point);
    163   FREE (lconv->mon_thousands_sep);
    164   FREE (lconv->mon_grouping);
    165   FREE (lconv->positive_sign);
    166   FREE (lconv->negative_sign);
    167 }
    168 
    169 static unsigned char Transform (LocaleObject locale_obj, UconvObject uconv_obj,
    170   UniChar (*TransFunc) (LocaleObject, UniChar), UniChar c, unsigned char fallback)
    171 {
    172   unsigned char sbcs;
    173   int nb = __from_ucs (uconv_obj, TransFunc (locale_obj, c), &sbcs, 1);
    174   return (nb == 1) ? sbcs : fallback;
    175 }
    176 
    177 static int cw_cmp (struct __collate_weight *w1, struct __collate_weight *w2)
    178 {
    179   return UniStrncmp (w1->weight, w2->weight, MIN (w1->len, w2->len));
    180 }
    181 
    182 static void Ucs2Sb (UniChar *ucs, char *sbs, size_t sl)
    183 {
    184   while (sl--)
    185     *sbs++ = *ucs++;
    186 }
    187 
    188 static int query_mbcs (UconvObject uconv_obj, char *mbcs,
    189   unsigned char *mbcsprefix, int *mb_cur_max)
    190 {
    191   unsigned i;
    192   uconv_attribute_t uconv_attr;
    193   unsigned char seqlen [256];
    194 
    195   if (UniQueryUconvObject (uconv_obj, &uconv_attr, sizeof (uconv_attr),
    196       seqlen, NULL, NULL))
    197     return -1;
    198 
    199   if (mb_cur_max)
    200     *mb_cur_max = uconv_attr.mb_max_len;
    201   *mbcs = (uconv_attr.mb_max_len > 1);
    202 
    203   memset (mbcsprefix, 0, 256/4);
    204   for (i = 0; i < 256; i++)
    205     if (seqlen [i] != 255)
    206       SET_MBCS_PREFIX (mbcsprefix, i, seqlen [i]);
    207 
    208   return 0;
    209 }
    210 
    211 #define ERROR(code) { errno = code; ret = NULL; goto normal_exit; }
    212 #define ERROR2(code) { _smutex_release (&__locale.lock); ERROR (code); }
    213 
    214 char *_STD(setlocale) (int category, const char *locale)
    215 {
    216   LocaleObject locale_obj = 0;
    217   UconvObject uconv_obj = 0;
    218   UniChar cpbuff [16];
    219   struct UniLconv *Lconv;
    220   char *x, *l, *m;
    221   size_t sl;
    222   char *ret = NULL;
    223   int i,def_val;
    224 
    225   /* Sanity check. */
    226   if (category >= __LC_COUNT)
    227   {
    228     errno = EINVAL;
    229     return NULL;
    230   }
    231 
    232   /* Check if user just queries current locale. */
    233   if (!locale)
    234     return __locale.name [category + 1];
    235 
    236   /* Check if user wants we to do the same job twice. */
    237   if (strcmp (locale, __locale.name [category + 1]) == 0)
    238     /* We have to return the value of LC_ALL */
    239     return __locale.name [0];
    240 
    241   /* We'll use OS/2 Unicode API to query all interesting information.
    242      But it works only with Unicode strings, so we have to convert all
    243      input information to UCS-2 and all output information from UCS-2. */
    244 
    245   /* Copy locale to a local storage since we'll modify it during parsing.
    246      If locale value is a empty string, user wants the defaults fetched from
    247      environment. */
    248   def_val = (locale [0] == 0);
    249   if (def_val)
    250   {
    251     char *env_val, *cur_cat = locale_cat;
    252     int cat;
    253 
    254     if (category == LC_ALL)
    255       /* Not in list */
    256       cur_cat = "LC_ALL";
     89
     90/**
     91 * There is one global object of this type that contains integral
     92 * information about last selected (with setlocale()) locale.
     93 * The locale information itself is split into parts to avoid linking
     94 * unused data into programs that use just the "C" locale and just
     95 * a few functions that use locale data (such as strdate()).
     96 */
     97typedef struct __libc_LocaleGlobal
     98{
     99  /** Category names. */
     100  char         *apszNames[_LC_LAST + 1];
     101  /* Lock for multi-threaded operations. */
     102  _smutex       lock;
     103} __LIBC_LOCALEGLOBAL, *__LIBC_PLOCALEGLOBAL;
     104
     105
     106/**
     107 * Internal working structure which we modify while
     108 * performing the setlocale() operation.
     109 */
     110struct temp_locale
     111{
     112    /** Which we have processed.*/
     113    int                         afProcessed[_LC_LAST + 1];
     114    /** The global data. */
     115    __LIBC_LOCALEGLOBAL         Global;
     116    /** Collate data. */
     117    __LIBC_LOCALECOLLATE        Collate;
     118    /** Ctype data. */
     119    __LIBC_LOCALECTYPE          Ctype;
     120    /** Time data. */
     121    __LIBC_LOCALETIME           Time;
     122    /** Numeric and monetary data. */
     123    __LIBC_LOCALELCONV          Lconv;
     124};
     125
     126
     127/*******************************************************************************
     128*   Global Variables                                                           *
     129*******************************************************************************/
     130/** Array of local categories. Use their defined value + 1 as index (LC_ALL is -1). */
     131static const char       gaszCategories[_LC_LAST + 1][16] =
     132{
     133    "LC_ALL",                           /* -1 */
     134    "LC_COLLATE",                       /* 0 */
     135    "LC_CTYPE",
     136    "LC_MONETARY",
     137    "LC_NUMERIC",
     138    "LC_TIME",
     139    "LC_MESSAGES"
     140};
     141/** Array of the lengths corresponding to the entries in the above array. */
     142static const unsigned char gacchCategories[_LC_LAST + 1] =
     143{
     144    sizeof("LC_ALL") - 1,
     145    sizeof("LC_COLLATE") - 1,
     146    sizeof("LC_CTYPE") - 1,
     147    sizeof("LC_MONETARY") - 1,
     148    sizeof("LC_NUMERIC") - 1,
     149    sizeof("LC_TIME") - 1,
     150    sizeof("LC_MESSAGES") - 1
     151};
     152
     153/** "C" string. */
     154static const char       gszC[] = "C";
     155
     156/** "POSIX" string. */
     157static const char       gszPOSIX[] = "POSIX";
     158
     159/** The currnet locale specifications. */
     160static __LIBC_LOCALEGLOBAL gLocale =
     161{
     162    .apszNames =
     163    {
     164        (char *)gszC,    /* LC_ALL      */
     165        (char *)gszC,    /* LC_COLLATE  */
     166        (char *)gszC,    /* LC_CTYPE    */
     167        (char *)gszC,    /* LC_NUMERIC  */
     168        (char *)gszC,    /* LC_MONETARY */
     169        (char *)gszC,    /* LC_TIME     */
     170        (char *)gszC     /* LC_MESSAGES */
     171    },
     172    .lock = 0
     173};
     174
     175/** "ISO8859-1" UniChar string. */
     176static const UniChar    gucsISO8859_1[] = {'I', 'S', 'O', '8', '8', '5', '9', '-', '1', '\0' };
     177
     178/** @page pg_env
     179 * @subsection pg_env_sub1_LIBC_SETLOCALE_OLDSTYLE      LIBC_SETLOCALE_OLDSTYLE
     180 *
     181 * When the LIBC_SETLOCALE_OLDSTYLE environment variable is present in the
     182 * environemnt LIBC will ask OS/2 about the country and codepage so the right
     183 * default locale can be found when none of the POSIX variables are present.
     184 *
     185 * The default behaviour (i.e. when LIBC_SETLOCALE_OLDSTYLE is not present) is
     186 * to use the 'C' locale if none of the LANG or LC_* variables can be found.
     187 */
     188
     189/** Whether or not to use the old style where we query extra stuff from OS/2.
     190 * The new style is more conforming to POSIX and with VAC.
     191 * The presense of LIBC_SETLOCALE_OLDSTYLE forces the old style.
     192 *
     193 * If the value is negative Then init is required.
     194 */
     195static int  gfOldStyle = -1;
     196
     197
     198/*******************************************************************************
     199*   Internal Functions                                                         *
     200*******************************************************************************/
     201static int unierr2errno(int rc);
     202static int convert_ucs(UconvObject uobj, UniChar *in, char **out);
     203static void Ucs2Sb(UniChar *ucs, char *sbs, size_t cch);
     204static const char *getDefaultLocale(const char *pszCategory, char *pszBuffer, int *pfDefault);
     205static int getCodepage(const char *pszCodepage, const char *pszLocale, LocaleObject lobj, UniChar *pucsCodepage, unsigned cucCodepage);
     206static int query_mbcs(UconvObject uobj, char *mbcs, unsigned char *au2MBCSPrefixs, int *pmb_cur_max);
     207
     208static int localeCollateDo(__LIBC_PLOCALECOLLATE pCollate, UconvObject uobj, LocaleObject lobj);
     209static void localeCollateFree(__LIBC_PLOCALECOLLATE pCollate);
     210static inline unsigned char Transform(LocaleObject lobj, UconvObject uobj,
     211                                      UniChar (*pfnTransFunc) (LocaleObject, UniChar),
     212                                      UniChar uc, unsigned char uchFallback);
     213static int localeCtypeDo(__LIBC_PLOCALECTYPE pCtype, UconvObject uobj, LocaleObject lobj, const char *pszLocale);
     214static void localeCtypeFree(__LIBC_PLOCALECTYPE pCtype);
     215static int query_item(LocaleObject lobj, UconvObject uobj, LocaleItem iItem, char **ppszOut);
     216static int query_array(LocaleObject lobj, UconvObject uobj, int cElements, LocaleItem iFirst, char **papszOut);
     217static int localeTimeDo(__LIBC_PLOCALETIME pTime, UconvObject uobj, LocaleObject lobj);
     218static void localeTimeFree(__LIBC_PLOCALETIME pTime);
     219static void localeNumericFree(__LIBC_PLOCALELCONV pLconv);
     220static void localeMonetaryFree(__LIBC_PLOCALELCONV pLconv);
     221static int localeNumericDo(__LIBC_PLOCALELCONV pLconv, UconvObject uobj, struct UniLconv *pULconv);
     222static int localeMonetaryDo(__LIBC_PLOCALELCONV pLconv, UconvObject uobj, struct UniLconv *pULconv);
     223static void localeGlobalFree(__LIBC_PLOCALEGLOBAL pGlobal, int iCategory);
     224static int localeCreateObjects(const char *pszLocale, const char *pszCodepage, char *pszCodepageActual, LocaleObject *plobj, UconvObject *puobj);
     225static int localeParseLocale(char *pszLocale, const char **ppszCodepage);
     226static int localeDoOne(struct temp_locale *pTemp, int iCategory, const char *pszLocale, const char *pszCodepage);
     227static int localeDo(struct temp_locale *pTemp, int iCategory, char *pszLocale, int fDefaultValue);
     228static char *localeCommit(struct temp_locale *pTemp, int iCategory);
     229static void localeFree(struct temp_locale *pTemp);
     230
     231static int setlocalForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     232
     233
     234
     235
     236
     237
     238/**
     239 * Converts from Uni api error code to errno.
     240 *
     241 * @returns errno
     242 * @param   rc      Uni api error code.
     243 */
     244static int unierr2errno(int rc)
     245{
     246    switch (rc)
     247    {
     248        case ULS_SUCCESS:           return 0;
     249        case ULS_MAXFILESPERPROC:   return -EMFILE;
     250        case ULS_MAXFILES:          return -ENFILE;
     251        case ULS_BADOBJECT:         return -EBADF;
     252        case ULS_BADHANDLE:         return -EBADF;
     253        case ULS_NOTIMPLEMENTED:    return -ENOSYS;
     254        case ULS_RANGE:             return -ERANGE;
     255        case ULS_NOMEMORY:          return -ENOMEM;
     256        case ULS_OTHER:
     257        case ULS_ILLEGALSEQUENCE:
     258        case ULS_NOOP:
     259        case ULS_TOOMANYKBD:
     260        case ULS_KBDNOTFOUND:
     261        case ULS_NODEAD:
     262        case ULS_NOSCAN:
     263        case ULS_INVALIDSCAN:
     264        case ULS_INVALID:
     265        case ULS_NOTOKEN:
     266        case ULS_NOMATCH:
     267        case ULS_BUFFERFULL:
     268        case ULS_UNSUPPORTED:
     269        case ULS_BADATTR:
     270        case ULS_VERSION:
     271        default:
     272            return -EINVAL;
     273    }
     274}
     275
     276static int convert_ucs(UconvObject uobj, UniChar *in, char **out)
     277{
     278    size_t usl = UniStrlen (in) + 1;
     279    /* Allocate twice as much as we need - just in case every character is DBCS
     280       or desired encoding is UCS-2. */
     281    size_t osl = usl * 2;
     282    size_t in_left = usl;
     283    size_t nonid, out_left = osl;
     284    char *tmp = malloc (osl);
     285    UniChar *inbuf = in;
     286    void *outbuf = tmp;
     287    int try_count = 0;
     288    FS_VAR();
     289
     290    FS_SAVE_LOAD();
     291    try_again:
     292
     293    if (try_count > 10)
     294    {
     295        /* Well... nobody will say we gave it no chance ... */
     296        free(tmp);
     297        FS_RESTORE();
     298        return -1;
     299    }
     300
     301    switch (UniUconvFromUcs (uobj, &inbuf, &in_left, &outbuf, &out_left, &nonid))
     302    {
     303        case 0:
     304            break;
     305
     306        case UCONV_E2BIG:
     307            /* Out buffer too small, make one larger */
     308            inbuf = in; in_left = usl;
     309            out_left = (osl *= 2);
     310            outbuf = tmp = realloc (tmp, osl);
     311            try_count++;
     312            goto try_again;
     313
     314        default:
     315            /* Unexpected error. */
     316            free (tmp);
     317            FS_RESTORE();
     318            return -1;
     319    }
     320
     321    usl = (char *)outbuf - (char *)tmp;
     322    (*out) = (char *)malloc (usl);
     323    memcpy (*out, tmp, usl);
     324    free (tmp);
     325    FS_RESTORE();
     326
     327    return 0;
     328}
     329
     330static void Ucs2Sb(UniChar *ucs, char *sbs, size_t cch)
     331{
     332    while (cch--)
     333        *sbs++ = *ucs++;
     334}
     335
     336
     337static int query_mbcs(UconvObject uobj, char *mbcs, unsigned char *au2MBCSPrefixs, int *pmb_cur_max)
     338{
     339    unsigned            i;
     340    uconv_attribute_t   uconv_attr;
     341    unsigned char       uchSeqlen[256];
     342    int                 rc;
     343
     344    /*
     345     * Query data.
     346     */
     347    rc = UniQueryUconvObject(uobj, &uconv_attr, sizeof(uconv_attr), (char *)&uchSeqlen[0], NULL, NULL);
     348    if (rc)
     349        return -unierr2errno(rc);
     350
     351    /*
     352     * Create the return values.
     353     */
     354    if (pmb_cur_max)
     355        *pmb_cur_max = uconv_attr.mb_max_len;
     356    *mbcs = (uconv_attr.mb_max_len > 1);
     357
     358    memset(au2MBCSPrefixs, 0, 256/4);
     359    for (i = 0; i < 256; i++)
     360        if (uchSeqlen[i] != 255)
     361            SET_MBCS_PREFIX(au2MBCSPrefixs, i, uchSeqlen[i]);
     362
     363    return 0;
     364}
     365
     366/**
     367 * Sets the LC_COLLATE part of the locale.
     368 *
     369 * @returns 0 on success.
     370 * @returns negated errno on failure.
     371 * @param   pCollate        The collate structure to operate on.
     372 * @param   uobj            The UconvObject to use. Collate is responsible for freeing it.
     373 * @param   lobj            The LocaleObject to use. Collate is responsible for freeing it.
     374 */
     375static int localeCollateDo(__LIBC_PLOCALECOLLATE pCollate, UconvObject uobj, LocaleObject lobj)
     376{
     377    int rc;
     378
     379    /* Cleanup in case of some special LC_ALL call. */
     380    localeCollateFree(pCollate);
     381
     382    /*
     383     * Query multi-byte related stuff.
     384     */
     385    rc = query_mbcs(uobj, &pCollate->mbcs, &pCollate->au2MBCSPrefixs[0], NULL);
     386    if (rc)
     387        return rc;
     388
     389    if (&pCollate->mbcs)
     390    {
     391        /*
     392         * In MBCS mode we just borrow the conversion and locale objects
     393         * and leave the real work to the Unicode subsystem.
     394         */
     395        pCollate->lobj          = lobj;
     396        pCollate->uobj          = uobj;
     397    }
    257398    else
    258       for (cat = 0; cat != category; cat++)
    259         cur_cat = strchr (cur_cat, 0) + 1;
    260 
    261     env_val = getenv (cur_cat);
    262     if (env_val)
    263       locale = env_val;
     399    {
     400        /*
     401         * In SBCS we query the weight of every character and use the
     402         * weights directly, without the need to invoke the Unicode API.
     403         */
     404        struct __collate_weight     aCW[256];
     405        int                         i, j;
     406
     407        /* Initialize character weights. */
     408        for (i = 0; i < 256; i++)
     409        {
     410            UniChar ucs[2];
     411            if (!__libc_ucs2To(uobj, (unsigned char *)&i, 1, &ucs[0]))
     412            {
     413                LIBC_ASSERTM_FAILED("__libc_ucs2To failed for char %d\n", i);
     414                ucs[0] = (UniChar)i;
     415            }
     416            ucs[1] = '\0';
     417
     418            aCW[i].code = i;
     419            aCW[i].len  = UniStrxfrm(lobj, aCW[i].ucsWeight, &ucs[0], sizeof(aCW[i].ucsWeight) / sizeof(aCW[i].ucsWeight[0]));
     420            if (aCW[i].len >= sizeof(aCW[i].ucsWeight) / sizeof(aCW[i].ucsWeight[0]))
     421            {
     422                LIBC_ASSERTM_FAILED("This cannot happen... :-) i=%d len=%d \n", i, aCW[i].len);
     423                aCW[i].len = sizeof(aCW[i].ucsWeight) / sizeof(aCW[i].ucsWeight[0]);
     424            }
     425        }
     426
     427        /*
     428         * Do bubble sorting since qsort() doesn't guarantee that the order
     429         * of equal elements stays the same.
     430         */
     431        for (i = 0; i < 256; i++)
     432            for (j = i; j < 256; j++)
     433                if (UniStrncmp(aCW[j].ucsWeight, aCW[j + 1].ucsWeight, MIN(aCW[j].len, aCW[j + 1].len)) > 0)
     434                    _memswap(&aCW[j], &aCW[j + 1], sizeof(aCW[j]));
     435
     436        /*
     437         * Store the result.
     438         */
     439        for (i = 0; i < 256; i++)
     440            pCollate->auchWeight[aCW[i].code] = i;
     441
     442        /* cleanup */
     443        UniFreeUconvObject(uobj);
     444        UniFreeLocaleObject(lobj);
     445    }
     446
     447    return 0;
     448}
     449
     450/**
     451 * Frees system and CRT resources assocated with a collate structure.
     452 * @param   pCollate    The collate structure.
     453 */
     454static void localeCollateFree(__LIBC_PLOCALECOLLATE pCollate)
     455{
     456    /* Free old pszLocale objects, if any */
     457    if (pCollate->uobj)
     458    {
     459        UniFreeUconvObject(pCollate->uobj);
     460        pCollate->uobj = NULL;
     461    }
     462    if (pCollate->lobj)
     463    {
     464        UniFreeLocaleObject(pCollate->lobj);
     465        pCollate->lobj = NULL;
     466    }
     467}
     468
     469
     470static inline unsigned char Transform(LocaleObject lobj, UconvObject uobj,
     471                                      UniChar (* APIENTRY pfnTransFunc) (LocaleObject, UniChar),
     472                                      UniChar uc, unsigned char uchFallback)
     473{
     474    unsigned char   sbcs;
     475    int nb = __libc_ucs2From(uobj, pfnTransFunc(lobj, uc), &sbcs, 1);
     476    return (nb == 1) ? sbcs : uchFallback;
     477}
     478
     479
     480/**
     481 * Sets the LC_TYPE part of the locale.
     482 *
     483 * @returns 0 on success.
     484 * @returns negated errno on failure.
     485 * @param   pCtype          The Ctype structure to operate on.
     486 * @param   uobj            The UconvObject to use. Ctype is responsible for freeing it.
     487 * @param   lobj            The LocaleObject to use. Ctype is responsible for freeing it.
     488 */
     489static int localeCtypeDo(__LIBC_PLOCALECTYPE pCtype, UconvObject uobj, LocaleObject lobj, const char *pszLocale)
     490{
     491    int         rc;
     492    unsigned    i;
     493
     494    /* Cleanup in case of some special LC_ALL call. */
     495    localeCtypeFree(pCtype);
     496
     497    /*
     498     * Query multi-byte related stuff.
     499     */
     500    rc = query_mbcs(uobj, &pCtype->mbcs, &pCtype->au2MBCSPrefixs[0], NULL);
     501    if (rc)
     502        return rc;
     503
     504    /*
     505     * For speeding up isXXX() and lower/upper case mapping functions
     506     * we'll cache the type of every character into a variable.
     507     *
     508     * Do every character separately to avoid errors that could result
     509     * when some character in the middle cannot be conerted from or to
     510     * Unicode - this would lead in a shift of the entire string.
     511     */
     512    for (i = 0; i < 256; i++)
     513    {
     514        unsigned short  usfType = 0;
     515        unsigned char   uchUpper;
     516        unsigned char   uchLower;
     517        UniChar         ucs;
     518
     519        if (!__libc_ucs2To(uobj, (unsigned char *)&i, 1, &ucs))
     520            ucs = i;
     521
     522        /* isxxx() do not support DBCS characters at all */
     523        if (!IS_MBCS_PREFIX(pCtype, i))
     524        {
     525            /* ASSUMES CT_* == __* ! */
     526            UNICTYPE *pCtype = UniQueryCharType(ucs);
     527            if (pCtype)
     528                usfType = (pCtype->itype) & (__UPPER  | __LOWER  | __DIGIT | __SPACE |
     529                                             __PUNCT  | __CNTRL  | __BLANK | __XDIGIT |
     530                                             __ALPHA  | __ALNUM  | __GRAPH | __PRINT |
     531                                             __NUMBER | __SYMBOL | __ASCII);
     532            uchUpper = Transform(lobj, uobj, UniTransUpper, ucs, i);
     533            uchLower = Transform(lobj, uobj, UniTransLower, ucs, i);
     534            /** @todo isn't there apis for getting all this at once? */
     535        }
     536        else
     537            uchUpper = uchLower = i;
     538
     539        pCtype->ausfType[i]  = usfType;
     540        pCtype->auchUpper[i] = uchUpper;
     541        pCtype->auchLower[i] = uchLower;
     542    }
     543
     544    /*
     545     * In the "C" pszLocale second half of the cflags table should be empty.
     546     */
     547    if (    IS_C_LOCALE(pszLocale)
     548        ||  IS_POSIX_LOCALE(pszLocale))
     549    {
     550        memset(&pCtype->ausfType[128], 0, 128 * sizeof(pCtype->ausfType[0]));
     551        for (i = 128; i < 255; i++)
     552        {
     553            pCtype->auchUpper[i] = i;
     554            pCtype->auchLower[i] = i;
     555        }
     556    }
     557
     558    /*
     559     * Store the objects.
     560     */
     561    pCtype->uobj          = uobj;
     562    if (pCtype->mbcs)
     563    {
     564        /*
     565         * In MBCS mode we just borrow the local object and leave the
     566         * real work to the Unicode subsystem.
     567         */
     568        pCtype->lobj      = lobj;
     569    }
    264570    else
    265     {
    266       env_val = getenv ("LANG");
    267       if (env_val)
    268         locale = env_val;
    269       else
    270       {
    271         /* Not specified nor in environment, ask country info */
    272         COUNTRYCODE cc;
    273         COUNTRYINFO ci;
    274         ULONG il;
    275         memset (&cc, 0, sizeof (cc));
    276         memset (&ci, 0, sizeof (ci));
    277         if (DosQueryCtryInfo (sizeof (ci), &cc, &ci, &il))
     571        UniFreeLocaleObject(lobj);
     572
     573    return 0;
     574}
     575
     576
     577/**
     578 * Frees system and CRT resources assocated with a ctype structure.
     579 * @param   pCtype    The collate structure.
     580 */
     581static void localeCtypeFree(__LIBC_PLOCALECTYPE pCtype)
     582{
     583    if (pCtype->uobj)
     584    {
     585        UniFreeUconvObject(pCtype->uobj);
     586        pCtype->uobj = NULL;
     587    }
     588    if (pCtype->lobj)
     589    {
     590        UniFreeLocaleObject(pCtype->lobj);
     591        pCtype->lobj = NULL;
     592    }
     593}
     594
     595/**
     596 * Query one item from a locale object.
     597 */
     598static int query_item(LocaleObject lobj, UconvObject uobj, LocaleItem iItem, char **ppszOut)
     599{
     600    /*
     601     * Query item.
     602     */
     603    UniChar    *pucsItem;
     604    int rc = UniQueryLocaleItem(lobj, iItem, &pucsItem);
     605    if (rc)
     606    {
     607        LIBC_ASSERTM_FAILED("UniQueryLocaleItem(,%d,) -> rc=%d\n", iItem, rc);
     608        return -unierr2errno(rc);
     609    }
     610
     611    /*
     612     * Convert from Ucs2.
     613     */
     614    rc = convert_ucs(uobj, pucsItem, ppszOut);
     615
     616    UniFreeMem(pucsItem);
     617    return rc;
     618}
     619
     620/**
     621 * Query an array of locale string items.
     622 */
     623static int query_array(LocaleObject lobj, UconvObject uobj, int cElements, LocaleItem iFirst, char **papszOut)
     624{
     625    int     i;
     626    for (i = 0; i < cElements; i++)
     627    {
     628        int rc = query_item(lobj, uobj, iFirst + i, &papszOut[i]);
     629        if (rc)
     630            return rc;
     631    }
     632    return 0;
     633}
     634
     635/**
     636 * Sets the LC_TIME part of the locale.
     637 *
     638 * @returns 0 on success.
     639 * @returns negated errno on failure.
     640 * @param   pTime   The time structure to operate on.
     641 * @param   uobj    The UconvObject to use.
     642 * @param   lobj    The LocaleObject to use.
     643 */
     644static int localeTimeDo(__LIBC_PLOCALETIME pTime, UconvObject uobj, LocaleObject lobj)
     645{
     646    int         rc;
     647
     648    /* free old stuff. */
     649    localeTimeFree(pTime);
     650
     651    /* query the items. */
     652    if (    (rc = query_item( lobj, uobj,     D_T_FMT, &pTime->date_time_fmt))
     653        ||  (rc = query_item( lobj, uobj,     D_FMT,   &pTime->date_fmt))
     654        ||  (rc = query_item( lobj, uobj,     T_FMT,   &pTime->time_fmt))
     655        ||  (rc = query_item( lobj, uobj,     AM_STR,  &pTime->am))
     656        ||  (rc = query_item( lobj, uobj,     PM_STR,  &pTime->pm))
     657        ||  (rc = query_array(lobj, uobj,  7, DAY_1,   &pTime->lwdays[0]))
     658        ||  (rc = query_array(lobj, uobj,  7, ABDAY_1, &pTime->swdays[0]))
     659        ||  (rc = query_array(lobj, uobj, 12, MON_1,   &pTime->lmonths[0]))
     660        ||  (rc = query_array(lobj, uobj, 12, ABMON_1, &pTime->smonths[0]))
     661            )
     662    {
     663        return rc;
     664    }
     665
     666    return 0;
     667}
     668
     669/**
     670 * Frees the CRT resources held up by a time structure.
     671 * @param   pTime   The time structure.
     672 */
     673static void localeTimeFree(__LIBC_PLOCALETIME pTime)
     674{
     675    if (!pTime->fConsts)
     676    {
     677        /*
     678         * Everything is pointers to heap here!
     679         */
     680        char **ppsz = (char **)pTime;
     681        char **ppszEnd = (char **)pTime->fConsts;
     682        while (ppsz < ppszEnd)
    278683        {
    279 ctry_error:
    280           locale = "C";
     684            void *pv = *ppsz;
     685            if (pv)
     686            {
     687                free(pv);
     688                *ppsz = NULL;
     689            }
     690        }
     691    }
     692    pTime->fConsts = 0;
     693}
     694
     695
     696/**
     697 * Frees all heap strings in the monetary part of the lconv structure.
     698 * @param   pLconv  What to work on.
     699 */
     700static void localeNumericFree(__LIBC_PLOCALELCONV pLconv)
     701{
     702#define FREE(x) do { if (pLconv->s.x && !pLconv->fNumericConsts) free(pLconv->s.x); pLconv->s.x = NULL; } while (0)
     703    FREE(decimal_point);
     704    FREE(thousands_sep);
     705    FREE(grouping);
     706                                                                                                                                                                                                                                                                pLconv->fNumericConsts = 0;
     707#undef FREE
     708}
     709
     710/**
     711 * Frees all heap strings in the monetary part of the lconv structure.
     712 * @param   pLconv  What to work on.
     713 */
     714static void localeMonetaryFree(__LIBC_PLOCALELCONV pLconv)
     715{
     716#define FREE(x) do { if (pLconv->s.x && !pLconv->fMonetaryConsts) free(pLconv->s.x); pLconv->s.x = NULL; } while (0)
     717    FREE(int_curr_symbol);
     718    FREE(currency_symbol);
     719    FREE(mon_decimal_point);
     720    FREE(mon_thousands_sep);
     721    FREE(mon_grouping);
     722    FREE(positive_sign);
     723    FREE(negative_sign);
     724    pLconv->fMonetaryConsts = 0;
     725#undef FREE
     726}
     727
     728/**
     729 * Converts a grouping array.
     730 */
     731static int localeConvertGrouping(short *pasGrouping, char **pachRet)
     732{
     733    short  *ps;
     734    char   *pch;
     735    int     cch;
     736
     737    for (cch = 1, ps = pasGrouping; *ps && *ps != -1; ps++)
     738        cch++;
     739    *pachRet = pch = malloc(cch);
     740    if (!pch)
     741        return -ENOMEM;
     742    for (ps = pasGrouping; cch > 0; cch--)
     743        *pch++ = (char)*ps++;
     744
     745    return 0;
     746}
     747
     748/**
     749 * Sets the LC_NUMERIC part of the locale.
     750 *
     751 * @returns 0 on success.
     752 * @returns negated errno on failure.
     753 * @param   pLconv      The lconv structure to operate on.
     754 * @param   uobj        The UconvObject to use.
     755 * @param   pULconv     Pointer to the pULconv structure to get the data from.
     756 */
     757static int localeNumericDo(__LIBC_PLOCALELCONV pLconv, UconvObject uobj, struct UniLconv *pULconv)
     758{
     759    int     rc;
     760    /* free any old stuff. */
     761    localeNumericFree(pLconv);
     762
     763    /*
     764     * Convert the stuff.
     765     */
     766#define CONVERT_UCS(field) \
     767    do  { rc = convert_ucs(uobj, pULconv->field, &pLconv->s.field); if (rc) return rc; } while (0)
     768    CONVERT_UCS(decimal_point);
     769    CONVERT_UCS(thousands_sep);
     770#undef CONVERT_UCS
     771
     772    return localeConvertGrouping(pULconv->grouping, &pLconv->s.grouping);
     773}
     774
     775
     776/**
     777 * Sets the LC_MONETARY part of the locale.
     778 *
     779 * @returns 0 on success.
     780 * @returns negated errno on failure.
     781 * @param   pLconv      The lconv structure to operate on.
     782 * @param   uobj        The UconvObject to use.
     783 * @param   pULconv     Pointer to the pULconv structure to get the data from.
     784 */
     785static int localeMonetaryDo(__LIBC_PLOCALELCONV pLconv, UconvObject uobj, struct UniLconv *pULconv)
     786{
     787    int rc;
     788    /* free any old stuff. */
     789    localeMonetaryFree(pLconv);
     790
     791    /*
     792     * Convert the stuff.
     793     */
     794#define CONVERT_UCS(field) \
     795    do  { rc = convert_ucs(uobj, pULconv->field, &pLconv->s.field); if (rc) return rc; } while (0)
     796    CONVERT_UCS(int_curr_symbol);
     797    CONVERT_UCS(currency_symbol);
     798    CONVERT_UCS(mon_decimal_point);
     799    CONVERT_UCS(mon_thousands_sep);
     800    CONVERT_UCS(positive_sign);
     801    CONVERT_UCS(negative_sign);
     802    pLconv->s.int_frac_digits   = pULconv->int_frac_digits;
     803    pLconv->s.frac_digits       = pULconv->frac_digits;
     804    pLconv->s.p_cs_precedes     = pULconv->p_cs_precedes;
     805    pLconv->s.p_sep_by_space    = pULconv->p_sep_by_space;
     806    pLconv->s.n_cs_precedes     = pULconv->n_cs_precedes;
     807    pLconv->s.n_sep_by_space    = pULconv->n_sep_by_space;
     808    pLconv->s.p_sign_posn       = pULconv->p_sign_posn;
     809    pLconv->s.n_sign_posn       = pULconv->n_sign_posn;
     810#undef CONVERT_UCS
     811    return localeConvertGrouping(pULconv->mon_grouping, &pLconv->s.mon_grouping);
     812}
     813
     814/**
     815 * Free an entry in the global locale data array.
     816 */
     817static void localeGlobalFree(__LIBC_PLOCALEGLOBAL pGlobal, int iCategory)
     818{
     819    if (pGlobal->apszNames[iCategory + 1])
     820    {
     821        if (   pGlobal->apszNames[iCategory + 1] != gszC
     822            && pGlobal->apszNames[iCategory + 1] != gszPOSIX)
     823            free(pGlobal->apszNames[iCategory + 1]);
     824        pGlobal->apszNames[iCategory + 1] = NULL;
     825    }
     826}
     827
     828/**
     829 * Parses out the locale spec and the code page spec.
     830 */
     831static int localeParseLocale(char *pszLocale, const char **ppszCodepage)
     832{
     833    /*
     834     * Strip of modifier.
     835     */
     836    char *psz = strchr(pszLocale, '@');
     837    if (psz)
     838    {
     839        LIBCLOG_MSG2("Ignoring locale modifier '%s'\n", psz);
     840        *psz = '\0';
     841    }
     842
     843    /*
     844     * Codepage.
     845     */
     846    psz = strchr(pszLocale, '.');
     847    if (psz)
     848        *psz++ = '\0';
     849    *ppszCodepage = psz;
     850
     851    return 0;
     852}
     853
     854/**
     855 * Get the default local specification.
     856 * @returns Pointer to default local (can be environment or it could be pszBuffer).
     857 * @param   pszBuffer   Where to store the default local.
     858 */
     859static const char *getDefaultLocale(const char *pszCategory, char *pszBuffer, int *pfDefault)
     860{
     861    /* Copy pszLocale to a local storage since we'll modify it during parsing.
     862       If pszLocale value is a empty string, user wants the defaults fetched from
     863       environment. */
     864    const char *pszRet = getenv("LC_ALL");
     865    if (pszRet && *pszRet)
     866        *pfDefault = 0;                 /* LC_ALL is not default, it's an override of everything else. */
     867    else
     868    {
     869        *pfDefault = 1;
     870        pszRet = getenv(pszCategory);
     871        if (!pszRet)
     872        {
     873            pszRet = getenv("LANG");
     874            if (!pszRet)
     875            {
     876                /*
     877                 * The default is 'C' or 'POSIX'.
     878                 *
     879                 * But if old style is enabled we'll be using the country
     880                 * info to get a locale.
     881                 */
     882                pszRet = gszC;
     883                if (gfOldStyle < 0)
     884                    gfOldStyle = getenv("LIBC_SETLOCALE_OLDSTYLE") != NULL;
     885                if (gfOldStyle)
     886                {
     887                    /*
     888                     * Not specified nor in environment, use country info.
     889                     * This is actually wrong in POSIX sense, but it makes "OS/2 sense". :)
     890                     */
     891                    COUNTRYCODE ctryc = {0,0};
     892                    COUNTRYINFO ctryi = {0};
     893                    ULONG       cb;
     894                    int         rc;
     895                    FS_VAR()
     896
     897                    FS_SAVE_LOAD();
     898                    rc = DosQueryCtryInfo(sizeof(ctryi), &ctryc, &ctryi, &cb);
     899                    if (!rc /*|| rc == ERROR_COU*/)
     900                    {
     901                        UniChar     ucs[50];
     902                        rc = UniMapCtryToLocale(ctryi.country, ucs, sizeof(ucs));
     903                        if (!rc)
     904                        {
     905                            Ucs2Sb(ucs, pszBuffer, UniStrlen(ucs) + 1);
     906                            pszRet = pszBuffer;
     907                        }
     908                        else
     909                            LIBC_ASSERTM_FAILED("UniMapCtryToLocale(%ld) failed rc=%d\n", ctryi.country, rc);
     910                    }
     911                    else
     912                        LIBC_ASSERTM_FAILED("DosQueryCtryInfo failed rc=%d\n", rc);
     913                    FS_RESTORE();
     914                }
     915            }
     916        }
     917    }
     918    return pszRet;
     919}
     920
     921/**
     922 * Extracts the code page from the locale spec or gets the default
     923 * code page.
     924 * @returns 0 on success.
     925 * @returns negated errno on failure.
     926 * @param   pszCodepage     Pointer to where the codepage specifier starts.
     927 * @param   pucsCodepage    Where to store the code page.
     928 * @param   cucCodepage     Number of UniChar's in the buffer.
     929 */
     930static int getCodepage(const char *pszCodepage, const char *pszLocale, LocaleObject lobj, UniChar *pucsCodepage, unsigned cucCodepage)
     931{
     932    /*
     933     * Look at what the user provides.
     934     */
     935    if (pszCodepage && *pszCodepage)
     936        __libc_TranslateCodepage(pszCodepage, pucsCodepage);
     937    else
     938    {
     939        int      rc = -1;
     940        if (gfOldStyle < 0)
     941            gfOldStyle = getenv("LIBC_SETLOCALE_OLDSTYLE") != NULL;
     942
     943        /*
     944         * The locale object contains codepage information.
     945         * We'll use that unless someone want's the old style.
     946         */
     947        if (!gfOldStyle)
     948        {
     949            UniChar *pucsItem;
     950            rc = UniQueryLocaleItem(lobj, LOCI_sISOCodepage, &pucsItem);
     951            if (!rc)
     952            {
     953                UniChar *pucs = pucsItem;
     954                while ( (*pucsCodepage++ = *pucs++) != '\0')
     955                    /* nada */;
     956                UniFreeMem(pucsItem);
     957                return 0;
     958            }
     959        }
     960
     961        /*
     962         * Old style / fallback.
     963         */
     964        if (IS_C_LOCALE(pszLocale) || IS_POSIX_LOCALE(pszLocale))
     965            /*
     966             * The "C" character encoding maps to ISO8859-1 which is not quite true,
     967             * but Unicode API doesn't have a codepage that matches the POSIX "C"
     968             * pszCodepage, so that's what we presume when user requests the "C" pszCodepage.
     969             */
     970            memcpy(pucsCodepage, gucsISO8859_1, sizeof(gucsISO8859_1));
     971        else
     972        {
     973            /*
     974             * Consider current process codepage as default for specified language.
     975             */
     976            ULONG   aulCPs[5];
     977            ULONG   cb;
     978            int     rc;
     979            FS_VAR()
     980
     981            FS_SAVE_LOAD();
     982            rc = DosQueryCp(sizeof(aulCPs), &aulCPs[0], &cb);
     983            if (rc)
     984            {
     985                FS_RESTORE();
     986                LIBC_ASSERTM_FAILED("DosQueryCp failed with rc=%d\n", rc);
     987                return -__libc_native2errno(rc);
     988            }
     989            LIBC_ASSERT(cb >= sizeof(ULONG));
     990            LIBCLOG_MSG2("locale: using process codepage %ld\n", aulCPs[0]);
     991            rc = UniMapCpToUcsCp(aulCPs[0], pucsCodepage, cucCodepage);
     992            FS_RESTORE();
     993            if (rc)
     994            {
     995                LIBC_ASSERTM_FAILED("UniMapCpToUcsCp(%ld,,) -> %d\n", aulCPs[0], rc);
     996                return -unierr2errno(rc);
     997            }
     998        }
     999    }
     1000    return 0;
     1001}
     1002
     1003
     1004/**
     1005 * Creates the libuni objects we need.
     1006 */
     1007static int localeCreateObjects(const char *pszLocale, const char *pszCodepage, char *pszCodepageActual, LocaleObject *plobj, UconvObject *puobj)
     1008{
     1009    LIBCLOG_ENTER("pszLocale=%p:{%s} pszCodepage=%p:{%s} pszCodepageActual=%p plobj=%p puobj=%p\n",
     1010                  pszLocale, pszLocale, pszCodepage, pszCodepage, pszCodepageActual, (void *)plobj, (void *)puobj);
     1011    UniChar ucsCodepage[CODEPAGE_MAX_LENGTH];
     1012    int     rc;
     1013
     1014    /*
     1015     * Create locale object.
     1016     */
     1017    if (IS_POSIX_LOCALE(pszLocale))
     1018        rc = UniCreateLocaleObject(UNI_MBS_STRING_POINTER, gszC, plobj);
     1019    else
     1020        rc = UniCreateLocaleObject(UNI_MBS_STRING_POINTER, pszLocale, plobj);
     1021    if (rc)
     1022    {
     1023        LIBC_ASSERTM_FAILED("UniCreateLocaleObject(,%p:{%s},) -> rc=%d\n", pszLocale, pszLocale, rc);
     1024        rc = -unierr2errno(rc);
     1025        LIBCLOG_RETURN_INT(rc);
     1026    }
     1027
     1028    /*
     1029     * Calc code page and create object.
     1030     */
     1031    rc = getCodepage(pszCodepage, pszLocale, *plobj, &ucsCodepage[0], sizeof(ucsCodepage) / sizeof(ucsCodepage[0]));
     1032    if (!rc)
     1033    {
     1034        rc = UniCreateUconvObject(ucsCodepage, puobj);
     1035        if (!rc)
     1036        {
     1037            if (pszCodepageActual)
     1038                Ucs2Sb(ucsCodepage, pszCodepageActual, UniStrlen(ucsCodepage) + 1);
     1039            LIBCLOG_RETURN_MSG(rc, "ret 0 *plobj=%08x *puobj=%08x pszCodepageActual=%p:{%s}\n",
     1040                               (unsigned)*plobj, (unsigned)*puobj, pszCodepageActual, pszCodepageActual);
     1041        }
     1042
     1043        LIBC_ASSERTM_FAILED("UniCreateUconvObject(%ls,) -> rc=%d\n", (wchar_t *)ucsCodepage, rc);
     1044        rc = -unierr2errno(rc);
     1045    }
     1046
     1047    UniFreeUconvObject(*puobj);
     1048    LIBCLOG_RETURN_INT(rc);
     1049}
     1050
     1051
     1052
     1053/**
     1054 * Performe the locale operation on one category.
     1055 */
     1056static int localeDoOne(struct temp_locale *pTemp, int iCategory, const char *pszLocale, const char *pszCodepage)
     1057{
     1058    LIBCLOG_ENTER("pTemp=%p iCategory=%d (%s) pszLocale=%p:{%s} pszCodepage=%p:{%s}\n",
     1059                  (void *)pTemp, iCategory, gaszCategories[iCategory + 1], pszLocale, pszLocale, pszCodepage, pszCodepage);
     1060    char            szCodepageActual[CODEPAGE_MAX_LENGTH];
     1061    UconvObject     uobj;
     1062    LocaleObject    lobj;
     1063    int             rc;
     1064    int             fFree;
     1065
     1066
     1067    /*
     1068     * Create the objects.
     1069     */
     1070    rc = localeCreateObjects(pszLocale, pszCodepage, &szCodepageActual[0], &lobj, &uobj);
     1071    if (rc)
     1072        return rc;
     1073
     1074    /*
     1075     * Call the worker for the locale category.
     1076     */
     1077    fFree = 1;
     1078    pTemp->afProcessed[iCategory + 1] = 1;
     1079    switch (iCategory)
     1080    {
     1081        case LC_COLLATE:
     1082            rc = localeCollateDo(&pTemp->Collate, uobj, lobj);
     1083            fFree = rc != 0;
     1084            break;
     1085
     1086        case LC_CTYPE:
     1087            rc = localeCtypeDo(&pTemp->Ctype, uobj, lobj, pszLocale);
     1088            fFree = rc != 0;
     1089            break;
     1090
     1091        case LC_TIME:
     1092            rc = localeTimeDo(&pTemp->Time, uobj, lobj);
     1093            break;
     1094
     1095        case LC_NUMERIC:
     1096        case LC_MONETARY:
     1097        {
     1098            /*
     1099             * Query the unicode data..
     1100             */
     1101            struct UniLconv *pULconv;
     1102            rc = UniQueryLocaleInfo(lobj, &pULconv);
     1103            if (!rc)
     1104            {
     1105                if (iCategory == LC_NUMERIC)
     1106                    rc = localeNumericDo(&pTemp->Lconv, uobj, pULconv);
     1107                else
     1108                    rc = localeMonetaryDo(&pTemp->Lconv, uobj, pULconv);
     1109                UniFreeLocaleInfo(pULconv);
     1110            }
     1111            else
     1112            {
     1113                LIBC_ASSERTM_FAILED("UniQueryLocaleInfo -> %d\n", rc);
     1114                rc = -unierr2errno(rc);
     1115            }
     1116            break;
     1117        }
     1118
     1119        case LC_MESSAGES:
     1120            /* Nothing to do for now */
     1121        default:
     1122            rc = 0;
     1123            break;
     1124    }
     1125
     1126
     1127    /*
     1128     * Cleanup.
     1129     */
     1130    if (fFree)
     1131    {
     1132        UniFreeLocaleObject(lobj);
     1133        UniFreeUconvObject(uobj);
     1134    }
     1135
     1136    if (!rc)
     1137    {
     1138        /*
     1139         * Build and set catagory value.
     1140         * The 'pszLocale' variable already contains language and country.
     1141         */
     1142        localeGlobalFree(&pTemp->Global, iCategory);
     1143        if (!pszCodepage || !*pszCodepage)
     1144        {
     1145            /* (no codepage specified) */
     1146            if (IS_C_LOCALE(pszLocale))
     1147                pTemp->Global.apszNames[iCategory + 1] = (char *)gszC;
     1148            else if (IS_POSIX_LOCALE(pszLocale))
     1149                pTemp->Global.apszNames[iCategory + 1] = (char *)gszPOSIX;
     1150            else
     1151            {
     1152                pTemp->Global.apszNames[iCategory + 1] = strdup(pszLocale);
     1153                if (!pTemp->Global.apszNames[iCategory + 1])
     1154                    return -ENOMEM;
     1155            }
    2811156        }
    2821157        else
    2831158        {
    284           UniChar cobuff [50];
    285           if (UniMapCtryToLocale (ci.country, cobuff, sizeof (cobuff)))
    286             goto ctry_error;
    287           locale = (char *)cpbuff;
    288           Ucs2Sb (cobuff, (char *)locale, UniStrlen (cobuff) + 1);
     1159            /* pszLocale + "." + szCodepageActual. */
     1160            int     cch1 = strlen(pszLocale);
     1161            int     cch2 = strlen(szCodepageActual);
     1162            char   *psz = malloc(cch1 + cch2 + 2);
     1163            if (!psz)
     1164                return -ENOMEM;
     1165
     1166            memcpy(psz, pszLocale, cch1);
     1167            psz[cch1] = '.';
     1168            memcpy(psz + cch1 + 1, szCodepageActual, cch2);
     1169            psz[cch1 + 1 + cch2] = '\0';
     1170
     1171            pTemp->Global.apszNames[iCategory + 1] = psz;
    2891172        }
    290       }
    291     }
    292   }
    293   sl = strlen (locale) + 1;
    294   l = (char *)alloca (sl);
    295   memcpy (l, locale, sl);
    296 
    297   /* Parse the locale string user passed to us. This is either a string
    298      in the XPG format (see below) or a list of values of the
    299      form "CATEGORY1=value1;CATEGORY2=value2[;...]", where values are
    300      also in XPG format: "language[_territory[.codeset]][@modifier]".
    301      Currently we're ignoring the modifier. */
    302 
    303   if (category == LC_ALL)
    304   {
    305     /* User supplied a list of category=value statements separated with ';'. */
    306     if ((m = strchr (l, ';')))
    307     {
    308       x = l;
    309       while (m)
    310       {
    311         int cat;
    312         char *cur_cat = locale_cat;
    313 
    314         /* Remove the ';' at the end of assignment. */
    315         *m = 0;
    316         for (cat = 0; *cur_cat; cat++, cur_cat = strchr (cur_cat, 0) + 1)
     1173    }
     1174
     1175    LIBCLOG_RETURN_INT(rc);
     1176}
     1177
     1178
     1179
     1180/**
     1181 * Perform the more complex setlocale() operations which requires that
     1182 * failure doesn't change anything. It will use an auto variable for
     1183 * the temporary locale structure comitting it if all goes fine.
     1184 *
     1185 * @returns 0 on success.
     1186 * @returns Negative errno on failure.
     1187 */
     1188static int localeDo(struct temp_locale *pTemp, int iCategory, char *pszLocale, int fDefaultValue)
     1189{
     1190    LIBCLOG_ENTER("pTemp=%p iCategory=%d (%s) pszLocale=%p:{%s} fDefaultValue=%d\n",
     1191                  (void *)pTemp, iCategory, gaszCategories[iCategory + 1], pszLocale, pszLocale, fDefaultValue);
     1192    const char *pszCodepage;
     1193    char       *pszNext;
     1194    int         rc;
     1195
     1196    /*
     1197     * Process it.
     1198     */
     1199    if (iCategory != LC_ALL)
     1200    {
     1201        rc = localeParseLocale(pszLocale, &pszCodepage);
     1202        if (!rc)
     1203            rc = localeDoOne(pTemp, iCategory, pszLocale, pszCodepage);
     1204    }
     1205    else
     1206    {
     1207        /*
     1208         * Parse the pszLocale string user passed to us. This is either a string
     1209         * in the XPG format (see below) or a list of values of the
     1210         * form "CATEGORY1=value1;CATEGORY2=value2[;...]", where values are
     1211         * also in XPG format: "language[_territory[.codeset]][@modifier]".
     1212         * Currently we're ignoring the modifier.
     1213         */
     1214        pszNext = strchr(pszLocale, ';');
     1215        if (pszNext)
    3171216        {
    318           int sl = strlen (cur_cat);
    319           if (strncmp (x, cur_cat, sl) == 0
    320            && (x [sl] == '='))
    321           {
    322             setlocale (cat, x + sl + 1);
    323             break;
    324           }
    325         }
    326 
    327         m = strchr (x = m + 1, ';');
    328         if (!m && *x)
    329           m = strchr (x, 0);
    330       }
    331     }
    332     else
    333     {
    334       int cat;
    335       char *env_val, *cur_cat = locale_cat;
    336 
    337       /* Set all locale categories to given value */
    338       for (cat = 0; *cur_cat; cat++, cur_cat = strchr (cur_cat, 0) + 1)
    339         /* If user wants default values, check environment first. */
    340         if (def_val && (env_val = getenv (cur_cat)))
    341           setlocale (cat, env_val);
    342         else
    343           setlocale (cat, l);
    344     }
    345   }
    346   else
    347   {
    348     /* Look if the modifier is present and strip it off. */
    349     m = strchr (l, '@');
    350     if (m) *m = 0;
    351 
    352     /* Look which codepage the user provides. */
    353     x = strchr (l, '.');
    354     if (x)
    355     {
    356       *x++ = 0;
    357       __convert_codepage (x, cpbuff);
    358     }
    359     else if (IS_C_LOCALE (l))
    360     /* The "C" character encoding maps to ISO8859-1 which is not quite true,
    361        but Unicode API doesn't have a codepage that matches the POSIX "C"
    362        locale, so that's what we presume when user requests the "C" locale. */
    363       memcpy (cpbuff, L"ISO8859-1", 10 * sizeof (wchar_t));
    364     else
    365     {
    366       ULONG cp [3], cplen;
    367 
    368       /* Consider current process codepage as default for specified language */
    369       if (DosQueryCp (sizeof (cp), cp, &cplen))
    370         ERROR (EINVAL);
    371 
    372       if (UniMapCpToUcsCp (cp [0], cpbuff, sizeof (cpbuff) / sizeof (UniChar)))
    373         ERROR (EINVAL);
    374     }
    375 
    376     if (UniCreateUconvObject (cpbuff, &uconv_obj))
    377       ERROR (EINVAL);
    378 
    379     if (UniCreateLocaleObject (UNI_MBS_STRING_POINTER, l, &locale_obj))
    380       ERROR (EINVAL);
    381 
    382     _smutex_request (&__locale.lock);
    383 
    384     switch (category)
    385     {
    386       case LC_COLLATE:
    387       {
    388         int j;
    389         struct __collate_weight cw [256];
    390         if (query_mbcs (uconv_obj, &__locale_collate.mbcs,
    391                         __locale_collate.mbcsprefix, NULL))
    392           ERROR2 (EINVAL);
    393 
    394         /* Free old locale objects, if any */
    395         if (__locale_collate.uconv)
    396           UniFreeUconvObject (__locale_collate.uconv);
    397         __locale_collate.uconv = NULL;
    398         if (__locale_collate.locale)
    399           UniFreeLocaleObject (__locale_collate.locale);
    400         __locale_collate.locale = NULL;
    401 
    402         if (__locale_collate.mbcs)
    403         {
    404           /* In MBCS mode we just borrow the conversion and locale objects
    405              and leave the real work to the Unicode subsystem. */
    406           __locale_collate.locale = locale_obj;
    407           locale_obj = NULL;
    408           __locale_collate.uconv = uconv_obj;
    409           uconv_obj = NULL;
     1217            /*
     1218             * User supplied a list of iCategory=value statements separated with ';'.
     1219             */
     1220            char *pszCur = pszLocale;
     1221            *pszNext++ = '\0';          /* remove the ';'. */
     1222            for (;;)
     1223            {
     1224                int iCat;
     1225                /* Search for the variable, ignoring those we cannot find.s */
     1226                for (rc = 0, iCat = LC_ALL; iCat < _LC_LAST; iCat++)
     1227                {
     1228                    unsigned    cch = gacchCategories[iCat + 1];
     1229                    if (    strncmp(pszCur, gaszCategories[iCat + 1], cch) == 0
     1230                        &&  pszCur[cch] == '=')
     1231                    {
     1232                        char        *pszVal = &pszCur[cch + 1];
     1233                        const char  *pszValCp;
     1234                        /* parse the locale value. */
     1235                        rc = localeParseLocale(pszVal, &pszValCp);
     1236                        if (!rc)
     1237                        {
     1238                            if (iCat != LC_ALL)
     1239                                rc = localeDoOne(pTemp, iCat, pszVal, pszValCp);
     1240                            else /* Iterate all categories except LC_ALL. */
     1241                                for (iCat = LC_ALL + 1; !rc && iCat < _LC_LAST; iCat++)
     1242                                    rc = localeDoOne(pTemp, iCat, pszVal, pszValCp);
     1243                        }
     1244                        break;
     1245                    }
     1246                }
     1247
     1248                /* next */
     1249                if (!pszNext || rc < 0)
     1250                    break;
     1251                pszCur = pszNext;
     1252                pszNext = strchr(pszCur, ';');
     1253                if (pszNext)
     1254                    *pszNext++ = '\0';
     1255            }
    4101256        }
    4111257        else
    4121258        {
    413           /* In SBCS we query the weight of every character and use the
    414              weights directly, without the need to invoke the Unicode API. */
    415 
    416           /* Initialize character weights. */
    417           for (i = 0; i < 256; i++)
    418           {
    419             UniChar ucs;
    420             UniChar us [2];
    421 
    422             if (!__to_ucs (uconv_obj, (unsigned char *)&i, 1, &ucs))
    423               ucs = i;
    424 
    425             us [0] = ucs; us [1] = 0;
    426 
    427             cw [i].code = i;
    428             cw [i].len = UniStrxfrm (locale_obj, cw [i].weight, us,
    429               sizeof (cw [i].weight) / sizeof (UniChar));
    430             if (cw [i].len >= sizeof (cw [i].weight) / sizeof (UniChar))
    431               /* This should never happen. */
    432               cw [i].len = sizeof (cw [i].weight) / sizeof (UniChar);
    433           }
    434 
    435           /* Do bubble sorting since qsort() doesn't guarantee that the order
    436              of equal elements stays the same. */
    437           for (i = 0; i < 256; i++)
    438             for (j = i; j < 256; j++)
    439               if (cw_cmp (&cw [j], &cw [j + 1]) > 0)
    440                 _memswap (&cw [j], &cw [j + 1], sizeof (struct __collate_weight));
    441 
    442           for (i = 0; i < 256; i++)
    443             __locale_collate.weight [cw [i].code] = i;
     1259            /*
     1260             * Set all pszLocale categories to given value.
     1261             * Parse it first to save time.
     1262             */
     1263            rc = localeParseLocale(pszLocale, &pszCodepage);
     1264            if (!rc)
     1265            {
     1266                int iCat;
     1267                for (iCat = LC_ALL + 1; !rc && iCat < _LC_LAST; iCat++)
     1268                {
     1269                    const char *pszEnv;
     1270                    /*
     1271                     * If user wants default values, we must check environment first.
     1272                     */
     1273                    if (fDefaultValue && (pszEnv = getenv(gaszCategories[iCat + 1])) != NULL)
     1274                    {
     1275                        const char *pszCodepageEnv;
     1276                        char *pszCopy = alloca(strlen(pszEnv) + 1);
     1277                        if (!pszCopy)
     1278                            LIBCLOG_RETURN_INT(-ENOMEM);
     1279                        rc = localeParseLocale(strcpy(pszCopy, pszEnv), &pszCodepageEnv);
     1280                        if (!rc)
     1281                            rc = localeDoOne(pTemp, iCat, pszCopy, pszCodepageEnv);
     1282                    }
     1283                    else
     1284                        rc = localeDoOne(pTemp, iCat, pszLocale, pszCodepage);
     1285                }
     1286            }
    4441287        }
    445 
    446         break;
    447       }
    448 
    449       case LC_CTYPE:
    450       {
    451         if (query_mbcs (uconv_obj, &__locale_ctype.mbcs,
    452                         __locale_ctype.mbcsprefix, &MB_CUR_MAX))
    453           ERROR2 (EINVAL);
    454 
    455         /* For speeding up isXXX() and lower/upper case mapping functions
    456            we'll cache the type of every character into a variable.
    457 
    458            Do every character separately to avoid errors that could result
    459            when some character in the middle cannot be conerted from or to
    460            Unicode - this would lead in a shift of the entire string. */
    461         for (i = 0; i < 256; i++)
     1288    }
     1289    LIBCLOG_RETURN_INT(rc);
     1290}
     1291
     1292
     1293/**
     1294 * Commits a temporary local and updates the global locale strings.
     1295 */
     1296static char *localeCommit(struct temp_locale *pTemp, int iCategory)
     1297{
     1298    char   *pszRet;
     1299    char   *pszAll;
     1300    int     cch;
     1301    int     iCat;
     1302
     1303    /*
     1304     * Lock the structure.
     1305     */
     1306    _smutex_request(&gLocale.lock);
     1307
     1308    /*
     1309     * Copy all the data.
     1310     */
     1311    if (pTemp->afProcessed[LC_COLLATE + 1])
     1312    {
     1313        localeCollateFree(&__libc_gLocaleCollate);
     1314        memcpy(&__libc_gLocaleCollate, &pTemp->Collate, sizeof(__libc_gLocaleCollate));
     1315        pTemp->afProcessed[LC_COLLATE + 1] = 0;
     1316        gLocale.apszNames[LC_COLLATE + 1] = pTemp->Global.apszNames[LC_COLLATE + 1];
     1317    }
     1318
     1319    if (pTemp->afProcessed[LC_CTYPE + 1])
     1320    {
     1321        localeCtypeFree(&__libc_GLocaleCtype);
     1322        memcpy(&__libc_GLocaleCtype, &pTemp->Ctype, sizeof(__libc_GLocaleCtype));
     1323        pTemp->afProcessed[LC_CTYPE + 1] = 0;
     1324        gLocale.apszNames[LC_CTYPE + 1] = pTemp->Global.apszNames[LC_CTYPE + 1];
     1325    }
     1326
     1327    if (pTemp->afProcessed[LC_TIME + 1])
     1328    {
     1329        localeTimeFree(&__libc_gLocaleTime);
     1330        memcpy(&__libc_gLocaleTime, &pTemp->Time, sizeof(__libc_gLocaleTime));
     1331        pTemp->afProcessed[LC_TIME + 1] = 0;
     1332        gLocale.apszNames[LC_TIME + 1] = pTemp->Global.apszNames[LC_TIME + 1];
     1333    }
     1334
     1335    if (pTemp->afProcessed[LC_NUMERIC + 1])
     1336    {
     1337        localeNumericFree(&__libc_gLocaleLconv);
     1338        __libc_gLocaleLconv.fNumericConsts   = pTemp->Lconv.fNumericConsts;
     1339        __libc_gLocaleLconv.s.decimal_point  = pTemp->Lconv.s.decimal_point;
     1340        __libc_gLocaleLconv.s.thousands_sep  = pTemp->Lconv.s.thousands_sep;
     1341        __libc_gLocaleLconv.s.grouping       = pTemp->Lconv.s.grouping;
     1342        pTemp->afProcessed[LC_NUMERIC + 1] = 0;
     1343        gLocale.apszNames[LC_NUMERIC + 1] = pTemp->Global.apszNames[LC_NUMERIC + 1];
     1344    }
     1345
     1346    if (pTemp->afProcessed[LC_MONETARY + 1])
     1347    {
     1348        localeMonetaryFree(&__libc_gLocaleLconv);
     1349        __libc_gLocaleLconv.fMonetaryConsts      = pTemp->Lconv.fMonetaryConsts;
     1350        __libc_gLocaleLconv.s.int_curr_symbol    = pTemp->Lconv.s.int_curr_symbol;
     1351        __libc_gLocaleLconv.s.currency_symbol    = pTemp->Lconv.s.currency_symbol;
     1352        __libc_gLocaleLconv.s.mon_decimal_point  = pTemp->Lconv.s.mon_decimal_point;
     1353        __libc_gLocaleLconv.s.mon_thousands_sep  = pTemp->Lconv.s.mon_thousands_sep;
     1354        __libc_gLocaleLconv.s.mon_grouping       = pTemp->Lconv.s.mon_grouping;
     1355        __libc_gLocaleLconv.s.positive_sign      = pTemp->Lconv.s.positive_sign;
     1356        __libc_gLocaleLconv.s.negative_sign      = pTemp->Lconv.s.negative_sign;
     1357        __libc_gLocaleLconv.s.int_frac_digits    = pTemp->Lconv.s.int_frac_digits;
     1358        __libc_gLocaleLconv.s.frac_digits        = pTemp->Lconv.s.frac_digits;
     1359        __libc_gLocaleLconv.s.p_cs_precedes      = pTemp->Lconv.s.p_cs_precedes;
     1360        __libc_gLocaleLconv.s.p_sep_by_space     = pTemp->Lconv.s.p_sep_by_space;
     1361        __libc_gLocaleLconv.s.n_cs_precedes      = pTemp->Lconv.s.n_cs_precedes;
     1362        __libc_gLocaleLconv.s.n_sep_by_space     = pTemp->Lconv.s.n_sep_by_space;
     1363        __libc_gLocaleLconv.s.p_sign_posn        = pTemp->Lconv.s.p_sign_posn;
     1364        __libc_gLocaleLconv.s.n_sign_posn        = pTemp->Lconv.s.n_sign_posn;
     1365        pTemp->afProcessed[LC_MONETARY + 1] = 0;
     1366        gLocale.apszNames[LC_MONETARY + 1] = pTemp->Global.apszNames[LC_MONETARY + 1];
     1367    }
     1368    if (pTemp->afProcessed[LC_MESSAGES + 1])
     1369    {
     1370        pTemp->afProcessed[LC_MONETARY + 1] = 0;
     1371        gLocale.apszNames[LC_MESSAGES + 1] = pTemp->Global.apszNames[LC_MESSAGES + 1];
     1372    }
     1373
     1374
     1375    /*
     1376     * Now we must build the LC_ALL string.
     1377     *
     1378     * If all the entries are not identical we must make a "category=value"
     1379     * string for LC_ALL. Else we can just duplicate one of the others.
     1380     */
     1381    pszAll = gLocale.apszNames[1];
     1382    cch = gacchCategories[1] + 1 + strlen(pszAll) + 1 + 1;
     1383    for (iCat = 2; iCat <= _LC_LAST; iCat++)
     1384    {
     1385        int cchCat = strlen(gLocale.apszNames[iCat]);
     1386        cch += gacchCategories[iCat] + 1 + cchCat + 1;
     1387        if (pszAll && strcmp(pszAll, gLocale.apszNames[iCat]))
     1388            pszAll = NULL;
     1389    }
     1390
     1391    if (!pszAll)
     1392    {
     1393        /*
     1394         * Not identical. Generate composite value.
     1395         */
     1396        char *psz = pszAll = malloc(cch); /* If we're out of memory here, then it's just too bad :-/ */
     1397        for (iCat = 1; iCat <= _LC_LAST; iCat++) /* (iCat is array index not lc idx this time) */
    4621398        {
    463           UniChar ucs;
    464           unsigned short ct = 0;
    465           unsigned char uc, lc;
    466 
    467           if (!__to_ucs (uconv_obj, (unsigned char *)&i, 1, &ucs))
    468             ucs = i;
    469 
    470           /* isxxx() do not support DBCS characters at all */
    471           if (!IS_MBCS_PREFIX (__locale_ctype,i))
    472           {  /* isn't there apis for getting all this at once? */
    473 #if 0
    474             if (UniQueryUpper (locale_obj, ucs))
    475               ct |= __UPPER;
    476             if (UniQueryLower (locale_obj, ucs))
    477               ct |= __LOWER;
    478             if (UniQueryDigit (locale_obj, ucs))
    479               ct |= __DIGIT;
    480             if (UniQueryXdigit (locale_obj, ucs))
    481               ct |= __XDIGIT;
    482             if (UniQueryCntrl (locale_obj, ucs))
    483               ct |= __CNTRL;
    484             if (UniQuerySpace (locale_obj, ucs))
    485               ct |= __SPACE;
    486             if (UniQueryPunct (locale_obj, ucs))
    487               ct |= __PUNCT;
    488             if (UniQueryPrint (locale_obj, ucs))
    489               ct |= __PRINT;
    490             if (UniQueryBlank (locale_obj, ucs))
    491               ct |= __BLANK;
    492 #else
    493             UNICTYPE * pctype = UniQueryCharType (ucs);
    494             if (pctype)
    495               /* ASSUMES CT_* == __* */
    496               ct = (pctype->itype) & (__UPPER  | __LOWER  | __DIGIT | __SPACE |
    497                                       __PUNCT  | __CNTRL  | __BLANK | __XDIGIT |
    498                                       __ALPHA  | __ALNUM  | __GRAPH | __PRINT |
    499                                       __NUMBER | __SYMBOL | __ASCII);
    500 
    501 #endif
    502 
    503             uc = Transform (locale_obj, uconv_obj, UniTransUpper, ucs, i);
    504             lc = Transform (locale_obj, uconv_obj, UniTransLower, ucs, i);
    505           }
    506           else
    507             uc = lc = i;
    508 
    509           __locale_ctype.cflags [i] = ct;
    510 
    511           __locale_ctype.upcase [i] = uc;
    512           __locale_ctype.locase [i] = lc;
     1399            int cchCat = gacchCategories[iCat];
     1400            memcpy(psz, gaszCategories[iCat], cchCat);
     1401            psz += cchCat;
     1402            *psz++ = '=';
     1403            cchCat = strlen(gLocale.apszNames[iCat]);
     1404            memcpy(psz, gLocale.apszNames[iCat], cchCat);
     1405            psz += cchCat;
     1406            *psz++ = ';';
    5131407        }
    514 
    515         /* In the "C" locale second half of the cflags table should be empty */
    516         if (IS_C_LOCALE (l))
     1408        *psz = '\0';
     1409        localeGlobalFree(&gLocale, LC_ALL);
     1410        gLocale.apszNames[LC_ALL + 1] = pszAll;
     1411    }
     1412    else if (strcmp(gLocale.apszNames[LC_ALL + 1], pszAll))
     1413    {
     1414        localeGlobalFree(&gLocale, LC_ALL);
     1415        gLocale.apszNames[LC_ALL + 1] = strdup(pszAll);
     1416    }
     1417
     1418    /*
     1419     * Unlock and returns.
     1420     */
     1421    pszRet = gLocale.apszNames[iCategory + 1];
     1422    _smutex_release(&gLocale.lock);
     1423
     1424    return pszRet;
     1425}
     1426
     1427
     1428/**
     1429 * Clean up the temporary locale instance structure.
     1430 * @param   pTemp   Stuff to cleanup.
     1431 */
     1432static void localeFree(struct temp_locale *pTemp)
     1433{
     1434    int iCat;
     1435    if (pTemp->afProcessed[LC_COLLATE + 1])
     1436        localeCollateFree(&pTemp->Collate);
     1437    if (pTemp->afProcessed[LC_CTYPE + 1])
     1438        localeCtypeFree(&pTemp->Ctype);
     1439    if (pTemp->afProcessed[LC_TIME + 1])
     1440        localeTimeFree(&pTemp->Time);
     1441    if (pTemp->afProcessed[LC_NUMERIC + 1])
     1442        localeNumericFree(&pTemp->Lconv);
     1443    if (pTemp->afProcessed[LC_MONETARY + 1])
     1444        localeMonetaryFree(&pTemp->Lconv);
     1445    for (iCat = 0; iCat < _LC_LAST; iCat++)
     1446        if (pTemp->afProcessed[iCat + 1])
     1447            localeGlobalFree(&pTemp->Global, iCat);
     1448}
     1449
     1450
     1451/**
     1452 * This setlocale() implementation differs from the specs in that any
     1453 * options specified by '@...' is ignored.
     1454 */
     1455char *_STD(setlocale)(int iCategory, const char *pszLocale)
     1456{
     1457    LIBCLOG_ENTER("iCategory=%d pszLocale=%p:{%s}\n", iCategory, pszLocale, pszLocale);
     1458    char            szTmpBuf[64];
     1459    int             fDefaultValue;
     1460    size_t          cch;
     1461    char           *pszLocaleCopy;
     1462    char           *pszRet;
     1463    int             rc;
     1464
     1465    /*
     1466     * Validate input.
     1467     */
     1468    if (iCategory < LC_ALL || iCategory >= _LC_LAST)
     1469    {
     1470        LIBC_ASSERTM_FAILED("iCategory=%d is invalid!\n", iCategory);
     1471        errno = EINVAL;
     1472        LIBCLOG_RETURN_P(NULL);
     1473    }
     1474
     1475    /*
     1476     * Check if user just queries current pszLocale.
     1477     */
     1478    if (!pszLocale)
     1479    {
     1480        pszRet = gLocale.apszNames[iCategory + 1];
     1481        LIBCLOG_RETURN_MSG(pszRet, "ret %p:{%s}\n", pszRet, pszRet);
     1482    }
     1483
     1484    /*
     1485     * Check if user wants we to do the same job twice.
     1486     */
     1487    if (strcmp(pszLocale, gLocale.apszNames[iCategory + 1]) == 0)
     1488    {
     1489        /* We have to return the value of LC_ALL */
     1490        pszRet = gLocale.apszNames[iCategory + 1];
     1491        LIBCLOG_RETURN_MSG(pszRet, "ret %p:{%s} (already set)\n", pszRet, pszRet);
     1492    }
     1493
     1494
     1495    /*
     1496     * If pszLocale value is a empty string, user wants the defaults fetched from
     1497     * environment.
     1498     */
     1499    fDefaultValue = *pszLocale == '\0';
     1500    if (fDefaultValue)
     1501        pszLocale = getDefaultLocale(gaszCategories[iCategory + 1], szTmpBuf, &fDefaultValue);
     1502
     1503    /*
     1504     * Copy pszLocale to a local storage since we'll modify it during parsing.
     1505     */
     1506    cch = strlen(pszLocale) + 1;
     1507    pszLocaleCopy = (char *)alloca(cch);
     1508    if (!pszLocaleCopy)
     1509    {
     1510        errno = ENOMEM;
     1511        LIBCLOG_RETURN_P(NULL);
     1512    }
     1513    memcpy(pszLocaleCopy, pszLocale, cch);
     1514
     1515
     1516    /*
     1517     * Allocate a temporary locale state and perform
     1518     * the locale operation on that.
     1519     */
     1520    struct temp_locale *pTemp = alloca(sizeof(struct temp_locale));
     1521    memset(pTemp, 0, sizeof(struct temp_locale));
     1522
     1523    rc = localeDo(pTemp, iCategory, pszLocaleCopy, fDefaultValue);
     1524
     1525    /*
     1526     * If successful commit the temporary locale.
     1527     */
     1528    if (!rc)
     1529        pszRet = localeCommit(pTemp, iCategory);
     1530    else
     1531    {
     1532        errno = -rc;
     1533        pszRet = NULL;
     1534    }
     1535
     1536    /*
     1537     * Cleanup and exit.
     1538     */
     1539    localeFree(pTemp);
     1540
     1541    LIBCLOG_RETURN_MSG(pszRet, "ret %p:{%s}\n", pszRet, pszRet);
     1542}
     1543
     1544#undef ERROR
     1545
     1546#undef  __LIBC_LOG_GROUP
     1547#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_FORK
     1548
     1549
     1550_FORK_CHILD1(0xffffff00, setlocalForkChild1)
     1551
     1552/**
     1553 * Create any unicode objects used by the locale stuff.
     1554 *
     1555 * !describe me!
     1556 */
     1557static int setlocalForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     1558{
     1559    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     1560    int rc;
     1561    switch (enmOperation)
     1562    {
     1563        case __LIBC_FORK_OP_FORK_CHILD:
    5171564        {
    518           memset (__locale_ctype.cflags + 128, 0, 128);
    519           for (i = 128; i < 255; i++)
    520           {
    521             __locale_ctype.upcase [i] = i;
    522             __locale_ctype.locase [i] = i;
    523           }
     1565            gLocale.lock = 0;
     1566
     1567            rc = 0;
     1568            if (    __libc_GLocaleCtype.lobj
     1569                ||  __libc_GLocaleCtype.uobj
     1570                ||  __libc_gLocaleCollate.lobj
     1571                ||  __libc_gLocaleCollate.uobj
     1572                )
     1573            {
     1574                LocaleObject    lobj;
     1575                UconvObject     uobj;
     1576                const char *pszCodepage;
     1577                int     cch1 = strlen(gLocale.apszNames[LC_CTYPE + 1]);
     1578                int     cch2 = strlen(gLocale.apszNames[LC_COLLATE + 1]);
     1579                int     cch = cch1 > cch2 ? cch1 + 1 : cch2 + 1;
     1580                char   *psz = alloca(cch);
     1581                if (!psz)
     1582                    LIBCLOG_RETURN_INT(-ENOMEM);
     1583
     1584                if (    __libc_GLocaleCtype.lobj
     1585                    ||  __libc_GLocaleCtype.uobj)
     1586                {
     1587                    memcpy(psz, gLocale.apszNames[LC_CTYPE + 1], cch);
     1588                    localeParseLocale(psz, &pszCodepage);
     1589                    rc = localeCreateObjects(psz, pszCodepage, NULL, &lobj, &uobj);
     1590                    if (!rc)
     1591                        LIBCLOG_RETURN_INT(rc);
     1592
     1593                    if (__libc_GLocaleCtype.lobj)
     1594                        __libc_GLocaleCtype.lobj = lobj;
     1595                    else
     1596                        UniFreeLocaleObject(lobj);
     1597
     1598                    if (__libc_GLocaleCtype.uobj)
     1599                        __libc_GLocaleCtype.uobj = uobj;
     1600                    else
     1601                        UniFreeUconvObject(uobj);
     1602                }
     1603
     1604                if (    __libc_gLocaleCollate.lobj
     1605                    ||  __libc_gLocaleCollate.uobj)
     1606                {
     1607                    memcpy(psz, gLocale.apszNames[LC_COLLATE + 1], cch);
     1608                    localeParseLocale(psz, &pszCodepage);
     1609                    rc = localeCreateObjects(psz, pszCodepage, NULL, &lobj, &uobj);
     1610                    if (!rc)
     1611                        LIBCLOG_RETURN_INT(rc);
     1612
     1613                    if (__libc_gLocaleCollate.lobj)
     1614                        __libc_gLocaleCollate.lobj = lobj;
     1615                    else
     1616                        UniFreeLocaleObject(lobj);
     1617
     1618                    if (__libc_gLocaleCollate.uobj)
     1619                        __libc_gLocaleCollate.uobj = uobj;
     1620                    else
     1621                        UniFreeUconvObject(uobj);
     1622                }
     1623            }
     1624            break;
    5241625        }
    525 
    526         if (__locale_ctype.uconv)
    527           UniFreeUconvObject (__locale_ctype.uconv);
    528         __locale_ctype.uconv = NULL;
    529         if (__locale_ctype.locale)
    530           UniFreeLocaleObject (__locale_ctype.locale);
    531         __locale_ctype.locale = NULL;
    532 
    533         __locale_ctype.uconv = uconv_obj;
    534         uconv_obj = NULL;
    535 
    536         if (__locale_ctype.mbcs)
    537         {
    538           /* In MBCS mode we just borrow the locale object
    539              and leave the real work to the Unicode subsystem. */
    540           __locale_ctype.locale = locale_obj;
    541           locale_obj = NULL;
    542         }
    543 
    544         break;
    545       }
    546 
    547       case LC_TIME:
    548       {
    549         struct __locale_time loc_time;
    550         UniChar *item;
    551 
    552         memset (&loc_time, 0, sizeof (loc_time));
    553 
    554         if (UniQueryLocaleItem (locale_obj, D_T_FMT, &item)
    555          || convert_ucs (uconv_obj, item, &loc_time.date_time_fmt)
    556          || UniQueryLocaleItem (locale_obj, D_FMT, &item)
    557          || convert_ucs (uconv_obj, item, &loc_time.date_fmt)
    558          || UniQueryLocaleItem (locale_obj, T_FMT, &item)
    559          || convert_ucs (uconv_obj, item, &loc_time.time_fmt)
    560          || UniQueryLocaleItem (locale_obj, AM_STR, &item)
    561          || convert_ucs (uconv_obj, item, &loc_time.am)
    562          || UniQueryLocaleItem (locale_obj, PM_STR, &item)
    563          || convert_ucs (uconv_obj, item, &loc_time.pm)
    564          || query_array (locale_obj, uconv_obj, 7, DAY_1, loc_time.lwdays)
    565          || query_array (locale_obj, uconv_obj, 7, ABDAY_1, loc_time.swdays)
    566          || query_array (locale_obj, uconv_obj, 12, MON_1, loc_time.lmonths)
    567          || query_array (locale_obj, uconv_obj, 12, ABMON_1, loc_time.smonths))
    568         {
    569           free_time (&loc_time);
    570           ERROR2 (EINVAL);
    571         }
    572 
    573         /* Free the old time formatting info if needed. */
    574         if (__locale.name [LC_TIME + 1] != __locale_C)
    575           free_time (&__locale_time);
    576 
    577         /* Assign value to static variable. */
    578         __locale_time = loc_time;
    579         break;
    580       }
    581 
    582       case LC_MESSAGES:
    583         /* Nothing to do for now */
    584         break;
    585 
    586       case LC_NUMERIC:
    587       case LC_MONETARY:
    588       {
    589         struct lconv lconv;
    590 
    591         if (UniQueryLocaleInfo (locale_obj, &Lconv))
    592           ERROR2 (EINVAL);
    593 
    594         lconv = __locale_lconv;
    595 
    596 #define CONVERT_UCS(field) \
    597         if (convert_ucs (uconv_obj, Lconv->field, &lconv.field)) \
    598           ERROR3 (EINVAL);
    599 
    600         if (category == LC_NUMERIC)
    601         {
    602 #define ERROR3(code) \
    603         { free_numeric (&lconv); UniFreeLocaleInfo (Lconv); ERROR2 (code); }
    604 
    605           /* Initialize fields with NULLs (for the case we will fail) */
    606           lconv.decimal_point = lconv.thousands_sep = lconv.grouping = NULL;
    607 
    608           CONVERT_UCS (decimal_point);
    609           CONVERT_UCS (thousands_sep);
    610           CONVERT_UCS (grouping);
    611 
    612           if (__locale.name [LC_NUMERIC + 1] != __locale_C)
    613             free_numeric (&__locale_lconv);
    614 #undef ERROR3
    615         }
    616 
    617         if (category == LC_MONETARY)
    618         {
    619 #define ERROR3(code) { free_monetary (&lconv); ERROR2 (code); }
    620 
    621           /* Initialize fields with NULLs (for the case we will fail) */
    622           lconv.int_curr_symbol = lconv.currency_symbol =
    623           lconv.mon_decimal_point = lconv.mon_thousands_sep =
    624           lconv.mon_grouping = lconv.positive_sign =
    625           lconv.negative_sign = NULL;
    626 
    627           CONVERT_UCS (int_curr_symbol);
    628           CONVERT_UCS (currency_symbol);
    629           CONVERT_UCS (mon_decimal_point);
    630           CONVERT_UCS (mon_thousands_sep);
    631           CONVERT_UCS (mon_grouping);
    632           CONVERT_UCS (positive_sign);
    633           CONVERT_UCS (negative_sign);
    634           lconv.int_frac_digits = Lconv->int_frac_digits;
    635           lconv.frac_digits = Lconv->frac_digits;
    636           lconv.p_cs_precedes = Lconv->p_cs_precedes;
    637           lconv.p_sep_by_space = Lconv->p_sep_by_space;
    638           lconv.n_cs_precedes = Lconv->n_cs_precedes;
    639           lconv.n_sep_by_space = Lconv->n_sep_by_space;
    640           lconv.p_sign_posn = Lconv->p_sign_posn;
    641           lconv.n_sign_posn = Lconv->n_sign_posn;
    642 
    643           if (__locale.name [LC_MONETARY + 1] != __locale_C)
    644             free_monetary (&__locale_lconv);
    645 #undef ERROR3
    646         }
    647 #undef CONVERT_UCS
    648 
    649         UniFreeLocaleInfo (Lconv);
    650 
    651         /* Okay, since we got no errors, copy to its final location. */
    652         __locale_lconv = lconv;
    653         break;
    654       }
    655     } /* endcase */
    656 
    657     /* Build and set category value.
    658        'l' already contains language and country. */
    659     if (IS_C_LOCALE (l))
    660       setname (category, l, 0);
    661     else
    662     {
    663       char *loc;
    664       int j = 0;
    665       i = strlen (l);
    666       sl = i + UniStrlen (cpbuff) + 2;
    667       loc = malloc (sl);
    668       memcpy (loc, l, i);
    669       loc [i++] = '.';
    670       /* Suppose codepage names always use 7-bit characters (which is true) */
    671       while (i < sl)
    672         loc [i++] = (char)cpbuff [j++];
    673       setname (category, loc, 1);
    674     } /* endif */
    675 
    676     _smutex_release (&__locale.lock);
    677   }
    678 
    679   /* Check if all locale categories are equal. If not, return a list in
    680      the "category=value" format, otherwise just return the value itself. */
    681   ret = __locale.name [1];
    682   sl = 0;
    683   x = locale_cat;
    684   for (i = 0; i < __LC_COUNT; i++)
    685   {
    686     if (ret && strcmp (ret, __locale.name [i + 1]) != 0)
    687       /* We have to return a list value. */
    688       ret = NULL;
    689     sl += strlen (x) + strlen (__locale.name [i + 1]) + 2;
    690     x = strchr (x, 0) + 1;
    691   }
    692 
    693   i = 0;
    694   if (!ret)
    695   {
    696     /* Generate a list value. */
    697     ret = malloc (sl);
    698     x = locale_cat;
    699     sl = 0;
    700     for (/*i = 0*/; i < __LC_COUNT; i++)
    701     {
    702       strcpy (ret + sl, x);
    703       sl += strlen (ret + sl);
    704       ret [sl++] = '=';
    705       strcpy (ret + sl, __locale.name [i + 1]);
    706       sl += strlen (ret + sl);
    707       if (i < __LC_COUNT - 1)
    708         ret [sl++] = ';';
    709       x = strchr (x, 0) + 1;
    710     }
    711   } /* endif */
    712 
    713   /* If all values (except LC_ALL) are equal, ret is set to that value.
    714      In this case we must set LC_ALL to that value as well.
    715      If values are partially different, ret points to a composite value.
    716      In this case we also must set LC_ALL to this composite value.
    717      If i is not zero, then we have a composite value which is already
    718      allocated from heap (so avoid setname() allocating it again). */
    719   setname (LC_ALL, ret, i);
    720 
    721   /* But in any case, the returned value is the one actually set for
    722      the category in question. */
    723   ret = __locale.name [category + 1];
    724 
    725 normal_exit:
    726   if (locale_obj)
    727     UniFreeLocaleObject (locale_obj);
    728   if (uconv_obj)
    729     UniFreeUconvObject (uconv_obj);
    730 
    731   return ret;
    732 }
    733 
    734 #undef ERROR
     1626        default:
     1627            rc = 0;
     1628            break;
     1629    }
     1630    LIBCLOG_RETURN_INT(rc);
     1631}
     1632
  • trunk/src/emx/src/lib/malloc/_hinitheap.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1453 r1454  
    8484     * Allocate the initial heap block.
    8585     */
    86     cbInitial = 4*1024*1024;
     86    cbInitial = _INITIAL_DEFAULT_HEAP_SIZE;
    8787    fClean = _BLOCK_CLEAN;
    8888    pvInitial = __libc_HimemDefaultAlloc(NULL, &cbInitial, &fClean);
     
    9898    Heap = _ucreate2(pvInitial, cbInitial, fClean,
    9999                     _HEAP_REGULAR | _HEAP_HIGHMEM,
    100                      __libc_HimemDefaultAlloc, __libc_HimemDefaultRelease,
     100                     __libc_HimemDefaultAlloc,  __libc_HimemDefaultRelease,
    101101                     NULL, NULL);
    102102    if (Heap == NULL)
  • trunk/src/emx/src/lib/malloc/calloc.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/defalloc.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/defexpan.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/defrelea.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/defshrin.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/expand.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/free.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/heapchk.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/heapmin.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/heapset.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/iaddmem.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/ialloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    88#include <umalloc.h>
    99#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    10 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    11 #include <sys/rmutex.h>
     10#include <sys/fmutex.h>
    1211#include <emx/umalloc.h>
    1312
  • trunk/src/emx/src/lib/malloc/ifree.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/imisc.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/initr.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    11/* initr.c (emx+gcc) -- Copyright (c) 1996 by Eberhard Mattes */
    22
     3
     4/*******************************************************************************
     5*   Header Files                                                               *
     6*******************************************************************************/
    37#include "libc-alias.h"
    48#include <umalloc.h>
     
    610#include <sys/smutex.h>
    711#include <InnoTekLIBC/thread.h>
     12#include <InnoTekLIBC/fork.h>
     13#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_HEAP
     14#include <InnoTekLIBC/logstrict.h>
    815
     16
     17/*******************************************************************************
     18*   Global Variables                                                           *
     19*******************************************************************************/
    920/** This is the default regular heap. */
    10 Heap_t _um_regular_heap;
     21Heap_t      _um_regular_heap;
     22
     23/** Fork cleanup indicator. */
     24static int  gfForkCleanupDone;
     25
     26
     27/*******************************************************************************
     28*   Internal Functions                                                         *
     29*******************************************************************************/
     30static int  umForkParent1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     31static void umForkCompletion(void *pvArg, int rc, __LIBC_FORKCTX enmCtx);
     32
     33
    1134
    1235/**
     
    78101}
    79102
     103
     104#undef  __LIBC_LOG_GROUP
     105#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_FORK
     106
     107_FORK_PARENT1(0xffffff01, umForkParent1)
     108
     109/**
     110 * Parent fork callback.
     111 *
     112 * The purpose of this is to lock the three heaps we knows about while
     113 * we're doing the fork() operation.
     114 *
     115 * @returns 0 on success.
     116 * @returns -errno on failure.
     117 * @param   pForkHandle     Pointer to fork handle.
     118 * @param   enmOperation    Fork operation.
     119 */
     120static int umForkParent1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     121{
     122    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     123    int rc;
     124
     125    switch (enmOperation)
     126    {
     127        /*
     128         * Lock the heaps before fork() scheduling an unlocking
     129         * completion callback after fork() is done.
     130         */
     131        case __LIBC_FORK_OP_EXEC_PARENT:
     132            gfForkCleanupDone = 0;
     133            rc = pForkHandle->pfnCompletionCallback(pForkHandle, umForkCompletion, NULL, __LIBC_FORK_CTX_BOTH);
     134            if (rc >= 0)
     135            {
     136                LIBCLOG_MSG("Locking the heaps.\n");
     137                if (_um_tiled_heap)
     138                    _um_heap_lock(_um_tiled_heap);
     139                if (_um_high_heap)
     140                    _um_heap_lock(_um_high_heap);
     141                if (_um_low_heap)
     142                    _um_heap_lock(_um_low_heap);
     143            }
     144            break;
     145
     146        default:
     147            rc = 0;
     148            break;
     149    }
     150    LIBCLOG_RETURN_INT(rc);
     151}
     152
     153
     154/**
     155 * Fork completion callback used to release the locks on the default heaps.
     156 *
     157 * @param   pvArg   NULL.
     158 * @param   rc      The fork() result. Negative on failure.
     159 * @param   enmCtx  The calling context.
     160 */
     161static void umForkCompletion(void *pvArg, int rc, __LIBC_FORKCTX enmCtx)
     162{
     163    LIBCLOG_ENTER("pvArg=%p rc=%d enmCtx=%d - gfForkCleanupDone=%d\n", pvArg, rc, enmCtx, gfForkCleanupDone);
     164
     165    if (!gfForkCleanupDone)
     166    {
     167        LIBCLOG_MSG("Unlocking the heaps.\n");
     168        if (_um_tiled_heap)
     169            _um_heap_unlock(_um_tiled_heap);
     170        if (_um_high_heap)
     171            _um_heap_unlock(_um_high_heap);
     172        if (_um_low_heap)
     173            _um_heap_unlock(_um_low_heap);
     174        gfForkCleanupDone = 1;
     175    }
     176    LIBCLOG_RETURN_VOID();
     177}
     178
  • trunk/src/emx/src/lib/malloc/irealloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    88#include <umalloc.h>
    99#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    10 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    11 #include <sys/rmutex.h>
     10#include <sys/fmutex.h>
    1211#include <emx/umalloc.h>
    1312
  • trunk/src/emx/src/lib/malloc/iwalk.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/malloc.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/mheap.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/msize.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/realloc.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/tcalloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/tfree.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/theapmin.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/tmalloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/trealloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/uaddmem.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/ucalloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/uclose.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
     
    1514      || h == _um_regular_heap || h == _um_tiled_heap)
    1615    return -1;
    17   _rmutex_close (&h->rsem);
     16  _fmutex_close (&h->fsem);
    1817  return 0;
    1918}
  • trunk/src/emx/src/lib/malloc/ucreate.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/ucreate2.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
     
    8180
    8281  /* Initialize the mutex semaphore. */
    83   if (_rmutex_create (&h->rsem, (type & _HEAP_SHARED) ? _FMC_SHARED : 0) != 0)
     82  if (_fmutex_create (&h->fsem, (type & _HEAP_SHARED) ? _FMC_SHARED : 0) != 0)
    8483    return NULL;
    8584
  • trunk/src/emx/src/lib/malloc/udefault.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/udestroy.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
     
    8988     decrements the open count to 0, destroying the semaphore. */
    9089
    91   _rmutex_close (&h->rsem);
     90  _fmutex_close (&h->fsem);
    9291  return 0;
    9392}
  • trunk/src/emx/src/lib/malloc/uheapchk.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/uheapmin.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    88#include <umalloc.h>
    99#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    10 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    11 #include <sys/rmutex.h>
     10#include <sys/fmutex.h>
    1211#include <emx/umalloc.h>
    1312
  • trunk/src/emx/src/lib/malloc/uheapset.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/umalloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/uopen.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
     
    1514      || h == _um_regular_heap || h == _um_tiled_heap)
    1615    return -1;
    17   if (_rmutex_open (&h->rsem) != 0)
     16  if (_fmutex_open (&h->fsem) != 0)
    1817    return -1;
    1918  return 0;
  • trunk/src/emx/src/lib/malloc/ustats.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/utcalloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/utdefaul.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110#include <InnoTekLIBC/thread.h>
  • trunk/src/emx/src/lib/malloc/utmalloc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    77#include <umalloc.h>
    88#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    9 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    10 #include <sys/rmutex.h>
     9#include <sys/fmutex.h>
    1110#include <emx/umalloc.h>
    1211
  • trunk/src/emx/src/lib/malloc/utype.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/uwalk.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/malloc/uwalk2.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    66#include <umalloc.h>
    77#include <sys/builtin.h>        /* For <sys/fmutex.h> */
    8 #include <sys/fmutex.h>         /* For <sys/rmutex.h> */
    9 #include <sys/rmutex.h>
     8#include <sys/fmutex.h>
    109#include <emx/umalloc.h>
    1110
  • trunk/src/emx/src/lib/mbyte/mblen.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    2323*/
    2424
    25 #define __INTERNAL_DEFS
    2625#include "libc-alias.h"
    2726#include <stdlib.h>
    28 #include <sys/locale.h>
     27#include <InnoTekLIBC/locale.h>
    2928
    3029int _STD(mblen) (const char *s, size_t n)
     
    3332  if (!n)
    3433    return -1;
    35   CHK_MBCS_PREFIX (__locale_ctype, *s, pl);
     34  CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *s, pl);
    3635  return pl ? pl : -1;
    3736}
  • trunk/src/emx/src/lib/mbyte/mbstowcs.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    2525#define INCL_FSMACROS
    2626#include <os2emx.h>
    27 #define __INTERNAL_DEFS
    2827#include "libc-alias.h"
    29 #include <sys/locale.h>
     28#include <InnoTekLIBC/locale.h>
    3029#include <stdlib.h>
    3130#include <string.h>
     
    3837
    3938  FS_SAVE_LOAD();
    40   rc = UniUconvToUcs (__locale_ctype.uconv, (void *)&s, &sl, &pwcs, &nw, &nonid);
     39  rc = UniUconvToUcs (__libc_GLocaleCtype.uobj, (void *)&s, &sl, &pwcs, &nw, &nonid);
    4140  FS_RESTORE();
    4241  if (rc)
  • trunk/src/emx/src/lib/mbyte/mbtowc.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1453 r1454  
    2727#define INCL_FSMACROS
    2828#include <os2emx.h>
    29 #define __INTERNAL_DEFS
    3029#include "libc-alias.h"
    31 #include <sys/locale.h>
     30#include <InnoTekLIBC/locale.h>
    3231#include <string.h>
    3332#include <stdlib.h>
     
    4342
    4443  FS_SAVE_LOAD();
    45   rc = UniUconvToUcs (__locale_ctype.uconv, (void *)&s, &ni, &pwc, &no, &nonid);
     44  rc = UniUconvToUcs (__libc_GLocaleCtype.uobj, (void *)&s, &ni, &pwc, &no, &nonid);
    4645  FS_RESTORE();
    4746
  • trunk/src/emx/src/lib/mbyte/wcstombs.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    2424#define INCL_FSMACROS
    2525#include <os2emx.h>
    26 #define __INTERNAL_DEFS
    2726#include "libc-alias.h"
    28 #include <sys/locale.h>
     27#include <InnoTekLIBC/locale.h>
    2928#include <string.h>
    3029#include <stdlib.h>
     
    3736
    3837  FS_SAVE_LOAD();
    39   rc = UniUconvFromUcs (__locale_ctype.uconv, (UniChar **)&pwcs, &sl, (void *)&s, &nw, &nonid);
     38  rc = UniUconvFromUcs (__libc_GLocaleCtype.uobj, (UniChar **)&pwcs, &sl, (void *)&s, &nw, &nonid);
    4039  FS_RESTORE();
    4140  if (rc)
  • trunk/src/emx/src/lib/mbyte/wctomb.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    1919#define INCL_FSMACROS
    2020#include <os2emx.h>
    21 #define __INTERNAL_DEFS
    2221#include "libc-alias.h"
    23 #include <sys/locale.h>
     22#include <InnoTekLIBC/locale.h>
    2423#include <stdlib.h>
    2524
     
    3534
    3635  FS_SAVE_LOAD();
    37   rc = UniUconvFromUcs (__locale_ctype.uconv, &ucs, &ni, (void **)&s, &no, &nonid);
     36  rc = UniUconvFromUcs (__libc_GLocaleCtype.uobj, &ucs, &ni, (void **)&s, &no, &nonid);
    3837  FS_RESTORE();
    3938  if (rc)
  • trunk/src/emx/src/lib/misc/abspath.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    11/* abspath.c (emx+gcc) -- Copyright (c) 1992-1998 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdlib.h>
     
    98#include <sys/param.h>
    109#include <emx/syscalls.h>
    11 #include <sys/locale.h>
     10#include <InnoTekLIBC/locale.h>
    1211
    1312#define FALSE   0
     
    7271          while (*s != 0)
    7372            {
    74               if (CHK_MBCS_PREFIX (__locale_ctype, *s, mbcl) && s[1] != 0)
     73              if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *s, mbcl) && s[1] != 0)
    7574                {
    7675                  if (i < sizeof (dir) - mbcl)
  • trunk/src/emx/src/lib/misc/defext.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    11/* defext.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdlib.h>
    65#include <string.h>
    7 #include <sys/locale.h>
     6#include <InnoTekLIBC/locale.h>
    87
    98#define FALSE   0
     
    1615  dot = FALSE; sep = TRUE;
    1716  while (*dst != 0)
    18     if (CHK_MBCS_PREFIX (__locale_ctype, *dst, mbcl))
     17    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *dst, mbcl))
    1918      {
    2019        if (dst[1] == 0)        /* Invalid DBCS character */
  • trunk/src/emx/src/lib/misc/fnmatch.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    11/* fnmatch.c (emx+gcc) -- Copyright (c) 1994-1998 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <string.h>
     5#include <emx/fnmatch.h>
     6#include <InnoTekLIBC/locale.h>
    67#include <ctype.h>
    7 #include <emx/fnmatch.h>
    8 #include <sys/locale.h>
    98
    109/* In OS/2 and DOS styles, both / and \ separate components of a path.
     
    3231
    3332  while (!IS_OS2_COMP_END (*src))
    34     if (CHK_MBCS_PREFIX (__locale_ctype, *src, mbcl) && src[1] != 0)
     33    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *src, mbcl) && src[1] != 0)
    3534      src += mbcl;
    3635    else
     
    5453    if (*p == ':')
    5554      return 1;
    56     else if (CHK_MBCS_PREFIX (__locale_ctype, p[0], mbcl) && p[1] != 0)
     55    else if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, p[0], mbcl) && p[1] != 0)
    5756      p += mbcl;
    5857    else
     
    7877
    7978  for (;;)
    80     if (CHK_MBCS_PREFIX (__locale_ctype, *mask, mbcl) && mask[1] != 0)
     79    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *mask, mbcl) && mask[1] != 0)
    8180      {
    8281        if (memicmp (mask, name, mbcl))
     
    125124          if (*name != '.' && !IS_OS2_COMP_END (*name))
    126125            {
    127               if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     126              if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, name[0], mbcl) && name[1] != 0)
    128127                name += mbcl;
    129128              else
     
    151150              if (*name == '.' && (flags & _FNM_STYLE_MASK) == _FNM_DOS)
    152151                return FNM_NOMATCH;
    153               if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     152              if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, name[0], mbcl) && name[1] != 0)
    154153                name += mbcl;
    155154              else
     
    212211      s = name;
    213212      while (!IS_OS2_COMP_END (*s) && *s != '.')
    214         if (CHK_MBCS_PREFIX (__locale_ctype, s[0], mbcl) && s[1] != 0)
     213        if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, s[0], mbcl) && s[1] != 0)
    215214          s += mbcl;
    216215        else
     
    252251
    253252  for (;;)
    254     if (CHK_MBCS_PREFIX (__locale_ctype, *mask, mbcl))
     253    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *mask, mbcl))
    255254      {
    256255        if (memicmp (mask, name, mbcl))
     
    287286            return FNM_NOMATCH;
    288287          ++mask;
    289           if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     288          if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, name[0], mbcl) && name[1] != 0)
    290289            name += mbcl;
    291290          else
     
    315314              if ((flags & FNM_PATHNAME) && IS_UNIX_COMP_SEP (*name))
    316315                return FNM_NOMATCH;
    317               if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     316              if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, name[0], mbcl) && name[1] != 0)
    318317                name += mbcl;
    319318              else
     
    365364              ++mask; invert = 1;
    366365            }
    367           else if (IS_MBCS_PREFIX (__locale_ctype, *name))
     366          else if (IS_MBCS_PREFIX (&__libc_GLocaleCtype, *name))
    368367            {
    369368              /* DBCS characters can only match inverted sets. */
     
    384383
    385384              c1 = *mask++;
    386               if (IS_MBCS_PREFIX (__locale_ctype, c1))
     385              if (IS_MBCS_PREFIX (&__libc_GLocaleCtype, c1))
    387386                return _FNM_ERR; /* DBCS characters not supported in sets */
    388387              if (!(flags & FNM_NOESCAPE) && c1 == '\\')
     
    406405                    break;
    407406                  c2 = *mask++;
    408                   if (IS_MBCS_PREFIX (__locale_ctype, c2))
     407                  if (IS_MBCS_PREFIX (&__libc_GLocaleCtype, c2))
    409408                    return _FNM_ERR; /* DBCS chars not supported in sets */
    410409                }
     
    439438              if (*name != 0)
    440439                {
    441                   if (CHK_MBCS_PREFIX (__locale_ctype, name[0], mbcl) && name[1] != 0)
     440                  if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, name[0], mbcl) && name[1] != 0)
    442441                    name += mbcl;
    443442                  else
     
    597596int _STD(fnmatch) (const char *mask, const char *name, int flags)
    598597{
    599   return _fnmatch_unsigned (mask, name, flags);
    600 }
     598  return _fnmatch_unsigned ((const unsigned char *)mask, (const unsigned char *)name, flags);
     599}
  • trunk/src/emx/src/lib/misc/fnslashi.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    11/* fnslashi.c (emx+gcc) -- Copyright (c) 1996 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdlib.h>
    6 #include <sys/locale.h>
     5#include <InnoTekLIBC/locale.h>
    76
    87char *_fnslashify (char *name)
     
    1312  p = name;
    1413  while (*p != 0)
    15     if (CHK_MBCS_PREFIX (__locale_ctype, *p, mbcl) && p[1] != 0)
     14    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *p, mbcl) && p[1] != 0)
    1615      p += mbcl;
    1716    else if (*p == '\\')
  • trunk/src/emx/src/lib/misc/getext.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    11/* getext.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdlib.h>
    65#include <string.h>
    7 #include <sys/locale.h>
     6#include <InnoTekLIBC/locale.h>
    87
    98#define FALSE   0
     
    1716  sep = TRUE; dotp = NULL;
    1817  while (*path != 0)
    19     if (CHK_MBCS_PREFIX (__locale_ctype, *path, mbcl))
     18    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *path, mbcl))
    2019      {
    2120        if (path[1] == 0)       /* Invalid DBCS character */
  • trunk/src/emx/src/lib/misc/getname.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    55#include <stdlib.h>
    66#include <string.h>
    7 #include <sys/locale.h>
     7#include <InnoTekLIBC/locale.h>
    88
    99char *_getname (const char *path)
     
    1414  p = path;
    1515  while (*path != 0)
    16     if (CHK_MBCS_PREFIX (__locale_ctype, *path, mbcl))
     16    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *path, mbcl))
    1717      {
    1818        if (path[1] == 0)       /* Invalid DBCS character */
  • trunk/src/emx/src/lib/misc/makepath.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    11/* makepath.c (emx+gcc) -- Copyright (c) 1993-1996 by Eberhard Mattes */
    22
    3 #define __INTERNAL_DEFS
    43#include "libc-alias.h"
    54#include <stdlib.h>
    6 #include <sys/locale.h>
     5#include <InnoTekLIBC/locale.h>
    76#include <string.h>
    87
     
    2423      while (n < _MAX_PATH - 1 && *dir != 0)
    2524        {
    26           if (CHK_MBCS_PREFIX (__locale_ctype, *dir, mbcl))
     25          if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *dir, mbcl))
    2726            {
    2827              if (dir[1] == 0)
  • trunk/src/emx/src/lib/misc/remext.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    55#include <stdlib.h>
    66#include <string.h>
    7 #include <sys/locale.h>
     7#include <InnoTekLIBC/locale.h>
    88
    99#define FALSE   0
     
    1717  dot = FALSE; sep = TRUE; dotp = NULL;
    1818  while (*path != 0)
    19     if (CHK_MBCS_PREFIX (__locale_ctype, *path, mbcl))
     19    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, *path, mbcl))
    2020      {
    2121        if (path[1] == 0)       /* Invalid DBCS character */
  • trunk/src/emx/src/lib/misc/splitpat.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    66#include <string.h>
    77#include <sys/param.h>
    8 #include <sys/locale.h>
     8#include <InnoTekLIBC/locale.h>
    99
    1010void _splitpath (const char *src, char *drive, char *dir, char *fname,
     
    1515  i = 0;
    1616  while (src[i] != 0)
    17     if (CHK_MBCS_PREFIX (__locale_ctype, src[i], mbcl))
     17    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, src[i], mbcl))
    1818      {
    1919        if (src[i+1] == 0)      /* Invalid DBCS character */
     
    3434  else if (drive != NULL)
    3535    *drive = 0;
    36  
     36
    3737  i = 0; j = 0;
    3838  while (src[j] != 0)
    39     if (CHK_MBCS_PREFIX (__locale_ctype, src[j], mbcl))
     39    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, src[j], mbcl))
    4040      {
    4141        if (src[j+1] == 0)      /* Invalid DBCS character */
     
    5151    _strncpy (dir, src, MIN (_MAX_DIR, i + 1));
    5252  src += i;
    53  
     53
    5454  i = 0; j = 0;
    5555  while (src[j] != 0)
    56     if (CHK_MBCS_PREFIX (__locale_ctype, src[j], mbcl))
     56    if (CHK_MBCS_PREFIX (&__libc_GLocaleCtype, src[j], mbcl))
    5757      {
    5858        if (src[j+1] == 0)      /* Invalid DBCS character */
     
    7070    _strncpy (fname, src, MIN (_MAX_FNAME, i + 1));
    7171  src += i;
    72  
     72
    7373  if (ext != NULL)
    7474    _strncpy (ext, src, _MAX_EXT);
  • trunk/src/emx/src/lib/misc/syserr.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    4242  /* 35 EAGAIN         */ "Resource temporarily unavailable",
    4343  /* 36 EINPROGRESS    */ "Operation now in progress",
    44   /* 37 EALREADY       */ "Operation already in progress"
     44  /* 37 EALREADY       */ "Operation already in progress",
    4545  /* 38 ENOTSOCK       */ "Socket operation on non-socket",
    4646  /* 39 EDESTADDRREQ   */ "Destination address required",
  • trunk/src/emx/src/lib/process/386/_errno.s

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    66        .globl  __errno_fun
    77
     8    .data
     9initterm_errno:
     10    .long  0
     11
    812        .text
    9 
    1013        ALIGN
    1114
     
    1316__errno_fun:
    1417    movl    ___libc_gpTLS, %eax
     18    orl     %eax, %eax
     19    jnz     ok
     20
     21    /* ignore calls before TLS inits. (fork registration failure) */
     22    movl    $initterm_errno, %eax
     23    jmp     done
     24    ALIGN
     25ok:
    1526    movl    (%eax), %eax
    1627    orl     %eax, %eax
    1728    jnz     done
    1829    call    ___libc_threadCurrentSlow
     30    jmp     done
     31
     32    ALIGN
    1933done:
    2034        EPILOGUE(_errno)
  • trunk/src/emx/src/lib/process/fmutex.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    66#define INCL_DOSERRORS
    77#define INCL_FSMACROS
     8#define INCL_EXAPIS
    89#include <os2.h>
    910#include <stdlib.h>
     
    1415#include <InnoTekLIBC/logstrict.h>
    1516
     17
    1618/* These functions are available even in single-thread libraries. */
    1719
     
    1921unsigned _fmutex_create(_fmutex *sem, unsigned flags)
    2022{
    21     LIBCLOG_ENTER("sem=%p flags=%#x\n", sem, flags);
     23    LIBCLOG_ENTER("sem=%p flags=%#x\n", (void *)sem, flags);
    2224    unsigned rc;
    23     FS_VAR();
     25
    2426    sem->fs         = _FMS_AVAILABLE;
    2527    sem->flags      = flags;
    2628    sem->padding[0] = 'f';
    2729    sem->padding[1] = 'm';
    28     FS_SAVE_LOAD();
    29     rc = DosCreateEventSem(NULL, (PHEV)&sem->hev,
    30                            (flags & _FMC_SHARED) ? DC_SEM_SHARED : 0,
    31                            FALSE);
    32     FS_RESTORE();
     30    rc = DosCreateEventSemEx(NULL, (PHEV)&sem->hev,
     31                             (flags & _FMC_SHARED) ? DC_SEM_SHARED : 0,
     32                             FALSE);
     33
    3334    LIBCLOG_RETURN_UINT(rc);
    3435}
     
    3738unsigned _fmutex_open(_fmutex *sem)
    3839{
    39     LIBCLOG_ENTER("sem=%p\n", sem);
    40     unsigned rc;
    41     FS_VAR();
    42     FS_SAVE_LOAD();
    43     rc = DosOpenEventSem(NULL, (PHEV)&sem->hev);
    44     FS_RESTORE();
     40    LIBCLOG_ENTER("sem=%p\n", (void *)sem);
     41    unsigned rc = DosOpenEventSemEx(NULL, (PHEV)&sem->hev);
    4542    LIBCLOG_RETURN_UINT(rc);
    4643}
     
    4946unsigned _fmutex_close(_fmutex *sem)
    5047{
    51     LIBCLOG_ENTER("sem=%p\n", sem);
    52     unsigned rc;
    53     FS_VAR();
    54     FS_SAVE_LOAD();
    55     rc = DosCloseEventSem(sem->hev);
    56     FS_RESTORE();
     48    LIBCLOG_ENTER("sem=%p\n", (void *)sem);
     49    unsigned rc = DosCloseEventSemEx(sem->hev);
    5750    LIBCLOG_RETURN_UINT(rc);
    5851}
     
    6154unsigned __fmutex_request_internal(_fmutex *sem, unsigned flags, signed char fs)
    6255{
    63     LIBCLOG_ENTER("sem=%p flags=%#x fs=%#x\n", sem, flags, (int)fs);
    64     ULONG rc, count;
    65     PTIB  pTib;
    66     PPIB  pPib;
     56    LIBCLOG_ENTER("sem=%p flags=%#x fs=%#x\n", (void *)sem, flags, (int)fs);
     57    int     rc;
     58    PTIB    pTib;
     59    PPIB    pPib;
    6760
    6861    if (fs == _FMS_UNINIT)
     
    8477    for (;;)
    8578    {
     79        ULONG ulCount;
    8680        FS_VAR();
    8781        FS_SAVE_LOAD();
    88         rc = DosResetEventSem(sem->hev, &count);
     82        rc = DosResetEventSem(sem->hev, &ulCount);
    8983        FS_RESTORE();
    9084        if (rc != 0 && rc != ERROR_ALREADY_RESET)
     
    9690        do
    9791        {
    98             rc = DosWaitEventSem (sem->hev, sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000);
     92            rc = DosWaitEventSem(sem->hev, sem->flags & _FMC_SHARED ? SEM_INDEFINITE_WAIT : 3000);
    9993            if (rc == ERROR_INTERRUPT)
    10094            {
     
    146140unsigned __fmutex_release_internal(_fmutex *sem)
    147141{
    148     LIBCLOG_ENTER("sem=%p\n", sem);
    149     ULONG rc;
     142    LIBCLOG_ENTER("sem=%p\n", (void *)sem);
     143    unsigned rc;
    150144    FS_VAR();
    151145
     
    209203void _fmutex_dummy(_fmutex *sem)
    210204{
    211     LIBCLOG_ENTER("sem=%p\n", sem);
     205    LIBCLOG_ENTER("sem=%p\n", (void *)sem);
    212206    sem->fs  = _FMS_AVAILABLE;
    213207    sem->hev = 0;
  • trunk/src/emx/src/lib/process/fork.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    44#include <process.h>
    55#include <emx/syscalls.h>
    6 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS
     6#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_FORK
    77#include <InnoTekLIBC/logstrict.h>
    8 
    9 extern void _rmutex_fork(void);
    108
    119int _STD(fork)(void)
     
    1311    LIBCLOG_ENTER("\n");
    1412    int pid = __fork();
    15     if (pid == 0)
    16         _rmutex_fork();
    1713    LIBCLOG_RETURN_INT(pid);
    1814}
  • trunk/src/emx/src/lib/startup/386/crt0.s

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1453 r1454  
    3232#include <emx/asm386.h>
    3333
    34         .globl  __text
    35         .globl  __data
     34    .globl  __text
     35    .globl  __data
    3636
    37         .text
     37    .text
    3838
    3939__text:
     40
     41#if defined (FORK)
     42    /* Registering the fork module. If we're forking this call will not return. */
     43    pushl   $1
     44    pushl   $ForkModule
     45    call    ___libc_ForkRegisterModule
     46    addl    $8, %esp
     47#endif
    4048#if defined (HIGHMEM)
    4149    pushl    $1     /* vote for high mem for default stack */
     
    4351    pushl    $0     /* veto agains high mem for default stack */
    4452#endif
    45         call    ___init_app
     53    call    ___init_app
    4654    /* esp points to main() call frame. */
    47         cld
     55    cld
    4856#if defined (MCRT0)
    49         pushl   $__mcleanup
    50         call    _atexit
    51         pushl   $__etext
    52         pushl   $__text
    53         call    _monstartup
    54         addl    $3*4, %esp
     57    pushl   $__mcleanup
     58    call    _atexit
     59    pushl   $__etext
     60    pushl   $__text
     61    call    _monstartup
     62    addl    $3*4, %esp
    5563#endif
    56         call    __CRT_init
    57         call    _main
    58         addl    $3*4, %esp
    59         pushl   %eax
    60         call    _exit
    61 1:      jmp     1b              /* Just in case exit() returns :-) */
     64    call    __CRT_init
     65    call    _main
     66    addl    $3*4, %esp
     67do_exit:
     68    pushl   %eax
     69    call    _exit
     701:  jmp     1b      /* Just in case exit() returns :-) */
    6271
    6372
    64         .data
     73    .data
    6574
    6675__data:
    67         .long   0xba0bab        // Magic number (error detection)
    68         .long   __os2dll        // list of OS/2 DLL references
     76    .long   0xba0bab    // Magic number (error detection)
     77    .long   __os2dll    // list of OS/2 DLL references
    6978
    70         .stabs  "__os2dll", 21, 0, 0, 0xffffffff
    71         .stabs  "___CTOR_LIST__", 21, 0, 0, 0xffffffff
    72         .stabs  "___DTOR_LIST__", 21, 0, 0, 0xffffffff
    73         .stabs  "___crtinit1__", 21, 0, 0, 0xffffffff
    74         .stabs  "___crtexit1__", 21, 0, 0, 0xffffffff
    75         .stabs  "___eh_frame__", 21, 0, 0, 0xffffffff
    76         .stabs  "___eh_init__", 21, 0, 0, 0xffffffff
    77         .stabs  "___eh_term__", 21, 0, 0, 0xffffffff
     79    .stabs  "__os2dll", 21, 0, 0, 0xffffffff
     80    .stabs  "___CTOR_LIST__", 21, 0, 0, 0xffffffff
     81    .stabs  "___DTOR_LIST__", 21, 0, 0, 0xffffffff
     82    .stabs  "___crtinit1__", 21, 0, 0, 0xffffffff
     83    .stabs  "___crtexit1__", 21, 0, 0, 0xffffffff
     84    .stabs  "___eh_frame__", 21, 0, 0, 0xffffffff
     85    .stabs  "___eh_init__", 21, 0, 0, 0xffffffff
     86    .stabs  "___eh_term__", 21, 0, 0, 0xffffffff
    7887
     88#if defined (FORK)
     89    .stabs "___fork_parent1__", 21, 0, 0, 0xffffffff
     90    .stabs "___fork_child1__", 21, 0, 0, 0xffffffff
     91
     92ForkModule:
     93    .long  0x00010000                   // uVersion
     94    .long  __atfork_callback            // pfnAtFork
     95    .long  ___fork_parent1__            // papParent1
     96    .long  ___fork_child1__             // papChild1
     97    .long  __data                       // pvDataSegBase
     98    .long  _end                         // pvDataSegEnd
     99    .long  0x00000001                   // fFlags - __LIBC_FORKMODULE_FLAGS_EXECUTABLE
     100    .long  0                            // pNext
     101    .long  0                            // uReserved[8]
     102    .long  0                            // uReserved[8]
     103    .long  0                            // uReserved[8]
     104    .long  0                            // uReserved[8]
     105    .long  0                            // uReserved[8]
     106    .long  0                            // uReserved[8]
     107    .long  0                            // uReserved[8]
     108    .long  0                            // uReserved[8]
     109#endif
     110
  • trunk/src/emx/src/lib/startup/386/dll0.s

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r1453 r1454  
    3030#include <emx/asm386.h>
    3131
    32         .globl  __text
    33         .globl  __data
     32    .globl  __text
     33    .globl  __data
    3434
    35         .text
     35    .text
    3636
    3737__text:
     
    4444     */
    4545do_common_init:
     46#if defined(FORK)
     47    pushl   $0
     48    pushl   $ForkModule
     49    call    ___libc_ForkRegisterModule
     50    addl    $8, %esp
     51    cmpl    $0, %eax
     52    je      do_init
     53    jg      do_fork
     54
     55    /* return failure (eax < 0). */
     56    xorl    %eax, %eax
     57    ret
     58
     59    /* return success - we're forking; no init. */
     60do_fork:
     61    xorl    %eax, %eax
     62    inc     %al
     63    ret
     64
     65    /* normal dll init. */
     66do_init:
     67#endif
    4668#if defined (HIGHMEM)
    4769    pushl    $1     /* vote for high mem for default stack */
     
    4971    pushl    $0     /* veto against high mem for default stack */
    5072#endif
    51         call    ___init_dll
     73    call    ___init_dll
    5274    add     $4, %esp
    5375    orl     %eax, %eax
     
    6385     */
    6486do_initterm:
    65         cld
     87    cld
    6688    jmp     _DLL_InitTerm
    6789
    6890
    69         .data
     91    .data
    7092__data:
    71         .long   0xba0bab        // Magic number (error detection)
    72         .long   __os2dll        // list of OS/2 DLL references
     93    .long   0xba0bab    // Magic number (error detection)
     94    .long   __os2dll    // list of OS/2 DLL references
    7395
    74         .stabs  "__os2dll", 21, 0, 0, 0xffffffff
    75         .stabs  "___CTOR_LIST__", 21, 0, 0, 0xffffffff
    76         .stabs  "___DTOR_LIST__", 21, 0, 0, 0xffffffff
    77         .stabs  "___crtinit1__", 21, 0, 0, 0xffffffff
    78         .stabs  "___crtexit1__", 21, 0, 0, 0xffffffff
    79         .stabs  "___eh_frame__", 21, 0, 0, 0xffffffff
    80         .stabs  "___eh_init__", 21, 0, 0, 0xffffffff
    81         .stabs  "___eh_term__", 21, 0, 0, 0xffffffff
     96    .stabs  "__os2dll", 21, 0, 0, 0xffffffff
     97    .stabs  "___CTOR_LIST__", 21, 0, 0, 0xffffffff
     98    .stabs  "___DTOR_LIST__", 21, 0, 0, 0xffffffff
     99    .stabs  "___crtinit1__", 21, 0, 0, 0xffffffff
     100    .stabs  "___crtexit1__", 21, 0, 0, 0xffffffff
     101    .stabs  "___eh_frame__", 21, 0, 0, 0xffffffff
     102    .stabs  "___eh_init__", 21, 0, 0, 0xffffffff
     103    .stabs  "___eh_term__", 21, 0, 0, 0xffffffff
     104#if defined (FORK)
     105    .stabs  "___fork_parent1__", 21, 0, 0, 0xffffffff
     106    .stabs  "___fork_child1__", 21, 0, 0, 0xffffffff
    82107
     108ForkModule:
     109    .long  0x00010000                   // uVersion
     110    .long  __atfork_callback            // pfnAtFork
     111    .long  ___fork_parent1__            // papParent1
     112    .long  ___fork_child1__             // papChild1
     113    .long  __data                       // pvDataSegBase
     114    .long  _end                         // pvDataSegEnd
     115    .long  0                            // fFlags
     116    .long  0                            // pNext
     117    .long  0                            // uReserved[8]
     118    .long  0                            // uReserved[8]
     119    .long  0                            // uReserved[8]
     120    .long  0                            // uReserved[8]
     121    .long  0                            // uReserved[8]
     122    .long  0                            // uReserved[8]
     123    .long  0                            // uReserved[8]
     124    .long  0                            // uReserved[8]
     125#endif
     126
  • trunk/src/emx/src/lib/startup/_exit.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    55
    66/* mkstd.awk: NOUNDERSCORE(exit) */
    7 void _exit (int ret)
     7void _exit(int ret)
    88{
    9   if (ret < 0 || ret > 255)
    10     ret = 255;
    11   for (;;)
    12     __exit (ret);
     9    for (;;)
     10        __exit(ret);
    1311}
  • trunk/src/emx/src/lib/startup/startup.smak

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1453 r1454  
    99include common.smak
    1010
    11 .OBJS += $(addprefix $.$(.TKIND.DIR)src/lib/startup/,mcrt0.o gcrt0.o crt0hi.o dll0hi.o) \
     11.OBJS += $(addprefix $.$(.TKIND.DIR)src/lib/startup/,mcrt0.o gcrt0.o crt0fork.o dll0fork.o crt0hi.o dll0hi.o crt0hifork.o dll0hifork.o) \
    1212  $(addprefix $.omf/src/lib/startup/,mcrt0.obj gcrt0.obj \
    13   $(CPU)/crt0.obj $(CPU)/dll0.obj crt0hi.obj dll0hi.obj)
     13  $(CPU)/crt0.obj $(CPU)/dll0.obj crt0fork.obj dll0fork.obj crt0hi.obj dll0hi.obj crt0hifork.obj dll0hifork.obj)
    1414.DIRS := $(sort $(dir $(.OBJS)))
    1515TARGDIRS += $(.DIRS)
     
    2121        $(call CP,$^,$(dir $@))
    2222
     23$.aout/src/lib/startup/crt0fork.o: src/lib/startup/386/crt0.s
     24        $(call DO.COMPILE.s, -DFORK)
     25       
     26$.aout/src/lib/startup/dll0fork.o: src/lib/startup/386/dll0.s
     27        $(call DO.COMPILE.s, -DFORK)
     28
    2329$.aout/src/lib/startup/crt0hi.o: src/lib/startup/386/crt0.s
    2430        $(call DO.COMPILE.s, -DHIGHMEM)
     
    2632$.aout/src/lib/startup/dll0hi.o: src/lib/startup/386/dll0.s
    2733        $(call DO.COMPILE.s, -DHIGHMEM)
     34
     35$.aout/src/lib/startup/crt0hifork.o: src/lib/startup/386/crt0.s
     36        $(call DO.COMPILE.s, -DHIGHMEM -DFORK)
     37       
     38$.aout/src/lib/startup/dll0hifork.o: src/lib/startup/386/dll0.s
     39        $(call DO.COMPILE.s, -DHIGHMEM -DFORK)
     40
    2841                               
    2942$.aout/src/lib/startup/mcrt0.o: src/lib/startup/386/crt0.s
     
    4659$.omf/src/lib/startup/gcrt0.obj: $.aout/src/lib/startup/gcrt0.o
    4760        $(call DO.EMXOMF,-m__text)
     61$.omf/src/lib/startup/dll0fork.obj: $.aout/src/lib/startup/dll0fork.o
     62        $(call DO.EMXOMF,-l__text)
     63$.omf/src/lib/startup/crt0fork.obj: $.aout/src/lib/startup/crt0fork.o
     64        $(call DO.EMXOMF,-m__text)
    4865$.omf/src/lib/startup/dll0hi.obj: $.aout/src/lib/startup/dll0hi.o
    4966        $(call DO.EMXOMF,-l__text)
    5067$.omf/src/lib/startup/crt0hi.obj: $.aout/src/lib/startup/crt0hi.o
     68        $(call DO.EMXOMF,-m__text)
     69$.omf/src/lib/startup/dll0hifork.obj: $.aout/src/lib/startup/dll0hifork.o
     70        $(call DO.EMXOMF,-l__text)
     71$.omf/src/lib/startup/crt0hifork.obj: $.aout/src/lib/startup/crt0hifork.o
    5172        $(call DO.EMXOMF,-m__text)
    5273$.omf/src/lib/startup/386/dll0.obj: $.aout/src/lib/startup/386/dll0.o
  • trunk/src/emx/src/lib/str/memicmp.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1453 r1454  
    1010#define INCL_FSMACROS
    1111#include <os2emx.h>
    12 #define __INTERNAL_DEFS
    1312#include "libc-alias.h"
    14 #include <sys/locale.h>
     13#include <InnoTekLIBC/locale.h>
    1514#include <stddef.h>
    1615#include <string.h>
     
    2827  c1 = *s1; c2 = *s2;
    2928
    30   if (__locale_ctype.mbcs)
     29  if (__libc_GLocaleCtype.mbcs)
    3130  {
    3231    FS_VAR();
     
    3736      int d;
    3837
    39       if (IS_MBCS_PREFIX (__locale_ctype, c1)
    40        || IS_MBCS_PREFIX (__locale_ctype, c2))
     38      if (IS_MBCS_PREFIX (&__libc_GLocaleCtype, c1)
     39       || IS_MBCS_PREFIX (&__libc_GLocaleCtype, c2))
    4140      {
    4241        /* Translate unknown characters to Unicode, and compare them...
     
    4544        UniChar uc1, uc2;
    4645        int c1l, c2l;
    47         if (!(c1l = __to_ucs (__locale_ctype.uconv, s1, len, &uc1)))
     46        if (!(c1l = __libc_ucs2To (__libc_GLocaleCtype.uobj, s1, len, &uc1)))
    4847          uc1 = c1, c1l = 1;
    4948        else
    50           uc1 = UniTransLower (__locale_ctype.locale, uc1);
    51         if (!(c2l = __to_ucs (__locale_ctype.uconv, s2, len, &uc2)))
     49          uc1 = UniTransLower (__libc_GLocaleCtype.lobj, uc1);
     50        if (!(c2l = __libc_ucs2To (__libc_GLocaleCtype.uobj, s2, len, &uc2)))
    5251          uc2 = c2, c2l = 1;
    5352        else
    54           uc2 = UniTransLower (__locale_ctype.locale, uc2);
     53          uc2 = UniTransLower (__libc_GLocaleCtype.lobj, uc2);
    5554        d = uc1 - uc2;
    5655        c1l--; c2l--;
     
    5958      }
    6059      else
    61         d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     60        d = __libc_GLocaleCtype.auchLower [c1] - __libc_GLocaleCtype.auchLower [c2];
    6261      if (d)
    6362        {
     
    7978    for (;;)
    8079    {
    81       int d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     80      int d = __libc_GLocaleCtype.auchLower [c1] - __libc_GLocaleCtype.auchLower [c2];
    8281      if (d)
    8382        return d;
  • trunk/src/emx/src/lib/str/strcoll.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    1212#define INCL_FSMACROS
    1313#include <os2emx.h>
    14 #define __INTERNAL_DEFS
    1514#include "libc-alias.h"
    16 #include <sys/locale.h>
     15#include <InnoTekLIBC/locale.h>
    1716#include <alloca.h>
    1817#include <string.h>
     
    2423  unsigned char c2 = *s2;
    2524
    26   if (__locale_collate.mbcs)
     25  if (__libc_gLocaleCollate.mbcs)
    2726  {
    2827    FS_VAR();
     
    3332    for (;;)
    3433    {
    35       if (IS_MBCS_PREFIX (__locale_collate, c1)
    36        || IS_MBCS_PREFIX (__locale_collate, c2))
     34      if (IS_MBCS_PREFIX (&__libc_gLocaleCollate, c1)
     35       || IS_MBCS_PREFIX (&__libc_gLocaleCollate, c2))
    3736      {
    3837        /* Allright, we found a MBCS character. */
     
    4948          UniChar *outbuf = ucs [i] = alloca (sl * sizeof (UniChar));
    5049
    51           if (UniUconvToUcs (__locale_collate.uconv, &inbuf, &in_left, &outbuf,
     50          if (UniUconvToUcs (__libc_gLocaleCollate.uobj, &inbuf, &in_left, &outbuf,
    5251                &out_left, &nonid))
    5352          {
     
    6059
    6160        /* Okay, now we have two Unicode strings. Compare them. */
    62         d = UniStrcoll (__locale_collate.locale, ucs [0], ucs [1]);
     61        d = UniStrcoll (__libc_gLocaleCollate.lobj, ucs [0], ucs [1]);
    6362        FS_RESTORE();
    6463        return d;
    6564      }
    6665
    67       d = __locale_collate.weight [c1] - __locale_collate.weight [c2];
     66      d = __libc_gLocaleCollate.auchWeight [c1] - __libc_gLocaleCollate.auchWeight [c2];
    6867      if (d || !c1 || !c2)
    6968      {
     
    8079    for (;;)
    8180    {
    82       d = __locale_collate.weight [c1] - __locale_collate.weight [c2];
     81      d = __libc_gLocaleCollate.auchWeight [c1] - __libc_gLocaleCollate.auchWeight [c2];
    8382      if (d || !c1 || !c2)
    8483        return d;
  • trunk/src/emx/src/lib/str/stricmp.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    1010#define INCL_FSMACROS
    1111#include <os2emx.h>
    12 #define __INTERNAL_DEFS
    1312#include "libc-alias.h"
    14 #include <sys/locale.h>
     13#include <InnoTekLIBC/locale.h>
    1514#include <alloca.h>
     15#ifndef __USE_GNU /* __strnlen */
     16# define __USE_GNU
     17#endif
    1618#include <string.h>
    17 
    18 static int __strnlen (const char *s, int maxlen)
    19 {
    20   int sl = 0;
    21   while (*s++ && maxlen--)
    22     sl++;
    23   return sl;
    24 }
    2519
    2620int _STD(stricmp) (__const__ char *s1, __const__ char *s2)
     
    2923  unsigned char c2 = *s2;
    3024
    31   if (__locale_ctype.mbcs)
     25  if (__libc_GLocaleCtype.mbcs)
    3226  {
    3327    FS_VAR();
     
    3832      int d;
    3933
    40       if (IS_MBCS_PREFIX (__locale_ctype, c1)
    41        || IS_MBCS_PREFIX (__locale_ctype, c2))
     34      if (IS_MBCS_PREFIX (&__libc_GLocaleCtype, c1)
     35       || IS_MBCS_PREFIX (&__libc_GLocaleCtype, c2))
    4236      {
    4337        /* Translate unknown characters to Unicode, and compare them...
     
    4640        UniChar uc1, uc2;
    4741        int c1l, c2l;
    48         if (!(c1l = __to_ucs (__locale_ctype.uconv, s1, __strnlen (s1, 3), &uc1)))
     42        if (!(c1l = __libc_ucs2To (__libc_GLocaleCtype.uobj, (const unsigned char *)s1, __strnlen (s1, 3), &uc1)))
    4943          uc1 = c1, c1l = 1;
    5044        else
    51           uc1 = UniTransLower (__locale_ctype.locale, uc1);
    52         if (!(c2l = __to_ucs (__locale_ctype.uconv, s2, __strnlen (s2, 3), &uc2)))
     45          uc1 = UniTransLower (__libc_GLocaleCtype.lobj, uc1);
     46        if (!(c2l = __libc_ucs2To (__libc_GLocaleCtype.uobj, (const unsigned char *)s2, __strnlen (s2, 3), &uc2)))
    5347          uc2 = c2, c2l = 1;
    5448        else
    55           uc2 = UniTransLower (__locale_ctype.locale, uc2);
     49          uc2 = UniTransLower (__libc_GLocaleCtype.lobj, uc2);
    5650        d = uc1 - uc2;
    5751        s1 += c1l - 1;
     
    5953      }
    6054      else
    61         d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     55        d = __libc_GLocaleCtype.auchLower [c1] - __libc_GLocaleCtype.auchLower [c2];
    6256
    6357      if (d || !c1 || !c2)
     
    7569    for (;;)
    7670    {
    77       int d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     71      int d = __libc_GLocaleCtype.auchLower [c1] - __libc_GLocaleCtype.auchLower [c2];
    7872      if (d || !c1 || !c2)
    7973        return d;
  • trunk/src/emx/src/lib/str/strlwr.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    1010#define INCL_FSMACROS
    1111#include <os2emx.h>
    12 #define __INTERNAL_DEFS
    1312#include "libc-alias.h"
    14 #include <sys/locale.h>
     13#include <InnoTekLIBC/locale.h>
    1514#include <string.h>
    1615
     
    2019  (void)arg;
    2120  for (c = ucs; *c; c++)
    22     *c = UniTransLower (__locale_ctype.locale, *c);
     21    *c = UniTransLower (__libc_GLocaleCtype.lobj, *c);
    2322  return 1;
    2423}
     
    2928  unsigned char *s = (unsigned char *)string;
    3029
    31   if (__locale_ctype.mbcs)
     30  if (__libc_GLocaleCtype.mbcs)
    3231  {
    3332    while ((c = *s))
    3433    {
    35       if (IS_MBCS_PREFIX (__locale_ctype, c))
     34      if (IS_MBCS_PREFIX (&__libc_GLocaleCtype, c))
    3635      {
    37         /* Allright, we encountered a MBCS character. Convert everything
     36        /* Alright, we encountered a MBCS character. Convert everything
    3837           until the end to Unicode, do the work in Unicode and then
    3938           convert back to MBCS. */
    4039        FS_VAR();
    4140        FS_SAVE_LOAD();
    42         __do_Unicode (__locale_ctype.uconv, s, s, __uni_strlwr);
     41        __libc_ucs2Do (__libc_GLocaleCtype.uobj, (char *)s, s, __uni_strlwr);
    4342        FS_RESTORE();
    4443        break;
    4544      }
    46       *s++ = __locale_ctype.locase [c];
     45      *s++ = __libc_GLocaleCtype.auchLower [c];
    4746    }
    4847  }
    4948  else
    5049    while ((c = *s))
    51       *s++ = __locale_ctype.locase [c];
     50      *s++ = __libc_GLocaleCtype.auchLower [c];
    5251
    5352  return string;
  • trunk/src/emx/src/lib/str/strnicmp.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1453 r1454  
    1111#define INCL_FSMACROS
    1212#include <os2emx.h>
    13 #define __INTERNAL_DEFS
    1413#include "libc-alias.h"
    1514#include <stddef.h>
    16 #include <sys/locale.h>
    1715#include <string.h>
     16#include <InnoTekLIBC/locale.h>
     17
    1818
    1919int _STD(strnicmp) (__const__ char *s1, __const__ char *s2, size_t len)
     
    2727  c1 = *s1; c2 = *s2;
    2828
    29   if (__locale_ctype.mbcs)
     29  if (__libc_GLocaleCtype.mbcs)
    3030  {
    3131    FS_VAR();
     
    3636      int d;
    3737
    38       if (IS_MBCS_PREFIX (__locale_ctype, c1)
    39        || IS_MBCS_PREFIX (__locale_ctype, c2))
     38      if (IS_MBCS_PREFIX (&__libc_GLocaleCtype, c1)
     39       || IS_MBCS_PREFIX (&__libc_GLocaleCtype, c2))
    4040      {
    4141        /* Translate unknown characters to Unicode, and compare them...
     
    4444        UniChar uc1, uc2;
    4545        int c1l, c2l;
    46         if (!(c1l = __to_ucs (__locale_ctype.uconv, s1, len, &uc1)))
     46        if (!(c1l = __libc_ucs2To (__libc_GLocaleCtype.uobj, (const unsigned char *)s1, len, &uc1)))
    4747          uc1 = c1, c1l = 1;
    4848        else
    49           uc1 = UniTransLower (__locale_ctype.locale, uc1);
    50         if (!(c2l = __to_ucs (__locale_ctype.uconv, s2, len, &uc2)))
     49          uc1 = UniTransLower (__libc_GLocaleCtype.lobj, uc1);
     50        if (!(c2l = __libc_ucs2To (__libc_GLocaleCtype.uobj, (const unsigned char *)s2, len, &uc2)))
    5151          uc2 = c2, c2l = 1;
    5252        else
    53           uc2 = UniTransLower (__locale_ctype.locale, uc2);
     53          uc2 = UniTransLower (__libc_GLocaleCtype.lobj, uc2);
    5454        d = uc1 - uc2;
    5555        c1l--; c2l--;
     
    5858      }
    5959      else
    60         d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     60        d = __libc_GLocaleCtype.auchLower [c1] - __libc_GLocaleCtype.auchLower [c2];
    6161      if (d || !c1 || !c2)
    6262      {
     
    7878    for (;;)
    7979    {
    80       int d = __locale_ctype.locase [c1] - __locale_ctype.locase [c2];
     80      int d = __libc_GLocaleCtype.auchLower [c1] - __libc_GLocaleCtype.auchLower [c2];
    8181      if (d || !c1 || !c2)
    8282        return d;
  • trunk/src/emx/src/lib/str/strupr.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1453 r1454  
    1010#define INCL_FSMACROS
    1111#include <os2emx.h>
    12 #define __INTERNAL_DEFS
    1312#include "libc-alias.h"
    14 #include <sys/locale.h>
     13#include <InnoTekLIBC/locale.h>
    1514#include <string.h>
    1615
     
    2019  (void)arg;
    2120  for (c = ucs; *c; c++)
    22     *c = UniTransUpper (__locale_ctype.locale, *c);
     21    *c = UniTransUpper (__libc_GLocaleCtype.lobj, *c);
    2322  return 1;
    2423}
     
    2928  unsigned char *s = (unsigned char *)string;
    3029
    31   if (__locale_ctype.mbcs)
     30  if (__libc_GLocaleCtype.mbcs)
    3231  {
    3332    while ((c = *s))
    3433    {
    35       if (IS_MBCS_PREFIX (__locale_ctype, c))
     34      if (IS_MBCS_PREFIX (&__libc_GLocaleCtype, c))
    3635      {
    3736        /* Allright, we encountered a MBCS character. Convert everything
     
    4039        FS_VAR();
    4140        FS_SAVE_LOAD();
    42         __do_Unicode (__locale_ctype.uconv, s, s, __uni_strupr);
     41        __libc_ucs2Do (__libc_GLocaleCtype.uobj, (char *)s, s, __uni_strupr);
    4342        FS_RESTORE();
    4443        break;
    4544      }
    46       *s++ = __locale_ctype.upcase [c];
     45      *s++ = __libc_GLocaleCtype.auchUpper [c];
    4746    }
    4847  }
    4948  else
    5049    while ((c = *s))
    51       *s++ = __locale_ctype.upcase [c];
     50      *s++ = __libc_GLocaleCtype.auchUpper [c];
    5251
    5352  return string;
  • trunk/src/emx/src/lib/str/strxfrm.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    1212#define INCL_FSMACROS
    1313#include <os2emx.h>
    14 #define __INTERNAL_DEFS
    1514#include "libc-alias.h"
    16 #include <sys/locale.h>
     15#include <InnoTekLIBC/locale.h>
    1716#include <stddef.h>
    1817#include <string.h>
     
    4039   */
    4140
    42   size_t rs = UniStrxfrm (__locale_collate.locale, (UniChar *)x->out,
     41  size_t rs = UniStrxfrm (__libc_gLocaleCollate.lobj, (UniChar *)x->out,
    4342    ucs, x->size);
    4443  /* rs is in UniChar's without trailing zero */
     
    6968  size_t ret = 1; /* We need at least space for trailing zero */
    7069
    71   if (__locale_collate.mbcs)
     70  if (__libc_gLocaleCollate.mbcs)
    7271  {
    7372    /* When using MBCS codepaes, we will convert the entire string to
     
    8180    x.out = s1;
    8281    x.size = size / sizeof (UniChar);
    83     __do_Unicode (__locale_collate.uconv, (char *)s2, &x, __uni_strxfrm);
     82    __libc_ucs2Do (__libc_gLocaleCollate.uobj, (char *)s2, &x, __uni_strxfrm);
    8483    FS_RESTORE();
    8584    return x.size;
     
    9089    if (size)
    9190    {
    92       *s1++ = __locale_collate.weight [c];
     91      *s1++ = __libc_gLocaleCollate.auchWeight [c];
    9392      size--;
    9493    }
  • trunk/src/emx/src/lib/sys/__dup.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    7171     * Done.
    7272     */
    73     if (rc != 0)
     73    if (rc)
    7474    {
    75         _sys_set_errno(rc);
     75        if (rc > 0)
     76            _sys_set_errno(rc);
     77        else
     78            errno = -rc;
    7679        return -1;
    7780    }
  • trunk/src/emx/src/lib/sys/__dup2.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    104104    if (rc)
    105105    {
    106         _sys_set_errno(rc);
     106        if (rc > 0)
     107            _sys_set_errno(rc);
     108        else
     109            errno = -rc;
    107110        return -1;
    108111    }
  • trunk/src/emx/src/lib/sys/__exit.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    1 /* sys/exit.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
     1/* sys/exit.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes
     2                           Copyright (c) 2004 knut st. osmundsen */
    23
    34#include "libc-alias.h"
    45#define INCL_FSMACROS
    56#include <os2emx.h>
    6 void __exit (int rc);
     7#include <emx/syscalls.h>
     8#include <InnoTekLIBC/sharedpm.h>
    79
    8 void __exit (int rc)
     10void __exit(int rc)
    911{
    10   FS_VAR();
    11   FS_SAVE_LOAD();
    12   while (1)
    13     DosExit (EXIT_PROCESS, rc);
     12    FS_VAR();
     13
     14    /*
     15     * Update the SPM data base with the right exit reason and code.
     16     */
     17    __libc_spmTerm(__LIBC_EXIT_REASON_EXIT, rc);
     18
     19    /*
     20     * Actually exit the process.
     21     */
     22    FS_SAVE_LOAD();
     23    for (;;)
     24        DosExit(EXIT_PROCESS, rc < 0 || rc > 255 ? 255 : rc);
    1425}
  • trunk/src/emx/src/lib/sys/__fcntl.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1453 r1454  
    1010#define INCL_FSMACROS
    1111#include <os2emx.h>
     12#include <386/builtin.h>
    1213#include <emx/io.h>
    1314#include <emx/syscalls.h>
    1415#include "syscalls.h"
    15 
    16 static int __fcntl_locking(int handle, int request, struct flock *pflock);
    17 
    18 int __fcntl(int handle, int request, int arg)
     16#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_IO
     17#include <InnoTekLIBC/logstrict.h>
     18
     19
     20/*******************************************************************************
     21*   Internal Functions                                                         *
     22*******************************************************************************/
     23static int __fcntl_getfd(__LIBC_PFH pFH, int hFile);
     24static int __fcntl_setfd(__LIBC_PFH pFH, int hFile, int arg);
     25static int __fcntl_locking(int hFile, int iRequest, struct flock *pFlock);
     26
     27
     28int __fcntl(int hFile, int iRequest, int arg)
    1929{
    20     ULONG     rc;
    21     ULONG     fulState;
    22     PLIBCFH   pFH;
    23     FS_VAR();
     30    LIBCLOG_ENTER("hFile=%d iRequest=%#x arg=%#x\n", hFile, iRequest, arg);
     31    int         rc;
     32    __LIBC_PFH  pFH;
    2433
    2534    /*
    26      * Get the file handle data.
     35     * Get the file hFile data.
    2736     */
    28     pFH = __libc_FH(handle);
     37    pFH = __libc_FH(hFile);
    2938    if (!pFH)
    3039    {
    3140        errno = EBADF;
    32         return -1;
     41        LIBCLOG_RETURN_INT(-1);
    3342    }
    3443
     
    3645    {
    3746        /*
    38          * Standard OS/2 File handle.
     47         * Standard OS/2 File hFile.
    3948         */
    40         switch (request)
     49        switch (iRequest)
    4150        {
    4251            /*
     
    4453             */
    4554            case F_GETFL:
    46                 return pFH->fFlags & (O_ACCMODE | O_APPEND | O_NONBLOCK | O_SYNC /*| O_*SYNC*/);
     55            {
     56                unsigned fFlags = pFH->fFlags & (O_ACCMODE | O_APPEND | O_NONBLOCK | O_SYNC /*| O_*SYNC*/);
     57                LIBCLOG_RETURN_INT(fFlags);
     58            }
    4759
    4860            /*
     
    5062             */
    5163            case F_SETFL:
     64            {
    5265                /** @todo implement this properly. See FCNTLFLAGS. */
    53                 return 0;
     66                LIBC_ASSERTM_FAILED("F_SETFL isn't implemented but returns success. arg=%#x\n", arg);
     67                LIBCLOG_RETURN_INT(0);
     68            }
    5469
    5570            /*
    5671             * Get file descriptor flags.
    57              * (At the moment FD_CLOEXEC is the only flag.)
    5872             */
    5973            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);
     74                rc = __fcntl_getfd(pFH, hFile);
     75                LIBCLOG_RETURN_INT(rc);
    6976
    7077            /*
    7178             * Set file descriptor flags.
    72              * (At the moment FD_CLOEXEC is the only flag.)
    7379             */
    7480            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;
     81                rc = __fcntl_setfd(pFH, hFile, arg);
     82                LIBCLOG_RETURN_INT(rc);
    9783
    9884            /*
     
    10288            case F_SETLK:   /* set record locking information */
    10389            case F_SETLKW:  /* F_SETLK; wait if blocked */
    104                 return __fcntl_locking(handle, request, (struct flock*)arg);
     90            {
     91                int rc = __fcntl_locking(hFile, iRequest, (struct flock*)arg);
     92                LIBCLOG_RETURN_INT(rc);
     93            }
    10594
    10695            default:
     96                LIBC_ASSERTM_FAILED("Invalid iRequest %#x\n", iRequest);
    10797                errno = EINVAL;
    108                 return -1;
     98                LIBCLOG_RETURN_INT(-1);
    10999        }
    110100    }
     
    112102    {
    113103        /*
    114          * Non-standard handle - call registered method.
     104         * Non-standard hFile - call registered method.
    115105         */
    116106        int rcRet = 0;
    117         rc = pFH->pOps->pfnFileControl(pFH, handle, request, arg, &rcRet);
     107        rc = pFH->pOps->pfnFileControl(pFH, hFile, iRequest, arg, &rcRet);
    118108        if (rc)
    119109        {
    120             _sys_set_errno(rc);
    121             return -1;
    122         }
    123         return rcRet;
     110            if (rc > 0)
     111                _sys_set_errno(rc);
     112            else
     113                errno = -rc;
     114            LIBCLOG_RETURN_INT(-1);
     115        }
     116
     117        /*
     118         * Post process to keep the OS/2 fake hFile up to date (on success).
     119         */
     120        switch (iRequest)
     121        {
     122            case F_SETFD:
     123                rc = __fcntl_setfd(pFH, hFile, arg);
     124                if (rc == -1)
     125                    LIBCLOG_RETURN_INT(-1);
     126                break;
     127        }
     128        LIBCLOG_RETURN_INT(rcRet);
    124129    }
    125130}
    126131
    127132
    128 /* Handle locking requests.
    129 
    130    Please excuse the Hungarian and indenting used in this code,
    131    it's take from elsewhere. */
    132 
    133 static int __fcntl_locking(int hFile, int request, struct flock *pflock)
     133
     134/**
     135 * F_GETFD operation on standard OS/2 hFile.
     136 * Gets file descriptor flags, which at the moment is limited to FD_CLOEXEC.
     137 *
     138 * @returns 0 on success.
     139 * @returns -1 an errno on failure.
     140 * @param   pFH     File handler structure.
     141 * @param   hFile  File hFile.
     142 */
     143static int __fcntl_getfd(__LIBC_PFH pFH, int hFile)
     144{
     145    LIBCLOG_ENTER("pFH=%p hFile=%d\n", (void *)pFH, hFile);
     146    int     rc;
     147    ULONG   fulState;
     148    FS_VAR();
     149
     150    FS_SAVE_LOAD();
     151    rc = DosQueryFHState(hFile, &fulState);
     152    FS_RESTORE();
     153    if (!rc)
     154    {
     155        unsigned fFlags = pFH->fFlags;
     156        /* flags out of sync? */
     157        if (    ( (fulState & OPEN_FLAGS_NOINHERIT) != 0 )
     158            !=  (   (fFlags & (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)))
     159                 == (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)) ) )
     160        {
     161            LIBC_ASSERTM_FAILED("Inherit flags are out of sync for file hFile %d (%#x)! fulState=%08lx fFlags=%08x\n",
     162                                hFile, hFile, fulState, fFlags);
     163            if (fulState & OPEN_FLAGS_NOINHERIT)
     164                fFlags |= O_NOINHERIT | FD_CLOEXEC;
     165            else
     166                fFlags &= ~(O_NOINHERIT | FD_CLOEXEC);
     167            __atomic_xchg(&pFH->fFlags, fFlags);
     168        }
     169
     170        fFlags >>= __LIBC_FH_FDFLAGS_SHIFT;
     171        LIBCLOG_RETURN_INT(fFlags);
     172    }
     173
     174    /* failure. */
     175    _sys_set_errno(rc);
     176    LIBCLOG_RETURN_INT(-1);
     177}
     178
     179
     180/**
     181 * F_SETFD operation on standard OS/2 hFile.
     182 * Sets file descriptor flags, which at the moment is limited to FD_CLOEXEC.
     183 *
     184 * @returns 0 on success.
     185 * @returns -1 an errno on failure.
     186 * @param   pFH     File handler structure.
     187 * @param   hFile  File hFile.
     188 * @param   arg     New file descriptor flags.
     189 */
     190static int __fcntl_setfd(__LIBC_PFH pFH, int hFile, int arg)
     191{
     192    LIBCLOG_ENTER("pFH=%p hFile=%d arg=%#x\n", (void *)pFH, hFile, arg);
     193    int     rc;
     194    ULONG   fulState;
     195    FS_VAR();
     196
     197    FS_SAVE_LOAD();
     198    rc = DosQueryFHState(hFile, &fulState);
     199    if (!rc)
     200    {
     201        ULONG fulNewState;
     202        LIBC_ASSERTM(     ( (fulState & OPEN_FLAGS_NOINHERIT) != 0 )
     203                      ==  (   (pFH->fFlags & (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)))
     204                           == (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)) ),
     205                     "Inherit flags are out of sync for file hFile %d (%#x)! fulState=%08lx fFlags=%08x\n",
     206                     hFile, hFile, fulState, pFH->fFlags);
     207        if (arg & FD_CLOEXEC)
     208            fulNewState = fulState | OPEN_FLAGS_NOINHERIT;
     209        else
     210            fulNewState = fulState & ~OPEN_FLAGS_NOINHERIT;
     211        if (fulNewState != fulState)
     212        {
     213            fulNewState &= 0x7f88; /* Mask the flags accepted the API. */
     214            rc = DosSetFHState(hFile, fulNewState);
     215        }
     216    }
     217    FS_RESTORE();
     218
     219    if (!rc)
     220    {
     221        unsigned fFlags = pFH->fFlags;
     222        fFlags = (fFlags & ~__LIBC_FH_FDFLAGS_MASK) | (arg << __LIBC_FH_FDFLAGS_SHIFT);
     223        if (arg & FD_CLOEXEC)
     224            fFlags |= O_NOINHERIT;
     225        else
     226            fFlags &= ~O_NOINHERIT;
     227        __atomic_xchg(&pFH->fFlags, fFlags);
     228        LIBCLOG_RETURN_INT(0);
     229    }
     230
     231    /* error! */
     232    _sys_set_errno(rc);
     233    LIBCLOG_RETURN_INT(-1);
     234}
     235
     236
     237/**
     238 * Handle locking requests.
     239 * @returns
     240 * @param   hFile       File hFile.
     241 * @param   iRequest     Lock iRequest.
     242 * @param   pFlock      Pointer to flock structure.
     243 */
     244static int __fcntl_locking(int hFile, int iRequest, struct flock *pFlock)
    134245{
    135246    APIRET        rc;
     
    146257    /* check input */
    147258    /** @todo: Implement F_GETLK */
    148     if (!pflock || request == F_GETLK)
     259    if (!pFlock || iRequest == F_GETLK)
    149260    {
    150261        errno = EINVAL;
     
    180291
    181292        /* range */
    182         cbRange = pflock->l_len ? pflock->l_len : OFF_MAX;
     293        cbRange = pFlock->l_len ? pFlock->l_len : OFF_MAX;
    183294
    184295        /* offset */
    185         switch (pflock->l_whence)
    186         {
    187             case SEEK_SET:  offStart = pflock->l_start; break;
    188             case SEEK_CUR:  offStart = tell(hFile) + pflock->l_start; break;
    189             case SEEK_END:  offStart = cbFile - pflock->l_start; break;
     296        switch (pFlock->l_whence)
     297        {
     298            case SEEK_SET:  offStart = pFlock->l_start; break;
     299            case SEEK_CUR:  offStart = tell(hFile) + pFlock->l_start; break;
     300            case SEEK_END:  offStart = cbFile - pFlock->l_start; break;
    190301            default:
    191302                errno = EINVAL;
     
    201312        /* flags and order */
    202313        fAccess = 0; /* exclusive */
    203         switch (pflock->l_type)
     314        switch (pFlock->l_type)
    204315        {
    205316            case F_UNLCK:
     
    219330
    220331        /* timeout */
    221         if (request == F_SETLKW)
     332        if (iRequest == F_SETLKW)
    222333            ulTimeout = SEM_INDEFINITE_WAIT;
    223334        else
  • trunk/src/emx/src/lib/sys/__fstat.c

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1453 r1454  
    5252            LIBCLOG_RETURN_INT(-1);
    5353        }
    54         switch (pFH->fFlags & F_TYPEMASK)
     54        switch (pFH->fFlags & __LIBC_FH_TYPEMASK)
    5555        {
    5656            case F_DEV:     pStat->st_mode = S_IFCHR; break;
  • trunk/src/emx/src/lib/sys/__init.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r1453 r1454  
    2626#include <alloca.h>
    2727#include <InnoTekLIBC/thread.h>
     28#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_INITTERM
     29#include <InnoTekLIBC/logstrict.h>
    2830
    2931
     
    440442{
    441443    __asm__ ("cld");              /* Don't trust */
     444LIBCLOG_MSG2("!!! num %08lx flags %08lx nested %p whatever %p\n", report->ExceptionNum, report->fHandlerFlags, report->NestedExceptionReportRecord, whatever);
    442445    if (report->fHandlerFlags & (EH_UNWINDING | EH_EXIT_UNWIND))
    443446        return XCPT_CONTINUE_SEARCH;
  • trunk/src/emx/src/lib/sys/__initdll.c

    • Property cvs2svn:cvs-rev changed from 1.10 to 1.11
    r1453 r1454  
    2424#undef _osminor
    2525#include <string.h>
     26#include <errno.h>
    2627#include <sys/builtin.h>
    2728#include <sys/fmutex.h>
     
    3031#include <emx/umalloc.h>
    3132#include <alloca.h>
     33#include <InnoTekLIBC/fork.h>
    3234#include "syscalls.h"
    3335#include <InnoTekLIBC/thread.h>
     36#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_INITTERM
     37#include <InnoTekLIBC/logstrict.h>
    3438
    3539/* Make this function an weak external. */
    3640#pragma weak __init_largefileio
     41
     42/*******************************************************************************
     43*   Structures and Typedefs                                                    *
     44*******************************************************************************/
     45/**
     46 * Argument to initdllForkTLM().
     47 */
     48typedef struct TLMARGS_s
     49{
     50    /** Pointer to the TLM entry. */
     51    PULONG          pTLM;
     52    /** Pointer to the current thread. */
     53    __LIBC_PTHREAD  pCurThread;
     54} TLMARGS, *PTLMARGS;
    3755
    3856
     
    4664
    4765
     66/*******************************************************************************
     67*   Internal Functions                                                         *
     68*******************************************************************************/
     69static int initdllForkParent1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     70static int initdllForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     71static int initdllForkTLM(__LIBC_PFORKHANDLE pForkHandle, void *pvArg, size_t cbArg);
     72
     73
    4874/**
    4975 * Common init code for crt0 and dll0.
     
    5278int __init_dll(int fDefaultHeapInHighMem)
    5379{
    54     ULONG   aul[2];
    55     ULONG   rc;
    56     PTIB    ptib;
    57     PPIB    ppib;
    58     static int initialized = 0;
     80    ULONG               aul[2];
     81    int                 rc;
     82    PTIB                ptib;
     83    PPIB                ppib;
     84    __LIBC_PSPMPROCESS  pSelf;
     85    static int fInitialized = 0;
    5986
    6087    /*
     
    6693     * The rest must only be executed once.
    6794     */
    68     if (initialized)
     95    if (fInitialized)
    6996        return 0;
    70     initialized = 1;
     97    fInitialized = 1;
    7198
    7299    /*
     
    106133    if (_fmutex_create(&_sys_gmtxHimem, 0) != 0)
    107134        return -1;
     135    if (_fmutex_create(&__libc_gmtxExec, 0) != 0)
     136        return -1;
    108137
    109138    /*
    110139     * Initialize TLS.
    111140     */
    112     if (!__libc_gpTLS)                  /* !paranoia! */
    113     {
    114         rc = DosAllocThreadLocalMemory(1, (PULONG*)&__libc_gpTLS);
    115         if (rc)
    116             return -1;
     141    rc = DosAllocThreadLocalMemory(1, (PULONG*)(void*)&__libc_gpTLS);
     142    if (rc)
     143    {
     144        LIBC_ASSERTM_FAILED("DosAllocThreadLocalMemory() failed. rc=%d\n", rc);
     145        return -1;
    117146    }
    118147
     
    122151    rc = _sys_init_environ(ppib->pib_pchenv);
    123152    if (rc)
    124         return -1;
     153    {
     154        LIBC_ASSERTM_FAILED("_sys_init_environ() failed\n");
     155        return -1;
     156    }
     157
     158    /*
     159     * Get the current process.
     160     */
     161    pSelf = __libc_spmSelf();
     162    if (!pSelf)
     163    {
     164        LIBC_ASSERTM_FAILED("__libc_spmSelf() failed\n");
     165        return -1;
     166    }
    125167
    126168    /*
     
    135177     * Init file handles.
    136178     */
    137     rc = _sys_init_filehandles();
     179    rc = __libc_fhInit(pSelf->pInherit ? pSelf->pInherit->pFHBundles : NULL);
    138180    if (rc)
    139         return -1;
     181    {
     182        LIBC_ASSERTM_FAILED("__libc_fhInit(%p) failed\n", pSelf->pInherit ? (void *)pSelf->pInherit->pFHBundles : NULL);
     183        return -1;
     184    }
    140185
    141186    /*
     
    146191}
    147192
     193
     194#undef  __LIBC_LOG_GROUP
     195#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_FORK
     196
     197_FORK_PARENT1(0xffffffff, initdllForkParent1)
     198
     199/**
     200 * Fork callback which transfere the TLM to the child.
     201 *
     202 * @returns 0 on success.
     203 * @returns -errno on failure.
     204 * @param   pForkHandle     Pointer to fork handle.
     205 * @param   enmOperation    Fork operation.
     206 */
     207int initdllForkParent1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     208{
     209    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     210    int     rc;
     211    switch (enmOperation)
     212    {
     213        case __LIBC_FORK_OP_EXEC_PARENT:
     214        {
     215            TLMARGS Args;
     216            Args.pTLM       = (PULONG)__libc_gpTLS;
     217            Args.pCurThread = *__libc_gpTLS;
     218            rc = pForkHandle->pfnInvoke(pForkHandle, initdllForkTLM, &Args, sizeof(Args));
     219            break;
     220        }
     221
     222        default:
     223            rc = 0;
     224            break;
     225    }
     226
     227    LIBCLOG_RETURN_INT(rc);
     228}
     229
     230
     231_FORK_CHILD1(0xffffffff, initdllForkChild1)
     232
     233/**
     234 * Fork callback which updates the thread structure in the child.
     235 *
     236 * @returns 0 on success.
     237 * @returns -errno on failure.
     238 * @param   pForkHandle     Pointer to fork handle.
     239 * @param   enmOperation    Fork operation.
     240 */
     241static int initdllForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     242{
     243    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     244    int     rc;
     245    switch (enmOperation)
     246    {
     247        case __LIBC_FORK_OP_FORK_CHILD:
     248        {
     249            LIBCLOG_MSG("Adjusts thread nesting level. from %d to %d\n", (*__libc_gpTLS)->cDefLoggerDepth,
     250                        (*__libc_gpTLS)->cDefLoggerDepth - 2);
     251            (*__libc_gpTLS)->cDefLoggerDepth -= 2;
     252            rc = 0;
     253            break;
     254        }
     255
     256        default:
     257            rc = 0;
     258            break;
     259    }
     260
     261    LIBCLOG_RETURN_INT(rc);
     262}
     263
     264
     265/**
     266 * Callback which allocates the TLM entry which the parent is using.
     267 * and initializes it with the pointer to the thread used by the
     268 * parent. The global variable is not set, we must wait on the
     269 * data segment and heap duplication there.
     270 *
     271 * @returns 0 on success.
     272 * @returns -errno on failure.
     273 * @param   pForkHandle     Pointer to fork handle.
     274 * @param   pvArg           Pointer to a TLMARGS structure.
     275 * @param   cbArg           Size of argument pointed to by pvArg.
     276 */
     277static int initdllForkTLM(__LIBC_PFORKHANDLE pForkHandle, void *pvArg, size_t cbArg)
     278{
     279    LIBCLOG_ENTER("pForkHandle=%p pvArg=%p cbArg=%d\n", (void *)pForkHandle, pvArg, cbArg);
     280    PTLMARGS    pArgs = (PTLMARGS)pvArg;
     281    int         rc = 0;
     282    PULONG      apulTLM[64];
     283    int         iTLM;
     284    LIBC_ASSERT(cbArg == sizeof(TLMARGS));
     285
     286    for (iTLM = 0; iTLM < sizeof(apulTLM) / sizeof(apulTLM[0]); iTLM++)
     287    {
     288        /*
     289         * Allocate.
     290         */
     291        rc = DosAllocThreadLocalMemory(1, &apulTLM[iTLM]);
     292        if (rc)
     293            break;
     294
     295        /*
     296         * The right one?
     297         */
     298        if (apulTLM[iTLM] == pArgs->pTLM)
     299        {
     300            *apulTLM[iTLM] = (ULONG)pArgs->pCurThread;
     301            break;
     302        }
     303    }
     304
     305    /*
     306     * Cleanup.
     307     */
     308    while (iTLM-- > 0)
     309        DosFreeThreadLocalMemory(apulTLM[iTLM]);
     310
     311    if (!rc)
     312        LIBCLOG_RETURN_INT(0);
     313    LIBCLOG_RETURN_INT(-ENOMEM);
     314}
     315
  • trunk/src/emx/src/lib/sys/__ioctl2.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    114114        if (rc)
    115115        {
    116             _sys_set_errno(rc);
     116            if (rc > 0)
     117                _sys_set_errno(rc);
     118            else
     119                errno = -rc;
    117120            return -1;
    118121        }
  • trunk/src/emx/src/lib/sys/__read.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    4545         *      Allocate a buffer in the low heap.
    4646         */
    47         if (    (pFH->fFlags & F_TYPEMASK) == F_DEV
     47        if (    (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV
    4848            &&  (unsigned)buf >= 512*1024*1024)
    4949        {
     
    7878    if (rc)
    7979    {
    80         _sys_set_errno(rc);
     80        if (rc > 0)
     81            rc = -__libc_native2errno(rc);
     82
    8183        /* If we don't have read access, EBADF should be returned, not EACCES. */
    82         if (    errno == EACCES
     84        if (    rc == -EACCES
    8385            &&  (pFH->fFlags & O_ACCMODE) != O_RDONLY
    8486            &&  (pFH->fFlags & O_ACCMODE) != O_RDWR)
    85             errno = EBADF;
     87            rc = -EBADF;
     88        errno = -rc;
    8689        return -1;
    8790    }
  • trunk/src/emx/src/lib/sys/__spawnve.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    1111#include <os2emx.h>
    1212#include <emx/syscalls.h>
     13#include <InnoTekLIBC/sharedpm.h>
    1314#include "syscalls.h"
     15
     16
     17/**
     18 * Collects and creates the inherit stuff we send down to a LIBC child.
     19 * @returns Pointer to inherit structure on success.
     20 * @returns NULL and errno on failure.
     21 */
     22static __LIBC_PSPMINHERIT doInherit(void)
     23{
     24    size_t                  cbFH;
     25    __LIBC_PSPMINHFHBHDR    pFH;
     26    __LIBC_PSPMINHERIT      pRet = NULL;
     27
     28    /*
     29     * Get FH stuff.
     30     */
     31    pFH = __libc_fhInheritPack(&cbFH);
     32    if (pFH)
     33    {
     34        /*
     35         * Allocate shared memory.
     36         */
     37        size_t  cb = sizeof(__LIBC_SPMINHERIT) + ((cbFH + 3) & ~3);
     38        pRet = __libc_spmAlloc(cb);
     39        if (pRet)
     40        {
     41            pRet->cb = sizeof(*pRet);
     42            pRet->pFHBundles = (__LIBC_PSPMINHFHBHDR)(pRet + 1);
     43            memcpy(pRet->pFHBundles, pFH, cbFH);
     44            free(pFH);
     45            return pRet;
     46        }
     47        /* cleanup on failure */
     48        __libc_fhInheritDone();
     49        free(pFH);
     50    }
     51
     52    return pRet;
     53}
     54
     55
     56/**
     57 * Cleans up any globale inherit stuff.
     58 */
     59static void doInheritDone(void)
     60{
     61    __libc_fhInheritDone();
     62}
    1463
    1564/* Note: We are allowed to call _trealloc() as this module is not used
     
    4190  size_t arg_size, arg_alloc, len;
    4291  int i, quote, bs, method;
     92  __LIBC_PSPMPROCESS    pEmbryo;
    4393  FS_VAR();
    4494
     
    142192  *arg_ptr++ = '\0';
    143193  *arg_ptr++ = '\0';
    144   FS_SAVE_LOAD();
    145   rc = DosExecPgm (obj, sizeof (obj), exec_flag, arg_buf,
    146                    (const char *)np->env_off, &res, pgm_name);
    147   FS_RESTORE();
     194
     195  /*
     196   * Now create an embryo process.
     197   */
     198  pEmbryo = __libc_spmCreateEmbryo(getpid());
     199  if (pEmbryo)
     200  {
     201      /*
     202       * Do inheritance stuff.
     203       */
     204      pEmbryo->pInherit = doInherit();
     205      if (pEmbryo->pInherit)
     206      {
     207          /*
     208           * Create the process.
     209           */
     210          FS_SAVE_LOAD();
     211          rc = DosExecPgm (obj, sizeof (obj), exec_flag, (PCSZ)arg_buf, (PCSZ)np->env_off, &res, (PCSZ)pgm_name);
     212          FS_RESTORE();
     213          if (!rc)
     214          {
     215              /* cleanup embryo and other stuff. */
     216              __libc_spmRelease(pEmbryo);
     217              doInheritDone();
     218              if (arg_buf != NULL)
     219                  _tfree (arg_buf);
     220
     221              /* exit depends on the mode. */
     222              switch (mode & 0xff)
     223                {
     224                case P_WAIT:
     225                  return res.codeResult;
     226                case P_NOWAIT:
     227                  return res.codeTerminate;
     228                case P_OVERLAY:
     229                  FS_SAVE_LOAD();
     230                  while (1)
     231                    DosExit (EXIT_PROCESS, 0);
     232                default:
     233                  errno = EINVAL;
     234                  return -1;
     235                }
     236              /* won't ever get here! */
     237          }
     238          else
     239            _sys_set_errno (rc);
     240          doInheritDone();
     241      }
     242      /* cleanup embryo */
     243      __libc_spmRelease(pEmbryo);
     244  }
     245
    148246  if (arg_buf != NULL)
    149247    _tfree (arg_buf);
    150   if (rc != 0)
    151     {
    152       _sys_set_errno (rc);
    153       return -1;
    154     }
    155   switch (mode & 0xff)
    156     {
    157     case P_WAIT:
    158       return res.codeResult;
    159     case P_NOWAIT:
    160       return res.codeTerminate;
    161     case P_OVERLAY:
    162       FS_SAVE_LOAD();
    163       while (1)
    164         DosExit (EXIT_PROCESS, 0);
    165     default:
    166       errno = EINVAL;
    167       return -1;
    168     }
     248  return -1;
    169249}
  • trunk/src/emx/src/lib/sys/__write.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    4545         * Devices doesn't like getting high addresses.
    4646         */
    47         if (    (pFH->fFlags & F_TYPEMASK) == F_DEV
     47        if (    (pFH->fFlags & __LIBC_FH_TYPEMASK) == F_DEV
    4848            &&  (unsigned)buf >= 512*1024*1024)
    4949        {
     
    8787    if (rc)
    8888    {
    89         _sys_set_errno(rc);
     89        if (rc > 0)
     90            rc = -__libc_native2errno(rc);
     91
    9092        /* If we don't have write access, EBADF should be returned, not EACCES. */
    91         if (    errno == EACCES
     93        if (    rc == -EACCES
    9294            &&  (pFH->fFlags & O_ACCMODE) != O_WRONLY
    9395            &&  (pFH->fFlags & O_ACCMODE) != O_RDWR)
    94             errno = EBADF;
     96            rc = -EBADF;
     97        errno = -rc;
    9598        return -1;
    9699    }
  • trunk/src/emx/src/lib/sys/filehandles.c

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r1453 r1454  
    44 * LIBC File Handles.
    55 *
    6  * Copyright (c) 2003 knut st. osmundsen <bird-srcspam@anduin.net>
     6 * Copyright (c) 2003-2004 knut st. osmundsen <bird-srcspam@anduin.net>
    77 *
    88 *
     
    2727*******************************************************************************/
    2828/** Maximum number of file handles. */
    29 #define __LIBC_MAX_FHS  10000
     29#define __LIBC_MAX_FHS      10000
    3030/** Number of file handles to increase the max value with. */
    31 #define __LIBC_INC_FHS    64
     31#define __LIBC_INC_FHS      64
     32
    3233
    3334/*******************************************************************************
     
    4243#include <sys/fcntl.h>
    4344#include <errno.h>
     45#include <InnoTekLIBC/fork.h>
     46#include <InnoTekLIBC/sharedpm.h>
     47#include <InnoTekLIBC/tcpip.h>
    4448#include <emx/io.h>
    4549#include <emx/umalloc.h>
    4650#include "syscalls.h"
     51
     52#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_INITTERM
     53#include <InnoTekLIBC/logstrict.h>
    4754
    4855
     
    5562static _fmutex              gmtx;
    5663/** Array of file handle pointers. */
    57 static PLIBCFH             *gpapFHs;
     64static __LIBC_PFH          *gpapFHs;
    5865/** Number of entires in the file handle table. */
    5966static unsigned             gcFHs;
     
    6471static unsigned             gcPreAllocatedAvail;
    6572
     73/** Indicator whether or not inherit flags and other stuff have been cleaned
     74 * up after fork. */
     75static int                  gfForkCleanupDone;
     76
    6677extern int _fmode_bin;
    6778
     
    7081*   Internal Functions                                                         *
    7182*******************************************************************************/
    72 static int __libc_fhMoreHandles(unsigned cMin);
    73 static int __libc_fhAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh, int fOwnSem);
    74 static PLIBCFH __libc_fh(int fh);
     83static int      fhMoreHandles(unsigned cMin);
     84static int      fhAllocate(int fh, unsigned fFlags, int cb, __LIBC_PCFHOPS pOps, __LIBC_PFH *ppFH, int *pfh, int fOwnSem);
     85static void     fhFreeHandle(__LIBC_PFH pFH);
     86static __LIBC_PFH  fhGet(int fh);
     87static int      fhForkParent1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     88static int      fhForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     89static void     fhForkCompletion(void *pvArg, int rc, __LIBC_FORKCTX enmCtx);
    7590
    7691
     
    8095 * @returns 0 on success.
    8196 * @returns -1 on failure.
    82  */
    83 int     _sys_init_filehandles(void)
     97 * @param   pInherit    Pointer to inherited filehandle data.
     98 */
     99int __libc_fhInit(__LIBC_PSPMINHFHBHDR  pInherit)
    84100{
    85101    ULONG   cMaxFHs = 0;
     
    93109    if (gcFHs)
    94110    {
    95 #ifdef DEBUG
    96         __asm__("int $3");
    97 #endif
     111        LIBC_ASSERTM_FAILED("already initialized!\n");
    98112        return 0;
    99113    }
     
    112126    if (rc)
    113127    {
    114 #ifdef DEBUG
    115         __asm__("int $3");
    116 #endif
     128        LIBC_ASSERTM_FAILED("DosSetRelMaxFH failed with rc=%d when querying current values\n", rc);
    117129        cMaxFHs = 20;
    118130    }
     
    125137
    126138
    127     /*
    128      * Work thru the handles checking if they are in use.
    129      * Was previously done in init_files() in startup.c.
    130      *      We need to allocate the handles and initialize them accordingly.
    131      * Bird Feb 12 2004 9:12pm: We do not have to do more than the first 3 handles.
    132      *      Other open files will be automatically added when __libc_FH() is called
    133      *      for usage validation in any of LIBC apis.
    134      */
    135     if (cMaxFHs > 3)
    136         cMaxFHs = 3;
    137     for (i = 0; i < cMaxFHs; i++)
    138         __libc_fh(i);
     139    if (!pInherit)
     140    {
     141        /*
     142         * Work thru the handles checking if they are in use.
     143         * Was previously done in init_files() in startup.c.
     144         *      We need to allocate the handles and initialize them accordingly.
     145         * Bird Feb 12 2004 9:12pm: We do not have to do more than the first 3 handles.
     146         *      Other open files will be automatically added when __libc_FH() is called
     147         *      for usage validation in any of LIBC apis.
     148         */
     149        if (cMaxFHs > 3)
     150            cMaxFHs = 3;
     151        for (i = 0; i < cMaxFHs; i++)
     152            fhGet(i);
     153    }
     154    else
     155    {
     156        /*
     157         * Process the inherit data passed to us.
     158         */
     159        union
     160        {
     161            __LIBC_PSPMINHFHBHDR    pHdr;
     162            __LIBC_PSPMINHFHBSTD    pStds;
     163            __LIBC_PSPMINHFHBSOCK   pSockets;
     164            uintptr_t               u;
     165            void                   *pv;
     166        } u;
     167        u.pHdr = pInherit;
     168        while (u.pHdr->uchType != __LIBC_SPM_INH_FHB_TYPE_END)
     169        {
     170            unsigned    i = 0;
     171            unsigned    c = u.pHdr->cHandles;
     172            unsigned    iFH = u.pHdr->fhStart;
     173            switch (u.pHdr->uchType)
     174            {
     175                case __LIBC_SPM_INH_FHB_TYPE_STANDARD:
     176                    for (i = 0; i < c; i++)
     177                    {
     178                        if (fhAllocate(iFH, u.pStds->afFlags[i], sizeof(__LIBC_FH), NULL, NULL, NULL, 0))
     179                        {
     180                            LIBC_ASSERTM_FAILED("Failed to allocated inherited file handle! iFH=%d\n", iFH);
     181                            return -1;
     182                        }
     183                    }
     184                    u.pv = &u.pStds->afFlags[c];
     185                    break;
     186
     187                case __LIBC_SPM_INH_FHB_TYPE_SOCKET_44:
     188                    for (i = 0; i < c; i++)
     189                    {
     190                        if (TCPNAMEG44(AllocFHEx)(iFH, u.pSockets->aHandles[i].usSocket, u.pSockets->aHandles[i].fFlags, 0, NULL))
     191                        {
     192                            LIBC_ASSERTM_FAILED("Failed to allocated inherited socket (4.4) handle! iFH=%d iSocket=%d\n",
     193                                                iFH, u.pSockets->aHandles[i].usSocket);
     194                            return -1;
     195                        }
     196                    }
     197                    u.pv = &u.pSockets->aHandles[c];
     198                    break;
     199
     200                case __LIBC_SPM_INH_FHB_TYPE_SOCKET_43:
     201                    for (i = 0; i < c; i++)
     202                    {
     203                        if (TCPNAMEG43(AllocFHEx)(iFH, u.pSockets->aHandles[i].usSocket, u.pSockets->aHandles[i].fFlags, 0, NULL))
     204                        {
     205                            LIBC_ASSERTM_FAILED("Failed to allocated inherited socket (4.3) handle! iFH=%d iSocket=%d\n",
     206                                                iFH, u.pSockets->aHandles[i].usSocket);
     207                            return -1;
     208                        }
     209                    }
     210                    u.pv = &u.pSockets->aHandles[c];
     211                    break;
     212
     213                /*
     214                 * Unknown - skip it.
     215                 */
     216                default:
     217                {
     218                    size_t cb = __LIBC_SPM_INH_FHB_SIZE(u.pHdr->uchType);
     219                    cb *= u.pHdr->cHandles;
     220                    u.u += cb + sizeof(*u.pHdr);
     221                    break;
     222                }
     223
     224            }
     225        }
     226    }
    139227
    140228    return 0;
    141229}
    142230
    143 
     231#if 0 // not used
    144232/**
    145233 * Terminate the file handles.
     
    152240    if (!gcFHs)
    153241    {
    154 #ifdef DEBUG
    155             __asm__("int $3");
    156 #endif
     242        LIBC_ASSERTM_FAILED("gcFHs is zero - we've already been terminated!\n");
    157243        return 0;
    158244    }
     
    171257    return 0;
    172258}
     259#endif
     260
     261
     262/**
     263 * Pack down file handles for exec.
     264 *
     265 * @returns Pointer to a high heap buffer of the size indicated in *pch containing
     266 *          the bundles for all the current file handles. The filehandle semaphore
     267 *          is also owned. Called __libc_fhInheritDone() to release the semaphore.
     268 * @returns NULL and errno on failure.
     269 * @param   pcb     Where to store the size of the returned data.
     270 */
     271__LIBC_PSPMINHFHBHDR    __libc_fhInheritPack(size_t *pcb)
     272{
     273    LIBCLOG_ENTER("pcb=%p\n", (void *)pcb);
     274    size_t                  cb = 0x1000;
     275    unsigned                iFH;
     276    unsigned                cFHs;
     277    int                     rc;
     278    __LIBC_PSPMINHFHBHDR    pRet;
     279    union
     280    {
     281        __LIBC_PSPMINHFHBHDR    pHdr;
     282        __LIBC_PSPMINHFHBSTD    pStds;
     283        __LIBC_PSPMINHFHBSOCK   pSockets;
     284        uintptr_t               u;
     285        void                   *pv;
     286    } u;
     287
     288    /*
     289     * Allocate buffer.
     290     */
     291    pRet = _hmalloc(cb);
     292    if (!pRet)
     293        LIBCLOG_RETURN_P(NULL);
     294
     295    /*
     296     * Lock the filehandle array.
     297     */
     298    rc = _fmutex_request(&gmtx, 0);
     299    if (rc)
     300    {
     301        _sys_set_errno(rc);
     302        free(pRet);
     303        LIBCLOG_RETURN_P(NULL);
     304    }
     305
     306    /*
     307     * Enumerate the handles.
     308     * UGLY!!!!!
     309     */
     310    for (cFHs = gcFHs, iFH = 0, u.pHdr = pRet; iFH < cFHs;)
     311    {
     312        __LIBC_FHTYPE   enmType;
     313        unsigned        i;
     314
     315        /*
     316         * Skip unused ones.
     317         */
     318        while (     iFH < cFHs
     319               &&   (   !gpapFHs[iFH]
     320                     || (gpapFHs[iFH]->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT)) ) )
     321            iFH++;
     322        if (iFH >= cFHs)
     323            break;
     324
     325        /*
     326         * Create new bundle.
     327         */
     328        /* Ensure space for max sized bundle and termination record. */
     329        if ( ((uintptr_t)&u.pSockets->aHandles[256] + sizeof(__LIBC_SPMINHFHBHDR) - (uintptr_t)pRet) > cb)
     330        {
     331            void *pv = realloc(pRet, cb + 0x1000);
     332            if (!pv)
     333            {
     334                _fmutex_release(&gmtx);
     335                free(pRet);
     336                LIBCLOG_RETURN_P(NULL);
     337            }
     338            u.u += (uintptr_t)pv - (uintptr_t)pv;
     339            pRet = pv;
     340            cb += 0x1000;
     341        }
     342        /* init the bundle. */
     343        enmType = gpapFHs[iFH]->pOps ? gpapFHs[iFH]->pOps->enmType : enmFH_File;
     344        switch (enmType)
     345        {
     346            case enmFH_File:
     347            {
     348                u.pStds->Hdr.uchType = __LIBC_SPM_INH_FHB_TYPE_STANDARD;
     349                u.pStds->Hdr.fhStart = iFH;
     350                /* walk file handles. */
     351                for (i = 0; ; )
     352                {
     353                    u.pStds->afFlags[i] = gpapFHs[iFH]->fFlags;
     354                    /* next */
     355                    i++; iFH++;
     356                    if (    i >= 255
     357                        ||  iFH >= cFHs
     358                        ||  !gpapFHs[iFH]
     359                        ||  gpapFHs[iFH]->pOps
     360                        || (gpapFHs[iFH]->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT)) )
     361                        break;
     362                }
     363                /* commit the bundle. */
     364                u.pStds->Hdr.cHandles = i;
     365                u.pv = &u.pStds->afFlags[i];
     366                break;
     367            }
     368
     369            case enmFH_Socket43:
     370            case enmFH_Socket44:
     371            {
     372                u.pSockets->Hdr.uchType = enmType == enmFH_Socket44
     373                    ? __LIBC_SPM_INH_FHB_TYPE_SOCKET_44 : __LIBC_SPM_INH_FHB_TYPE_SOCKET_43;
     374                u.pSockets->Hdr.fhStart = iFH;
     375                /* walk file handles. */
     376                for (i = 0; ; )
     377                {
     378                    u.pSockets->aHandles[i].fFlags   = gpapFHs[iFH]->fFlags;
     379                    u.pSockets->aHandles[i].usSocket = ((PLIBCSOCKETFH)gpapFHs[iFH])->iSocket;
     380                    /* next */
     381                    i++; iFH++;
     382                    if (    i >= 255
     383                        ||  iFH >= cFHs
     384                        ||  !gpapFHs[iFH]
     385                        ||  !gpapFHs[iFH]->pOps
     386                        ||  (gpapFHs[iFH]->pOps->enmType != enmType)
     387                        ||  (gpapFHs[iFH]->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT)) )
     388                        break;
     389                }
     390                /* commit the bundle. */
     391                u.pSockets->Hdr.cHandles = i;
     392                u.pv = &u.pSockets->aHandles[i];
     393                break;
     394            }
     395
     396            default:
     397            {   /* skip */
     398                for (;;)
     399                {
     400                    /* next */
     401                    iFH++;
     402                    if (    iFH >= cFHs
     403                        ||  !gpapFHs[iFH]
     404                        ||  !gpapFHs[iFH]->pOps
     405                        ||  (gpapFHs[iFH]->pOps->enmType != enmType))
     406                        break;
     407                }
     408                break;
     409            }
     410
     411        } /* switch handle type. */
     412
     413    } /* outer loop */
     414
     415    /*
     416     * Done. Let's add a termination bundle and calc the actual size.
     417     */
     418    u.pHdr->uchType  = __LIBC_SPM_INH_FHB_TYPE_END;
     419    u.pHdr->cHandles = 0;
     420    u.pHdr->fhStart  = ~0;
     421    cb = (uintptr_t)(u.pHdr + 1) - (uintptr_t)pRet;
     422    *pcb = (cb + 3) & ~3;               /* (This is safe.) */
     423    LIBCLOG_RETURN_MSG(pRet, "ret %p *pcb=%d\n", (void *)pRet, *pcb);
     424}
     425
     426
     427/**
     428 * Called as a response to a successful __libc_fhInheritPack() to
     429 * release the file handle mutex.
     430 */
     431void        __libc_fhInheritDone(void)
     432{
     433    _fmutex_release(&gmtx);
     434}
     435
     436
     437
     438#undef  __LIBC_LOG_GROUP
     439#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_BACK_IO
    173440
    174441
     
    190457
    191458    FS_SAVE_LOAD();
    192     rc = DosOpen("\\DEV\\NUL", &hFile, &ulAction, 0, FILE_NORMAL,
     459    rc = DosOpen((PCSZ)"\\DEV\\NUL", &hFile, &ulAction, 0, FILE_NORMAL,
    193460                 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
    194461                 OPEN_SHARE_DENYNONE | OPEN_ACCESS_WRITEONLY,
     
    211478}
    212479
     480
    213481/**
    214482 * Frees handle data.
     
    219487 * @remark  Must own the mutex upon entry!
    220488 */
    221 static void __libc_fhFreeHandle(PLIBCFH pFH)
     489static void fhFreeHandle(__LIBC_PFH pFH)
    222490{
    223491    /*
     
    245513 * @remark  Lock must be owned upon entry!
    246514 */
    247 static int __libc_fhMoreHandles(unsigned cMin)
     515static int fhMoreHandles(unsigned cMin)
    248516{
    249517    int     rc;
     
    297565         * Reallocate the array of handle pointers.
    298566         */
    299         PLIBCFH * papNewFHs = _hrealloc(gpapFHs, cNewMaxFHs * sizeof(gpapFHs[0]));
     567        __LIBC_PFH *papNewFHs = _hrealloc(gpapFHs, cNewMaxFHs * sizeof(gpapFHs[0]));
    300568        if (papNewFHs)
    301569        {
     
    333601        return -1;
    334602
    335     rc = __libc_fhMoreHandles(fh + 1);
     603    rc = fhMoreHandles(fh + 1);
    336604
    337605    _fmutex_release(&gmtx);
     
    352620        return -1;
    353621
    354     rc = __libc_fhMoreHandles(0);
     622    rc = fhMoreHandles(0);
    355623
    356624    _fmutex_release(&gmtx);
     
    378646 * @remark  The preallocated handles make this function somewhat big and messy.
    379647 */
    380 static int __libc_fhAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh, int fOwnSem)
    381 {
    382     PLIBCFH     pFH;
     648static int fhAllocate(int fh, unsigned fFlags, int cb, __LIBC_PCFHOPS pOps, __LIBC_PFH *ppFH, int *pfh, int fOwnSem)
     649{
     650    __LIBC_PFH  pFH;
    383651    int         rc;
    384652    FS_VAR();
     
    409677        if (cb == sizeof(LIBCFH) && gcPreAllocatedAvail)
    410678        {
    411             PLIBCFH pFHSearch;
     679            __LIBC_PFH pFHSearch;
    412680            for (pFHSearch = &gaPreAllocated[0];
    413681                 pFH < &gaPreAllocated[sizeof(gaPreAllocated) / sizeof(gaPreAllocated[0])];
     
    419687                    break;
    420688                }
    421 #ifdef DEBUG
    422             if (!pFH) __asm__("int $3");
    423 #endif
     689            LIBC_ASSERT(pFH);
    424690        }
    425691
     
    438704         */
    439705        pFH->fFlags     = fFlags;
     706        if (fFlags & O_NOINHERIT)
     707            fFlags |= FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT;
    440708        pFH->iLookAhead = -1;
    441709        pFH->pOps       = pOps;
     
    450718             * Open dummy device to find a handle number.
    451719             */
    452 #ifdef DEBUG
    453             if (!pOps)
    454                 __asm__("int $3");
    455 #endif
     720            LIBC_ASSERTM(pOps, "cannot open a non-standard handle without giving pOps!\n");
    456721            rc = __libc_fhOpenDummy(-1, &fh);
    457722            if (!rc)
     
    461726                 */
    462727                if (fh >= gcFHs)
    463                     rc = __libc_fhMoreHandles(fh + 1);
     728                    rc = fhMoreHandles(fh + 1);
    464729                if (!rc)
    465730                {
     
    469734                     */
    470735                    if (gpapFHs[fh])
    471                         __libc_fhFreeHandle(gpapFHs[fh]);
     736                        fhFreeHandle(gpapFHs[fh]);
    472737                    gpapFHs[fh] = pFH;
    473738                }
     
    490755            rc = 0;
    491756            if (fh >= gcFHs)
    492                 rc = __libc_fhMoreHandles(fh + 1);
     757                rc = fhMoreHandles(fh + 1);
    493758
    494759            if (!rc)
     
    507772                     */
    508773                    if (gpapFHs[fh])
    509                         __libc_fhFreeHandle(gpapFHs[fh]);
     774                        fhFreeHandle(gpapFHs[fh]);
    510775                    gpapFHs[fh] = pFH;
    511776                }
     
    523788        _sys_set_errno(rc);
    524789        if (pFH)
    525             __libc_fhFreeHandle(pFH);
     790            fhFreeHandle(pFH);
    526791        pFH = NULL;
    527792        fh = -1;
     
    557822 * @remark  The preallocated handles make this function somewhat big and messy.
    558823 */
    559 int __libc_FHAllocate(int fh, unsigned fFlags, int cb, PLIBCFHOPS pOps, PLIBCFH *ppFH, int *pfh)
    560 {
    561     return __libc_fhAllocate(fh, fFlags, cb, pOps, ppFH, pfh, 0);
     824int __libc_FHAllocate(int fh, unsigned fFlags, int cb, __LIBC_PCFHOPS pOps, __LIBC_PFH *ppFH, int *pfh)
     825{
     826    return fhAllocate(fh, fFlags, cb, pOps, ppFH, pfh, 0);
    562827}
    563828
     
    572837int __libc_FHClose(int fh)
    573838{
    574     PLIBCFH     pFH;
    575     ULONG       rc;
     839    __LIBC_PFH  pFH;
     840    int         rc;
    576841    FS_VAR();
    577842
     
    582847     * Validate input.
    583848     */
    584     if (!__libc_fh(fh))
    585     {
    586 /*#ifdef DEBUG
    587         __asm__("int $3");
    588 #endif*/
     849    if (!fhGet(fh))
     850    {
     851        LIBC_ASSERTM_FAILED("fh=%d is not opened according to our table!\n", fh);
    589852        _fmutex_release(&gmtx);
    590853        errno = EBADF;
     
    617880        rc2 = DosClose(fh);
    618881        FS_RESTORE();
     882        LIBC_ASSERTM(!rc2, "DosClose(%d) -> rc2=%d (rc=%d)\n", fh, rc2, rc);
    619883        if (!pFH->pOps)
    620884            rc = rc2;
    621 #ifdef DEBUG
    622         else if (rc2) __asm__("int $3");
    623 #endif
    624885
    625886        /*
     
    630891        {
    631892            gpapFHs[fh] = NULL;
    632             __libc_fhFreeHandle(pFH);
     893            fhFreeHandle(pFH);
    633894        }
    634895    }
     
    641902            _sys_set_errno(rc);
    642903        else
    643             errno = rc;
     904            errno = -rc;
    644905    }
    645906
     
    657918 * @internal
    658919 */
    659 static PLIBCFH __libc_fh(int fh)
    660 {
    661     PLIBCFH pFH = NULL;
     920static __LIBC_PFH fhGet(int fh)
     921{
     922    __LIBC_PFH pFH = NULL;
    662923
    663924    /*
     
    672933            cCur = gcFHs;
    673934        if (gcFHs != cCur)
    674             __libc_fhMoreHandles(cCur);
     935            fhMoreHandles(cCur);
    675936    }
    676937
     
    732993
    733994            /*
     995             * Inherit flags.
     996             */
     997            if (fulMode & OPEN_FLAGS_NOINHERIT)
     998                fLibc |= O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT);
     999
     1000            /*
    7341001             * Textflag.
    7351002             */
     
    7411008             * Allocate a new handle for this filehandle.
    7421009             */
    743             rc = __libc_fhAllocate(fh, fLibc, sizeof(LIBCFH), NULL, &pFH, NULL, 1);
     1010            rc = fhAllocate(fh, fLibc, sizeof(LIBCFH), NULL, &pFH, NULL, 1);
    7441011            if (rc)
    7451012                pFH = NULL;
     
    7591026 * @param   fh  Handle to lookup.
    7601027 */
    761 PLIBCFH __libc_FH(int fh)
    762 {
    763     PLIBCFH pFH;
     1028__LIBC_PFH __libc_FH(int fh)
     1029{
     1030    __LIBC_PFH pFH;
    7641031
    7651032    /** @todo shared access */
     
    7671034        return NULL;
    7681035
    769     pFH = __libc_fh(fh);
     1036    pFH = fhGet(fh);
    7701037
    7711038    _fmutex_release(&gmtx);
     
    7731040}
    7741041
     1042
     1043
     1044#undef  __LIBC_LOG_GROUP
     1045#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_FORK
     1046
     1047_FORK_PARENT1(0xfffff000, fhForkParent1)
     1048
     1049/**
     1050 * Parent fork callback.
     1051 *
     1052 * There are two purposes for this function. First, lock the filehandle
     1053 * array while forking. Second, force all handles to tempoarily be inherited
     1054 * by child process.
     1055 *
     1056 * @returns 0 on success.
     1057 * @returns -errno on failure.
     1058 * @param   pForkHandle     Pointer to fork handle.
     1059 * @param   enmOperation    Fork operation.
     1060 */
     1061static int fhForkParent1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     1062{
     1063    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     1064    int rc;
     1065
     1066    switch (enmOperation)
     1067    {
     1068        /*
     1069         * Take file handle semaphore.
     1070         * Mark all handles temporarily for inheritance.
     1071         */
     1072        case __LIBC_FORK_OP_EXEC_PARENT:
     1073        {
     1074            /*
     1075             * Acquire Semaphore and register completion handler for cleaning up.
     1076             */
     1077            rc = _fmutex_request(&gmtx, 0);
     1078            if (!rc)
     1079            {
     1080                gfForkCleanupDone = 0;
     1081                rc = pForkHandle->pfnCompletionCallback(pForkHandle, fhForkCompletion, NULL, __LIBC_FORK_CTX_BOTH);
     1082                if (rc < 0)
     1083                    _fmutex_release(&gmtx);
     1084                else
     1085                {
     1086                    /*
     1087                     * Iterate all file handles and do pre exec processing, i.e. mark as inherit.
     1088                     */
     1089                    unsigned iFH;
     1090                    unsigned cFHs = gcFHs;
     1091                    for (iFH = 0; iFH < cFHs; iFH++)
     1092                    {
     1093                        __LIBC_PFH pFH;
     1094                        if ((pFH = gpapFHs[iFH]) != NULL)
     1095                        {
     1096                            if (pFH->pOps && pFH->pOps->pfnForkParent)
     1097                            {
     1098                                rc = pFH->pOps->pfnForkParent(pFH, iFH, pForkHandle, __LIBC_FORK_OP_EXEC_PARENT);
     1099                                if (rc)
     1100                                {
     1101                                    LIBC_ASSERTM_FAILED("pfnForkParent(=%p) for handle %d failed with rc=%d\n",
     1102                                                        (void *)pFH->pOps->pfnForkParent, iFH, rc);
     1103                                    if (rc > 0)
     1104                                        rc = -__libc_native2errno(rc);
     1105                                    break;
     1106                                }
     1107                            }
     1108
     1109                            /* mark as inherit. */
     1110                            if (pFH->fFlags & (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)))
     1111                            {
     1112                                ULONG   fulState;
     1113
     1114                                rc = DosQueryFHState(iFH, &fulState);
     1115                                if (!rc)
     1116                                {
     1117                                    fulState = fulState & ~OPEN_FLAGS_NOINHERIT;
     1118                                    fulState &= 0x7f88; /* Mask the flags accepted by the API. */
     1119                                    rc = DosSetFHState(iFH, fulState);
     1120                                }
     1121                                if (rc)
     1122                                {
     1123                                    LIBC_ASSERTM_FAILED("DosSetFHState or DosQueryFHState failed with rc=%d for handle %d\n", rc, iFH);
     1124                                    rc = -__libc_native2errno(rc);
     1125                                    break;
     1126                                }
     1127                            }
     1128                        }
     1129                    } /* for */
     1130                    /* No need to clean up on failure. the completion callback will do that. */
     1131                }
     1132            }
     1133            else
     1134            {
     1135                LIBC_ASSERTM_FAILED("failed to get the filehandle mutex. rc=%d\n", rc);
     1136                rc = -__libc_native2errno(rc);
     1137            }
     1138            break;
     1139        }
     1140
     1141
     1142        /*
     1143         * Iterate all file handles and do fork exec processing.
     1144         * This is only done for non standard file handles.
     1145         */
     1146        case __LIBC_FORK_OP_FORK_PARENT:
     1147        {
     1148            unsigned iFH;
     1149            unsigned cFHs = gcFHs;
     1150            for (iFH = 0, rc = 0; iFH < cFHs; iFH++)
     1151            {
     1152                __LIBC_PFH pFH;
     1153                if ((pFH = gpapFHs[iFH]) != NULL)
     1154                {
     1155                    if (pFH->pOps && pFH->pOps->pfnForkParent)
     1156                    {
     1157                        rc = pFH->pOps->pfnForkParent(pFH, iFH, pForkHandle, __LIBC_FORK_OP_FORK_PARENT);
     1158                        if (rc)
     1159                        {
     1160                            LIBC_ASSERTM_FAILED("pfnForkParent(=%p) for handle %d failed with rc=%d\n",
     1161                                                (void *)pFH->pOps->pfnForkParent, iFH, rc);
     1162                            if (rc > 0)
     1163                                rc = -__libc_native2errno(rc);
     1164                            break;
     1165                        }
     1166                    }
     1167                }
     1168            }
     1169            break;
     1170        }
     1171
     1172        default:
     1173            rc = 0;
     1174            break;
     1175    }
     1176
     1177    LIBCLOG_RETURN_INT(rc);
     1178}
     1179
     1180
     1181
     1182_FORK_CHILD1(0xffffff00, fhForkChild1)
     1183
     1184/**
     1185 * Child fork callback.
     1186 *
     1187 * There are two purposes for this function. First, restore no-inherit handles
     1188 * and call pfnForkChild(). Second, to release the file handle mutex.
     1189 *
     1190 * Note that only __LIBC_FORK_OP_FORK_CHILD is propagated to pfnForkChild().
     1191 *
     1192 * @returns 0 on success.
     1193 * @returns -errno on failure.
     1194 * @param   pForkHandle     Pointer to fork handle.
     1195 * @param   enmOperation    Fork operation.
     1196 */
     1197static int fhForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     1198{
     1199    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     1200    int rc;
     1201
     1202    switch (enmOperation)
     1203    {
     1204        /*
     1205         * Clear all handles which was temporarily marked for inheritance.
     1206         * Release the file handle semaphore.
     1207         */
     1208        case __LIBC_FORK_OP_FORK_CHILD:
     1209        {
     1210            int         rc2;
     1211            unsigned    iFH;
     1212            unsigned    cFHs = gcFHs;
     1213            for (iFH = 0, rc = 0; iFH < cFHs; iFH++)
     1214            {
     1215                __LIBC_PFH pFH;
     1216                if ((pFH = gpapFHs[iFH]) != NULL)
     1217                {
     1218                    /* call pfnForkChild(). */
     1219                    if (pFH->pOps && pFH->pOps->pfnForkChild)
     1220                    {
     1221                        rc = pFH->pOps->pfnForkChild(pFH, iFH, pForkHandle, __LIBC_FORK_OP_FORK_PARENT);
     1222                        if (rc)
     1223                        {
     1224                            LIBC_ASSERTM_FAILED("pfnForkChild(=%p) for handle %d failed with rc=%d\n",
     1225                                                (void *)pFH->pOps->pfnForkChild, iFH, rc);
     1226                            if (rc > 0)
     1227                                rc = -__libc_native2errno(rc);
     1228                            break;
     1229                        }
     1230                    }
     1231
     1232                    /* clear flag. */
     1233                    if (pFH->fFlags & (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)))
     1234                    {
     1235                        ULONG fulState;
     1236                        rc = DosQueryFHState(iFH, &fulState);
     1237                        if (!rc)
     1238                        {
     1239                            fulState |= OPEN_FLAGS_NOINHERIT;
     1240                            fulState &= 0x7f88; /* Mask the flags accepted by the API. */
     1241                            rc = DosSetFHState(iFH, fulState);
     1242                        }
     1243                        LIBC_ASSERTM(!rc, "DosSetFHState or DosQueryFHState failed with rc=%d for handle %d\n", rc, iFH);
     1244                    }
     1245                }
     1246            }
     1247
     1248            /* release semaphore. */
     1249            rc2 = _fmutex_release(&gmtx);
     1250            if (rc2)
     1251            {
     1252                LIBC_ASSERTM_FAILED("_fmutex_release failed rc=%d\n", rc2);
     1253                if (rc >= 0)
     1254                    rc = -__libc_native2errno(rc2);
     1255            }
     1256            gfForkCleanupDone = 1;
     1257            break;
     1258        }
     1259
     1260        default:
     1261            rc = 0;
     1262            break;
     1263    }
     1264
     1265    LIBCLOG_RETURN_INT(rc);
     1266}
     1267
     1268
     1269/**
     1270 * Fork completion callback used to release the file handle semaphore
     1271 * and set the noinherit flags.
     1272 *
     1273 * @param   pvArg   NULL.
     1274 * @param   rc      The fork() result. Negative on failure.
     1275 * @param   enmCtx  The calling context.
     1276 */
     1277static void fhForkCompletion(void *pvArg, int rc, __LIBC_FORKCTX enmCtx)
     1278{
     1279    LIBCLOG_ENTER("pvArg=%p rc=%d enmCtx=%d\n", pvArg, rc, enmCtx);
     1280    rc = rc;
     1281    pvArg = pvArg;
     1282
     1283    if (    !gfForkCleanupDone
     1284        && (    !rc
     1285            ||  enmCtx == __LIBC_FORK_CTX_PARENT))
     1286    {
     1287        /*
     1288         * Iterate handles and set no-inherit flags.
     1289         *
     1290         * We assume that the non standard handles will do any necessary
     1291         * cleanup themselves. If they register completion callbacks they
     1292         * have all be executed by now since we registered our before them
     1293         * the the order is LIFO.
     1294         */
     1295        unsigned iFH;
     1296        unsigned cFHs = gcFHs;
     1297        for (iFH = 0, rc = 0; iFH < cFHs; iFH++)
     1298        {
     1299            __LIBC_PFH pFH;
     1300            if ((pFH = gpapFHs[iFH]) != NULL)
     1301            {
     1302                if (pFH->fFlags & (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)))
     1303                {
     1304                    ULONG fulState;
     1305                    rc = DosQueryFHState(iFH, &fulState);
     1306                    if (!rc)
     1307                    {
     1308                        fulState |= OPEN_FLAGS_NOINHERIT;
     1309                        fulState &= 0x7f88; /* Mask the flags accepted by the API. */
     1310                        rc = DosSetFHState(iFH, fulState);
     1311                    }
     1312                    LIBC_ASSERTM(!rc, "DosSetFHState or DosQueryFHState failed with rc=%d for handle %d\n", rc, iFH);
     1313                }
     1314            }
     1315        }
     1316    }
     1317
     1318    /*
     1319     * Release the mutex.
     1320     */
     1321    if (!gfForkCleanupDone)
     1322    {
     1323        gfForkCleanupDone = 1;
     1324        _fmutex_release(&gmtx);
     1325    }
     1326
     1327    LIBCLOG_RETURN_VOID();
     1328}
     1329
  • trunk/src/emx/src/lib/sys/heap.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    44#define INCL_DOSERRORS
    55#define INCL_FSMACROS
     6#define INCL_EXAPIS
    67#include <os2emx.h>
    78#include <errno.h>
     
    910#include <emx/syscalls.h>
    1011#include "syscalls.h"
     12#define  __LIBC_LOG_GROUP __LIBC_LOG_GRP_HEAP
     13#include <InnoTekLIBC/logstrict.h>
    1114
    1215
     
    2225
    2326  FS_SAVE_LOAD();
    24   if (DosAllocMem (&p, size, PAG_READ | PAG_WRITE) != 0)
     27  if (DosAllocMemEx (&p, size, PAG_READ | PAG_WRITE | OBJ_FORK) != 0)
    2528    {
    2629      FS_RESTORE();
     
    4043  /* We got a suitable object.  Free the bad one. */
    4144
    42   DosFreeMem (p);
     45  DosFreeMemEx (p);
    4346  FS_RESTORE();
    4447  return ret;
     
    5154ULONG _sys_expand_heap_obj_by (ULONG incr)
    5255{
     56  LIBCLOG_ENTER("incr=%ld\n", incr);
    5357  ULONG rc, old_brk, new_brk, addr, size, rest;
    5458
     
    5761
    5862  if (new_brk < _sys_top_heap_obj->base || new_brk > _sys_top_heap_obj->end)
    59     return 0;
     63    LIBCLOG_RETURN_ULONG(0UL);
    6064
    6165  addr = old_brk;
     
    7983      FS_RESTORE();
    8084      if (rc != 0)
    81         return 0;
     85        LIBCLOG_RETURN_ULONG(0UL);
    8286    }
    8387  _sys_top_heap_obj->brk = new_brk;
    84   return old_brk;
     88  LIBCLOG_RETURN_ULONG(old_brk);
    8589}
    8690
     
    9195ULONG _sys_shrink_heap_obj_by (ULONG decr)
    9296{
     97  LIBCLOG_ENTER("decr=%ld\n", decr);
    9398  ULONG rc, old_brk, new_brk, addr, high;
    9499
     
    97102
    98103  if (new_brk < _sys_top_heap_obj->base || new_brk > _sys_top_heap_obj->end)
    99     return 0;
     104    LIBCLOG_RETURN_ULONG(0UL);
    100105
    101106  addr = (new_brk + 0xfff) & ~0xfff;
     
    108113      FS_RESTORE();
    109114      if (rc != 0)
    110         return 0;
     115        LIBCLOG_RETURN_ULONG(0UL);
    111116    }
    112117  _sys_top_heap_obj->brk = new_brk;
    113   return old_brk;
     118  LIBCLOG_RETURN_ULONG(old_brk);
    114119}
    115120
     
    120125ULONG _sys_expand_heap_by (ULONG incr, ULONG sbrk_model)
    121126{
     127  LIBCLOG_ENTER("incr=%ld sbrk_model=%ld\n", incr, sbrk_model);
    122128  unsigned old_obj_count;
    123129  ULONG base, size;
     
    155161          FS_VAR();
    156162          FS_SAVE_LOAD();
    157           DosFreeMem ((void *)_sys_heap_objs[0].base);
     163          DosFreeMemEx ((void *)_sys_heap_objs[0].base);
    158164          FS_RESTORE();
    159165          _sys_heap_obj_count = 0;
    160166          _sys_top_heap_obj = NULL;
    161167        }
    162       return 0;                 /* Failure */
     168      LIBCLOG_RETURN_ULONG(0UL);  /* Failure */
    163169    }
    164170
     
    175181      if (sbrk_model == _UF_SBRK_CONTIGUOUS
    176182          || _sys_heap_obj_count >= MAX_HEAP_OBJS)
    177         return 0;
     183        LIBCLOG_RETURN_ULONG(0UL);
    178184
    179185      /* Allocate at least _sys_heap_size bytes.  The new object must
     
    199205          size /= 2;
    200206          if (size < incr)
    201             return 0;
     207            LIBCLOG_RETURN_ULONG(0UL);
    202208        }
    203209
     
    213219     expansion as an object might have been added. */
    214220
    215   return _sys_expand_heap_obj_by (incr);
     221  base = _sys_expand_heap_obj_by (incr);
     222  LIBCLOG_RETURN_ULONG(base);
    216223}
    217224
     
    222229ULONG _sys_shrink_heap_to (ULONG new_brk)
    223230{
     231  LIBCLOG_ENTER("new_brk=%ld\n", new_brk);
    224232  unsigned obj;
    225233  ULONG old_brk;
     
    250258    {
    251259      if ((_sys_uflags & _UF_SBRK_MODEL) == _UF_SBRK_CONTIGUOUS)
    252         return 0;
     260        LIBCLOG_RETURN_ULONG(0UL);
    253261      while (_sys_heap_obj_count - 1 > obj)
    254262        {
     
    256264          _sys_heap_obj_count -= 1;
    257265          FS_SAVE_LOAD();
    258           DosFreeMem ((void *)_sys_heap_objs[_sys_heap_obj_count].base);
     266          DosFreeMemEx ((void *)_sys_heap_objs[_sys_heap_obj_count].base);
    259267          FS_RESTORE();
    260268          _sys_heap_objs[_sys_heap_obj_count].base = 0;
     
    293301          _sys_heap_obj_count -= 1;
    294302          FS_SAVE_LOAD();
    295           DosFreeMem ((void *)_sys_heap_objs[_sys_heap_obj_count].base);
     303          DosFreeMemEx ((void *)_sys_heap_objs[_sys_heap_obj_count].base);
    296304          FS_RESTORE();
    297305          _sys_heap_objs[_sys_heap_obj_count].base = 0;
     
    312320  if (_sys_heap_obj_count > 0
    313321      && _sys_shrink_heap_obj_by (_sys_top_heap_obj->brk - new_brk) == 0)
    314     return 0;
    315   return old_brk;
     322      LIBCLOG_RETURN_ULONG(0UL);
     323  LIBCLOG_RETURN_ULONG(old_brk);
    316324}
    317325
     
    322330ULONG _sys_shrink_heap_by (ULONG decr, ULONG sbrk_model)
    323331{
     332  LIBCLOG_ENTER("decr=%ld sbrk_model=%ld\n", decr, sbrk_model);
     333  ULONG ulRet;
    324334  if (_sys_heap_obj_count == 0)
    325     return 0;
     335    LIBCLOG_RETURN_ULONG(0UL);
    326336  if (_sys_top_heap_obj->brk - decr < _sys_top_heap_obj->base)
    327     return 0;
    328   return _sys_shrink_heap_to (_sys_top_heap_obj->brk - decr);
    329 }
     337    LIBCLOG_RETURN_ULONG(0UL);
     338  ulRet = _sys_shrink_heap_to (_sys_top_heap_obj->brk - decr);
     339  LIBCLOG_RETURN_ULONG(ulRet);
     340}
  • trunk/src/emx/src/lib/sys/heaphigh.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    2323 *
    2424 */
     25
     26
     27/*******************************************************************************
     28*   Defined Constants And Macros                                               *
     29*******************************************************************************/
     30/** The size of a chunk descriptor pool (64KB). */
     31#define HIMEM_POOL_SIZE         (64*1024)
     32/** Default chunk size (16MB). */
     33#define HIMEM_CHUNK_SIZE        (16*1024*1024)
     34/** Minimum chunk size (64KB). */
     35#define HIMEM_CHUNK_SIZE_MIN    (64*1024)
     36/** Default commit size (256KB). */
     37#define HIMEM_COMMIT_SIZE       HIMEM_CHUNK_SIZE_MIN
     38
     39/** Round chunk size. */
     40#define HIMEM_ROUND_SIZE(cb, align) ( ((cb) + (align) - 1) & ~((align) - 1) )
     41
    2542
    2643
     
    3047#include "libc-alias.h"
    3148#define INCL_DOSMEMMGR
     49#define INCL_EXAPIS
    3250#define INCL_ERRORS
    3351#include <os2emx.h>
     
    3553#include <emx/umalloc.h>
    3654#include "syscalls.h"
     55#define  __LIBC_LOG_GROUP __LIBC_LOG_GRP_HEAP
     56#include <InnoTekLIBC/logstrict.h>
    3757
    3858
     
    4060*   Structures and Typedefs                                                    *
    4161*******************************************************************************/
    42 /** One chunk of memory
    43  * This structure is located at the very start of the chunk.
     62/**
     63 * Descriptor for a high memory chunk.
    4464 */
    4565typedef struct _HighChunk
    4666{
    47     /** Magic / padding the struct to 16 bytes. */
    48     char                szMagic[8];
    4967    /** Pointer to the next one. */
    5068    struct _HighChunk  *pNext;
     69    /** Pointer to the chunk. */
     70    void               *pv;
    5171    /** Size of the chunk. */
    5272    size_t              cb;
    53 } HIGHCHUNK, *PHIGHCHUNK;
     73    /** Size of the un committed memory. */
     74    size_t              cbUncommitted;
     75} HIGHCHUNK;
     76/** Pointer to a descriptor for a high memory chunk. */
     77typedef HIGHCHUNK *PHIGHCHUNK;
     78
     79/**
     80 * A pool of chunk descriptors.
     81 */
     82typedef struct _HighChunkPool
     83{
     84    /** Pointer to the next pool in the list.*/
     85    struct _HighChunkPool  *pNext;
     86    /** List of free chunks. */
     87    PHIGHCHUNK              pFreeHead;
     88    /** Index to the next uninitialized chunk.
     89     * ~0 if all are initialized. */
     90    unsigned                iUnitialized;
     91    /** Size of the pool. */
     92    unsigned                cChunks;
     93    /** Array of cChunks entires. */
     94    HIGHCHUNK               aChunks[1];
     95} HIGHCHUNKPOOL;
     96/** Pointer to a pool of chunk descriptors. */
     97typedef HIGHCHUNKPOOL *PHIGHCHUNKPOOL;
    5498
    5599
     
    57101*   Global Variables                                                           *
    58102*******************************************************************************/
    59 /** List of chuncks. Protected by _sys_gmtxHimem. */
    60 static PHIGHCHUNK   pHimemHead;
    61 
     103/** List of chuncks.
     104 * Protected by _sys_gmtxHimem. */
     105static PHIGHCHUNK       gpHimemHead;
     106/** Search hint containing NULL or the last used chunk.
     107 * Protected by _sys_gmtxHimem. */
     108static PHIGHCHUNK       gpHimemHint;
     109/** List of chunk pools.
     110 * Protected by _sys_gmtxHimem. */
     111static PHIGHCHUNKPOOL   gpHimemPoolHead;
     112
     113
     114
     115/*******************************************************************************
     116*   Internal Functions                                                         *
     117*******************************************************************************/
     118static PHIGHCHUNK himemAllocChunk(void);
     119static void himemFreeChunk(PHIGHCHUNK pChunk);
     120
     121
     122/**
     123 * Allocates a chunk descriptor.
     124 * Caller must not own semaphore.
     125 *
     126 * @returns Pointer to chunk descriptor.
     127 *          Owner of the semaphore. Caller must free it.
     128 * @returns NULL on failure.
     129 */
     130static PHIGHCHUNK himemAllocChunk(void)
     131{
     132    LIBCLOG_ENTER("\n");
     133    PHIGHCHUNK      pChunk;
     134    PHIGHCHUNKPOOL  pPool;
     135    PVOID           pv;
     136    int             rc;
     137
     138    /*
     139     * Take semaphore.
     140     */
     141    if (_fmutex_request(&_sys_gmtxHimem, _FMR_IGNINT))
     142        LIBCLOG_RETURN_P(NULL);
     143
     144    /*
     145     * Walk the pool list and look for free chunks.
     146     */
     147    pChunk = NULL;
     148    for (pPool = gpHimemPoolHead; pPool; pPool = pPool->pNext)
     149    {
     150        if (pPool->pFreeHead)
     151        {
     152            /* Unlink free chunk. */
     153            pChunk = pPool->pFreeHead;
     154            pPool->pFreeHead = pChunk->pNext;
     155            pChunk->pNext = NULL;
     156            LIBCLOG_RETURN_P(pChunk);
     157        }
     158        if (pPool->iUnitialized != ~0)
     159        {
     160            /* We commit page by page to make fork() as fast as possible. */
     161            if ((((uintptr_t)&pPool->aChunks[pPool->iUnitialized]) & 0xfff) == 0)
     162            {
     163                rc = DosSetMem(&pPool->aChunks[pPool->iUnitialized], 0x1000, PAG_DEFAULT | PAG_COMMIT);
     164                LIBC_ASSERTM(rc, "DosSetMem(%p, 0x1000,) -> rc=%d\n", (void *)&pPool->aChunks[pPool->iUnitialized], rc);
     165                if (rc)
     166                    continue;
     167            }
     168            /* initialize a new chunk and return it. */
     169            pChunk = &pPool->aChunks[pPool->iUnitialized++];
     170            if (pPool->iUnitialized >= pPool->cChunks)
     171                pPool->iUnitialized = ~0;
     172            LIBCLOG_RETURN_P(pChunk);
     173        }
     174    }
     175
     176    /*
     177     * We're out of chunk descriptors.
     178     * Allocate another pool.
     179     */
     180    rc = DosAllocMemEx(&pv, HIMEM_POOL_SIZE, PAG_WRITE  | PAG_READ | OBJ_ANY | OBJ_FORK);
     181    if (rc)
     182    {
     183        LIBC_ASSERTM_FAILED("Failed to allocate more chunks. rc=%d\n", rc);
     184        _fmutex_release(&_sys_gmtxHimem);
     185        LIBCLOG_RETURN_P(NULL);
     186    }
     187    /* Commit the first page. */
     188    rc = DosSetMem(pv, 0x1000, PAG_DEFAULT | PAG_COMMIT);
     189    if (rc)
     190    {
     191        LIBC_ASSERTM_FAILED("DosSetMem(%p, 0x1000,) -> rc=%d\n", pv, rc);
     192        DosFreeMemEx(pv);
     193        _fmutex_release(&_sys_gmtxHimem);
     194        LIBCLOG_RETURN_P(NULL);
     195    }
     196
     197    /*
     198     * Initialize the pool, allocate the first chunk and put the pool into the lifo.
     199     */
     200    pPool = (PHIGHCHUNKPOOL)pv;
     201    pPool->cChunks = (HIMEM_POOL_SIZE - sizeof(HIGHCHUNKPOOL)) / sizeof(HIGHCHUNK);
     202
     203    pPool->iUnitialized = 1;
     204    pChunk = &pPool->aChunks[0];
     205
     206    pPool->pNext = gpHimemPoolHead;
     207    gpHimemPoolHead = pPool;
     208
     209    LIBCLOG_RETURN_P(pChunk);
     210}
     211
     212
     213/**
     214 * Frees a chunk.
     215 * The caller must own the semaphore.
     216 *
     217 * @param   pChunk  The chunk to free.
     218 */
     219static void himemFreeChunk(PHIGHCHUNK pChunk)
     220{
     221    LIBCLOG_ENTER("pChunk=%p:{pv=%p cb=%#x}\n", (void *)pChunk, pChunk->pv, pChunk->cb);
     222    PHIGHCHUNKPOOL  pPool;
     223
     224    /*
     225     * Walk the pool list and look for free chunks.
     226     */
     227    for (pPool = gpHimemPoolHead; pPool; pPool = pPool->pNext)
     228    {
     229        if (    pChunk >= &pPool->aChunks[0]
     230            &&  pChunk < &pPool->aChunks[pPool->cChunks])
     231        {
     232            pChunk->pv = NULL;
     233            pChunk->cb = 0;
     234            pChunk->cbUncommitted = 0;
     235
     236            pChunk->pNext = pPool->pFreeHead;
     237            pPool->pFreeHead = pChunk;
     238            LIBCLOG_RETURN_VOID();
     239        }
     240    }
     241
     242    LIBC_ASSERTM_FAILED("couldn't find pool which chunk %p belongs in!\n", (void *)pChunk);
     243    LIBCLOG_RETURN_VOID();
     244}
    62245
    63246
    64247/**
    65248 * Heap callback function for allocating high memory.
     249 * We allocate a good deal of memory, but only commits the requested size.
    66250 *
    67251 * @returns Pointer to the allocated memory on success.
     
    73257 *                      pointed to by the returned address is clean
    74258 *                      (i.e zeroed) or not.
     259 *
     260 * @remark  Assumes it serves one heap only ATM!
    75261 */
    76262void *__libc_HimemDefaultAlloc(Heap_t Heap, size_t *pcb, int *pfClean)
    77263{
     264    LIBCLOG_ENTER("Heap=%p pcb=%p:{%#x} pfClean=%p\n", (void *)Heap, (void *)pcb, *pcb, (void *)pfClean);
    78265    size_t      cbAlloc;
     266    size_t      cbCommit;
     267    PVOID       pv;
    79268    int         rc;
    80269    PHIGHCHUNK  pChunk;
    81270
     271
     272    if (!gpHimemPoolHead)
     273    {
     274        /*
     275         * The first time we force the allocation of the chunk decriptor
     276         * pool before we allocate the actual chunk to optimize the address space.
     277         */
     278        pChunk = himemAllocChunk();
     279        if (pChunk)
     280        {
     281            himemFreeChunk(pChunk);
     282            _fmutex_release(&_sys_gmtxHimem);
     283        }
     284    }
     285    else
     286    {
     287        /*
     288         * Check if we have a chunk we can expand to satisfy the request.
     289         */
     290        if (_fmutex_request(&_sys_gmtxHimem, _FMR_IGNINT))
     291            LIBCLOG_RETURN_P(NULL);
     292        cbCommit = *pcb;
     293        cbCommit = HIMEM_ROUND_SIZE(cbCommit, HIMEM_COMMIT_SIZE);
     294        pChunk = gpHimemHint;
     295        if (!pChunk)
     296            pChunk = gpHimemHead;
     297        for (; pChunk; pChunk = pChunk->pNext)
     298        {
     299            if (pChunk->cbUncommitted >= cbCommit)
     300            {
     301                /* commit the rest if it's less than the minimum commit size. */
     302                if (pChunk->cbUncommitted - cbCommit < HIMEM_COMMIT_SIZE)
     303                    cbCommit = pChunk->cbUncommitted;
     304
     305                /*
     306                 * commit the lump.
     307                 */
     308                pv = (char *)pChunk->pv + pChunk->cb - pChunk->cbUncommitted;
     309                rc = DosSetMem(pv, cbCommit, PAG_DEFAULT | PAG_COMMIT);
     310                if (rc)
     311                {   /* page by page */
     312                    void   *pvCom = pv;
     313                    int     cbCom = (int)cbCommit;
     314                    for (rc = 0; cbCom > 0; cbCom -= 0x1000, pv = (char *)pv + 0x1000)
     315                    {
     316                        int rc2 = DosSetMem(pvCom, 0x1000, PAG_DEFAULT | PAG_COMMIT);
     317                        LIBC_ASSERTM(!rc2, "DosSetMem(%p, 0x1000, commit) -> %d\n", pvCom, rc2);
     318                        if (rc2)
     319                            rc = rc2;
     320                    }
     321                }
     322
     323                if (!rc)
     324                {
     325                    pChunk->cbUncommitted -= cbCommit;
     326                    gpHimemHint = pChunk->cbUncommitted ? pChunk : gpHimemHead;
     327                    _fmutex_release(&_sys_gmtxHimem);
     328
     329                    /* return pv and commit size. The heap takes care of joining
     330                     * it with the earlier part of the block. ASSUMES ONE HEAP!!! */
     331                    *pcb = cbCommit;
     332                    LIBCLOG_RETURN_MSG(pv, "ret %p *pcb=%#x\n", pv, *pcb);
     333                }
     334                LIBC_ASSERTM_FAILED("DosSetMem(%p, %#x, commit) -> %d\n", pv, cbCommit, rc);
     335                continue;
     336            }
     337        }
     338
     339        /* Out of luck, allocate a new chunk. */
     340        _fmutex_release(&_sys_gmtxHimem);
     341    }
     342
     343
    82344    /*
    83345     * Allocate a (rather big) memory block, there is generally speaking
    84      * more than enough high memory to allocate from. So, we'll align the
    85      * chunks on a rather high limit, 4MB to save kernel calls and list
    86      * elements.
    87      */
    88     cbAlloc = *pcb + sizeof(HIGHCHUNK);
    89     cbAlloc = (cbAlloc + (4*1024*1024 - 1)) & ~(4*1024*1024 - 1);
    90 
    91     rc = DosAllocMem((PPVOID)&pChunk, cbAlloc, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_ANY);
     346     * more than enough high memory to allocate from. So, we'll round the
     347     * chunks sizes up quite a bit to keep the object count low and the
     348     * heap as flexible as possible.
     349     */
     350    cbAlloc = *pcb;
     351    cbAlloc = HIMEM_ROUND_SIZE(cbAlloc, HIMEM_CHUNK_SIZE);
     352    rc = DosAllocMemEx(&pv, cbAlloc, PAG_READ | PAG_WRITE | OBJ_ANY | OBJ_FORK);
    92353    if (rc == ERROR_NOT_ENOUGH_MEMORY)
    93     {   /*
    94          * Retry with page alignment instead of 4MB.
     354    {
     355        /*
     356         * That's odd, we're out of address space or something.
     357         * Try again with the minimum rounding.
    95358         */
    96359        cbAlloc = *pcb + sizeof(HIGHCHUNK);
    97         cbAlloc = (cbAlloc + (0x1000 - 1)) & ~(0x1000 - 1);
    98         rc = DosAllocMem((PPVOID)&pChunk, cbAlloc, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_ANY);
    99     }
    100 
     360        cbAlloc = HIMEM_ROUND_SIZE(cbAlloc, HIMEM_CHUNK_SIZE_MIN);
     361        rc = DosAllocMemEx(pv, cbAlloc, PAG_READ | PAG_WRITE | OBJ_ANY | OBJ_FORK);
     362    }
    101363    if (rc)
    102         return NULL;
    103 
    104     /*
    105      * We've got a block. Now it's gotta go into the list.
    106      */
    107     memcpy(pChunk->szMagic, "HiChunk", sizeof(pChunk->szMagic));
    108     pChunk->cb = cbAlloc;
    109     if (_fmutex_request(&_sys_gmtxHimem, _FMR_IGNINT) != 0)
    110     {
    111         DosFreeMem(pChunk);
    112         return NULL;
    113     }
    114     pChunk->pNext = pHimemHead;
    115     pHimemHead = pChunk;
    116     _fmutex_release(&_sys_gmtxHimem);
    117 
    118 
    119     /*
    120      * Set the output values and return.
    121      */
    122     *pfClean = _BLOCK_CLEAN;
    123     *pcb = cbAlloc - sizeof(HIGHCHUNK);
    124     return &pChunk[1];
     364    {
     365        LIBC_ASSERTM_FAILED("Failed to allocate chunk! rc=%d cbAlloc=%d *pcb=%d\n", rc, cbAlloc, *pcb);
     366        LIBCLOG_RETURN_P(NULL);
     367    }
     368
     369    /*
     370     * Commit the requested memory size.
     371     */
     372    cbCommit = *pcb;
     373    cbCommit = HIMEM_ROUND_SIZE(cbCommit, HIMEM_COMMIT_SIZE);
     374    rc = DosSetMem(pv, cbCommit, PAG_DEFAULT | PAG_COMMIT);
     375    if (!rc)
     376    {
     377        /*
     378         * Allocate a chunk descriptor taking in the heap semaphore in the same run.
     379         */
     380        pChunk = himemAllocChunk();
     381        if (pChunk)
     382        {
     383            /* init */
     384            pChunk->pv          = pv;
     385            pChunk->cb          = cbAlloc;
     386            pChunk->cbUncommitted = cbAlloc - cbCommit;
     387            /* link in to the list. */
     388            pChunk->pNext = gpHimemHead;
     389            gpHimemHead   = pChunk;
     390            gpHimemHint   = pChunk;
     391
     392            /* release and return. */
     393            _fmutex_release(&_sys_gmtxHimem);
     394            *pcb = cbCommit;
     395            *pfClean = _BLOCK_CLEAN;
     396            LIBCLOG_RETURN_MSG(pv, "ret %p *pcb=%#x\n", pv, *pcb);
     397        }
     398    }
     399    else
     400        LIBC_ASSERTM_FAILED("DosSetMem(%p, %#x, PAG_DEFAULT | PAG_COMMIT) -> %d\n", pv, cbCommit, rc);
     401
     402    DosFreeMemEx(pv);
     403    LIBCLOG_RETURN_P(NULL);
    125404}
    126405
     
    135414void __libc_HimemDefaultRelease(Heap_t Heap, void *pv, size_t cb)
    136415{
     416    LIBCLOG_ENTER("Heap=%p pv=%p cb=%#x\n", (void *)Heap, pv, cb);
    137417    int         rc;
    138418    PHIGHCHUNK  pChunk;
    139419    PHIGHCHUNK  pPrevChunk;
    140420
    141     /*
    142      * Find and unlink the chunk.
     421    LIBC_ASSERT(cb);
     422    LIBC_ASSERT(!(cb & 0xfff));
     423    LIBC_ASSERT(pv);
     424    LIBC_ASSERT(!((uintptr_t)pv & 0xfff));
     425
     426
     427    /*
     428     * Take semaphore.
    143429     */
    144430    if (_fmutex_request(&_sys_gmtxHimem, _FMR_IGNINT) != 0)
    145431        return;
    146     for (pChunk = pHimemHead, pPrevChunk = NULL; pChunk; pPrevChunk = pChunk, pChunk = pChunk->pNext)
    147         if (&pChunk[1] == pv)
    148         {
    149             if (pPrevChunk)
    150                 pPrevChunk->pNext = pChunk->pNext;
    151             else
    152                 pHimemHead = pChunk->pNext;
    153             break;
    154         }
     432
     433    /*
     434     * Remove from top to bottom of the described block.
     435     *
     436     * We must (?) handle cases where the pv+cb describes a memory area
     437     * which covers several chunks. This is easier when done from the end.
     438     *
     439     * We ASSUME that the heap will not request areas which is not at the
     440     * end of the committed memory in a chunk.
     441     */
     442    do
     443    {
     444        void       *pvEnd = (char *)pv + cb;
     445        for (pChunk = gpHimemHead, pPrevChunk = NULL; pChunk; pPrevChunk = pChunk, pChunk = pChunk->pNext)
     446        {
     447            size_t  offEnd = (uintptr_t)pvEnd - (uintptr_t)pChunk->pv;
     448            if (offEnd <= pChunk->cb)
     449            {
     450                void   *pvFree;
     451                size_t  off = (uintptr_t)pv - (uintptr_t)pChunk->pv;
     452                if (off > pChunk->cb)
     453                    off = 0;
     454
     455                /* check that it's at the end of the committed area. */
     456                if (offEnd != pChunk->cb - pChunk->cbUncommitted)
     457                {
     458                    LIBC_ASSERTM_FAILED("Bad high heap release!! pv=%p cb=%#x off=%#x offEnd=%#x; chunk pv=%p cb=%#x cbUncomitted=%#x\n",
     459                                        pv, cb, off, offEnd, pChunk->pv, pChunk->cb, pChunk->cbUncommitted);
     460                    _fmutex_release(&_sys_gmtxHimem);
     461                    LIBCLOG_RETURN_VOID();
     462                }
     463
     464                /*
     465                 * Decommit part of the chunk.
     466                 */
     467                if (off > 0)
     468                {
     469                    size_t  cbDecommit = offEnd - off;
     470                    rc = DosSetMem(pv, cbDecommit, PAG_DECOMMIT);
     471                    if (rc)
     472                    {
     473                        LIBC_ASSERTM_FAILED("DosSetMem(%p, %#x, decommit) -> %d\n", pv, cbDecommit, rc);
     474                        /* page by page */
     475                        for (; cbDecommit; cbDecommit -= 0x1000)
     476                            DosSetMem(pv, 0x1000, PAG_DECOMMIT);
     477                    }
     478                    pChunk->cbUncommitted += cbDecommit;
     479
     480                    /* we're done. */
     481                    _fmutex_release(&_sys_gmtxHimem);
     482                    LIBCLOG_RETURN_VOID();
     483                }
     484
     485                /*
     486                 * Free the chunk.
     487                 */
     488                pvFree = pChunk->pv;
     489                /* unlink and free the chunk descriptor */
     490                if (pPrevChunk)
     491                    pPrevChunk->pNext = pChunk->pNext;
     492                else
     493                    gpHimemHead = pChunk->pNext;
     494                if (gpHimemHint == pChunk)
     495                    gpHimemHint = gpHimemHead;
     496                himemFreeChunk(pChunk);
     497
     498                /* free */
     499                rc = DosFreeMemEx(pvFree);
     500                LIBC_ASSERTM(!rc, "DosFreeMem(%p) -> %d\n", pvFree, rc);
     501
     502                /* Update size and restart loop. */
     503                cb -= offEnd - off;
     504                break;
     505            }
     506        }
     507
     508        LIBC_ASSERTM(pChunk, "Couldn't find any chunk containing the area pv=%p cb=%#x!\n", pv, cb);
     509    } while (cb && pChunk);
     510
    155511    _fmutex_release(&_sys_gmtxHimem);
    156 
    157     /*
    158      * Precautions and assertions.
    159      */
    160     if (!pChunk || cb + sizeof(HIGHCHUNK) != pChunk->cb)
    161     {
    162         #ifdef DEBUG
    163         __asm__("int $3");
    164         #endif
    165         return;
    166     }
    167 
    168     /*
    169      * Free it.
    170      */
    171     rc = DosFreeMem(pChunk);
    172     if (rc)
    173     {
    174         #ifdef DEBUG
    175         __asm__("int $3");
    176         #endif
    177     }
    178 }
     512    LIBCLOG_RETURN_VOID();
     513}
     514
     515
     516#if 0
     517int     __libc_HimemDefaultExpand(Heap_t Heap, void *pvBase, size_t cbOld, size_t *pcbNew, int *pfClean)
     518{
     519    LIBCLOG_ENTER("Heap=%p pvBase=%p cbOld=%#x pcbNew=%p:{%#x} pfClean=%p\n",
     520                  (void *)Heap, pvBase, cbOld, (void *)pcbNew, *pcbNew, (void *)pfClean);
     521
     522
     523    LIBCLOG_RETURN_INT(0);
     524}
     525
     526void    __libc_HimemDefaultShrink(Heap_t Heap, void *pvBase, size_t cbOld, size_t *pcbNew)
     527{
     528    LIBCLOG_ENTER("Heap=%p pvBase=%p cbOld=%#x pcbNew=%p:{%#x} pfClean=%p\n",
     529                  (void *)Heap, pvBase, cbOld, (void *)pcbNew, *pcbNew, (void *)pfClean);
     530
     531    LIBCLOG_RETURN_VOID(0);
     532}
     533#endif
    179534
    180535
  • trunk/src/emx/src/lib/sys/logstrict.c

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r1453 r1454  
    112112static inline unsigned getTimestamp(void);
    113113static inline unsigned getTid(void);
     114static inline unsigned getPid(void);
    114115static ULONG _System __libc_logXcptHandler(PEXCEPTIONREPORTRECORD pRepRec, struct _EXCEPTIONREGISTRATIONRECORD * pRegRec, PCONTEXTRECORD pCtxRec, PVOID pv);
    115116static int      __libc_logVSNPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, va_list args);
    116117static int      __libc_logSNPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, ...) __printflike(3, 4);
     118
    117119
    118120
     
    282284                                 "   |     |  |   |    |    errno in hex (0xface if not available).\n"
    283285                                 "   |     |  |   |    |    |      Function Name.\n"
    284                                  "   |     |  |   |    |    |      |        Millisconds In function (Optional).\n"
    285                                  "   v     v  v   v    v    v      v        v\n"
    286                                  "xxxxxxxx tt nn gggg dddd eeee function [( ms)]: message\n");
     286                                 "   |     |  |   |    |    |      |       Millisconds In function (Optional).\n"
     287                                 "   v     v  v   v    v    v      v       v\n"
     288                                 "xxxxxxxx tt nn gggg dddd eeee function [(ms)]: message\n");
    287289        DosWrite(pInst->hFile, pszMsg, cch, &cb);
    288290    }
     
    438440            { 1, "future" },            /* 22 */
    439441            { 1, "future" },            /* 23 */
    440             { 1, "future" },            /* 24 */
    441             { 1, "future" },            /* 25 */
     442            { 1, "SPM" },               /* 24 */
     443            { 1, "FORK" },              /* 25 */
    442444            { 1, "BACK_IO" },           /* 26 */
    443445            { 1, "INITTERM" },          /* 27 */
     
    450452            { 1, "ICONV" },             /* 34 */
    451453            { 1, "DLFCN" },             /* 35 */
    452             { 1, "PTHREAD" }            /* 36 */
     454            { 1, "PTHREAD" },           /* 36 */
     455            { 1, "DOSEX" }              /* 37 */
    453456        };
    454457        static __LIBC_LOGGROUPS DefGrps =
     
    464467         * Create the log instance.
    465468         */
    466         __libc_logSNPrintf(szFilename, sizeof(szFilename), "libc_%04x.log", getpid());
     469        __libc_logSNPrintf(szFilename, sizeof(szFilename), "libc_%04x.log", getPid());
    467470        if (__libc_logInit(&DefInst, 0, &DefGrps, szFilename))
    468471            pDefault = &DefInst;
     
    640643
    641644/**
     645 * Gets the current process id.
     646 */
     647inline static unsigned getPid(void)
     648{
     649    PTIB    pTib;
     650    PPIB    pPib;
     651    FS_VAR();
     652    FS_SAVE_LOAD();
     653    DosGetInfoBlocks(&pTib, &pPib);
     654    FS_RESTORE();
     655    return pPib->pib_ulpid;
     656}
     657
     658
     659/**
    642660 * Output an enter function log message.
    643661 * An enter message is considered to be one line and is appended a newline if
     
    790808
    791809    va_start(args, pszFormat);
    792     cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Leav %04x %s (%2d ms): ",
     810    cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Leav %04x %s (%d ms): ",
    793811                             uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags),
    794812                             pThread ? pThread->iErrNo : 0xface, pszFunction, uTS - uEnterTS);
     
    859877    va_start(args, pszFormat);
    860878    if (uEnterTS != ~0)
    861         cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Mesg %04x %s (%2d ms): ",
     879        cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Mesg %04x %s (%d ms): ",
    862880                                 uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags),
    863881                                 pThread ? pThread->iErrNo : 0xface, pszFunction, uTS - uEnterTS);
     
    9871005    va_start(args, pszFormat);
    9881006    if (uEnterTS != ~0)
    989         cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Dump %04x %s (%2d ms): ",
     1007        cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Dump %04x %s (%d ms): ",
    9901008                                 uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags),
    9911009                                 pThread ? pThread->iErrNo : 0xface, pszFunction, uTS - uEnterTS);
  • trunk/src/emx/src/lib/sys/seterrno.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    8686    errno = errno_tab[rc];
    8787}
     88
     89int __libc_native2errno (unsigned long rc)
     90{
     91  if (rc >= sizeof (errno_tab))
     92    return EINVAL;
     93  return errno_tab[rc];
     94}
     95
  • trunk/src/emx/src/lib/sys/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.10 to 1.11
    r1453 r1454  
    66#include "libc-alias.h"
    77#include <sys/signal.h>
     8#include <InnoTekLIBC/sharedpm.h>
    89
    910#ifndef __LIBC_THREAD_DECLARED
     
    140141#endif /* _OS2EMX_H */
    141142
    142 void _sys_set_errno (unsigned long rc);
    143143void _sys_get_clock (unsigned long *ms);
    144144
     
    150150ULONG _sys_shrink_heap_by (ULONG decr, ULONG sbrk_model);
    151151ULONG _sys_shrink_heap_obj_by (ULONG decr);
    152 #ifdef _FMC_SHARED
     152#ifdef _SYS_FMUTEX_H
    153153/** This mutex semaphore protects the heap. */
    154154EXTERN _fmutex          _sys_heap_fmutex;
     
    163163extern void             __init(int fDefaultHeapInHighMem);
    164164extern int              __init_dll(int fDefaultHeapInHighMem);
    165 extern void volatile    _sys_init_ret(void *stack);
     165extern void /*volatile*/_sys_init_ret(void *stack) __attribute__((__noreturn__));
    166166extern int              _sys_init_environ(const char *pszEnv);
    167167extern void             _sys_init_largefileio(void);
    168 extern int              _sys_init_filehandles(void);
     168extern int              __libc_fhInit(__LIBC_PSPMINHFHBHDR  pInherit);
     169/** @} */
     170
     171/** @defgroup grp_sys_inherit   Inherit Function
     172 * @{ */
     173__LIBC_PSPMINHFHBHDR    __libc_fhInheritPack(size_t *pcb);
     174void                    __libc_fhInheritDone(void);
    169175/** @} */
    170176
     
    174180/** @} */
    175181
     182
     183/** @group Error code and errno Functions.
     184 * @{ */
     185extern void             _sys_set_errno(unsigned long rc);
     186extern int              __libc_native2errno(unsigned long rc);
     187/** @} */
     188
     189/** @group Exec, Spawn and Fork stuff.
     190 * @{ */
     191#ifdef _SYS_FMUTEX_H
     192EXTERN _fmutex          __libc_gmtxExec INIT({0});
     193#endif
     194/** @} */
     195
  • trunk/src/emx/src/lib/time/strftime.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    2323#include <time.h>
    2424#include <limits.h>
    25 #include <sys/locale.h>
     25#include <InnoTekLIBC/locale.h>
    2626#include <emx/time.h>
    2727#include <sys/builtin.h>
     
    160160
    161161        case 'a':
    162           INS (__locale_time.swdays [t->tm_wday]);
     162          INS (__libc_gLocaleTime.swdays [t->tm_wday]);
    163163          break;
    164164        case 'A':
    165           INS (__locale_time.lwdays [t->tm_wday]);
     165          INS (__libc_gLocaleTime.lwdays [t->tm_wday]);
    166166          break;
    167167        case 'b':
    168168        case 'h':
    169           INS (__locale_time.smonths [t->tm_mon]);
     169          INS (__libc_gLocaleTime.smonths [t->tm_mon]);
    170170          break;
    171171        case 'B':
    172           INS (__locale_time.lmonths [t->tm_mon]);
     172          INS (__libc_gLocaleTime.lmonths [t->tm_mon]);
    173173          break;
    174174        case 'c':
    175           FMT (__locale_time.date_time_fmt);
     175          FMT (__libc_gLocaleTime.date_time_fmt);
    176176          break;
    177177        case 'C':
     
    209209          break;
    210210        case 'p':
    211           INS (t->tm_hour >= 12 ? __locale_time.pm : __locale_time.am);
     211          INS (t->tm_hour >= 12 ? __libc_gLocaleTime.pm : __libc_gLocaleTime.am);
    212212          break;
    213213        case 'r':
     
    233233          break;
    234234        case 'x':
    235           FMT (__locale_time.date_fmt);
     235          FMT (__libc_gLocaleTime.date_fmt);
    236236          break;
    237237        case 'X':
    238           FMT (__locale_time.time_fmt);
     238          FMT (__libc_gLocaleTime.time_fmt);
    239239          break;
    240240        case 'y':
     
    253253      }
    254254    }
    255     else if (!CHK_MBCS_PREFIX (__locale_ctype, c, i))
     255    else if (!CHK_MBCS_PREFIX (&__libc_GLocaleCtype, c, i))
    256256      CHR (c);
    257257    else
  • trunk/src/emx/src/lib/time/strptime.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1453 r1454  
    3131#include <string.h>
    3232#include <time.h>
     33#include <InnoTekLIBC/locale.h>
    3334#include <ctype.h>
    34 #include <sys/locale.h>
    3535#include <emx/time.h>
    3636
     
    4848    return NULL;
    4949
    50 static const unsigned char *parse_number (const unsigned char *s, int *dst,
     50static const char *parse_number (const char *s, int *dst,
    5151  int min, int max, int add)
    5252{
     
    6666}
    6767
    68 static const unsigned char *parse_string (const unsigned char *s,
     68static const char *parse_string (const char *s,
    6969  const char *str)
    7070{
     
    7979}
    8080
    81 static const unsigned char *parse_table (const unsigned char *s, int *dst,
     81static const char *parse_table (const char *s, int *dst,
    8282  char **tab, int n)
    8383{
     
    9999}
    100100
    101 static const unsigned char *parse_fmt (const unsigned char *s,
    102   const unsigned char *f, struct tm *tm, unsigned *retmask)
     101static const char *parse_fmt (const char *s,
     102  const char *f, struct tm *tm, unsigned *retmask)
    103103{
    104   const unsigned char *t;
     104  const char *t;
    105105  int week = -1;
    106106  int century = -1;
     
    165165
    166166        case 'a': /* Short weekday name */
    167           TABLE (&tm->tm_wday, __locale_time.swdays, 7);
     167          TABLE (&tm->tm_wday, __libc_gLocaleTime.swdays, 7);
    168168          mask |= MASK_WEEKDAY;
    169169          break;
    170170
    171171        case 'A': /* Long weekday name */
    172           TABLE (&tm->tm_wday, __locale_time.lwdays, 7);
     172          TABLE (&tm->tm_wday, __libc_gLocaleTime.lwdays, 7);
    173173          mask |= MASK_WEEKDAY;
    174174          break;
     
    176176        case 'b': /* Short month name */
    177177        case 'h':
    178           TABLE (&tm->tm_mon, __locale_time.smonths, 12);
     178          TABLE (&tm->tm_mon, __libc_gLocaleTime.smonths, 12);
    179179          mask |= MASK_MONTH;
    180180          break;
    181181
    182182        case 'B': /* Long month name */
    183           TABLE (&tm->tm_mon, __locale_time.lmonths, 12);
     183          TABLE (&tm->tm_mon, __libc_gLocaleTime.lmonths, 12);
    184184          mask |= MASK_MONTH;
    185185          break;
    186186
    187187        case 'c': /* Locale's defined time and date format */
    188           RECURSE (__locale_time.date_time_fmt);
     188          RECURSE (__libc_gLocaleTime.date_time_fmt);
    189189          break;
    190190
     
    242242           || (tm->tm_hour > 12))
    243243            return NULL;
    244           if ((t = parse_string (s, __locale_time.am)) != NULL)
     244          if ((t = parse_string (s, __libc_gLocaleTime.am)) != NULL)
    245245          {
    246246            if (tm->tm_hour == 12)
    247247              tm->tm_hour = 0;
    248248          }
    249           else if ((t = parse_string (s, __locale_time.pm)) != NULL)
     249          else if ((t = parse_string (s, __libc_gLocaleTime.pm)) != NULL)
    250250          {
    251251            if (tm->tm_hour != 12)
     
    296296
    297297        case 'x':
    298           RECURSE (__locale_time.date_fmt);
     298          RECURSE (__libc_gLocaleTime.date_fmt);
    299299          break;
    300300
    301301        case 'X':
    302           RECURSE (__locale_time.time_fmt);
     302          RECURSE (__libc_gLocaleTime.time_fmt);
    303303          break;
    304304
     
    410410char *_STD(strptime) (const char *buf, const char *format, struct tm *tm)
    411411{
    412   return (char *)parse_fmt ((const unsigned char *)buf,
    413                             (const unsigned char *)format, tm, NULL);
     412  return (char *)parse_fmt ((const char *)buf,
     413                            (const char *)format, tm, NULL);
    414414}
  • trunk/src/emx/src/libiconv/iconv.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    1 /* iconv wrapper based on OS/2 Unicode API. */
    2 
     1/* $Id$ */
     2/** @file
     3 *
     4 * iconv wrapper based on OS/2 Unicode API.
     5 *
     6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU General Public License as published by
     13 * the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
     26
     27
     28
     29/*******************************************************************************
     30*   Header Files                                                               *
     31*******************************************************************************/
     32#include <InnoTekLIBC/locale.h>
    333#define INCL_FSMACROS
    434#include <os2emx.h>
    535#include <uconv.h>
    636
    7 typedef struct _iconv_t
    8 {
    9   UconvObject from;             /* "From" conversion handle */
    10   UconvObject to;               /* "To" conversion handle */
    11 } *iconv_t;
    12 
    13 /* Tell "iconv.h" to not define iconv_t by itself.  */
    14 #define _ICONV_T
    15 #include "iconv.h"
    16 
     37#include <386/builtin.h>
     38#include <sys/smutex.h>
    1739#include <string.h>
    1840#include <malloc.h>
    1941#include <errno.h>
    2042#include <alloca.h>
    21 #include <emx/locale.h>
     43#include <InnoTekLIBC/fork.h>
     44#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_ICONV
     45#include <InnoTekLIBC/logstrict.h>
     46
     47typedef struct __libc_iconv_s
     48{
     49  UconvObject from;             /* "From" conversion handle */
     50  UconvObject to;               /* "To" conversion handle */
     51  UniChar * ucp_to;
     52  UniChar * ucp_from;
     53  struct __libc_iconv_s *pNext;
     54  struct __libc_iconv_s *pPrev;
     55} *iconv_t;
     56
     57/* Tell "iconv.h" to not define iconv_t by itself.  */
     58#define _ICONV_T
     59#include "iconv.h"
     60
     61
     62/*******************************************************************************
     63*   Global Variables                                                           *
     64*******************************************************************************/
     65/** List of open Iconv structures.
     66 * The purpose is to enable fork() to recreate the conversion objects. */
     67static iconv_t  gIconvHead = NULL;
     68/** Mutex protecting the list. */
     69static _smutex  gsmtxIconv = {0};
     70
     71/*******************************************************************************
     72*   Internal Functions                                                         *
     73*******************************************************************************/
     74static int iconvForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     75
    2276
    2377iconv_t
    2478iconv_open (const char *cp_to, const char *cp_from)
    2579{
    26   UniChar *ucp;
    2780  iconv_t conv;
    2881  uconv_attribute_t attr;
    2982  FS_VAR();
    3083
    31   conv = (iconv_t) malloc (sizeof (struct _iconv_t));
     84  conv = (iconv_t) calloc (sizeof (struct __libc_iconv_s), 1);
    3285  if (conv == NULL)
    3386    {
     
    3790
    3891  FS_SAVE_LOAD();
    39   ucp = (UniChar *) alloca ((strlen (cp_from) + 2 + 1) * sizeof (UniChar));
    40   __convert_codepage (cp_from, ucp);
    41   if (UniCreateUconvObject (ucp, &conv->from))
    42     {
     92  conv->ucp_from = (UniChar *) malloc ((strlen (cp_from) + 2 + 1) * sizeof (UniChar));
     93  if (conv->ucp_from == NULL)
     94    {
     95      free (conv);
     96      errno = ENOMEM;
     97      FS_RESTORE();
     98      return (iconv_t)(-1);
     99    }
     100  __libc_TranslateCodepage (cp_from, conv->ucp_from);
     101  if (UniCreateUconvObject (conv->ucp_from, &conv->from))
     102    {
     103      free (conv->ucp_from);
    43104      free (conv);
    44105      errno = EINVAL;
     
    47108    }
    48109
    49   ucp = (UniChar *) alloca ((strlen (cp_to) + 2 + 1) * sizeof (UniChar));
    50   __convert_codepage (cp_to, ucp);
    51   if (UniCreateUconvObject (ucp, &conv->to))
     110  conv->ucp_to = (UniChar *) malloc ((strlen (cp_to) + 2 + 1) * sizeof (UniChar));
     111  if (conv->ucp_to == NULL)
    52112    {
    53113      UniFreeUconvObject (conv->from);
     114      free (conv->ucp_from);
     115      free (conv);
     116      errno = ENOMEM;
     117      FS_RESTORE();
     118      return (iconv_t)(-1);
     119    }
     120  __libc_TranslateCodepage (cp_to, conv->ucp_to);
     121  if (UniCreateUconvObject (conv->ucp_to, &conv->to))
     122    {
     123      UniFreeUconvObject (conv->from);
     124      free (conv->ucp_from);
     125      free (conv->ucp_to);
    54126      free (conv);
    55127      errno = EINVAL;
     
    67139  attr.converttype &= ~(CVTTYPE_CTRL7F | CVTTYPE_PATH);
    68140  UniSetUconvObject (conv->from, &attr);
     141
     142  _smutex_request(&gsmtxIconv);
     143  conv->pPrev = NULL;
     144  conv->pNext = gIconvHead;
     145  if (conv->pNext)
     146    conv->pNext->pPrev = conv;
     147  gIconvHead = conv;
     148  _smutex_release(&gsmtxIconv);
    69149
    70150  FS_RESTORE();
     
    170250iconv_close (iconv_t conv)
    171251{
    172   if (!conv && conv != (iconv_t)(-1))
     252  if (conv && conv != (iconv_t)(-1))
    173253    {
    174254      FS_VAR();
     255
     256      _smutex_request(&gsmtxIconv);
     257      if (conv->pNext)
     258          conv->pNext->pPrev = conv->pPrev;
     259      if (conv->pPrev)
     260          conv->pPrev->pNext = conv->pNext;
     261      else
     262          gIconvHead = conv->pNext;
     263      _smutex_release(&gsmtxIconv);
     264
     265      free (conv->ucp_to);
     266      free (conv->ucp_from);
    175267      FS_SAVE_LOAD();
    176       UniFreeUconvObject (conv->to);
    177       UniFreeUconvObject (conv->from);
     268      if (conv->to) UniFreeUconvObject (conv->to);
     269      if (conv->from) UniFreeUconvObject (conv->from);
    178270      FS_RESTORE();
    179271      free (conv);
     
    181273  return 0;
    182274}
     275
     276
     277#undef  __LIBC_LOG_GROUP
     278#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_FORK
     279_FORK_CHILD1(0xffff0000, iconvForkChild1)
     280
     281/**
     282 * Walks the chain of iconv_t structures.
     283 *
     284 * @returns 0 on success.
     285 * @returns positive errno on warning.
     286 * @returns negative errno on failure. Fork will be aborted.
     287 * @param   pForkHandle     Pointer to fork handle.
     288 * @param   enmOperation    Callback operation.
     289 */
     290static int iconvForkChild1(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
     291{
     292    LIBCLOG_ENTER("pForkHandle=%p enmOperation=%d\n", (void *)pForkHandle, enmOperation);
     293    int rc = 0;
     294
     295    switch (enmOperation)
     296    {
     297        case __LIBC_FORK_OP_FORK_CHILD:
     298        {
     299            struct __libc_iconv_s *pCur;
     300            for (rc = 0, pCur = gIconvHead; !rc && pCur; pCur = pCur->pNext)
     301            {
     302                pCur->from = NULL;
     303                pCur->to   = NULL;
     304
     305                rc = UniCreateUconvObject(pCur->ucp_from, &pCur->from);
     306                if (!rc)
     307                {
     308                    rc = UniCreateUconvObject(pCur->ucp_to, &pCur->to);
     309                    if (!rc)
     310                    {
     311                        uconv_attribute_t   Attr;
     312                        UniQueryUconvObject(pCur->from, &Attr, sizeof(Attr), NULL, NULL, NULL);
     313                        Attr.converttype &= ~(CVTTYPE_CTRL7F | CVTTYPE_PATH);
     314                        UniSetUconvObject(pCur->from, &Attr);
     315                    }
     316                    else
     317                        LIBC_ASSERTM_FAILED("Failed to create the 'to' object. rc=%d spec=%ls\n", rc, pCur->ucp_to);
     318                }
     319                else
     320                    LIBC_ASSERTM_FAILED("Failed to create the 'from' object. rc=%d spec=%ls\n", rc, pCur->ucp_from);
     321            }
     322            if (rc)
     323                rc = -EACCES; /* bad, fixme */
     324            break;
     325        }
     326
     327        default:
     328            rc = 0;
     329            break;
     330    }
     331    LIBCLOG_RETURN_INT(rc);
     332}
     333
  • trunk/src/emx/src/libiconv/iconv.smak

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1453 r1454  
    22include comend.smak
    33
    4 .MODULE := iconv
     4.MODULE := libiconv
    55.MDESC  := POSIX iconv API library
     6
     7.TARGET := libiconv_p.a
     8.TKIND  := aout prof
     9.TSRC   := $(wildcard src/libiconv/*.c)
     10.INSDIR = lib/
     11include mklib.smak
    612
    713.TARGET := libiconv.a
     
    1117include mklib.smak
    1218
     19.TARGET := libiconv_l.a
     20.TKIND  := aout log
     21.TSRC   := $(wildcard src/libiconv/*.c)
     22.INSDIR = lib/
     23include mklib.smak
     24
    1325# Forget temporary variables
    1426include comend.smak
  • trunk/src/emx/src/libsocket/_getsockhandle.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4848{
    4949    LIBCLOG_ENTER("socket=%d\n", socket);
    50     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     50    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    5151    if (pFHSocket)
    5252        LIBCLOG_RETURN_INT(pFHSocket->iSocket);
  • trunk/src/emx/src/libsocket/_impsockhandle.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    5454    int             cb;
    5555    int             fh;
    56     int             rc;
    5756
    5857    /*
     
    6261    if (__libsocket_getsockopt(os2socket, SOL_SOCKET, SO_TYPE, (char*)&iType, &cb) < 0)
    6362    {
    64         __libsocket_setErrno(EBADF);
     63        __libc_TcpipSetErrno(EBADF);
    6564        LIBCLOG_RETURN_INT(-1);
    6665    }
     
    6968     * Allocate LIBC handle.
    7069     */
    71     rc = __libc_FHAllocate(-1, O_RDWR | F_SOCKET, sizeof(LIBCSOCKETFH), &__libsocket_gSocketOps, (PLIBCFH*)&pFH, &fh);
    72     if (rc)
     70    pFH = TCPNAMEG(AllocFH)(os2socket, &fh);
     71    if (!pFH)
    7372        LIBCLOG_RETURN_INT(-1);
    74     pFH->iSocket = os2socket;
    7573    LIBCLOG_RETURN_INT(fh);
    7674}
  • trunk/src/emx/src/libsocket/accept.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    3333#include <sys/fcntl.h>
    3434#include <emx/io.h>
     35#include <os2emx.h>
     36#include <InnoTekLIBC/sharedpm.h>
    3537#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_SOCKET
    3638#include <InnoTekLIBC/logstrict.h>
     
    3941int accept(int socket, struct sockaddr *addr, int *addrlen)
    4042{
    41     LIBCLOG_ENTER("socket=%d socketaddr=%p addrlen=%p\n",
    42                   socket, addr, addrlen);
    43     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     43    LIBCLOG_ENTER("socket=%d socketaddr=%p addrlen=%p:{%d}\n",
     44                  socket, (void *)addr, (void *)addrlen, addrlen ? *addrlen : -1);
     45    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4446    int             s;
    4547    if (pFHSocket)
     
    4850        if (s >= 0)
    4951        {
    50             int             rc;
    5152            int             fh;
    52             PLIBCSOCKETFH   pFH;
    53             rc = __libc_FHAllocate(-1, O_RDWR | F_SOCKET, sizeof(LIBCSOCKETFH), &__libsocket_gSocketOps, (PLIBCFH*)&pFH, &fh);
    54             if (!rc)
    55             {
    56                 pFH->iSocket = s;
     53            PLIBCSOCKETFH   pFH = TCPNAMEG(AllocFH)(s, &fh);
     54            if (pFH)
    5755                LIBCLOG_RETURN_INT(fh);
    58             }
    5956            else
    6057                __libsocket_soclose(s);
    61             __libsocket_setSocketErrno();
     58            __libc_TcpipSetSocketErrno();
    6259        }
    6360        else
    64             __libsocket_setLibcErrno();
     61            __libc_TcpipUpdateErrno();
    6562    }
    6663
  • trunk/src/emx/src/libsocket/bind.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d addr=%p addrlen=%d\n", socket, addr, addrlen);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/bsdselect.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    3838#include "socket.h"
    3939
    40 
    41 /*******************************************************************************
    42 *   Defined Constants And Macros                                               *
    43 *******************************************************************************/
    44 #ifdef TCPV40HDRS
    45 
    46 #define MY_FD_SET(fd, set)      FD_SET(fd, set)
    47 #define MY_FD_ISSET(fd, set)    FD_ISSET(fd, set)
    48 #define MY_FD_ZERO(set, cb)     memset(set, 0, cb);
    49 #define my_fd_set               fd_set
    50 
    51 #else
    52 
    53 #define MY_FD_SET(fd, set)      V5_FD_SET(fd, set)
    54 #define MY_FD_ISSET(fd, set)    V5_FD_ISSET(fd, set)
    55 #define MY_FD_ZERO(set, cb)     memset(set, 0, cb);
    56 #define my_fd_set               v5_fd_set
    57 
    58 #endif
    59 
    60 
    61 /**
    62  * Calculate the size required for the converted set structure.
    63  * @returns number of bytes.
    64  * @param   c       Number of file descriptors specified in the call.
    65  * @param   pFrom   The select input fd_set structure.
    66  * @parm    pcFDs   Store the new number of file descriptors (socket handles) to examin.
    67  */
    68 static inline int calcsize(int c, const struct fd_set *pFrom, int *pcFDs)
    69 {
    70     int cbRet;
    71     int i;
    72 #ifdef TCPV40HDRS
    73     /* here we need to figure out the max real socket handle */
    74     int iMax;
    75     for (iMax = *pcFDs - 1, i = 0; i < c; i++)
    76         if (FD_ISSET(i, pFrom))
    77         {
    78             PLIBCSOCKETFH   pFHSocket = __libsocket_FH(i);
    79             if (pFHSocket && iMax < pFHSocket->iSocket)
    80                 iMax = pFHSocket->iSocket;
    81         }
    82     cbRet = (iMax + 8) / 8;             /* iMax is index not count, thus +8 not +7. */
    83     *pcFDs = iMax + 1;
    84 #else
    85     for (cbRet = sizeof(u_short), i = 0; i < c; i++)
    86         if (FD_ISSET(i, pFrom))
    87             cbRet++;
    88     *pcFDs = c;
    89 #endif
    90     if (cbRet < sizeof(struct my_fd_set))
    91         return sizeof(struct my_fd_set);
    92     return cbRet;
    93 }
    94 
    95 /** Converts the LIBC fd_set strcture pointed to by pFrom with it's LIBC socket handles,
    96  * to the fd_set strcuture used by the OS/2 tcpip and the OS/2 socket handles.
    97  * @returns 0 on success.
    98  * @returns -1 on failure, both errnos set.
    99  * @param   c       Number of file descriptors specified in the call.
    100  * @param   cb      Size of pTo. (used for zeroing it)
    101  * @param   pFrom   The select input fd_set structure.
    102  * @param   pTo     The structure we present to OS/2 TCPIP.
    103  *                  This will be initialized.
    104  * @param   pszType Typestring to use in the log.
    105  */
    106 static inline int convert(int c, int cb, const struct fd_set *pFrom, struct my_fd_set *pTo, const char *pszType)
    107 {
    108     int i;
    109     MY_FD_ZERO(pTo, cb)
    110     for (i = 0; i < c; i++)
    111     {
    112         if (FD_ISSET(i, pFrom))
    113         {
    114             PLIBCSOCKETFH   pFHSocket = __libsocket_FH(i);
    115             if (!pFHSocket)
    116             {
    117                 LIBCLOG_MSG2("Invalid handle %d specified (%s).\n", i, pszType);
    118                 return -1;
    119             }
    120             MY_FD_SET(pFHSocket->iSocket, pTo);
    121             LIBCLOG_MSG2("%s: %02d -> %03d\n", pszType, i, pFHSocket->iSocket);
    122         }
    123     }
    124     pszType = pszType;
    125     return 0;
    126 }
    127 
    128 /**
    129  * Updates the pTo structure with the fds marked ready in pFrom.
    130  *
    131  * @param   c       Number of file descriptors specified in the call.
    132  * @param   pFrom   The structure returned from OS/2 TCPIP select.
    133  * @param   pTo     The structure passed in to select which have to
    134  *                  be updated for the return.
    135  * @param   pszType Typestring to use in the log.
    136  */
    137 static inline void update(int c, const struct my_fd_set *pFrom, struct fd_set *pTo, const char *pszType)
    138 {
    139     int i;
    140     for (i = 0; i < c; i++)
    141     {
    142         if (FD_ISSET(i, pTo))
    143         {
    144             PLIBCSOCKETFH   pFHSocket = __libsocket_FH(i);
    145             if (pFHSocket)
    146             {
    147                 if (!MY_FD_ISSET(pFHSocket->iSocket, pFrom))
    148                 {
    149                     FD_CLR(i, pTo);
    150                     LIBCLOG_MSG2("%s: %02d -> %03d set\n", pszType, i, pFHSocket->iSocket);
    151                 }
    152                 else
    153                     LIBCLOG_MSG2("%s: %02d -> %03d clear\n", pszType, i, pFHSocket->iSocket);
    154             }
    155         }
    156     }
    157     pszType = pszType;
    158 }
    159 
    160 
    161 
    16240int bsdselect(int nfds, struct fd_set *readfds, struct fd_set *writefds, struct fd_set *exceptfds, struct timeval *tv)
    16341{
    164     LIBCLOG_ENTER("nfds=%d readfds=%p writefds=%p exceptfds=%d tv=%p={tv_sec=%d, rv_usec=%d}\n",
    165                   nfds, readfds, writefds, exceptfds, tv, tv ? tv->tv_sec : -1, tv ? tv->tv_usec : -1);
    166 #ifdef TCPV40HDRS
    167     struct fd_set      *pRead;
    168     struct fd_set      *pWrite;
    169     struct fd_set      *pExcept;
    170 #else
    171     struct v5_fd_set   *pRead;
    172     struct v5_fd_set   *pWrite;
    173     struct v5_fd_set   *pExcept;
    174 #endif
    175     int                 rc;
    176     int                 cb = 0;
    177     int                 cFDs = 0;
    178 
    179     /*
    180      * Calculate bitmapsize.
    181      */
    182     if (readfds)
    183         cb = calcsize(nfds, readfds, &cFDs);
    184     if (writefds)
    185     {
    186         int cbT = calcsize(nfds, writefds, &cFDs);
    187         if (cbT > cb)
    188             cb = cbT;
    189     }
    190     if (exceptfds)
    191     {
    192         int cbT = calcsize(nfds, exceptfds, &cFDs);
    193         if (cbT > cb)
    194             cb = cbT;
    195     }
    196 
    197     /*
    198      * Allocate new bitmaps.
    199      */
    200     pRead = NULL;
    201     if (readfds)
    202     {
    203         pRead = alloca(cb);
    204         if (!pRead)
    205         {
    206             __libsocket_setErrno(ENOMEM);
    207             LIBCLOG_RETURN_INT(-1);
    208         }
    209     }
    210 
    211     pWrite = NULL;
    212     if (writefds)
    213     {
    214         pWrite = alloca(cb);
    215         if (!pWrite)
    216         {
    217             __libsocket_setErrno(ENOMEM);
    218             LIBCLOG_RETURN_INT(-1);
    219         }
    220     }
    221 
    222     pExcept = NULL;
    223     if (exceptfds)
    224     {
    225         pExcept = alloca(cb);
    226         if (!pExcept)
    227         {
    228             __libsocket_setErrno(ENOMEM);
    229             LIBCLOG_RETURN_INT(-1);
    230         }
    231     }
    232 
    233     /*
    234      * Convert the bitmaps.
    235      */
    236     if (readfds)
    237     {
    238         if (convert(nfds, cb, readfds, pRead, "read "))
    239             LIBCLOG_RETURN_INT(-1);
    240     }
    241 
    242     if (writefds)
    243     {
    244         if (convert(nfds, cb, writefds, pWrite, "write"))
    245             LIBCLOG_RETURN_INT(-1);
    246     }
    247 
    248     if (exceptfds)
    249     {
    250         if (convert(nfds, cb, exceptfds, pExcept, "excpt"))
    251             LIBCLOG_RETURN_INT(-1);
    252     }
    253 
    254     /*
    255      * Do the call.
    256      */
    257     LIBCLOG_MSG("calling native: cFDs=%d pRead=%p pWrite=%p, pExcept=%p tv=%p\n",
    258                 cFDs, pRead, pWrite, pExcept, tv);
    259     rc = __libsocket_bsdselect(cFDs, pRead, pWrite, pExcept, tv);
    260     if (rc < 0)
    261     {
    262         __libsocket_setLibcErrno();
    263         LIBCLOG_RETURN_INT(rc);
    264     }
    265 
    266     /*
    267      * Timeout?
    268      *  Just clear the bitmaps and return.
    269      */
    270     if (rc == 0)
    271     {
    272         cb = (nfds + 7) / 8;
    273         if (readfds)
    274             memset(readfds, 0, cb);
    275         if (writefds)
    276             memset(writefds, 0, cb);
    277         if (exceptfds)
    278             memset(exceptfds, 0, cb);
    279         LIBCLOG_RETURN_INT(0);
    280     }
    281 
    282     /*
    283      * Convert the bitmaps.
    284      */
    285     if (readfds)
    286         update(nfds, pRead, readfds, "read ");
    287     if (writefds)
    288         update(nfds, pWrite, writefds, "write");
    289     if (exceptfds)
    290         update(nfds, pExcept, exceptfds, "excpt");
    291 
     42    LIBCLOG_ENTER("nfds=%d readfds=%p writefds=%p exceptfds=%p tv=%p={tv_sec=%ld, rv_usec=%ld}\n",
     43                  nfds, (void *)readfds, (void *)writefds, (void *)exceptfds, (void *)tv,
     44                  tv ? tv->tv_sec : -1, tv ? tv->tv_usec : -1);
     45    int rc = TCPNAMEG(bsdselect)(nfds, readfds, writefds, exceptfds, tv);
    29246    LIBCLOG_RETURN_INT(rc);
    29347}
  • trunk/src/emx/src/libsocket/connect.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d addr=%p addrlen=%d\n", socket, addr, addrlen);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/getpeername.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d addr=%p addrlen=%d\n", socket, addr, addrlen);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/getsockname.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d addr=%p addrlen=%d\n", socket, addr, addrlen);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/getsockopt.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4141    LIBCLOG_ENTER("socket=%d level=%#x optname=%#x optval=%p optlen=%d\n",
    4242                  socket, level, optname, optval, optlen);
    43     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     43    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4444    if (pFHSocket)
    4545    {
     
    6969            LIBCLOG_RETURN_INT(rc);
    7070        }
    71         __libsocket_setLibcErrno();
     71        __libc_TcpipUpdateErrno();
    7272    }
    7373
  • trunk/src/emx/src/libsocket/listen.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d backlog=%d\n", socket, backlog);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/os2_ioctl.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4545{
    4646    LIBCLOG_ENTER("socket=%d request=%#x arg=%p len_arg=%d\n", socket, (int)request, arg, len_arg);
    47     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     47    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4848    if (pFHSocket)
    4949    {
     
    5656        if (rc >= 0)
    5757            LIBCLOG_RETURN_INT(rc);
    58         __libsocket_setLibcErrno();
     58        __libc_TcpipUpdateErrno();
    5959    }
    6060    LIBCLOG_RETURN_INT(-1);
  • trunk/src/emx/src/libsocket/os2_select.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    5252    if (aSockets)
    5353    {
    54         __libsocket_setErrno(ENOMEM);
     54        __libc_TcpipSetErrno(ENOMEM);
    5555        LIBCLOG_RETURN_INT(-1);
    5656    }
    5757    for (i = 0; i < cSockets; i++)
    5858    {
    59         PLIBCSOCKETFH   pFHSocket = __libsocket_FH(s[i]);
     59        PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(s[i]);
    6060        if (!pFHSocket)
    6161        {
    62             __libsocket_setErrno(EBADF);
     62            __libc_TcpipSetErrno(EBADF);
    6363            LIBCLOG_RETURN_INT(-1);
    6464        }
     
    7272    if (rc >= 0)
    7373        LIBCLOG_RETURN_INT(rc);
    74     __libsocket_setLibcErrno();
     74    __libc_TcpipUpdateErrno();
    7575    LIBCLOG_RETURN_INT(-1);
    7676}
  • trunk/src/emx/src/libsocket/recv.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d buf=%p len=%d flags=%#x\n", socket, buf, len, flags);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/recvfrom.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4141    LIBCLOG_ENTER("socket=%d buf=%p len=%d flags=%#x from=%p from=%d\n",
    4242                  socket, buf, len, flags, from, fromlen);
    43     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     43    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4444    if (pFHSocket)
    4545    {
     
    4848        if (rc >= 0)
    4949            LIBCLOG_RETURN_INT(rc);
    50         __libsocket_setLibcErrno();
     50        __libc_TcpipUpdateErrno();
    5151    }
    5252
  • trunk/src/emx/src/libsocket/recvmsg.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d msg=%p flags=%d\n", socket, msg, flags);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/send.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d buf=%p len=%d flags=%#x\n", socket, buf, len, flags);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/sendmsg.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d msg=%p flags=%#x\n", socket, msg, flags);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/sendto.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4141    LIBCLOG_ENTER("socket=%d buf=%p len=%d flags=%#x to=%p tolen=%p\n",
    4242                  socket, buf, len, flags, to, tolen);
    43     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     43    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4444    if (pFHSocket)
    4545    {
     
    4848        if (rc >= 0)
    4949            LIBCLOG_RETURN_INT(rc);
    50         __libsocket_setLibcErrno();
     50        __libc_TcpipUpdateErrno();
    5151    }
    5252
  • trunk/src/emx/src/libsocket/setsockopt.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4141    LIBCLOG_ENTER("socket=%d level=%#x optname=%#x optval=%p optlen=%d\n",
    4242                  socket, level, optname, optval, optlen);
    43     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     43    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4444    if (pFHSocket)
    4545    {
     
    6060        if (rc >= 0)
    6161            LIBCLOG_RETURN_INT(rc);
    62         __libsocket_setLibcErrno();
     62        __libc_TcpipUpdateErrno();
    6363    }
    6464
  • trunk/src/emx/src/libsocket/shutdown.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d how=%d\n", socket, how);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/so_cancel.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d\n", socket);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/so_ioctl.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    4242{
    4343    LIBCLOG_ENTER("socket=%d request=%#lx arg=%#lx\n", socket, request, (&request)[1]);
    44     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     44    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4545    if (pFHSocket)
    4646    {
  • trunk/src/emx/src/libsocket/so_readv.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d iov=%p iovcnt=%d\n", socket, iov, iovcnt);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/so_writev.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d iov=%p iovcnt=%d\n", socket, iov, iovcnt);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
     
    4747        if (rc >= 0)
    4848            LIBCLOG_RETURN_INT(rc);
    49         __libsocket_setLibcErrno();
     49        __libc_TcpipUpdateErrno();
    5050    }
    5151
  • trunk/src/emx/src/libsocket/soabort.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4343{
    4444    LIBCLOG_ENTER("socket=%d\n", socket);
    45     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     45    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4646    if (pFHSocket)
    4747    {
     
    5050        if (rc >= 0)
    5151            LIBCLOG_RETURN_INT(rc);
    52         __libsocket_setLibcErrno();
     52        __libc_TcpipUpdateErrno();
    5353    }
    5454
  • trunk/src/emx/src/libsocket/socket.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r1453 r1454  
    3333#include <sys/fcntl.h>
    3434#include <emx/io.h>
     35#include <os2emx.h>
     36#include <InnoTekLIBC/sharedpm.h>
    3537#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_SOCKET
    3638#include <InnoTekLIBC/logstrict.h>
     
    4648    if (s >= 0)
    4749    {
    48         int             rc;
    4950        int             fh;
    50         PLIBCSOCKETFH   pFH;
    51         rc = __libc_FHAllocate(-1, O_RDWR | F_SOCKET, sizeof(LIBCSOCKETFH), &__libsocket_gSocketOps, (PLIBCFH*)&pFH, &fh);
    52         if (!rc)
    53         {
    54             pFH->iSocket = s;
     51        PLIBCSOCKETFH   pFH = TCPNAMEG(AllocFH)(s, &fh);
     52        if (pFH)
    5553            LIBCLOG_RETURN_INT(fh);
    56         }
    5754        else
    5855            __libsocket_soclose(s);
    59         __libsocket_setSocketErrno();
     56        __libc_TcpipSetSocketErrno();
    6057    }
    6158    else
    62         __libsocket_setLibcErrno();
     59        __libc_TcpipUpdateErrno();
    6360
    6461    LIBCLOG_RETURN_INT(-1);
  • trunk/src/emx/src/libsocket/socket.h

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    44 * Interal libsocket stuff.
    55 *
    6  * Copyright (c) 2003 knut st. osmundsen <bird-srcspam@anduin.net>
     6 * Copyright (c) 2003-2004 knut st. osmundsen <bird-srcspam@anduin.net>
    77 *
    88 *
     
    2828#define __socket_h__
    2929
    30 
    31 /** @group libsocket    libsocket
    32  * @{
    33  */
    34 
    35 /*******************************************************************************
    36 *   Defined Constants And Macros                                               *
    37 *******************************************************************************/
    38 /** The offset the OS/2 TCP/IP errno values are skewed compared to the
    39  * LIBC errno values. */
    40 #define EOS2_TCPIP_OFFSET   10000
    41 
    42 /** Get the low word of the ioctl request number.
    43  * Used to support ioctl request numbers from old and new _IOC macros.
    44  */
    45 #define __IOCLW(a) ((unsigned short)(a))
    46 
    47 #ifndef TCPV40HDRS
    48 
    49 #define V5_FD_SETSIZE      64
    50 #define V5_FD_SET(fd, set) do { \
    51    /* if (((v5_fd_set *)(set))->fd_count < V5_FD_SETSIZE) - calcsize fixes this */ \
    52         ((v5_fd_set *)(set))->fd_array[((v5_fd_set *)(set))->fd_count++]=fd;\
    53 } while(0)
    54 #define V5_FD_ISSET(fd, set)    v5_isset(fd, set)
     30#include <InnoTekLIBC/tcpip.h>
     31#if 0
     32/* force all objects using socket.h to link in the init routine. */
     33asm(".stabs  \"___libsocket_init\",1,0,0,0");
     34#endif
    5535
    5636#endif
    57 
    58 
    59 /*******************************************************************************
    60 *   Structures and Typedefs                                                    *
    61 *******************************************************************************/
    62 /** Socket handle.*/
    63 typedef struct __libc_SocketHandle
    64 {
    65     /** the common fh core. */
    66     LIBCFH      core;
    67 
    68     /** OS/2 socket number. */
    69     int         iSocket;
    70 } LIBCSOCKETFH, *PLIBCSOCKETFH;
    71 
    72 
    73 #ifndef TCPV40HDRS
    74 
    75 #pragma pack(4)
    76 /** OS/2 oddities from the BSD 4.4 stack. */
    77 typedef struct v5_fd_set {
    78         u_short fd_count;               /* how many are SET? */
    79         int     fd_array[V5_FD_SETSIZE];/* an array of SOCKETs */
    80 } v5_fd_set;
    81 #pragma pack()
    82 
    83 /** internal helper */
    84 static inline int v5_isset(int fd, const struct v5_fd_set *set)
    85 {
    86     const int  *pfd = &set->fd_array[0];
    87     int         c   = set->fd_count;
    88     while (c > 0)
    89     {
    90         if (*pfd == fd)
    91             return 1;
    92         pfd++;
    93         c--;
    94     }
    95     return 0;
    96 }
    97 
    98 #endif
    99 
    100 
    101 /*******************************************************************************
    102 *   Global Variables                                                           *
    103 *******************************************************************************/
    104 extern LIBCFHOPS __libsocket_gSocketOps;
    105 
    106 
    107 /*******************************************************************************
    108 *   Internal Functions                                                         *
    109 *******************************************************************************/
    110 /** @defgroup libsocket_renamed     Renamed Imports.
    111  * @{ */
    112 int     TCPCALL __libsocket_accept(int, struct sockaddr *, int *);
    113 int     TCPCALL __libsocket_bind(int, __const__ struct sockaddr *, int);
    114 int     TCPCALL __libsocket_connect(int, __const__ struct sockaddr *, int);
    115 int     TCPCALL __libsocket_getpeername(int, struct sockaddr *, int *);
    116 int     TCPCALL __libsocket_getsockname(int, struct sockaddr *, int *);
    117 int     TCPCALL __libsocket_getsockopt(int, int, int, void *, int *);
    118 int     TCPCALL __libsocket_ioctl(int, int, char *);
    119 int     TCPCALL __libsocket_listen(int, int);
    120 int     TCPCALL __libsocket_os2_ioctl(int, unsigned long, char *, int);
    121 int     TCPCALL __libsocket_os2_select(int *, int, int, int, long);
    122 int     TCPCALL __libsocket_recv(int, void *, int, int);
    123 int     TCPCALL __libsocket_recv(int, void *, int, int);
    124 int     TCPCALL __libsocket_recvfrom(int, void *, int, int, struct sockaddr *, int *);
    125 int     TCPCALL __libsocket_recvmsg(int, struct msghdr *, int);
    126 int     TCPCALL __libsocket_send(int, __const__ void *, int, int);
    127 int     TCPCALL __libsocket_send(int, const void *, int, int);
    128 int     TCPCALL __libsocket_sendmsg(int, __const__ struct msghdr *, int);
    129 int     TCPCALL __libsocket_sendto(int, __const__ void *, int, int, __const__ struct sockaddr *, int);
    130 int     TCPCALL __libsocket_setsockopt(int, int, int, __const__ void *, int);
    131 int     TCPCALL __libsocket_shutdown(int, int);
    132 int     TCPCALL __libsocket_sock_errno(void);
    133 int     TCPCALL __libsocket_socket(int, int, int);
    134 int     TCPCALL __libsocket_socket(int, int, int);
    135 int     TCPCALL __libsocket_socketpair(int, int, int, int *);
    136 int     TCPCALL __libsocket_soclose(int);
    137 int     TCPCALL __libsocket_accept_and_recv(long, long*, struct sockaddr *, long*, struct sockaddr*, long*, caddr_t, size_t);
    138 void    TCPCALL __libsocket_addsockettolist(int);
    139 int     TCPCALL __libsocket_removesocketfromlist(int);
    140 ssize_t TCPCALL __libsocket_so_readv(int, struct iovec *, int);
    141 ssize_t TCPCALL __libsocket_so_writev(int, struct iovec *, int);
    142 int     TCPCALL __libsocket_so_cancel(int);
    143 int     TCPCALL __libsocket_soabort(int);
    144 int     TCPCALL __libsocket_Raccept(int, struct sockaddr *, int *);
    145 struct sockaddr_in;
    146 int     TCPCALL __libsocket_tcpip4_Rbind(int, struct sockaddr_in *, int, struct sockaddr_in *);
    147 int     TCPCALL __libsocket_Rbind(int, struct sockaddr *, int, struct sockaddr *);
    148 int     TCPCALL __libsocket_Rconnect(int, const struct sockaddr *, int);
    149 int     TCPCALL __libsocket_Rgetsockname(int, struct sockaddr *, int *);
    150 int     TCPCALL __libsocket_Rlisten(int, int);
    151 #ifndef TCPV40HDRS
    152 ssize_t TCPCALL __libsocket_send_file(int *, struct sf_parms *, int );
    153 int     TCPCALL __libsocket_socketpair(int af, int type, int flags, int *osfd);
    154 #endif
    155 char *  TCPCALL __libsocket_sock_strerror(int);
    156 #ifdef TCPV40HDRS
    157 int     TCPCALL __libsocket_bsdselect(int, fd_set *, fd_set *, fd_set *, struct timeval *);
    158 #else
    159 int     TCPCALL __libsocket_bsdselect(int, v5_fd_set *, v5_fd_set *, v5_fd_set *, struct timeval *);
    160 #endif
    161 void    TCPCALL __libsocket_set_errno(int);
    162 /** @} */
    163 
    164 
    165 /** @defgroup libsocket_internal    Internal helpers.
    166  * @{ */
    167 /**
    168  * Sets the LIBC and socket errno variables to a given error number.
    169  */
    170 static inline void  __libsocket_setErrno(int err)
    171 {
    172     errno = err;
    173     __libsocket_set_errno(err + EOS2_TCPIP_OFFSET);
    174 }
    175 
    176 /**
    177  * Updates the LIBC errno with the latest socket error.
    178  */
    179 static inline void  __libsocket_setLibcErrno(void)
    180 {
    181     int err = __libsocket_sock_errno();
    182     if (err >= EOS2_TCPIP_OFFSET && err < EOS2_TCPIP_OFFSET + 1000)
    183         errno = err - EOS2_TCPIP_OFFSET;
    184 }
    185 
    186 /**
    187  * Updates the socket errno with the latest LIBC error.
    188  */
    189 static inline void  __libsocket_setSocketErrno(void)
    190 {
    191     __libsocket_set_errno(errno + EOS2_TCPIP_OFFSET);
    192 }
    193 
    194 /**
    195  * Gets the socket errno translating it to a LIBC errno.
    196  */
    197 static inline int   __libsocket_getSocketErrno(void)
    198 {
    199     int err = __libsocket_sock_errno();
    200     if (err >= EOS2_TCPIP_OFFSET && err < EOS2_TCPIP_OFFSET + 1000)
    201         return err - EOS2_TCPIP_OFFSET;
    202     return EDOOFUS;
    203 }
    204 
    205 
    206 /**
    207  * Retrieve the socket handle structure for a given handle.
    208  * @returns Pointer to socket handle structure on success.
    209  * @returns NULL on failure with errno set to the appropriate value.
    210  * @param   socket  Socket handle number.
    211  */
    212 static inline PLIBCSOCKETFH   __libsocket_FH(int socket)
    213 {
    214     PLIBCSOCKETFH   pFHSocket = (PLIBCSOCKETFH)__libc_FH(socket);
    215     if (pFHSocket)
    216     {
    217         if ((pFHSocket->core.fFlags & F_TYPEMASK) == F_SOCKET)
    218             return pFHSocket;
    219         __libsocket_setErrno(ENOSYS);
    220     }
    221     else
    222         __libsocket_setErrno(EBADF);
    223     return NULL;
    224 }
    225 
    226 /** @} */
    227 
    228 
    229 /** @} */
    230 
    231 #endif
  • trunk/src/emx/src/libsocket/socketpair.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r1453 r1454  
    2828#include <sys/fcntl.h>
    2929#include <emx/io.h>
     30#include <os2emx.h>
     31#include <InnoTekLIBC/sharedpm.h>
    3032#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_SOCKET
    3133#include <InnoTekLIBC/logstrict.h>
     
    4648int     TCPCALL socketpair(int af, int type, int flags, int *osfd)
    4749{
    48     LIBCLOG_ENTER("af=%d type=%p flags=%#x osfd=%p\n", af, type, flags, osfd);
     50    LIBCLOG_ENTER("af=%d type=%d flags=%#x osfd=%p\n", af, type, flags, (void *)osfd);
    4951#ifdef TCPV40HDRS
    5052    int     rc;
     
    109111    osfd[0] = sock1accept;
    110112    osfd[1] = sock2;
    111     LIBCLOG_RETURN_INT(0);
     113    LIBCLOG_RETURN_MSG(0, "ret 0 osfd[0]=%d osfd[1]=%d\n", osfd[0], osfd[1]);
    112114
    113115failure:
     
    124126    int             fh1;
    125127    int             fh2;
    126     PLIBCSOCKETFH   pFH;
     128    PLIBCSOCKETFH   pFH1;
    127129
    128130    rc = __libsocket_socketpair(af, type, flags, osfd);
    129131    if (rc < 0)
    130132    {
    131         __libsocket_setLibcErrno();
     133        __libc_TcpipUpdateErrno();
    132134        LIBCLOG_RETURN_INT(-1);
    133135    }
     
    136138     * Allocate LIBC sockets.
    137139     */
    138     rc = __libc_FHAllocate(-1, O_RDWR | F_SOCKET, sizeof(LIBCSOCKETFH), &__libsocket_gSocketOps, (PLIBCFH*)&pFH, &fh1);
    139     if (!rc)
     140    pFH1 = TCPNAMEG(AllocFH)(osfd[0], &fh1);
     141    if (pFH1)
    140142    {
    141         pFH->iSocket = osfd[0];
    142         rc = __libc_FHAllocate(-1, O_RDWR | F_SOCKET, sizeof(LIBCSOCKETFH), &__libsocket_gSocketOps, (PLIBCFH*)&pFH, &fh2);
    143         if (!rc)
     143        PLIBCSOCKETFH   pFH2 = TCPNAMEG(AllocFH)(osfd[1], &fh2);
     144        if (pFH2)
    144145        {
    145             pFH->iSocket = osfd[1];
    146146            osfd[0] = fh1;
    147147            osfd[1] = fh2;
    148             LIBCLOG_RETURN_INT(0);
     148
     149            LIBCLOG_RETURN_MSG(0, "ret 0 osfd[0]=%d osfd[1]=%d\n", osfd[0], osfd[1]);
    149150        }
     151        __libsocket_soclose(osfd[1]);
    150152        __libc_FHClose(fh1);
    151153    }
     154    else
     155    {
     156        __libsocket_soclose(osfd[1]);
     157        __libsocket_soclose(osfd[0]);
     158    }
    152159
    153     __libsocket_soclose(osfd[0]);
    154     __libsocket_soclose(osfd[1]);
    155160    LIBCLOG_RETURN_INT(-1);
    156161#endif
  • trunk/src/emx/src/libsocket/soclose.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1453 r1454  
    4040{
    4141    LIBCLOG_ENTER("socket=%d\n", socket);
    42     PLIBCSOCKETFH   pFHSocket = __libsocket_FH(socket);
     42    PLIBCSOCKETFH   pFHSocket = __libc_TcpipFH(socket);
    4343    if (pFHSocket)
    4444    {
    4545        if (!__libc_FHClose(socket))
    4646            LIBCLOG_RETURN_INT(0);
    47         __libsocket_setSocketErrno();
     47        __libc_TcpipSetSocketErrno();
    4848    }
    4949
  • trunk/src/emx/src/os2/memory.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1453 r1454  
    2929#include <sys/builtin.h>
    3030#include <sys/fmutex.h>
     31#include <sys/rmutex.h>
    3132#include <sys/uflags.h>
    3233#include "emxdll.h"
     
    6465/* Mutex semaphore for protecting the heap. */
    6566
    66 static _fmutex heap_fmutex;
     67static _rmutex heap_rmutex;
    6768
    6869/* Number of memory objects registered with register_obj(). */
     
    254255void init_heap (void)
    255256{
    256   _fmutex_create (&heap_fmutex, 0);
     257  _rmutex_create (&heap_rmutex, 0);
    257258}
    258259
     
    545546  ULONG base;
    546547
    547   if (_fmutex_request (&heap_fmutex, _FMR_IGNINT) != 0)
     548  if (_rmutex_request (&heap_rmutex, _FMR_IGNINT) != 0)
    548549    return -1;
    549550
     
    553554    base = shrink_heap_by (-incr, uflags & _UF_SBRK_MODEL);
    554555
    555   if (_fmutex_release (&heap_fmutex) != 0)
     556  if (_rmutex_release (&heap_rmutex) != 0)
    556557    return -1;
    557558  return base != 0 ? (long)base : -1;
     
    565566  ULONG base;
    566567
    567   if (_fmutex_request (&heap_fmutex, _FMR_IGNINT) != 0)
     568  if (_rmutex_request (&heap_rmutex, _FMR_IGNINT) != 0)
    568569    return -1;
    569570
     
    577578    base = shrink_heap_to (brkp);
    578579
    579   if (_fmutex_release (&heap_fmutex) != 0)
     580  if (_rmutex_release (&heap_rmutex) != 0)
    580581    return -1;
    581582  return base != 0 ? 0 : -1;
  • trunk/src/emx/version.smak

    • Property cvs2svn:cvs-rev changed from 1.14 to 1.15
    r1453 r1454  
    44VH = 0
    55# Middle part of version number
    6 VM = 6
     6VM = 6a2
    77# Low part of version number
    88VL = 0
     
    2424
    2525# Copyright
    26 COPYRIGHT = Copyright (c) 2003 InnoTek Systemberatung GmbH
     26COPYRIGHT = Copyright (c) 2003-2004 InnoTek Systemberatung GmbH
Note: See TracChangeset for help on using the changeset viewer.