Changeset 1315
- Timestamp:
- Mar 17, 2004, 4:59:28 AM (21 years ago)
- 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
to1.2
r1314 r1315 176 176 /** Signal APIs and events. */ 177 177 #define __LIBC_LOG_GRP_SIGNAL 14 178 /** Environment APIs. */ 179 #define __LIBC_LOG_GRP_ENV 15 178 180 179 181 /** Init/Term APIs and Events. */ -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/include/InnoTekLIBC/thread.h
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.2
r1314 r1315 59 59 * Members most frequently used have been put together at the front. 60 60 */ 61 typedef struct __libc_thread CurrentSlow61 typedef struct __libc_thread 62 62 { 63 63 /** errno value. (Comes first, see errnofun.s.) */ … … 72 72 void *apvTLS[__LIBC_TLS_MAX]; 73 73 74 /** The nesting depth of the default logger. */ 75 unsigned cDefLoggerDepth; 74 76 /** Current rand() seed value. */ 75 77 unsigned int iRand; … … 135 137 #ifndef __LIBC_THREAD_DECLARED 136 138 #define __LIBC_THREAD_DECLARED 137 typedef struct __libc_thread CurrentSlow*__LIBC_PTHREAD, **__LIBC_PPTHREAD;139 typedef struct __libc_thread *__LIBC_PTHREAD, **__LIBC_PPTHREAD; 138 140 #endif 139 141 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/app/getenv.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1314 r1315 4 4 #include <stdlib.h> 5 5 #include <string.h> 6 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_ENV 7 #include <InnoTekLIBC/logstrict.h> 6 8 7 char *_STD(getenv) 9 char *_STD(getenv)(const char *name) 8 10 { 9 int len; 10 char **p; 11 LIBCLOG_ENTER("name=%s\n", name); 12 int len; 13 char **p; 11 14 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); 19 33 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/app/putenv.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1314 r1315 7 7 #include <emx/startup.h> 8 8 #include <emx/time.h> /* _tzset_flag */ 9 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_ENV 10 #include <InnoTekLIBC/logstrict.h> 9 11 10 int _STD(putenv) 12 int _STD(putenv)(const char *string) 11 13 { 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; 14 17 15 if (string == NULL)18 if (string == NULL) 16 19 { 17 errno = EINVAL; 18 return -1; 20 LIBC_ASSERTM_FAILED("bad string(=%p)\n", string); 21 errno = EINVAL; 22 LIBCLOG_RETURN_INT(-1); 19 23 } 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) 37 33 { 38 if (environ == _org_environ)34 while (*p != NULL) 39 35 { 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; 45 43 } 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) 47 51 { 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 *)); 51 59 } 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; 54 70 } 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); 58 80 } -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/app/setenv.c
-
Property cvs2svn:cvs-rev
changed from
1.3
to1.4
r1314 r1315 17 17 #include <emx/startup.h> 18 18 #include <emx/time.h> /* _tzset_flag */ 19 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_ENV 20 #include <InnoTekLIBC/logstrict.h> 19 21 20 22 … … 34 36 * @author knut st. osmundsen <bird-srcspam@anduin.net> 35 37 * @remark We skip the first equal in the environment value like BSD does. 38 * @remark Make environment updating and such thread safe! 36 39 */ 37 int _STD(setenv) 40 int _STD(setenv)(const char *envname, const char *envval, int overwrite) 38 41 { 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; 43 48 44 /* validate */45 if (envname == NULL || *envname == '\0' || strchr(envname, '=') != NULL)49 /* validate */ 50 if (envname == NULL || *envname == '\0' || strchr(envname, '=') != NULL) 46 51 { 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); 49 55 } 50 _tzset_flag = 0; /* Call tzset() */56 _tzset_flag = 0; /* Call tzset() */ 51 57 52 /* BSD Compatability. */53 if (*envval == '=')54 envval++;58 /* BSD Compatability. */ 59 if (*envval == '=') 60 envval++; 55 61 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 } 68 76 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) 72 80 { 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) 77 82 { 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); 80 92 } 81 93 } 82 else94 else 83 95 { 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) 86 98 { 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 *)); 93 106 } 94 else107 else 95 108 { 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; 100 114 } 101 115 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; 105 119 } 106 120 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); 115 130 } 116 131 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/app/stdio.c
-
Property cvs2svn:cvs-rev
changed from
1.7
to1.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 */ 2 3 3 4 #include "libc-alias.h" … … 9 10 #include <emx/io.h> 10 11 #include <emx/startup.h> 12 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_STREAM 13 #include <InnoTekLIBC/logstrict.h> 11 14 12 15 … … 53 56 void _init_streams(void) 54 57 { 58 LIBCLOG_ENTER("\n"); 55 59 struct _FILE *pFile; 56 60 struct _file2 *pFile2; … … 62 66 */ 63 67 if (fInited) 64 return;68 LIBCLOG_RETURN_VOID(); 65 69 fInited = 1; 70 LIBCLOG_MSG("_NFILES=%d\n", _NFILES); 66 71 67 72 /* … … 101 106 gaPreFiles[i]._flush = _flushstream; 102 107 if (_setmore(&gaPreFiles[i], 0)) 108 { 109 LIBC_ASSERTM_FAILED("_setmore failed for i=%d\n", i); 103 110 abort(); 111 } 104 112 105 113 /* … … 114 122 gaPreFiles[0]._buffer = gachStdIn; 115 123 gaPreFiles[0]._buf_size = BUFSIZ; 124 LIBCLOG_MSG("__stdinp=%p\n", __stdinp); 116 125 break; 117 126 … … 120 129 gaPreFiles[1]._flags |= _IOWRT | _IOBUFNONE 121 130 | ((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"); 122 133 break; 123 134 … … 125 136 /* stderr is always unbuffered. */ 126 137 gaPreFiles[2]._flags |= _IOWRT | _IOBUFNONE | _IONBF; 138 LIBCLOG_MSG("__stderrp=%p\n", __stderrp); 127 139 break; 128 140 } 129 141 } 142 else 143 LIBCLOG_MSG("No open file for %d\n", i); 130 144 } /* for standard handles. */ 145 LIBCLOG_RETURN_VOID(); 131 146 } 132 147 -
Property cvs2svn:cvs-rev
changed from
-
trunk/src/emx/src/lib/app/unsetenv.c
-
Property cvs2svn:cvs-rev
changed from
1.2
to1.3
r1314 r1315 2 2 /** @file 3 3 * 4 * unsetenv()4 * LIBC APP - unsetenv() 5 5 * 6 6 * Copyright (c) 2003 InnoTek Systemberatung GmbH … … 17 17 #include <errno.h> 18 18 #include <emx/startup.h> 19 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_ENV 20 #include <InnoTekLIBC/logstrict.h> 19 21 20 22 … … 26 28 * @returns -1 and errno=EINVAL if name is invalid in any way. 27 29 * @param name Name of environment variable to unset. 28 * Shall not be NULL, empty string o fcontain '='.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. 30 32 * @author knut st. osmundsen <bird-srcspam@anduin.net> 31 33 */ 32 34 int _STD(unsetenv)(const char *name) 33 35 { 36 LIBCLOG_ENTER("name=%s\n", name); 34 37 int lenname; 35 38 char ** p; 36 39 40 37 41 /* validate input */ 38 42 if (name == NULL || *name == '\0' || strchr(name, '=') != NULL) 39 43 { 40 44 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 } 44 48 45 49 /* search (thru all the environment in case of multiple defintions). */ … … 47 51 p = environ; 48 52 while (*p != NULL) 49 53 { 50 54 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. */ 53 59 char **p2 = p; 54 60 for (;;p2++) 55 61 if ((p2[0] = p2[1]) == NULL) 56 62 break; 57 } 63 LIBCLOG_MSG("deleted '%s'\n", s); 64 } 58 65 else 59 66 { 60 67 /* next */ 61 68 p++; 62 } 63 } 64 return 0; 69 } 70 } 71 72 LIBCLOG_RETURN_INT(0); 65 73 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.