Skip to contentSkip to conversation

win32: Add missing function setenv

PATCH In review Stefan Weil 2 participants 8 messages Jul 1, 2010 – Jul 2, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 win32: Add missing function setenv

Mingw32 does not provide a declaration and implementation of function setenv (which is used in sdl.c), so this patch adds both.

---
 os-win32.c |   15 +++++++++++++++
 osdep.h    |    2 ++
 2 files changed, 17 insertions(+), 0 deletions(-)
os-win32.c +15 -0
index d98fd77..dd46bf4 100644
@@ -34,6 +34,21 @@
 #include "qemu-options.h"
 
 /***********************************************************/
+/* Functions missing in mingw */
+
+int setenv(const char *name, const char *value, int overwrite)
+{
+    int result = 0;
+    if (overwrite || !getenv(name)) {
+        size_t length = strlen(name) + strlen(value) + 2;
+        char *string = qemu_malloc(length);
+        snprintf(string, length, "%s=%s", name, value);
+        result = putenv(string);
+    }
+    return result;
+}
+
+/***********************************************************/
 /* Polling handling */
 
 typedef struct PollingEntry {
osdep.h +2 -0
index 75b5816..1cdc7e2 100644
@@ -95,6 +95,8 @@ int qemu_create_pidfile(const char *filename);
 #ifdef _WIN32
 int ffs(int i);
 
+int setenv(const char *name, const char *value, int overwrite);
+
 typedef struct {
     long tv_sec;
     long tv_usec;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 4 lines · Stefan Weil

Mingw32 does not provide a declaration and implementation of function setenv (which is used in sdl.c), so this patch adds both.

[snip]

osdep.h int qemu_create_pidfile(const char *filename); · line 102

Quoted 13 lines
osdep.h +2 -0
index 75b5816..1cdc7e2 100644
@@ -95,6 +95,8 @@ int qemu_create_pidfile(const char *filename);
 #ifdef _WIN32
 int ffs(int i);
 
+int setenv(const char *name, const char *value, int overwrite);
+
 typedef struct {
     long tv_sec;
     long tv_usec;

Please move this to qemu-os-win32.h instead, otherwise the build will fail on POSIX systems due to setenv being redefined.

Thanks,
Jes

#2 lore raw

Am 01.07.2010 13:50, schrieb Jes Sorensen:

Quoted 26 lines · Stefan Weil
Quoted 6 lines

Mingw32 does not provide a declaration and implementation of function setenv (which is used in sdl.c), so this patch adds both.

[snip]

Quoted 6 lines
osdep.h +0 -0
index 75b5816..1cdc7e2 100644

osdep.h int qemu_create_pidfile(const char *filename); · line 102

Quoted 8 lines
osdep.h +2 -0
@@ -95,6 +95,8 @@ int qemu_create_pidfile(const char *filename);
  #ifdef _WIN32
  int ffs(int i);
 
+int setenv(const char *name, const char *value, int overwrite);
+
  typedef struct {
      long tv_sec;
      long tv_usec;

Please move this to qemu-os-win32.h instead, otherwise the build will fail on POSIX systems due to setenv being redefined.

Quoted 3 lines

Thanks,
Jes

It won't fail for two reasons:

* It is not redefined (at least for linux systems) because I used the POSIX declaration.

* It is compiled only for _WIN32 (see line 95).

Regards
Stefan

#3 lore raw
Quoted 4 lines · Stefan Weil

It won't fail for two reasons:

* It is not redefined (at least for linux systems) because I used the POSIX declaration.

This still fails with strict compiler flags.

Quoted 1 line

* It is compiled only for _WIN32 (see line 95).

True, but we need to move stuff out of osdep.h and into the other files as much as possible, so it is still preferred that you move it.

Cheers,
Jes

#4 lore raw

Am 01.07.2010 15:24, schrieb Jes Sorensen:

Quoted 6 lines · Stefan Weil
Quoted 4 lines

It won't fail for two reasons:

* It is not redefined (at least for linux systems) because I used the POSIX declaration.

Quoted 6 lines

This still fails with strict compiler flags.

Quoted 1 line

* It is compiled only for _WIN32 (see line 95).

True, but we need to move stuff out of osdep.h and into the other files as much as possible, so it is still preferred that you move it.

That's a valid argument. As there is more stuff to move out of osdep.h, I suggest doing that in a second step. Now, it is most important to get Windows builds working again (they fail currently with a linker error).

Quoted 4 lines

Cheers,
Jes

Cheers,
Stefan

#5 lore raw
Quoted 9 lines · Stefan Weil

Am 01.07.2010 15:24, schrieb Jes Sorensen:

Quoted 8 lines · Stefan Weil
Quoted 4 lines

It won't fail for two reasons:

* It is not redefined (at least for linux systems) because I used the POSIX declaration.

This still fails with strict compiler flags.

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

* It is compiled only for _WIN32 (see line 95).

True, but we need to move stuff out of osdep.h and into the other files as much as possible, so it is still preferred that you move it.

That's a valid argument. As there is more stuff to move out of osdep.h, I suggest doing that in a second step. Now, it is most important to get Windows builds working again (they fail currently with a linker error).

Rather than add it to remove it in the next patch, please update your patch and repost it. That causes less noise and will get win32 building again just as fast.

Cheers,
Jes

#6 lore raw

Am 01.07.2010 17:53, schrieb Jes Sorensen:

Quoted 23 lines · Stefan Weil
Quoted 13 lines

Am 01.07.2010 15:24, schrieb Jes Sorensen:

Quoted 10 lines · Stefan Weil
Quoted 6 lines

It won't fail for two reasons:

* It is not redefined (at least for linux systems) because I used the POSIX declaration.

This still fails with strict compiler flags.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

* It is compiled only for _WIN32 (see line 95).

True, but we need to move stuff out of osdep.h and into the other files as much as possible, so it is still preferred that you move it.

That's a valid argument. As there is more stuff to move out of osdep.h, I suggest doing that in a second step. Now, it is most important to get Windows builds working again (they fail currently with a linker error).

Quoted 7 lines

Rather than add it to remove it in the next patch, please update your patch and repost it. That causes less noise and will get win32 building again just as fast.

Cheers,
Jes

Two patches are needed anyway.

For reasons of economy, I won't send a new patch.
Feel free do send one which meets your criteria.

Regards,
Stefan

#7 lore raw
Quoted 8 lines · Stefan Weil

Two patches are needed anyway.

For reasons of economy, I won't send a new patch.
Feel free do send one which meets your criteria.

Regards,
Stefan

Well if you are not interested in working the way the community works, please don't expect us to fix your bugs either.

Jes