Changeset 2090


Ignore:
Timestamp:
Jun 27, 2005, 5:30:23 AM (20 years ago)
Author:
bird
Message:

o Rewrote the libcXXXX.dll install rule to not play with emxload since

emxload sticks around when first loaded.

o Made unsetenv() cause tzset reload just like putenv() and setenv().
o Changed putenv() behaviour for removal (no '=' in input) to be identical

to unsetenv(). This solves duplicate variable testcase.

o Changed filestreams opened for both reading and writing to switch

more willingly between read and write mode.

o Made sscan() return EOF on EOF.
o Made sscan() skip blanks in input for '%%'.
o Implemented the stdio_unlocked stuff with BSD and GLIBC extension.

TODO: Require a new locktype which support recursive usage! Currently

a hack using 8 free flag bits is used.

o Corrected realpath() behaviour to return the path up to the failure

point on error. _realrealpath() also does this now.
(This also saves us a temp buffer and a copy of the result.)

o Fixed a bug in the handling of ".." in the path resolver.
o Extended that path resolver to check the directoryness of the input

according to flags and any trailing slashes.

o Change the path resolver to be very strict about UNC - UNC have exactly

two slashes at the start of the path.

Location:
trunk/src/emx
Files:
3 added
40 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/ChangeLog.LIBC

    • Property cvs2svn:cvs-rev changed from 1.65 to 1.66
    r2089 r2090  
    11/* $Id$ */
     2
     32005-06-26: knut st. osmundsen <bird-gccos2-spam@anduin.net>
     4    - libc:
     5        o Added [__]isinf[fl] which seems to have been mislaid during the
     6          math source import.
     7        o Rewrote the libcXXXX.dll install rule to not play with emxload since
     8          emxload sticks around when first loaded.
     9        o Made unsetenv() cause tzset reload just like putenv() and setenv().
     10        o Changed putenv() behaviour for removal (no '=' in input) to be identical
     11          to unsetenv(). This solves duplicate variable testcase.
     12        o Changed filestreams opened for both reading and writing to switch
     13          more willingly between read and write mode.
     14        o Made sscan() return EOF on EOF.
     15        o Made sscan() skip blanks in input for '%%'.
     16        o Implemented the stdio_unlocked stuff with BSD and GLIBC extension.
     17          TODO: Require a new locktype which support recursive usage! Currently
     18                a hack using 8 free flag bits is used.
     19        o Corrected realpath() behaviour to return the path up to the failure
     20          point on error. _realrealpath() also does this now.
     21          (This also saves us a temp buffer and a copy of the result.)
     22        o Fixed a bug in the handling of ".." in the path resolver.
     23        o Extended that path resolver to check the directoryness of the input
     24          according to flags and any trailing slashes.
     25        o Change the path resolver to be very strict about UNC - UNC have exactly
     26          two slashes at the start of the path.
    227
    3282005-06-25: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/include/emx/io.h

    • Property cvs2svn:cvs-rev changed from 1.15 to 1.16
    r2089 r2090  
    88#include <InnoTekLIBC/fork.h>
    99#include <alloca.h>
     10#include <stdio.h>
    1011
    1112__BEGIN_DECLS
     
    148149#define _IONOCLOSEALL   0x00020000
    149150
     151/** This bit is set when the stream is locked by flockfile() or ftrylockfile().
     152 * !!TEMPORARY HACK!!
     153 * @todo replace the fmutex on the stream with a recursive lock! */
     154#define _IOLOCKED       0xff000000
    150155
    151156#define _FLUSH_FLUSH  (-1)
     
    192197
    193198#if defined (_SYS_FMUTEX_H)
    194 
    195199/* This semaphore (defined in app/stdio.c) protects _streamv[].  Only
    196200   concurrent access by _newstream(), _setmore(), and freopen() in
     
    204208#define STREAMV_LOCK    _fmutex_checked_request(&_streamv_fmutex, _FMR_IGNINT)
    205209#define STREAMV_UNLOCK  _fmutex_checked_release(&_streamv_fmutex)
    206 
    207 #define STREAM_LOCK(f) \
    208   ((f)->__uVersion != _FILE_STDIO_VERSION ? __stream_abort (f, "version error") \
    209    : _fmutex_request(&(f)->__u.__fsem, _FMR_IGNINT) != 0 \
    210    ? __stream_abort (f, "fmutex request") : 0)
    211 
    212 #define STREAM_UNLOCK(f) \
    213   (_fmutex_release(&(f)->__u.__fsem) != 0 ? __stream_abort (f, "fmutex release") : (void)0)
    214 
    215 #define STREAM_LOCK_NOWAIT(f) \
    216   (((f)->__uVersion == _FILE_STDIO_VERSION || __stream_abort (f, "version error")) && _fmutex_request(&(f)->__u.__fsem, _FMR_NOWAIT) == 0)
    217 
    218 #define STREAM_UNLOCKED(f) ((f)->__uVersion == _FILE_STDIO_VERSION && _fmutex_available(&(f)->__u.__fsem))
     210#endif /* _SYS_FMUTEX_H */
     211
     212#if defined (__FILE_FSEM_DECLARED)
    219213
    220214int __stream_abort(struct _FILE *f, const char *pszMsg);
    221215
    222 #endif /* defined (_SYS_FMUTEX_H) */
     216static int __inline__ stream_validate(struct _FILE *stream)
     217{
     218    if (stream->__uVersion != _FILE_STDIO_VERSION)
     219    {
     220        __stream_abort(stream, "version error");
     221        return 0;
     222    }
     223    return 1;
     224}
     225
     226static int __inline__ stream_lock(struct _FILE *stream)
     227{
     228    if (!stream_validate(stream))
     229        return 0;
     230    if (   !(stream->_flags & _IOLOCKED)
     231        || !_fmutex_is_owner(&stream->__u.__fsem))
     232    {
     233        if (_fmutex_request(&stream->__u.__fsem, _FMR_IGNINT) != 0)
     234        {
     235            __stream_abort(stream, "fmutex_request failed");
     236            return 0;
     237        }
     238        stream->_flags = 0x01000000 | (stream->_flags & ~_IOLOCKED);
     239    }
     240    else
     241        stream->_flags = ((stream->_flags & _IOLOCKED) + 0x01000000) | (stream->_flags & ~_IOLOCKED);
     242    return 1;
     243}
     244
     245static int __inline__ stream_trylock(struct _FILE *stream)
     246{
     247    if (!stream_validate(stream))
     248        return 0;
     249    if (   !(stream->_flags & _IOLOCKED)
     250        || !_fmutex_is_owner(&stream->__u.__fsem))
     251    {
     252        if (_fmutex_request(&stream->__u.__fsem, _FMR_NOWAIT) != 0)
     253        {
     254            __stream_abort(stream, "fmutex_request failed");
     255            return 0;
     256        }
     257        stream->_flags = 0x01000000 | (stream->_flags & ~_IOLOCKED);
     258    }
     259    else
     260        stream->_flags = ((stream->_flags & _IOLOCKED) + 0x01000000) | (stream->_flags & ~_IOLOCKED);
     261    return 1;
     262}
     263
     264static int __inline__ stream_unlock(struct _FILE *stream)
     265{
     266    if (!stream_validate(stream))
     267        return 0;
     268    if (!(stream->_flags & _IOLOCKED))
     269    {
     270        __stream_abort(stream, "unlock, 0 count");
     271        return 0;
     272    }
     273#ifdef __LIBC_STRICT
     274    if (!_fmutex_is_owner(&stream->__u.__fsem))
     275    {
     276        __stream_abort(stream, "unlock, not owner");
     277        return 0;
     278    }
     279#endif
     280    stream->_flags = ((stream->_flags & _IOLOCKED) - 0x01000000) | (stream->_flags & ~_IOLOCKED);
     281    if (   !(stream->_flags & _IOLOCKED)
     282        && _fmutex_release(&stream->__u.__fsem) != 0)
     283    {
     284        __stream_abort(stream, "fmutex_release failed");
     285        return 0;
     286    }
     287    return 1;
     288}
     289
     290#define STREAM_LOCK(f)          stream_lock(f)
     291#define STREAM_UNLOCK(f)        stream_unlock(f)
     292#define STREAM_LOCK_NOWAIT(f)   stream_trylock(f)
     293#define STREAM_UNLOCKED(f)      ((f)->__uVersion == _FILE_STDIO_VERSION && _fmutex_available(&(f)->__u.__fsem))
     294
     295#endif /* __FILE_FSEM_DECLARED */
    223296
    224297struct __libc_FileHandle;
     
    434507int _flushstream (struct _FILE *, int);
    435508void _closestream (struct _FILE *);
    436 int _fflush_nolock (struct _FILE *);
    437 int _fseek_nolock (struct _FILE *, off_t, int);
    438 off_t _ftell_nolock (struct _FILE *);
    439 size_t _fwrite_nolock (const void *, size_t, size_t, struct _FILE *);
     509int _fseek_unlocked (struct _FILE *, off_t, int);
     510off_t _ftello_unlocked (struct _FILE *);
    440511int _input (struct _FILE *, __const__ char *, char *);
    441512struct _FILE *_newstream (void);
  • trunk/src/emx/include/stdio.h

    • Property cvs2svn:cvs-rev changed from 1.14 to 1.15
    r2089 r2090  
    200200    {
    201201#if defined (_SYS_FMUTEX_H)
     202#define __FILE_FSEM_DECLARED
     203        /** @todo replace this by a nested lock construct, see flockfile(). */
    202204        _fmutex   __fsem;
    203205#endif
     
    287289long     ftell(FILE *);
    288290size_t   fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
    289 #if 0                                   /* bird: emx */
    290291int      getc(FILE *);
    291 #else                                   /* bird: emx */
    292 /** @todo: Check the standard, if this is correct or not. declaration might be required. */
    293 #define getc(s)   fgetc(s)              /* bird: emx */
    294 #endif                                  /* bird: emx */
    295292int      getchar(void);
    296293char    *gets(char *);
    297294void     perror(const char *);
    298295int      printf(const char * __restrict, ...);
    299 #if 0                                   /* bird: emx */
    300296int      putc(int, FILE *);
    301 #else                                   /* bird: emx */
    302 /** @todo: Check the standard, if this is correct or not. declaration might be required. */
    303 #define putc(c,s) fputc(c,s)            /* bird: emx */
    304 #endif                                  /* bird: emx */
    305297int      putchar(int);
    306298int      puts(const char *);
     
    356348
    357349#if __POSIX_VISIBLE >= 199506
    358 /** @todo int    ftrylockfile(FILE *); */
    359 /** @todo void   flockfile(FILE *); */
    360 /** @todo void   funlockfile(FILE *); */
     350int      ftrylockfile(FILE *);
     351void     flockfile(FILE *);
     352void     funlockfile(FILE *);
    361353
    362354/*
     
    364356 * requires functions as well.
    365357 */
    366 /** @todo int    getc_unlocked(FILE *); */
    367 /** @todo int    getchar_unlocked(void); */
    368 /** @todo int    putc_unlocked(int, FILE *); */
    369 /** @todo int    putchar_unlocked(int); */
     358int      getc_unlocked(FILE *);
     359int      getchar_unlocked(void);
     360int      putc_unlocked(int, FILE *);
     361int      putchar_unlocked(int);
    370362#endif
    371363#if __BSD_VISIBLE
    372 /** @todo void  clearerr_unlocked(FILE *); */
    373 /** @todo int   feof_unlocked(FILE *); */
    374 /** @todo int   ferror_unlocked(FILE *); */
    375 /** @todo int   fileno_unlocked(FILE *); */
     364void    clearerr_unlocked(FILE *);
     365int     feof_unlocked(FILE *);
     366int     ferror_unlocked(FILE *);
     367int     fileno_unlocked(FILE *);
     368#endif
     369#ifdef __USE_MISC
     370int     fflush_unlocked(FILE *);
     371size_t  fwrite_unlocked(const void * __restrict, size_t, size_t, FILE * __restrict);
     372size_t  fread_unlocked(void * __restrict, size_t, size_t, FILE * __restrict);
     373int     fgetc_unlocked(FILE *);
     374int     fputc_unlocked(int, FILE *);
     375int     fputs_unlocked(const char * __restrict, FILE * __restrict);
     376int     puts_unlocked(const char *);
    376377#endif
    377378
  • trunk/src/emx/include/sys/fmutex.h

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r2089 r2090  
    104104}
    105105
     106
     107static __inline__ int _fmutex_is_owner (_fmutex *sem)
     108{
     109    return sem->fs > _FMS_AVAILABLE && sem->Owner == fibGetTidPid();
     110}
     111
    106112/**
    107113 * Release a semaphore in the child process after the
  • trunk/src/emx/src/lib/app/putenv.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2089 r2090  
    2222        LIBCLOG_RETURN_INT(-1);
    2323    }
    24     _tzset_flag = 0;                    /* Call tzset() */
     24
    2525    s = strchr(string, '=');
    2626    if (s == NULL)
    27         len = strlen(string);           /* Use complete string */
    28     else
    29         len = s - string;
     27    {
     28        /* remove string, let unset do the work */
     29        int rc = unsetenv(string);
     30        LIBCLOG_RETURN_INT(rc);
     31    }
     32
     33    /* insert/replace */
     34    len = s - string;
    3035    p = environ;
    3136    env_size = 0;
     
    7378        LIBCLOG_MSG("replacing '%s' with '%s'\n", *p, string);
    7479        *p = (char *)string;
    75         /** @todo this doesn't match the unset policy, we should remove the
    76                   variable entirely from the environment when no value is
    77                   specified! */
    7880    }
     81
     82    _tzset_flag = 0;                    /* Call tzset() */
    7983    LIBCLOG_RETURN_INT(0);
    8084}
  • trunk/src/emx/src/lib/app/unsetenv.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2089 r2090  
    1717#include <errno.h>
    1818#include <emx/startup.h>
     19#include <emx/time.h>
    1920#define __LIBC_LOG_GROUP  __LIBC_LOG_GRP_ENV
    2021#include <InnoTekLIBC/logstrict.h>
     
    3738    int     lenname;
    3839    char ** p;
    39 
    4040
    4141    /* validate input */
     
    6262                    break;
    6363            LIBCLOG_MSG("deleted '%s'\n", s);
     64            _tzset_flag = 0;            /* Call tzset() */
    6465        }
    6566        else
  • trunk/src/emx/src/lib/io/_fill.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    3434    }
    3535
    36   /* Fail if the stream is in write mode. */
     36  /* switch to read mode if necessary. */
    3737
    3838  if (stream->_flags & _IOWRT)
    3939    {
    40       stream->_flags |= _IOERR;
    41       errno = EACCES;
    42       return EOF;
     40      if (stream->_flags & _IORW)
     41        {
     42          int rc = _fseek_unlocked (stream, 0, SEEK_CUR);
     43          if (rc)
     44            return EOF;
     45        }
     46      if (stream->_flags & _IOWRT)
     47        {
     48          stream->_flags |= _IOERR;
     49          errno = EACCES;
     50          return EOF;
     51        }
    4352    }
    4453
  • trunk/src/emx/src/lib/io/_flush.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    2828    }
    2929
    30   /* Fail if the stream is in read mode. */
     30  /* switch to write mode if necessary. */
    3131
    3232  if (stream->_flags & _IOREAD)
    3333    {
    34       stream->_flags |= _IOERR;
    35       errno = EACCES;
    36       return EOF;
     34      if (stream->_flags & _IORW)
     35        {
     36          int rc = _fseek_unlocked (stream, 0, SEEK_CUR);
     37          if (rc)
     38            return EOF;
     39        }
     40      if (stream->_flags & _IOREAD)
     41        {
     42          stream->_flags |= _IOERR;
     43          errno = EACCES;
     44          return EOF;
     45        }
    3746    }
    3847
  • trunk/src/emx/src/lib/io/_input.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r2089 r2090  
    275275  if (!ok)
    276276    {
    277       make_unread (v, c);
    278       v->status = MATCHING_FAILURE;
     277      if (c != EOF)
     278        {
     279          make_unread (v, c);
     280          v->status = MATCHING_FAILURE;
     281        }
     282      else
     283          v->status = INPUT_FAILURE;
    279284      return;
    280285    }
     
    352357  if (!ok)
    353358    {
    354       make_unread (v, c);
    355       v->status = MATCHING_FAILURE;
     359      if (c != EOF)
     360        {
     361          make_unread (v, c);
     362          v->status = MATCHING_FAILURE;
     363        }
     364      else
     365          v->status = INPUT_FAILURE;
    356366      return;
    357367    }
     
    489499      if (!ok)
    490500        {
    491           make_unread (v, c);
    492           v->status = MATCHING_FAILURE;
     501          if (c != EOF)
     502            {
     503              make_unread (v, c);
     504              v->status = MATCHING_FAILURE;
     505            }
     506          else
     507              v->status = INPUT_FAILURE;
    493508          return;
    494509        }
     
    505520          if (!isdigit (c))
    506521            {
    507               make_unread (v, c);
    508               v->status = MATCHING_FAILURE;
     522              if (c != EOF)
     523                {
     524                  make_unread (v, c);
     525                  v->status = MATCHING_FAILURE;
     526                }
     527              else
     528                  v->status = INPUT_FAILURE;
    509529              return;
    510530            }
     
    725745              if (f == 0)                 /* % at end of string */
    726746                return v->count;
    727               c = get0 (v);
     747              c = skip (v);
    728748              if (c != f)
    729749                return v->count;
     
    733753            {
    734754            case INPUT_FAILURE:
    735               return ((v->count == 0) ? EOF : v->count);
     755              return v->count == 0 ? EOF : v->count;
    736756            case MATCHING_FAILURE:
    737757            case OUT_OF_MEMORY:
  • trunk/src/emx/src/lib/io/_output.c

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r2089 r2090  
    7474  if (n >= 16)
    7575    {
    76       if (_fwrite_nolock (s, 1, n, v->stream) != n)
     76      if (fwrite_unlocked (s, 1, n, v->stream) != n)
    7777        return -1;
    7878      v->count += n;
  • trunk/src/emx/src/lib/io/_tmpbuf.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    2222  int result;
    2323
    24   result = _fflush_nolock (stream);
     24  result = fflush_unlocked (stream);
    2525  stream->_buf_size = 1;
    2626  stream->_ptr = stream->_buffer = &stream->_char_buf;
  • trunk/src/emx/src/lib/io/clearerr.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2089 r2090  
    44#include <stdio.h>
    55
    6 void _STD(clearerr) (FILE *stream)
     6void _STD(clearerr)(FILE *stream)
    77{
    8   stream->_flags &= ~(_IOERR|_IOEOF);
     8    stream->_flags &= ~(_IOERR|_IOEOF);
    99}
     10
     11void _STD(clearerr_unlocked)(FILE *stream)
     12{
     13    stream->_flags &= ~(_IOERR|_IOEOF);
     14}
  • trunk/src/emx/src/lib/io/fclose.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2089 r2090  
    22
    33#include "libc-alias.h"
    4 #include <stdio.h>
    54#include <stdlib.h>
    65#include <string.h>
     
    98#include <sys/fmutex.h>
    109#include <emx/io.h>
     10#include <stdio.h>
    1111
    1212int _STD(fclose) (FILE *stream)
  • trunk/src/emx/src/lib/io/feof.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    44#include <stdio.h>
    55
    6 int _STD(feof) (FILE *s)
     6int _STD(feof)(FILE *s)
    77{
    8   return (s->_flags & _IOEOF ? 1 : 0);
     8    return s->_flags & _IOEOF ? 1 : 0;
    99}
     10
     11int _STD(feof_unlocked)(FILE *s)
     12{
     13    return s->_flags & _IOEOF ? 1 : 0;
     14}
  • trunk/src/emx/src/lib/io/ferror.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    44#include <stdio.h>
    55
    6 int _STD(ferror) (FILE *s)
     6int _STD(ferror)(FILE *s)
    77{
    8   return (s->_flags & _IOERR ? 1 : 0);
     8    return s->_flags & _IOERR ? 1 : 0;
    99}
     10
     11int _STD(ferror_unlocked)(FILE *s)
     12{
     13    return s->_flags & _IOERR ? 1 : 0;
     14}
  • trunk/src/emx/src/lib/io/fflush.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r2089 r2090  
    1111#include <emx/io.h>
    1212
    13 int _fflush_nolock (FILE *stream)
     13int _STD(fflush_unlocked) (FILE *stream)
    1414{
    1515  int result, n, ft, saved_errno;
     
    5050      /* ISO 9899-1990, 7.9.5.2: "The fflush function returns EOF if a
    5151         write error occurs, otherwise zero." */
    52       pos = _ftell_nolock (stream);
     52      pos = _ftello_unlocked (stream);
    5353      if (pos != -1)
    5454        lseek (stream->_handle, pos, SEEK_SET);
     
    8181
    8282  STREAM_LOCK (stream);
    83   result = _fflush_nolock (stream);
     83  result = fflush_unlocked (stream);
    8484  STREAM_UNLOCK (stream);
    8585  return result;
  • trunk/src/emx/src/lib/io/fgetc.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2089 r2090  
    99#include "getputc.h"
    1010
    11 int _STD(fgetc) (FILE *stream)
     11int _STD(getc)(FILE *stream)
    1212{
    13   int r;
     13    return fgetc(stream);
     14}
    1415
    15   STREAM_LOCK (stream);
    16   r = _getc_inline (stream);
    17   STREAM_UNLOCK (stream);
    18   return r;
     16int _STD(fgetc)(FILE *stream)
     17{
     18    STREAM_LOCK(stream);
     19    int rc = _getc_inline(stream);
     20    STREAM_UNLOCK(stream);
     21    return rc;
    1922}
     23
     24int _STD(getc_unlocked)(FILE *stream)
     25{
     26    return fgetc_unlocked(stream);
     27}
     28
     29int _STD(fgetc_unlocked)(FILE *stream)
     30{
     31    return _getc_inline(stream);
     32}
  • trunk/src/emx/src/lib/io/fileno.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    44#include <stdio.h>
    55
    6 int _STD(fileno) (FILE *s)
     6int _STD(fileno)(FILE *s)
    77{
    8   return s->_handle;
     8    return s->_handle;
    99}
     10
     11int _STD(fileno_unlocked)(FILE *s)
     12{
     13    return s->_handle;
     14}
     15
  • trunk/src/emx/src/lib/io/flushall.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r2089 r2090  
    2222        {
    2323          ++n;
    24           _fflush_nolock (&sv->aFiles[i]);
     24          fflush_unlocked (&sv->aFiles[i]);
    2525          STREAM_UNLOCK (&sv->aFiles[i]);
    2626        }
  • trunk/src/emx/src/lib/io/fputc.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2089 r2090  
    22
    33#include "libc-alias.h"
    4 #include <sys/builtin.h>        /* For <sys/fmutex.h> */
    54#include <sys/fmutex.h>
    65#include <stdio.h>
     
    98#include "getputc.h"
    109
    11 int _STD(fputc) (int c, FILE *stream)
     10int _STD(putc)(int c, FILE *stream)
    1211{
    13   int r;
     12    return fputc(c, stream);
     13}
    1414
    15   STREAM_LOCK (stream);
    16   r = _putc_inline (c, stream);
    17   STREAM_UNLOCK (stream);
    18   return r;
     15int _STD(fputc)(int c, FILE *stream)
     16{
     17    int r;
     18
     19    STREAM_LOCK(stream);
     20    r = _putc_inline(c, stream);
     21    STREAM_UNLOCK(stream);
     22    return r;
    1923}
     24
     25int _STD(putc_unlocked)(int c, FILE *stream)
     26{
     27    return fputc_unlocked(c, stream);
     28}
     29
     30int _STD(fputc_unlocked)(int c, FILE *stream)
     31{
     32    int r;
     33
     34    STREAM_LOCK(stream);
     35    r = _putc_inline(c, stream);
     36    STREAM_UNLOCK(stream);
     37    return r;
     38}
  • trunk/src/emx/src/lib/io/fputs.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    55#include <string.h>
    66
    7 int _STD(fputs) (const char *string, FILE *stream)
     7int _STD(fputs)(const char *string, FILE *stream)
    88{
    9   int len;
     9    int len = strlen (string);
     10    return len == 0 || fwrite(string, len, 1, stream) == 1
     11        ? 0 : EOF;
     12}
    1013
    11   len = strlen (string);
    12   return (len == 0 || fwrite (string, len, 1, stream) == 1 ? 0 : EOF);
     14int _STD(fputs_unlocked)(const char *string, FILE *stream)
     15{
     16    int len = strlen(string);
     17    return len == 0 || fwrite_unlocked(string, len, 1, stream) == 1
     18        ? 0 : EOF;
    1319}
     20
  • trunk/src/emx/src/lib/io/fread.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2089 r2090  
    1212#include <emx/io.h>
    1313
    14 size_t _STD(fread) (void *buffer, size_t size, size_t count, FILE *stream)
     14size_t _STD(fread)(void *buffer, size_t size, size_t count, FILE *stream)
     15{
     16    STREAM_LOCK(stream);
     17    size_t cb = fread_unlocked(buffer, size, count, stream);
     18    STREAM_UNLOCK(stream);
     19    return cb;
     20}
     21
     22size_t _STD(fread_unlocked)(void *buffer, size_t size, size_t count, FILE *stream)
    1523{
    1624  size_t total, left, n;
     
    2836    }
    2937
    30   STREAM_LOCK (stream);
    3138  if (nbuf (stream))
    3239    _fbuf (stream);
     
    120127        }
    121128    }
    122   STREAM_UNLOCK (stream);
    123129  return (total - left) / size;
    124130}
  • trunk/src/emx/src/lib/io/fseek.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r2089 r2090  
    1010#include <emx/io.h>
    1111
    12 int _fseek_nolock (FILE *stream, off_t offset, int origin)
     12int _fseek_unlocked (FILE *stream, off_t offset, int origin)
    1313{
    1414  off_t     cur_pos;
     
    4040      file_pos = tell (stream->_handle);
    4141      if (file_pos == -1) return EOF;
    42       cur_pos = _ftell_nolock (stream);
     42      cur_pos = _ftello_unlocked (stream);
    4343      if (origin == SEEK_CUR)
    4444        {
     
    146146
    147147  if (origin == SEEK_CUR && cur_pos == -1)
    148     cur_pos = _ftell_nolock (stream);
     148    cur_pos = _ftello_unlocked (stream);
    149149#endif
    150150
    151   fflush_result = _fflush_nolock (stream);
     151  fflush_result = fflush_unlocked (stream);
    152152  stream->_flags &= ~_IOEOF;
    153153  if (stream->_flags & _IORW)
     
    157157    {
    158158      if (cur_pos == -1)
    159         cur_pos = _ftell_nolock (stream);
     159        cur_pos = _ftello_unlocked (stream);
    160160      if (cur_pos == -1)
    161161        {
     
    184184
    185185    STREAM_LOCK (stream);
    186     result = _fseek_nolock (stream, offset, origin);
     186    result = _fseek_unlocked (stream, offset, origin);
    187187    STREAM_UNLOCK (stream);
    188188    return result;
  • trunk/src/emx/src/lib/io/ftell.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r2089 r2090  
    1212#include <emx/io.h>
    1313
    14 off_t _ftell_nolock (FILE *stream)
     14off_t _ftello_unlocked (FILE *stream)
    1515{
    1616  off_t     pos;
     
    104104
    105105  STREAM_LOCK (stream);
    106   off = _ftell_nolock (stream);
     106  off = _ftello_unlocked (stream);
    107107  STREAM_UNLOCK (stream);
    108108  return off;
  • trunk/src/emx/src/lib/io/fwrite.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2089 r2090  
    102102}
    103103
    104 
    105 size_t _fwrite_nolock (const void *buffer, size_t size, size_t count,
    106                        FILE *stream)
     104size_t _STD(fwrite_unlocked) (const void *buffer, size_t size, size_t count, FILE *stream)
    107105{
    108106  size_t total, left, n;
    109107  const char *src, *newline;
    110108
    111   if (stream->_flags & _IOREAD)    /* File in read mode? */
     109  /* switch to write mode if necessary. */
     110  if (stream->_flags & _IOREAD)
    112111    {
    113       stream->_flags |= _IOERR;
    114       errno = EACCES;
    115       return 0;
     112      if (stream->_flags & _IORW)
     113        {
     114          int rc = _fseek_unlocked (stream, 0, SEEK_CUR);
     115          if (rc)
     116            return EOF;
     117        }
     118      if (stream->_flags & _IOREAD)
     119        {
     120          stream->_flags |= _IOERR;
     121          errno = EACCES;
     122          return EOF;
     123        }
    116124    }
    117   if (count == 0)
     125  if (size == 0 || count == 0)
    118126    return 0;
    119   if (size == 0)
    120     return count;
    121127  total = size * count;
    122128  if (total / count != size)
     
    143149            {
    144150              /* Note that the return value will be inaccurate if
    145                  _fflush_nolock() fails, but that's also true for
     151                 fflush_unlocked() fails, but that's also true for
    146152                 _IOFBF. */
    147153
    148               if (_fflush_nolock (stream) != 0)
     154              if (fflush_unlocked (stream) != 0)
    149155                left = total;
    150156              else if (left != 0)
     
    164170
    165171  STREAM_LOCK (stream);
    166   r = _fwrite_nolock (buffer, size, count, stream);
     172  r = fwrite_unlocked (buffer, size, count, stream);
    167173  STREAM_UNLOCK (stream);
    168174  return r;
  • trunk/src/emx/src/lib/io/getchar.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    44#include <stdio.h>
    55
    6 int _STD(getchar) (void)
     6int _STD(getchar)(void)
    77{
    8   return getc (stdin);
     8    return getc(stdin);
    99}
     10
     11int _STD(getchar_unlocked)(void)
     12{
     13    return getc_unlocked(stdin);
     14}
  • trunk/src/emx/src/lib/io/putchar.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    44#include <stdio.h>
    55
    6 int _STD(putchar) (int c)
     6int _STD(putchar)(int c)
    77{
    8   return putc (c, stdout);
     8    return putc(c, stdout);
    99}
     10
     11int _STD(putchar_unlocked)(int c)
     12{
     13    return putc_unlocked(c, stdout);
     14}
  • trunk/src/emx/src/lib/io/puts.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2089 r2090  
    1212int _STD(puts) (const char *string)
    1313{
    14   int result, len;
    15   void *tb;
     14    STREAM_LOCK(stdout);
     15    int rc = puts_unlocked(string);
     16    STREAM_UNLOCK(stdout);
     17    return rc;
     18}
    1619
    17   len = strlen (string);
    18   STREAM_LOCK (stdout);
    19   if (nbuf (stdout))
    20     _fbuf (stdout);
    21   _tmpbuf (stdout, tb);
    22   if (len == 0 || _fwrite_nolock (string, len, 1, stdout) == 1)
    23     result = _putc_inline ('\n', stdout);
    24   else
    25     result = EOF;
    26   if (_endbuf (stdout) != 0)
    27     result = EOF;
    28   STREAM_UNLOCK (stdout);
    29   return result;
     20int _STD(puts_unlocked) (const char *string)
     21{
     22    int result;
     23
     24    int len = strlen(string);
     25    if (nbuf(stdout))
     26        _fbuf (stdout);
     27    void *tb;
     28    _tmpbuf(stdout, tb);
     29    if (    len == 0
     30        ||  fwrite_unlocked(string, len, 1, stdout) == 1)
     31        result = _putc_inline('\n', stdout);
     32    else
     33        result = EOF;
     34    if (_endbuf(stdout) != 0)
     35        result = EOF;
     36    return result;
    3037}
  • trunk/src/emx/src/lib/io/rewind.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2089 r2090  
    1111{
    1212  STREAM_LOCK (stream);
    13   _fflush_nolock (stream);
    14   _fseek_nolock (stream, 0, SEEK_SET);
     13  fflush_unlocked (stream);
     14  _fseek_unlocked (stream, 0, SEEK_SET);
    1515  stream->_flags &= ~_IOERR;
    1616  STREAM_UNLOCK (stream);
  • trunk/src/emx/src/lib/io/setvbuf.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2089 r2090  
    1515
    1616  STREAM_LOCK (stream);
    17   _fflush_nolock (stream);
     17  fflush_unlocked (stream);
    1818  if ((stream->_flags & _IOBUFMASK) == _IOBUFLIB)
    1919    free (stream->_buffer);
  • trunk/src/emx/src/lib/io/ungetc.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2089 r2090  
    112112          || ft != HT_FILE)
    113113        return EOF;
    114      
     114
    115115      /* OK, we can flush the stream buffer.  We flush the buffer
    116116         completely and don't attempt to keep some data (that would be
     
    119119
    120120      uc = stream->_ungetc_count;
    121       if (_fflush_nolock (stream) != 0)
     121      if (fflush_unlocked (stream) != 0)
    122122        return EOF;
    123123      stream->_ungetc_count = uc;
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.116 to 1.117
    r2089 r2090  
    533533    "__fbuf" @546
    534534    "__fcloseall" @547
    535     "__fflush_nolock" @548
     535    "__std_fflush_unlocked" @548
    536536    "__filesys" @549
    537537    "__fill" @550
     
    558558    "__fpreset" @571
    559559    "__fseek_hdr" @572
    560     "__fseek_nolock" @573
     560    "__fseek_unlocked" @573
    561561    "__fsetmode" @574
    562562    "__fsopen" @575
    563     "__ftell_nolock" @576
     563    "__ftello_unlocked" @576
    564564    "__fullpath" @577
    565     "__fwrite_nolock" @578
     565    "__std_fwrite_unlocked" @578
    566566    "__fxam" @579
    567567    "__fxaml" @580
     
    17191719    "__std_mkdtemp" @1722
    17201720    "__std_mkstemps" @1723
     1721    ; unlocked file stream stuff.
     1722    "__std_clearerr_unlocked" @1724
     1723    "__std_feof_unlocked" @1725
     1724    "__std_ferror_unlocked" @1726
     1725    "__std_fgetc_unlocked" @1727
     1726    "__std_fileno_unlocked" @1728
     1727    "__std_flockfile" @1729
     1728    "__std_ftrylockfile" @1730
     1729    "__std_funlockfile" @1731
     1730    "__std_getc" @1732
     1731    "__std_getchar_unlocked" @1733
     1732    "__std_getc_unlocked" @1734
     1733    "__std_putchar_unlocked" @1735
     1734    "__std_fputc_unlocked" @1736
     1735    "__std_putc" @1737
     1736    "__std_putc_unlocked" @1738
     1737    "__std_fputs_unlocked" @1739
     1738    "__std_puts_unlocked" @1740
     1739    "__std_fread_unlocked" @1741
     1740    "___isinff" @1742
     1741    "___isinfl" @1743
     1742    "__std_isinf" @1744
  • trunk/src/emx/src/lib/libc.smak

    • Property cvs2svn:cvs-rev changed from 1.69 to 1.70
    r2089 r2090  
    364364
    365365$(INS)lib/$(notdir $(LIBC.DLL)): $(LIBC.DLL)
    366         if test -f $@; then emxload emxomfld && unlock $(subst /,\\,$@) && cp $< $@ && emxload -u emxomfld; else cp $< $@; fi
     366        if test -f $@; then rm -f $@ || (unlock $(subst /,\\,$@) && rm -f $@); fi
     367        cp $< $@
    367368       
    368369$(INS)lib/$(notdir $(LIBC.DLL:.dll=.map)): $(LIBC.DLL:.dll=.map)
  • trunk/src/emx/src/lib/libc06b4.def

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r2089 r2090  
    531531    "__fbuf" @546
    532532    "__fcloseall" @547
    533     "__fflush_nolock" @548
     533    "__std_fflush_unlocked" @548
    534534    "__filesys" @549
    535535    "__fill" @550
     
    556556    "__fpreset" @571
    557557    "__fseek_hdr" @572
    558     "__fseek_nolock" @573
     558    "__fseek_unlocked" @573
    559559    "__fsetmode" @574
    560560    "__fsopen" @575
    561     "__ftell_nolock" @576
     561    "__ftello_unlocked" @576
    562562    "__fullpath" @577
    563     "__fwrite_nolock" @578
     563    "__std_fwrite_unlocked" @578
    564564    "__fxam" @579
    565565    "__fxaml" @580
  • trunk/src/emx/src/lib/misc/_realrealpath.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r2089 r2090  
    5353    LIBCLOG_ENTER("pszPath=%p:{%s} pszResolved=%p cchResolved=%d\n", (void *)pszPath, pszPath, pszResolved, cchResolved);
    5454
     55    if (!pszPath)
     56    {
     57        errno = EINVAL;
     58        LIBC_ASSERTM_FAILED("pszPath is NULL!\n");
     59        LIBCLOG_RETURN_INT(NULL);
     60    }
     61
    5562    int rc;
    5663    if (!pszResolved)
     
    7582        else
    7683            rc = -ENOMEM;
    77     }
    78     else
    79     {
    80         rc = __libc_Back_fsPathResolve(pszPath, pszResolved, cchResolved, __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE);
    81         if (!rc)
    82             LIBCLOG_RETURN_MSG(pszResolved, "ret %p:{%s}\n", pszResolved, pszResolved);
     84        errno = -rc;
     85        LIBCLOG_RETURN_P(NULL);
    8386    }
    8487
    85     errno = -rc;
    86     LIBCLOG_RETURN_P(NULL);
     88    char *pszRet = pszResolved;
     89    rc = __libc_Back_fsPathResolve(pszPath, pszResolved, cchResolved, __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE);
     90    if (rc)
     91    {
     92        errno = -rc;
     93        pszRet = NULL;
     94    }
     95    LIBCLOG_RETURN_MSG(pszRet, "ret %p pszResolved=%p:{%s}\n", pszRet, pszResolved, pszResolved);
    8796}
    8897
  • trunk/src/emx/src/lib/misc/realpath.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2089 r2090  
    5353    LIBCLOG_ENTER("path=%p:{%s} resolved_path=%p\n", (void *)path, path, resolved_path);
    5454
     55    if (!path)
     56    {
     57        errno = EINVAL;
     58        LIBC_ASSERTM_FAILED("path is NULL!\n");
     59        LIBCLOG_RETURN_P(NULL);
     60    }
     61
    5562    int rc;
    5663    if (!resolved_path)
     
    7380        else
    7481            rc = -ENOMEM;
    75     }
    76     else
    77     {
    78         rc = __libc_Back_fsPathResolve(path, resolved_path, PATH_MAX, 0);
    79         if (!rc)
    80             LIBCLOG_RETURN_MSG(resolved_path, "ret %p:{%s}\n", resolved_path, resolved_path);
     82        errno = -rc;
     83        LIBCLOG_RETURN_P(NULL);
    8184    }
    8285
    83     errno = -rc;
    84     LIBCLOG_RETURN_P(NULL);
     86    char *pszRet = resolved_path;
     87    rc = __libc_Back_fsPathResolve(path, resolved_path, PATH_MAX, 0);
     88    if (rc)
     89    {
     90        errno = -rc;
     91        pszRet = NULL;
     92    }
     93    LIBCLOG_RETURN_MSG(pszRet, "ret %p resolved_path=%p:{%s}\n", pszRet, resolved_path, resolved_path);
    8594}
    8695
  • trunk/src/emx/src/lib/msun/std-math.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2089 r2090  
    284284double  drem(double, double);
    285285int     finite(double) __pure2;
    286 int     isnanf(float) __pure2;
     286int     _STD(isnanf)(float) __pure2;
    287287
    288288/*
  • trunk/src/emx/src/lib/sys/b_fs.h

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r2089 r2090  
    106106 *
    107107 * @returns 0 on success.
    108  * @returns -1 and errno on failure.
     108 * @returns Negative error code (errno.h) on failiure.
    109109 * @param   pszUserPath     The user path.
    110110 * @parm    fFlags          Flags controlling the operation of the function.
  • trunk/src/emx/src/lib/sys/b_fsPathResolve.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2089 r2090  
    6666    int     fInUnixTree;
    6767    char    szNativePath[PATH_MAX];
     68    szNativePath[0] = '\0';
    6869    rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_DIR_MAYBE, szNativePath, &fInUnixTree);
    69     if (!rc)
     70
     71    /*
     72     * Copy the (half) result back to the caller.
     73     */
     74    char *pszSrc = &szNativePath[0];
     75    if (!(fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE) && fInUnixTree)
    7076    {
    71         char *pszSrc = &szNativePath[0];
    72         if (!(fFlags & __LIBC_BACKFS_FLAGS_RESOLVE_NATIVE) && fInUnixTree)
    73         {
    74             pszSrc += __libc_gcchUnixRoot;
    75             LIBC_ASSERTM(*pszSrc == '/', "bogus fInUnixTree flag! pszSrc='%s' whole think '%s'\n", pszSrc, szNativePath);
    76         }
    77         __libc_back_fsMutexRelease();
     77        pszSrc += __libc_gcchUnixRoot;
     78        LIBC_ASSERTM(*pszSrc == '/', "bogus fInUnixTree flag! pszSrc='%s' whole thing is '%s'\n", pszSrc, szNativePath);
     79    }
     80    __libc_back_fsMutexRelease();
    7881
    79         int cch = strlen(pszSrc) + 1;
    80         if (cch < cchBuf)
    81         {
    82             memcpy(pszBuf, pszSrc, cchBuf);
    83             LIBCLOG_RETURN_MSG(0, "ret 0 pszPath=%p:{%s}\n", (void *)pszPath, pszPath);
    84         }
    85         else
    86             rc = -ERANGE;
    87     }
    88     else
    89         __libc_back_fsMutexRelease();
    90     LIBCLOG_RETURN_INT(rc);
     82    int cch = strlen(pszSrc) + 1;
     83    if (cch < cchBuf)
     84        memcpy(pszBuf, pszSrc, cchBuf);
     85    else if (!rc)
     86        rc = -ERANGE;
     87
     88    LIBCLOG_RETURN_MSG(rc, "ret %d pszPath=%p:{%s}\n", rc, (void *)pszPath, pszPath);
    9189}
    9290
  • trunk/src/emx/src/lib/sys/fs.c

    • Property cvs2svn:cvs-rev changed from 1.17 to 1.18
    r2089 r2090  
    604604 * @returns Number of bytes in the clean path.
    605605 * @param   pszPath     The path to cleanup.
    606  * @parm    fFlags          Flags controlling the operation of the function.
    607  *                          See the BACKFS_FLAGS_* defines.
    608  */
    609 static int fsCleanPath(char *pszPath, int fFlags)
     606 * @param   fFlags      Flags controlling the operation of the function.
     607 *                      See the BACKFS_FLAGS_* defines.
     608 * @param   pfFlags     Where to clear the BACKFS_FLAGS_RESOLVE_DIR_MAYBE_ flag if a
     609 *                      trailing slash was found.
     610 */
     611static int fsCleanPath(char *pszPath, unsigned fFlags, unsigned *pfFlags)
    610612{
    611613    /*
     
    616618    char   *pszTrg = pszPath;
    617619    if (    (pszPath[0] == '\\' || pszPath[0] == '/')
    618         &&  (pszPath[1] == '\\' || pszPath[1] == '/'))
     620        &&  (pszPath[1] == '\\' || pszPath[1] == '/')
     621        &&   pszPath[2] != '\\' && pszPath[2] != '/')
    619622    {   /* Skip first slash in a unc path. */
    620623        pszSrc++;
     
    654657        &&  pszTrg[-2] != ':'
    655658        &&  pszTrg[-2] != '/')
     659    {
    656660        pszPath[--cch] = '\0';
     661        if (pfFlags)
     662            *pfFlags &= ~BACKFS_FLAGS_RESOLVE_DIR_MAYBE_;
     663    }
    657664
    658665    return cch;
     
    664671 *
    665672 * @returns 0 on success.
    666  * @returns -1 and errno on failure.
     673 * @returns Negative error code (errno.h) on failiure.
    667674 * @param   pszUserPath     The user path.
    668675 * @parm    fFlags          Flags controlling the operation of the function.
     
    674681int __libc_back_fsResolve(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree)
    675682{
    676     if (!__libc_gfNoUnix)
    677         return fsResolveUnix(pszUserPath, fFlags, pszNativePath, pfInUnixTree);
    678     else
    679         return fsResolveOS2(pszUserPath, fFlags, pszNativePath, pfInUnixTree);
     683    if (pszUserPath && *pszUserPath)
     684    {
     685        if (!__libc_gfNoUnix)
     686            return fsResolveUnix(pszUserPath, fFlags, pszNativePath, pfInUnixTree);
     687        else
     688            return fsResolveOS2(pszUserPath, fFlags, pszNativePath, pfInUnixTree);
     689    }
     690
     691    /* failure */
     692    *pszNativePath = '\0';
     693    if (pfInUnixTree)
     694        *pfInUnixTree = 0;
     695
     696    LIBC_ASSERT(pszUserPath);
     697    if (!pszUserPath)
     698        return -EINVAL;
     699    return -ENOENT;
    680700}
    681701
     
    685705 *
    686706 * @returns 0 on success.
    687  * @returns -1 and errno on failure.
     707 * @returns Negative error code (errno.h) on failiure.
    688708 * @param   pszUserPath     The user path.
    689709 * @parm    fFlags          Flags controlling the operation of the function.
     
    698718                  (void *)pszUserPath, pszUserPath, (void *)pszNativePath, (void *)pfInUnixTree);
    699719    const char *pszUserPathIn = pszUserPath;
    700     char        szTmp[PATH_MAX];
    701720    char        _achBuffer[SIZEOF_ACHBUFFER + 4];
    702721    char       *pachBuffer = (char *)((uintptr_t)&_achBuffer[3] & ~3);
     
    739758                ULONG ulDisk;
    740759                rc = DosQueryCurrentDisk(&ulDisk, &ul);
    741                 szTmp[0] = ulDisk + 'A' - 1;
    742                 ul = sizeof(szTmp) - 2;
     760                pszNativePath[0] = ulDisk + 'A' - 1;
     761                ul = PATH_MAX - 2;
    743762                if (!rc)
    744                     rc = DosQueryCurrentDir(0, (PSZ)&szTmp[3], &ul);
     763                    rc = DosQueryCurrentDir(0, (PSZ)&pszNativePath[3], &ul);
    745764                iRoot = __libc_gfInUnixTree ? __libc_gcchUnixRoot : 2;
    746765                /* fInUnixTree remains whatever it is */
     
    751770                 * Drive letter but no root slash.
    752771                 */
    753                 szTmp[0] = pszUserPath[0];
    754                 ul = sizeof(szTmp) - 2;
    755                 rc = DosQueryCurrentDir(pszUserPath[0] - (pszUserPath[0] >= 'A' && pszUserPath[0] <= 'Z' ? 'A' : 'a') + 1, (PSZ)&szTmp[3], &ul);
     772                pszNativePath[0] = pszUserPath[0];
     773                ul = PATH_MAX - 2;
     774                rc = DosQueryCurrentDir(pszUserPath[0] - (pszUserPath[0] >= 'A' && pszUserPath[0] <= 'Z' ? 'A' : 'a') + 1, (PSZ)&pszNativePath[3], &ul);
    756775                pszUserPath += 2;
    757776                iRoot = 2;
     
    768787             * Add the path stuff from the user.
    769788             */
    770             szTmp[1] = ':';
    771             szTmp[2] = '/';
    772             int cch = strlen(szTmp);
    773             szTmp[cch++] = '/';
     789            pszNativePath[1] = ':';
     790            pszNativePath[2] = '/';
     791            int cch = strlen(pszNativePath);
     792            pszNativePath[cch++] = '/';
    774793            int cchUserPath = strlen(pszUserPath) + 1;
    775794            if (cch + cchUserPath > PATH_MAX)
     
    778797                break;
    779798            }
    780             memcpy(&szTmp[cch], pszUserPath, cchUserPath);
    781             pszUserPath = memcpy(pachBuffer, szTmp, cch + cchUserPath);
     799            memcpy(&pszNativePath[cch], pszUserPath, cchUserPath);
     800            pszUserPath = memcpy(pachBuffer, pszNativePath, cch + cchUserPath);
    782801        }
    783802
     
    802821        /*
    803822         * Apply rewrite rules.
    804          * Path now goes to szTmp buffer.
     823         * Path now goes to pszNativePath buffer.
    805824         */
    806         int cchTmp = __libc_PathRewrite(pszUserPath, szTmp, sizeof(szTmp));
    807         if (cchTmp > 0)
     825        int cchNativePath = __libc_PathRewrite(pszUserPath, pszNativePath, PATH_MAX);
     826        if (cchNativePath > 0)
    808827        {
    809828            /*
    810829             * Redetermin root because of rewrite.
    811830             */
    812             iRoot = szTmp[1] == ':' ? 2 : 0;
     831            iRoot = pszNativePath[1] == ':' ? 2 : 0;
    813832        }
    814         else if (!cchTmp)
    815         {
    816             cchTmp = strlen(pszUserPath);
    817             if (cchTmp + 2 > sizeof(szTmp))
     833        else if (!cchNativePath)
     834        {
     835            cchNativePath = strlen(pszUserPath);
     836            if (cchNativePath + 2 > PATH_MAX)
    818837            {
    819838                rcRet = -ENAMETOOLONG;
    820839                break;
    821840            }
    822             memcpy(szTmp, pszUserPath, cchTmp + 1);
     841            memcpy(pszNativePath, pszUserPath, cchNativePath + 1);
    823842        }
    824843        else
     
    831850         * Check if special OS/2 name.
    832851         */
    833         if (szTmp[0] == '/' || szTmp[0] == '\\')
     852        if (pszNativePath[0] == '/' || pszNativePath[0] == '\\')
    834853        {
    835854            int fDone = 0;
    836             if (    (szTmp[1] == 'p' || szTmp[1] == 'P')
    837                 &&  (szTmp[2] == 'i' || szTmp[2] == 'I')
    838                 &&  (szTmp[3] == 'p' || szTmp[3] == 'P')
    839                 &&  (szTmp[4] == 'e' || szTmp[4] == 'E')
    840                 &&  (szTmp[5] == '/' || szTmp[5] == '\\'))
     855            if (    (pszNativePath[1] == 'p' || pszNativePath[1] == 'P')
     856                &&  (pszNativePath[2] == 'i' || pszNativePath[2] == 'I')
     857                &&  (pszNativePath[3] == 'p' || pszNativePath[3] == 'P')
     858                &&  (pszNativePath[4] == 'e' || pszNativePath[4] == 'E')
     859                &&  (pszNativePath[5] == '/' || pszNativePath[5] == '\\'))
    841860                fDone = 1;
    842             else if ((szTmp[1]== 'd' || szTmp[1] == 'D')
    843                 &&  (szTmp[2] == 'e' || szTmp[2] == 'E')
    844                 &&  (szTmp[3] == 'v' || szTmp[3] == 'V')
    845                 &&  (szTmp[4] == '/' || szTmp[4] == '\\')
     861            else if ((pszNativePath[1]== 'd' || pszNativePath[1] == 'D')
     862                &&  (pszNativePath[2] == 'e' || pszNativePath[2] == 'E')
     863                &&  (pszNativePath[3] == 'v' || pszNativePath[3] == 'V')
     864                &&  (pszNativePath[4] == '/' || pszNativePath[4] == '\\')
    846865                )
    847866            {
    848867                PFSQBUFFER2 pfsqb = (PFSQBUFFER2)pachBuffer;
    849868                ULONG       cb = SIZEOF_ACHBUFFER;
    850                 fDone = !DosQueryFSAttach((PCSZ)szTmp, 0, FSAIL_QUERYNAME, pfsqb, &cb);
    851             }
    852 
    853             /* If it was, copy path to szTmp and go to exit code. */
     869                fDone = !DosQueryFSAttach((PCSZ)pszNativePath, 0, FSAIL_QUERYNAME, pfsqb, &cb);
     870            }
     871
     872            /* If it was, copy path to pszNativePath and go to exit code. */
    854873            if (fDone)
    855874            {
    856                 int cch = strlen(szTmp) + 1;
     875                int cch = strlen(pszNativePath) + 1;
    857876                if (cch <= PATH_MAX)
    858877                {
    859                     fsCleanPath(&szTmp[0], fFlags);
     878                    fsCleanPath(pszNativePath, fFlags, NULL);
    860879                    rcRet = 0;
    861880                }
     
    869888         * Remove excessive slashing and convert all slashes to '/'.
    870889         */
    871         cchTmp = fsCleanPath(&szTmp[0], fFlags);
     890        cchNativePath = fsCleanPath(pszNativePath, fFlags, &fFlags);
    872891
    873892        /*
    874893         * Expand unix root or add missing drive letter.
    875894         */
    876         if (szTmp[0] == '/' && szTmp[1] != '/')
    877         {
    878             memcpy(pachBuffer, szTmp, cchTmp + 1);
     895        if (pszNativePath[0] == '/' && pszNativePath[1] != '/')
     896        {
     897            memcpy(pachBuffer, pszNativePath, cchNativePath + 1);
    879898            if (__libc_gcchUnixRoot)
    880899            {
    881900                iRoot = __libc_gcchUnixRoot;
    882                 if (cchTmp + iRoot >= PATH_MAX)
     901                if (cchNativePath + iRoot >= PATH_MAX)
    883902                {
    884903                    rcRet = -ENAMETOOLONG;
    885904                    break;
    886905                }
    887                 memcpy(szTmp, __libc_gszUnixRoot, iRoot);
     906                memcpy(pszNativePath, __libc_gszUnixRoot, iRoot);
    888907                fInUnixTree = 1;
    889908            }
     
    894913                ULONG   ul;
    895914                DosQueryCurrentDisk(&ulDisk, &ul);
    896                 if (cchTmp + iRoot >= PATH_MAX)
     915                if (cchNativePath + iRoot >= PATH_MAX)
    897916                {
    898917                    rcRet = -ENAMETOOLONG;
    899918                    break;
    900919                }
    901                 szTmp[0] = ulDisk + 'A' - 1;
    902                 szTmp[1] = ':';
    903             }
    904             if (cchTmp != 1 || iRoot <= 2)
    905                 memcpy(&szTmp[iRoot], pachBuffer, cchTmp + 1);
     920                pszNativePath[0] = ulDisk + 'A' - 1;
     921                pszNativePath[1] = ':';
     922            }
     923            if (cchNativePath != 1 || iRoot <= 2)
     924                memcpy(&pszNativePath[iRoot], pachBuffer, cchNativePath + 1);
    906925            else
    907                 szTmp[iRoot] = szTmp[iRoot + 1] = '\0'; /* The +1 fixes '/' access in an compartement (pszPrev below). */
    908             cchTmp += iRoot;
     926                pszNativePath[iRoot] = pszNativePath[iRoot + 1] = '\0'; /* The +1 fixes '/' access in an compartement (pszPrev below). */
     927            cchNativePath += iRoot;
    909928        }
    910929
     
    920939         * up with an optimal path in the end.
    921940         */
     941        /** @todo If we've retreived the current directory, we can safely save of the effort of validating it! */
    922942
    923943        /*
     
    926946        char *pszPrev;
    927947        char *psz;
    928         if (szTmp[0] == '/' && szTmp[1] == '/')
     948        if (pszNativePath[0] == '/' && pszNativePath[1] == '/' && pszNativePath[2] != '/')
    929949        {
    930950            /* UNC - skip past the share name. */
    931             psz = strchr(&szTmp[2], '/');
     951            psz = strchr(&pszNativePath[2], '/');
    932952            if (!psz)
    933953            {
     
    938958            if (!psz)
    939959            {
    940                 strupr(szTmp);          /* The server + share is uppercased for consistant ino_t calculations. */
     960                strupr(pszNativePath);  /* The server + share is uppercased for consistant ino_t calculations. */
    941961                rcRet = 0;
    942962                break;
    943963            }
    944964            *psz = '\0';                /* The server + share is uppercased for consistant ino_t calculations. */
    945             strupr(szTmp);
     965            strupr(pszNativePath);
    946966            *psz = '/';
    947967            pszPrev = ++psz;
    948968            fInUnixTree = 0;            /* Unix root cannot be UNC. */
    949             iRoot = psz - &szTmp[0];
     969            iRoot = psz - pszNativePath;
    950970            psz = strchr(psz, '/');
    951971        }
     
    953973        {
    954974            /* drive letters are always uppercase! (inode dev number req) */
    955             LIBC_ASSERT(szTmp[1] == ':');
    956             if (szTmp[0] >= 'a' && szTmp[0] <= 'z')
    957                 szTmp[0] -= 'a' - 'A';
    958             pszPrev = &szTmp[iRoot + 1];
     975            LIBC_ASSERT(pszNativePath[1] == ':');
     976            if (pszNativePath[0] >= 'a' && pszNativePath[0] <= 'z')
     977                pszNativePath[0] -= 'a' - 'A';
     978            pszPrev = &pszNativePath[iRoot + 1];
    959979            psz = strchr(pszPrev, '/');
    960980        }
    961         LIBC_ASSERTM(pszPrev - &szTmp[0] >= iRoot, "iRoot=%d  pszPrev offset %d  szTmp=%s\n", iRoot, pszPrev - &szTmp[0], szTmp);
     981        LIBC_ASSERTM(pszPrev - pszNativePath >= iRoot, "iRoot=%d  pszPrev offset %d  pszNativePath=%s\n", iRoot, pszPrev - pszNativePath, pszNativePath);
    962982        /* If only one component, we'll check if the fVerifyLast was requested. */
    963983        if (    !psz
    964984            &&  (fFlags & (BACKFS_FLAGS_RESOLVE_FULL | BACKFS_FLAGS_RESOLVE_FULL_SYMLINK))
    965985            &&  *pszPrev)
    966             psz = strchr(szTmp, '\0');
     986            psz = strchr(pszNativePath, '\0');
    967987
    968988        /*
     
    9831003            {
    9841004                if (    pszPrev[1] != '\0'
    985                     &&  (uintptr_t)(pszPrev - &szTmp[0]) != iRoot + 1)
     1005                    &&  (uintptr_t)(pszPrev - pszNativePath) != iRoot + 1)
    9861006                {
    9871007                    for (pszPrev -= 2; *pszPrev != '/'; pszPrev--)
     
    9901010                }
    9911011                *psz = chSlash;
    992                 memmove(pszPrev - 1, psz, cchTmp - (psz - &szTmp[0]) + 1);
    993                 cchTmp -= psz - pszPrev - 1;
     1012                memmove(pszPrev - 1, psz, cchNativePath - (psz - pszNativePath) + 1);
     1013                cchNativePath -= psz - (pszPrev - 1);
    9941014
    9951015                /*
     
    10361056             * getting the caseing resolved.)
    10371057             */
    1038             LIBC_ASSERT(psz - szTmp == cchTmp);
     1058            LIBC_ASSERT(psz - pszNativePath == cchNativePath);
    10391059            PFILEFINDBUF4 pFindBuf = (PFILEFINDBUF4)pachBuffer;
    10401060            ULONG cFiles = 1;
     
    10421062            psz[0] = '?';
    10431063            psz[1] = '\0';
    1044             int rc = DosFindFirst((PCSZ)&szTmp[0], &hDir, FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED,
     1064            int rc = DosFindFirst((PCSZ)pszNativePath, &hDir, FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED,
    10451065                                  pFindBuf, SIZEOF_ACHBUFFER, &cFiles, FIL_QUERYEASIZE);
    10461066            psz[0] = '\0';
     
    10541074            if (rc || cFiles == 0)
    10551075            {
    1056                 LIBCLOG_MSG("DosFindFirst/Next('%s',,,,,) -> %d resolving '%s'\n", szTmp, rc, pszUserPathIn);
     1076                LIBCLOG_MSG("DosFindFirst/Next('%s',,,,,) -> %d resolving '%s'\n", pszNativePath, rc, pszUserPathIn);
    10571077                if ((fFlags & BACKFS_FLAGS_RESOLVE_FULL_MAYBE_) && !chSlash)
    10581078                {
     
    10851105                EaOp.oError     = 0;
    10861106                EaOp.fpFEA2List->cbList = SIZEOF_ACHBUFFER;
    1087                 rc = DosQueryPathInfo((PCSZ)&szTmp[0], FIL_QUERYEASFROMLIST, &EaOp, sizeof(EaOp));
     1107                rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, &EaOp, sizeof(EaOp));
    10881108                if (rc)
    10891109                {
    1090                     LIBCLOG_MSG("DosQueryPathInfo('%s',,,) -> %d resolving '%s'\n", szTmp, rc, pszUserPathIn);
     1110                    LIBCLOG_MSG("DosQueryPathInfo('%s',,,) -> %d resolving '%s'\n", pszNativePath, rc, pszUserPathIn);
    10911111                    if ((fFlags & BACKFS_FLAGS_RESOLVE_FULL_MAYBE_) && !chSlash)
    10921112                        rcRet = 0;
     
    11251145                    /* Cleanup the symlink and find it's length. */
    11261146                    pszSymlink[pusType[1]] = '\0';
    1127                     int cchSymlink = fsCleanPath(pszSymlink, fFlags);
     1147                    int cchSymlink = fsCleanPath(pszSymlink, fFlags, NULL);
    11281148
    11291149                    /* Merge symlink with the path. */
    1130                     int cchLeft = cchTmp - (psz - &szTmp[0]);
     1150                    int cchLeft = cchNativePath - (psz - pszNativePath);
    11311151                    if (*pszSymlink == '/' || *pszSymlink == '\\' || pszSymlink[1] == ':')
    11321152                    {
     
    11561176                         * Squeeze the symlink in instead of the current path component.
    11571177                         */
    1158                         if (cchSymlink + cchTmp + 2 >= PATH_MAX)
     1178                        if (cchSymlink + cchNativePath + 2 >= PATH_MAX)
    11591179                        {
    11601180                            rcRet = -ENAMETOOLONG;
     
    11901210
    11911211            /*
    1192              * If we get here it was not a symlink and we should check if the directoryness
     1212             * If we get here it was not a symlink and we should check how the directoryness
    11931213             * of it fit's into the big picture...
    11941214             */
    11951215            if (!fIsDirectory && chSlash)
    11961216            {
    1197                 LIBCLOG_MSG("'%s' is not a directory (resolving '%s')\n", szTmp, pszUserPathIn);
     1217                LIBCLOG_MSG("'%s' is not a directory (resolving '%s')\n", pszNativePath, pszUserPathIn);
    11981218                rcRet = -ENOTDIR;
    11991219                break;
     
    12071227            {
    12081228                rcRet = 0;
     1229                if (    (fFlags & (BACKFS_FLAGS_RESOLVE_DIR | BACKFS_FLAGS_RESOLVE_DIR_MAYBE_)) == BACKFS_FLAGS_RESOLVE_DIR
     1230                    &&  !fIsDirectory)
     1231                    rcRet = -ENOTDIR;
    12091232                break;
    12101233            }
     
    12411264    if (!rcRet)
    12421265    {
    1243         int cch = strlen(szTmp) + 1;
    1244         if (cch == 1 || (cch == 3 && szTmp[1] == ':'))
    1245         {
    1246             szTmp[cch - 1] = '/';
    1247             szTmp[cch++] = '\0';
     1266        int cch = strlen(pszNativePath) + 1;
     1267        if (cch == 1 || (cch == 3 && pszNativePath[1] == ':'))
     1268        {
     1269            pszNativePath[cch - 1] = '/';
     1270            pszNativePath[cch] = '\0';
    12481271        }
    1249         memcpy(pszNativePath, szTmp, cch);
    12501272        if (pfInUnixTree)
    12511273            *pfInUnixTree = fInUnixTree;
     
    12631285 *
    12641286 * @returns 0 on success.
    1265  * @returns -1 and errno on failure.
     1287 * @returns Negative error code (errno.h) on failiure.
    12661288 * @param   pszUserPath     The user path.
    12671289 * @parm    fFlags          Flags controlling the operation of the function.
     
    12791301     * Apply rewrite rule.
    12801302     */
    1281     int cch = __libc_PathRewrite(pszUserPath, pszNativePath, sizeof(pszNativePath));
     1303    int cch = __libc_PathRewrite(pszUserPath, pszNativePath, PATH_MAX);
    12821304    if (cch < 0)
    12831305        LIBCLOG_RETURN_INT(-EINVAL);
Note: See TracChangeset for help on using the changeset viewer.