Hi,
here is the modified patch, hope I got everything :)
Thanks,
Pawel.
On Sat, Sep 20, 2008 at 3:27 PM, Pedro Alves <[EMAIL PROTECTED]> wrote:
> On Saturday 20 September 2008 22:37:40, Pawel Veselov wrote:
>>
[ skipped ]
Index: src/newlib/newlib/libc/sys/wince/sys/shared.h
===================================================================
--- src/newlib/newlib/libc/sys/wince/sys/shared.h (revision 1195)
+++ src/newlib/newlib/libc/sys/wince/sys/shared.h (working copy)
@@ -30,10 +30,17 @@ extern "C" {
_SHMBLK _shared_init(int pgid);
void _shared_dump(_SHMBLK shmblk);
-int _shared_getshowwindow();
+int _shared_getshowwindow(_SHMBLK shmblk);
void _shared_setshowwindow(_SHMBLK shmblk, int show);
void _shared_setenvironblk(_SHMBLK shmblk, char **env);
-void _shared_getenvironblk(_SHMBLK shmblk, char **env);
+
+/*
+ * returns the amount of environment variables extracted
+ * from the shared block. The environment variables are
+ * written into *env, which is allocated using malloc()
+ */
+int _shared_getenvironblk(_SHMBLK shmblk, char **env);
+
void _shared_reset(_SHMBLK shmblk);
void _shared_getcwd(_SHMBLK shmblk, char *cwd);
void _shared_setcwd(_SHMBLK shmblk, char *cwd);
Index: src/newlib/newlib/libc/sys/wince/startup.c
===================================================================
--- src/newlib/newlib/libc/sys/wince/startup.c (revision 1195)
+++ src/newlib/newlib/libc/sys/wince/startup.c (working copy)
@@ -548,7 +548,6 @@ static void inherit_parent(void)
atexit(_ioatexit);
_shared_dump(shmblk);
- _shared_getenvblk(shmblk, environ);
__pgid = _shared_getpgid(shmblk);
_shared_getcwd(shmblk, buf);
Index: src/newlib/newlib/libc/sys/wince/env.c
===================================================================
--- src/newlib/newlib/libc/sys/wince/env.c (revision 1195)
+++ src/newlib/newlib/libc/sys/wince/env.c (working copy)
@@ -80,20 +80,25 @@ void _initenv(_SHMBLK shmblk)
{
if (shmblk)
{
- char buf[MAX_ENVIRONBLK];
+ char * buf;
+ int no;
- /* We are being initialized from a cegcc app.
- Kill environ set from the registry. */
- environ[0] = 0;
- _shared_getenvblk(shmblk, buf);
- if(buf[0] != 0)
- _initenv_from_envblock(buf);
- else
- _initenv_from_reg();
- _shared_setenvblk(shmblk, "");
+ /* We are being initialized from a cegcc app.
+ Only use registry environment if there are
+ no environment variables in the shared block. */
+
+ no = _shared_getenvironblk(shmblk, &buf);
+
+ if (no) {
+ _initenv_from_envblock(buf);
+ free(buf);
+ } else {
+ _initenv_from_reg();
+ }
}
else
{
_initenv_from_reg();
}
}
+
Index: src/newlib/newlib/libc/sys/wince/spawn.c
===================================================================
--- src/newlib/newlib/libc/sys/wince/spawn.c (revision 1195)
+++ src/newlib/newlib/libc/sys/wince/spawn.c (working copy)
@@ -93,7 +93,7 @@ _spawnv(const char *command, char * cons
}
WCETRACE(WCE_IO, "spawnv: _shared_init returns %x", shmblk);
- _shared_setenvblk(shmblk, environ);
+ _shared_setenvironblk(shmblk, environ);
getcwd(buf, BUFSIZE);
WCETRACE(WCE_IO, "spawnv: cwd \"%s\"", buf);
_shared_setcwd(shmblk, buf);
@@ -155,7 +155,7 @@ _spawnvp(const char *command, char * con
}
WCETRACE(WCE_IO, "spawnv: _shared_init returns %x", shmblk);
- _shared_setenvblk(shmblk, environ);
+ _shared_setenvironblk(shmblk, environ);
getcwd(buf, BUFSIZE);
WCETRACE(WCE_IO, "spawnvp: cwd \"%s\"", buf);
_shared_setcwd(shmblk, buf);
@@ -190,7 +190,7 @@ _newlib_pre_spawn(int pgid, int infd, in
return(-1);
}
- _shared_setenvblk(shmblk, environ);
+ _shared_setenvironblk(shmblk, environ);
getcwd(buf, BUFSIZE);
_shared_setcwd(shmblk, buf);
_shared_setstdinfd(shmblk, (infd >= 0) ? _fdtab[infd].fd : infd);
Index: src/newlib/newlib/libc/sys/wince/shared.c
===================================================================
--- src/newlib/newlib/libc/sys/wince/shared.c (revision 1195)
+++ src/newlib/newlib/libc/sys/wince/shared.c (working copy)
@@ -194,7 +194,7 @@ _shared_setstderrfd(_SHMBLK shmblk, int
}
void
-_shared_setenvblk(_SHMBLK shmblk, char **env)
+_shared_setenvironblk(_SHMBLK shmblk, char **env)
{
char *d;
int i, len;
@@ -209,7 +209,7 @@ _shared_setenvblk(_SHMBLK shmblk, char *
for (i = 0, d = shmblk->pginfo.environ; env[i] != NULL; i++) {
len = strlen(env[i]);
if (d + len >= endp) {
- WCETRACE(WCE_IO, "_shared_setenvblk: FATAL space exhausted (max %d)",
+ WCETRACE(WCE_IO, "_shared_setenvironblk: FATAL space exhausted (max %d)",
MAX_ENVIRONBLK);
exit(1);
}
@@ -219,28 +219,34 @@ _shared_setenvblk(_SHMBLK shmblk, char *
*d = 0;
}
-void
-_shared_getenvblk(_SHMBLK shmblk, char **env)
+int
+_shared_getenvironblk(_SHMBLK shmblk, char **env)
{
char *s;
int i, len;
- if (shmblk == NULL)
- return;
+ if (!shmblk) {
+ return 0;
+ }
for (i = 0, s = shmblk->pginfo.environ; *s; i++) {
- len = strlen(s);
- if (env[i] != NULL) {
- free(env[i]);
- }
- env[i] = malloc(len + 1);
- if (env[i] == NULL) {
- WCETRACE(WCE_IO, "_shared_getenvblk: FATAL ERROR malloc failed");
- exit(1);
- }
- memcpy(env[i], s, len + 1);
- s += len + 1;
- }
+ s += strlen(s) + 1;
+ }
+
+ if (i) {
+
+ len = s - shmblk->pginfo.environ + 1;
+ *env = malloc(len);
+ if (!*env) {
+ WCETRACE(WCE_IO, "_shared_getenvironblk: FATAL ERROR malloc failed for %d more bytes", len);
+ exit(1);
+ }
+
+ memcpy(*env, shmblk->pginfo.environ, len);
+ }
+
+
+ return i;
}
BOOL
Index: src/newlib/ChangeLog.cegcc
===================================================================
--- src/newlib/ChangeLog.cegcc (revision 1195)
+++ src/newlib/ChangeLog.cegcc (working copy)
@@ -1,3 +1,22 @@
+2008-10-03 Pawel Veselov <[EMAIL PROTECTED]>
+
+ * newlib/libc/sys/wince/sys/shared.h (_shared_getshowwindow) :
+ Redefine to include _SHMBLK argument.
+ * newlib/libc/sys/wince/sys/shared.h (_shared_getenvironblk) :
+ Redefine to return int, added a comment explaining what the
+ function does.
+ * newlib/libc/sys/wince/startup.c (inherit_parent) : Don't call
+ _shared_getenvblk there, it's called somewhere else
+ * newlib/libc/sys/wince/env.c (_initenv) : Use new
+ _shared_getenvironblk semantics
+ * newlib/libc/sys/wince/spawn.c (_spawnv, _spawnvp, _newlib_pre_spawn) :
+ Use correct function name.
+ * newlib/libc/sys/wince/shared.c: renamed _shared_setenvblk to
+ _shared_setenvironblk to match the header file definition
+ * newlib/libc/sys/wince/shared.c (_shared_getenvironblk) : allocate
+ memory for the copy of the shared environment block, and return
+ the number of variables found
+
2008-09-24 Pedro Alves <[EMAIL PROTECTED]>
* config.sub: Add cegcc support.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel