Changeset 1315


Ignore:
Timestamp:
Mar 17, 2004, 4:59:28 AM (21 years ago)
Author:
bird
Message:

More logging.

Location:
trunk/src/emx
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/InnoTekLIBC/logstrict.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1314 r1315  
    176176/** Signal APIs and events. */
    177177#define __LIBC_LOG_GRP_SIGNAL       14
     178/** Environment APIs. */
     179#define __LIBC_LOG_GRP_ENV          15
    178180
    179181/** Init/Term APIs and Events. */
  • trunk/src/emx/include/InnoTekLIBC/thread.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1314 r1315  
    5959 * Members most frequently used have been put together at the front.
    6060 */
    61 typedef struct __libc_threadCurrentSlow
     61typedef struct __libc_thread
    6262{
    6363    /** errno value. (Comes first, see errnofun.s.) */
     
    7272    void           *apvTLS[__LIBC_TLS_MAX];
    7373
     74    /** The nesting depth of the default logger. */
     75    unsigned        cDefLoggerDepth;
    7476    /** Current rand() seed value. */
    7577    unsigned int    iRand;
     
    135137#ifndef __LIBC_THREAD_DECLARED
    136138#define __LIBC_THREAD_DECLARED
    137 typedef struct __libc_threadCurrentSlow *__LIBC_PTHREAD, **__LIBC_PPTHREAD;
     139typedef struct __libc_thread *__LIBC_PTHREAD, **__LIBC_PPTHREAD;
    138140#endif
    139141
  • trunk/src/emx/src/lib/app/getenv.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1314 r1315  
    44#include <stdlib.h>
    55#include <string.h>
     6#define __LIBC_LOG_GROUP  __LIBC_LOG_GRP_ENV
     7#include <InnoTekLIBC/logstrict.h>
    68
    7 char *_STD(getenv) (const char *name)
     9char *_STD(getenv)(const char *name)
    810{
    9   int len;
    10   char **p;
     11    LIBCLOG_ENTER("name=%s\n", name);
     12    int len;
     13    char **p;
    1114
    12   if (name == NULL || environ == NULL)
    13     return NULL;
    14   len = strlen (name);
    15   for (p = environ; *p != NULL; ++p)
    16     if (strncmp (*p, name, len) == 0 && (*p)[len] == '=')
    17       return *p + len + 1;
    18   return NULL;
     15    if (name == NULL || environ == NULL)
     16    {
     17        LIBC_ASSERTM(name, "invalid parameter name(%p)\n", name);
     18        LIBC_ASSERTM(environ, "environment is not configured!!!\n");
     19        LIBCLOG_RETURN_P(NULL);
     20    }
     21    LIBC_ASSERTM(!strchr(name, '='), "name contains '='\n");
     22    LIBC_ASSERTM(*name, "name is empty\n");
     23
     24    len = strlen(name);
     25    for (p = environ; *p != NULL; ++p)
     26        if (    strncmp(*p, name, len) == 0
     27            &&  (*p)[len] == '=')
     28        {
     29            char *pszRet = *p + len + 1;
     30            LIBCLOG_RETURN_MSG(pszRet, "ret %p(='%s')\n", pszRet, pszRet);
     31        }
     32    LIBCLOG_RETURN_P(NULL);
    1933}
  • trunk/src/emx/src/lib/app/putenv.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1314 r1315  
    77#include <emx/startup.h>
    88#include <emx/time.h>           /* _tzset_flag */
     9#define __LIBC_LOG_GROUP  __LIBC_LOG_GRP_ENV
     10#include <InnoTekLIBC/logstrict.h>
    911
    10 int _STD(putenv) (const char *string)
     12int _STD(putenv)(const char *string)
    1113{
    12   char *s, **p;
    13   int len, env_size;
     14    LIBCLOG_ENTER("string=%s\n", string);
     15    char *s, **p;
     16    int len, env_size;
    1417
    15   if (string == NULL)
     18    if (string == NULL)
    1619    {
    17       errno = EINVAL;
    18       return -1;
     20        LIBC_ASSERTM_FAILED("bad string(=%p)\n", string);
     21        errno = EINVAL;
     22        LIBCLOG_RETURN_INT(-1);
    1923    }
    20   _tzset_flag = 0;              /* Call tzset() */
    21   s = strchr (string, '=');
    22   if (s == NULL)
    23     len = strlen (string);        /* Use complete string */
    24   else
    25     len = s - string;
    26   p = environ;
    27   env_size = 0;
    28   if (p != NULL)
    29     while (*p != NULL)
    30       {
    31         s = *p;
    32         if (strncmp (s, string, len) == 0 && (s[len] == 0 || s[len] == '='))
    33           break;
    34         ++p; ++env_size;
    35       }
    36   if (p == NULL || *p == NULL)
     24    _tzset_flag = 0;                    /* Call tzset() */
     25    s = strchr(string, '=');
     26    if (s == NULL)
     27        len = strlen(string);           /* Use complete string */
     28    else
     29        len = s - string;
     30    p = environ;
     31    env_size = 0;
     32    if (p != NULL)
    3733    {
    38       if (environ == _org_environ)
     34        while (*p != NULL)
    3935        {
    40           p = malloc ((env_size+2) * sizeof (char *));
    41           if (p == NULL) return -1;
    42           environ = p;
    43           if (env_size != 0)
    44             memcpy (environ, _org_environ, env_size * sizeof (char *));
     36            s = *p;
     37            if (    strncmp(s, string, len) == 0
     38                &&  (   s[len] == '\0'
     39                     || s[len] == '='))
     40                break;
     41            ++p;
     42            ++env_size;
    4543        }
    46       else
     44    }
     45    else
     46        LIBC_ASSERTM_FAILED("environment not initiated!\n");
     47
     48    if (p == NULL || *p == NULL)
     49    {
     50        if (environ == _org_environ)
    4751        {
    48           p = realloc (environ, (env_size+2) * sizeof (char *));
    49           if (p == NULL) return -1;
    50           environ = p;
     52            LIBCLOG_MSG("env_size=%d; new, first new\n", env_size);
     53            p = malloc((env_size + 2) * sizeof (char *));
     54            if (p == NULL)
     55                LIBCLOG_RETURN_INT(-1);
     56            environ = p;
     57            if (env_size != 0)
     58                memcpy(environ, _org_environ, env_size * sizeof (char *));
    5159        }
    52       environ[env_size+0] = (char *)string;
    53       environ[env_size+1] = NULL;
     60        else
     61        {
     62            LIBCLOG_MSG("env_size=%d; new, resize environ array\n", env_size);
     63            p = realloc(environ, (env_size + 2) * sizeof (char *));
     64            if (p == NULL)
     65                LIBCLOG_RETURN_INT(-1);
     66            environ = p;
     67        }
     68        environ[env_size + 0] = (char *)string;
     69        environ[env_size + 1] = NULL;
    5470    }
    55   else
    56     *p = (char *)string;
    57   return 0;
     71    else
     72    {
     73        LIBCLOG_MSG("replacing '%s' with '%s'\n", *p, string);
     74        *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! */
     78    }
     79    LIBCLOG_RETURN_INT(0);
    5880}
  • trunk/src/emx/src/lib/app/setenv.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r1314 r1315  
    1717#include <emx/startup.h>
    1818#include <emx/time.h>           /* _tzset_flag */
     19#define __LIBC_LOG_GROUP  __LIBC_LOG_GRP_ENV
     20#include <InnoTekLIBC/logstrict.h>
    1921
    2022
     
    3436 * @author  knut st. osmundsen <bird-srcspam@anduin.net>
    3537 * @remark  We skip the first equal in the environment value like BSD does.
     38 * @remark  Make environment updating and such thread safe!
    3639 */
    37 int _STD(setenv) (const char *envname, const char *envval, int overwrite)
     40int _STD(setenv)(const char *envname, const char *envval, int overwrite)
    3841{
    39   char **p;
    40   int   lenname;
    41   int   lenval;
    42   int   env_size;
     42    LIBCLOG_ENTER("envname=%s envval=%s overwrite=%d\n", envname, envval, overwrite);
     43    char **p;
     44    char *psz;
     45    int   lenname;
     46    int   lenval;
     47    int   env_size;
    4348
    44   /* validate */
    45   if (envname == NULL || *envname == '\0' || strchr(envname, '=') != NULL)
     49    /* validate */
     50    if (envname == NULL || *envname == '\0' || strchr(envname, '=') != NULL)
    4651    {
    47       errno = EINVAL;
    48       return -1;
     52        LIBC_ASSERTM_FAILED("invalid argument envname(%p='%s')\n", envname, envname);
     53        errno = EINVAL;
     54        LIBCLOG_RETURN_INT(-1);
    4955    }
    50   _tzset_flag = 0;              /* Call tzset() */
     56    _tzset_flag = 0;              /* Call tzset() */
    5157
    52   /* BSD Compatability. */
    53   if (*envval == '=')
    54       envval++;
     58    /* BSD Compatability. */
     59    if (*envval == '=')
     60        envval++;
    5561
    56   /* search for existing variable iinstance  */
    57   lenname = strlen (envname);
    58   p = environ;
    59   env_size = 0;
    60   if (p != NULL)
    61     while (*p != NULL)
    62       {
    63         char *s = *p;
    64         if (strncmp (s, envname, lenname) == 0 && (s[lenname] == 0 || s[lenname] == '='))
    65           break;
    66         ++p; ++env_size;
    67       }
     62    /* search for existing variable iinstance  */
     63    lenname = strlen(envname);
     64    p = environ;
     65    env_size = 0;
     66    if (p != NULL)
     67        while (*p != NULL)
     68        {
     69            char *s = *p;
     70            if (    strncmp(s, envname, lenname) == 0
     71                && (    s[lenname] == '\0'
     72                    ||  s[lenname] == '='))
     73                break;
     74            ++p; ++env_size;
     75        }
    6876
    69   /* found it? */
    70   lenval = strlen(envval);
    71   if (p != NULL && *p != NULL)
     77    /* found it? */
     78    lenval = strlen(envval);
     79    if (p != NULL && *p != NULL)
    7280    {
    73       if (!overwrite)
    74         return 0;
    75       /* if the older is larger then overwrite it */
    76       if (strlen(*p + lenname + 1) >= lenval)
     81        if (!overwrite)
    7782        {
    78            memcpy(*p + lenname + 1, envval, lenval + 1);
    79            return 0;
     83            LIBCLOG_MSG("exists, requested not to overwrite it\n");
     84            LIBCLOG_RETURN_INT(0);
     85        }
     86        /* if the older is larger then overwrite it */
     87        LIBCLOG_MSG("exists, overwrite\n");
     88        if (strlen(*p + lenname + 1) >= lenval)
     89        {
     90            memcpy(*p + lenname + 1, envval, lenval + 1);
     91            LIBCLOG_RETURN_INT(0);
    8092        }
    8193    }
    82   else
     94    else
    8395    {
    84       /* new variable: reallocate the environment pointer block */
    85       if (environ == _org_environ)
     96        /* new variable: reallocate the environment pointer block */
     97        if (environ == _org_environ)
    8698        {
    87           p = malloc ((env_size+2) * sizeof (char *));
    88           if (p == NULL)
    89               return -1;
    90           environ = p;
    91           if (env_size != 0)
    92             memcpy (environ, _org_environ, env_size * sizeof (char *));
     99            LIBCLOG_MSG("env_size=%d; new, first new\n", env_size);
     100            p = malloc((env_size + 2) * sizeof (char *));
     101            if (p == NULL)
     102                LIBCLOG_RETURN_INT(-1);
     103            environ = p;
     104            if (env_size != 0)
     105                memcpy(environ, _org_environ, env_size * sizeof (char *));
    93106        }
    94       else
     107        else
    95108        {
    96           p = realloc (environ, (env_size+2) * sizeof (char *));
    97           if (p == NULL)
    98               return -1;
    99           environ = p;
     109            LIBCLOG_MSG("env_size=%d; new, resize environ array\n", env_size);
     110            p = realloc(environ, (env_size + 2) * sizeof (char *));
     111            if (p == NULL)
     112                LIBCLOG_RETURN_INT(-1);
     113            environ = p;
    100114        }
    101115
    102       /* Add to end. */
    103       p = &environ[env_size+0];
    104       environ[env_size+1] = NULL;
     116        /* Add to end. */
     117        p = &environ[env_size + 0];
     118        environ[env_size + 1] = NULL;
    105119    }
    106120
    107   /* Allocate space for new variable and assign it. */
    108   *p = malloc(lenname + lenval + 2);
    109   if (!*p)
    110     return -1;
    111   memcpy(*p, envname, lenname);
    112   (*p)[lenname] = '=';
    113   memcpy(*p + lenname + 1, envval, lenval + 1);
    114   return 0;
     121    /* Allocate space for new variable and assign it. */
     122    psz = malloc(lenname + lenval + 2);
     123    if (!psz)
     124        LIBCLOG_RETURN_INT(-1);
     125    memcpy(psz, envname, lenname);
     126    psz[lenname] = '=';
     127    memcpy(psz + lenname + 1, envval, lenval + 1);
     128    *p = psz;
     129    LIBCLOG_RETURN_INT(0);
    115130}
    116131
  • trunk/src/emx/src/lib/app/stdio.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r1314 r1315  
    1 /* stdio.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
     1/* stdio.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
     2                     -- Copyright (c) 2003-2004 by knut st. osmundsen */
    23
    34#include "libc-alias.h"
     
    910#include <emx/io.h>
    1011#include <emx/startup.h>
     12#define __LIBC_LOG_GROUP  __LIBC_LOG_GRP_STREAM
     13#include <InnoTekLIBC/logstrict.h>
    1114
    1215
     
    5356void _init_streams(void)
    5457{
     58    LIBCLOG_ENTER("\n");
    5559    struct _FILE       *pFile;
    5660    struct _file2      *pFile2;
     
    6266     */
    6367    if (fInited)
    64         return;
     68        LIBCLOG_RETURN_VOID();
    6569    fInited = 1;
     70    LIBCLOG_MSG("_NFILES=%d\n", _NFILES);
    6671
    6772    /*
     
    101106            gaPreFiles[i]._flush     = _flushstream;
    102107            if (_setmore(&gaPreFiles[i], 0))
     108            {
     109                LIBC_ASSERTM_FAILED("_setmore failed for i=%d\n", i);
    103110                abort();
     111            }
    104112
    105113            /*
     
    114122                    gaPreFiles[0]._buffer    = gachStdIn;
    115123                    gaPreFiles[0]._buf_size  = BUFSIZ;
     124                    LIBCLOG_MSG("__stdinp=%p\n", __stdinp);
    116125                    break;
    117126
     
    120129                    gaPreFiles[1]._flags |= _IOWRT | _IOBUFNONE
    121130                        | ((pFH->fFlags & F_TYPEMASK) == F_DEV ? _IONBF : _IOFBF);
     131                    LIBCLOG_MSG("__stdoutp=%p flags=%#x (%s)\n", __stdoutp, gaPreFiles[1]._flags,
     132                                (pFH->fFlags & F_TYPEMASK) == F_DEV ? "dev" : "none-dev");
    122133                    break;
    123134
     
    125136                    /* stderr is always unbuffered. */
    126137                    gaPreFiles[2]._flags |= _IOWRT | _IOBUFNONE | _IONBF;
     138                    LIBCLOG_MSG("__stderrp=%p\n", __stderrp);
    127139                    break;
    128140            }
    129141        }
     142        else
     143            LIBCLOG_MSG("No open file for %d\n", i);
    130144    } /* for standard handles. */
     145    LIBCLOG_RETURN_VOID();
    131146}
    132147
  • trunk/src/emx/src/lib/app/unsetenv.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1314 r1315  
    22/** @file
    33 *
    4  * unsetenv()
     4 * LIBC APP - unsetenv()
    55 *
    66 * Copyright (c) 2003 InnoTek Systemberatung GmbH
     
    1717#include <errno.h>
    1818#include <emx/startup.h>
     19#define __LIBC_LOG_GROUP  __LIBC_LOG_GRP_ENV
     20#include <InnoTekLIBC/logstrict.h>
    1921
    2022
     
    2628 * @returns -1 and errno=EINVAL if name is invalid in any way.
    2729 * @param   name    Name of environment variable to unset.
    28  *                  Shall not be NULL, empty string of contain '='.
    29  * @remark  May be leaking memory, but that's what BSD does.
     30 *                  Shall not be NULL, empty string or contain '='.
     31 * @remark  Leaks memory, but that's what BSD does too.
    3032 * @author  knut st. osmundsen <bird-srcspam@anduin.net>
    3133 */
    3234int _STD(unsetenv)(const char *name)
    3335{
     36    LIBCLOG_ENTER("name=%s\n", name);
    3437    int     lenname;
    3538    char ** p;
    3639
     40
    3741    /* validate input */
    3842    if (name == NULL || *name == '\0' || strchr(name, '=') != NULL)
    39       {
     43    {
    4044        errno = EINVAL;
    41         return -1;
    42       }
    43 
     45        LIBC_ASSERTM_FAILED("name(%p='%s') is invalid\n", name, name);
     46        LIBCLOG_RETURN_INT(-1);
     47    }
    4448
    4549    /* search (thru all the environment in case of multiple defintions). */
     
    4751    p = environ;
    4852    while (*p != NULL)
    49       {
     53    {
    5054        char *s = *p;
    51         if (strncmp (s, name, lenname) == 0 && (s[lenname] == 0 || s[lenname] == '='))
    52           { /* shift down the remaining entries. */
     55        if (    strncmp(s, name, lenname) == 0
     56            && (    s[lenname] == '\0'
     57                ||  s[lenname] == '='))
     58        { /* shift down the remaining entries. */
    5359            char **p2 = p;
    5460            for (;;p2++)
    5561                if ((p2[0] = p2[1]) == NULL)
    5662                    break;
    57           }
     63            LIBCLOG_MSG("deleted '%s'\n", s);
     64        }
    5865        else
    59           {
     66        {
    6067            /* next */
    6168            p++;
    62           }
    63       }
    64     return 0;
     69        }
     70    }
     71
     72    LIBCLOG_RETURN_INT(0);
    6573}
Note: See TracChangeset for help on using the changeset viewer.