Changeset 2119


Ignore:
Timestamp:
Jun 30, 2005, 6:50:38 AM (20 years ago)
Author:
bird
Message:

Added fgets_unlocked and gets_unlocked.

Location:
trunk/src/emx
Files:
5 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.75 to 1.76
    r2118 r2119  
    88        o Added ieeefp.h and functions from FreeBSD - this is
    99          the SysV/386 FP control interface. (inline only)
     10        o Added fgets_unlocked and gets_unlocked.
    1011
    11122005-06-28: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/include/stdio.h

    • Property cvs2svn:cvs-rev changed from 1.16 to 1.17
    r2118 r2119  
    374374int     fputc_unlocked(int, FILE *);
    375375int     fputs_unlocked(const char * __restrict, FILE * __restrict);
     376char    *fgets_unlocked(char * __restrict, int, FILE * __restrict);
    376377int     puts_unlocked(const char *);
     378char    *gets_unlocked(char *);
    377379#endif
    378380
  • trunk/src/emx/src/lib/io/fgets.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2118 r2119  
    99#include "getputc.h"
    1010
    11 char *_STD(fgets) (char *buffer, int n, FILE *stream)
     11char *_STD(fgets)(char *buffer, int n, FILE *stream)
    1212{
    13   int c;
    14   char *dst;
     13    STREAM_LOCK(stream);
     14    char *psz = fgets_unlocked(buffer, n, stream);
     15    STREAM_UNLOCK(stream);
     16    return psz;
     17}
    1518
    16   if (n <= 0)
    17     return NULL;
    18   dst = buffer;
    1919
    20   STREAM_LOCK (stream);
    21   while (n > 1)
     20char *_STD(fgets_unlocked)(char *buffer, int n, FILE *stream)
     21{
     22    int c;
     23    char *dst;
     24
     25    if (n <= 0)
     26        return NULL;
     27    dst = buffer;
     28
     29    while (n > 1)
    2230    {
    23       c = _getc_inline (stream);
    24       if (c == EOF)
     31        c = _getc_inline(stream);
     32        if (c == EOF)
    2533        {
    26           /* ISO/IEC 9899:1990, 7.9.7.2: "If end-of-file is
    27              encountered and no characters have been read into the
    28              array, the contents of the array remain unchanged and a
    29              null pointer is returned.  If a read error occurs during
    30              the operation, the array contents are indeterminate and a
    31              null pointer is returned." */
     34            /* ISO/IEC 9899:1990, 7.9.7.2: "If end-of-file is
     35               encountered and no characters have been read into the
     36               array, the contents of the array remain unchanged and a
     37               null pointer is returned.  If a read error occurs during
     38               the operation, the array contents are indeterminate and a
     39               null pointer is returned." */
    3240
    33           if (dst == buffer || ferror (stream))
    34             {
    35               STREAM_UNLOCK (stream);
    36               return NULL;
    37             }
    38           else
     41            if (dst == buffer || ferror(stream))
     42                return NULL;
    3943            break;              /* EOF after reading at least one char */
    4044        }
    41       *dst++ = (char)c;
    42       if (c == '\n')
    43         break;
    44       --n;
     45        *dst++ = (char)c;
     46        if (c == '\n')
     47            break;
     48        --n;
    4549    }
    46   STREAM_UNLOCK (stream);
    47   *dst = 0;
    48   return buffer;
     50    *dst = '\0';
     51    return buffer;
    4952}
     53
  • trunk/src/emx/src/lib/io/gets.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2118 r2119  
    99#include "getputc.h"
    1010
    11 char *_STD(gets) (char *buffer)
     11char *_STD(gets_unlocked)(char *buffer)
    1212{
    13   int c;
    14   char *dst;
     13    int c;
     14    char *dst;
    1515
    16   dst = buffer;
    17   STREAM_LOCK (stdin);
    18   for (;;)
     16    dst = buffer;
     17    for (;;)
    1918    {
    20       c = _getc_inline (stdin);
    21       if (c == EOF)
     19        c = _getc_inline(stdin);
     20        if (c == EOF)
    2221        {
    23           if (dst == buffer)
     22            if (dst == buffer)
    2423            {
    25               *dst = 0;
    26               STREAM_UNLOCK (stdin);
    27               return NULL;
     24                *dst = '\0';
     25                return NULL;
    2826            }
    29           else
    3027            break;
    3128        }
    32       if (c == '\n')
    33         break;
    34       *dst++ = (char)c;
     29        if (c == '\n')
     30            break;
     31        *dst++ = (char)c;
    3532    }
    36   STREAM_UNLOCK (stdin);
    37   *dst = 0;
    38   return buffer;
     33    *dst = 0;
     34    return buffer;
    3935}
     36
     37char *_STD(gets)(char *buffer)
     38{
     39    STREAM_LOCK(stdin);
     40    char *psz = gets_unlocked(buffer);
     41    STREAM_UNLOCK(stdin);
     42    return psz;
     43}
     44
     45
     46
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.118 to 1.119
    r2118 r2119  
    17441744    "__std_rawmemchr" @1745
    17451745    "__std_strchrnul" @1746
     1746    "__std_fgets_unlocked" @1747
     1747    "__std_gets_unlocked" @1748
Note: See TracChangeset for help on using the changeset viewer.