[PATCH] Improve portability
Dan Fandrich
dan at coneharvesters.com
Sun Sep 6 05:01:30 UTC 2009
On Sun, Sep 06, 2009 at 02:23:58AM +0200, Denys Vlasenko wrote:
> Applied part of the patch (see attached). If you want
> the rest to be applied, please explain why each kind
> of change is necessary or useful.
The remaining patches fall mostly into these four categories:
1) Empty struct initializers, e.g.
static const struct suffix_mult sfx[] = {
{ "s", 1 },
{ } // <= should be { "", 0 }
};
I'm unable to determine if this is actually allowed by ANSI C or not, but
at least two compilers I've tried don't handle it.
2) Automatic variables used as initializers, e.g.
char delim = 1;
const char delimiter[2] = { delim, 0 };
C90 requires automatic struct variables to have initializers containing
only constant expressions.
3) #include files added to satisfy dependencies required by system include
files that are not self-contained, which happens in some non-glibc systems.
Requiring <sys/socket.h> before <netinet/in.h> seems to be a relatively
common one on pre-SuS systems.
4) Conditional operator missing the second expression, e.g.
getlogin() ? : getpwuid(cur_uid))
Most of these were taken up from the first patch, but the ones that weren't
seem to be the ones that required a function call be called again in the
second expression. In those cases, I added a temporary variable to hold the
result of the function to avoid a duplicate expensive function call and/or
potential race condition. For readability, I changed some of these to use
the MAX() macro instead.
The remaining two patches are these:
diff --git a/editors/awk.c b/editors/awk.c
index cef7334..4c2837a 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -114,7 +114,7 @@ typedef struct nvblock_s {
var *pos;
struct nvblock_s *prev;
struct nvblock_s *next;
- var nv[0];
+ var nv[];
} nvblock;
typedef struct tsplitter_s {
Explicitly zero-length arrays seems to be allowed in C++ but not C, which
uses an empty array size instead.
diff --git a/libbb/login.c b/libbb/login.c
index ba9f4d2..3e6f7c4 100644
--- a/libbb/login.c
+++ b/libbb/login.c
@@ -9,7 +9,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <sys/param.h> /* MAXHOSTNAMELEN */
+#include <sys/types.h>
#include <sys/utsname.h>
#include "libbb.h"
MAXHOSTNAMELEN isn't referenced in this file, so I removed that include line.
The sys/types.h file was included because sys/utsname.h isn't self-contained
on Watcom C (I don't know how common this is compared to the netinet/in.h
case).
>>> Dan
--
http://www.MoveAnnouncer.com The web change of address service
Let webmasters know that your web site has moved
More information about the busybox
mailing list