svn commit: trunk/uClibc/utils
vapier at uclibc.org
vapier at uclibc.org
Mon Feb 9 21:48:50 UTC 2009
Author: vapier
Date: 2009-02-09 21:48:48 +0000 (Mon, 09 Feb 2009)
New Revision: 25281
Log:
unify the headers/random defines into porting.h to avoid duplication/rot
Added:
trunk/uClibc/utils/porting.h
Modified:
trunk/uClibc/utils/Makefile.in
trunk/uClibc/utils/chroot_realpath.c
trunk/uClibc/utils/ldconfig.c
trunk/uClibc/utils/ldd.c
trunk/uClibc/utils/readelf.c
trunk/uClibc/utils/readsoname2.c
Changeset:
Modified: trunk/uClibc/utils/Makefile.in
===================================================================
--- trunk/uClibc/utils/Makefile.in 2009-02-09 21:25:15 UTC (rev 25280)
+++ trunk/uClibc/utils/Makefile.in 2009-02-09 21:48:48 UTC (rev 25281)
@@ -9,6 +9,9 @@
CFLAGS-utils := \
$(SSP_ALL_CFLAGS) \
+ -I$(top_srcdir)ldso/include \
+ -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
+ -DUCLIBC_LDSO=$(UCLIBC_LDSO) \
-I$(top_srcdir)/$(KERNEL_HEADERS) \
-DNOT_IN_libc \
-B$(top_builddir)lib \
@@ -20,21 +23,14 @@
CFLAGS-utils-shared :=
endif
-CFLAGS-ldconfig := \
- -I$(top_srcdir)ldso/include \
- -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
- -DUCLIBC_LDSO=$(UCLIBC_LDSO)
+CFLAGS-ldconfig :=
ifeq ($(UCLIBC_STATIC_LDCONFIG),y)
CFLAGS-ldconfig += -static
else
CFLAGS-ldconfig += $(CFLAGS-utils-shared)
endif
-CFLAGS-ldd := \
- -I$(top_srcdir)ldso/include \
- -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
- -DUCLIBC_LDSO=$(UCLIBC_LDSO) \
- $(CFLAGS-utils-shared)
+CFLAGS-ldd := $(CFLAGS-utils-shared)
CFLAGS-readelf := $(CFLAGS-utils-shared)
@@ -52,24 +48,17 @@
LDSO_CACHE_SUPPORT := -D__LDSO_CACHE_SUPPORT__=1
endif
-BUILD_CFLAGS-ldconfig.host := \
+BUILD_CFLAGS-utils := \
-include $(top_srcdir)include/elf.h \
-I$(top_srcdir)ldso/include \
-DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
-DUCLIBC_LDSO=$(UCLIBC_LDSO) \
- $(LDSO_CACHE_SUPPORT) \
+ $(LDSO_CACHE_SUPPORT)
+BUILD_CFLAGS-ldconfig.host := $(BUILD_CFLAGS-utils)
+BUILD_CFLAGS-ldd.host := $(BUILD_CFLAGS-utils)
+BUILD_CFLAGS-readelf.host := $(BUILD_CFLAGS-utils)
-BUILD_CFLAGS-ldd.host := \
- -include $(top_srcdir)include/elf.h \
- -I$(top_srcdir)ldso/include \
- -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
- -DUCLIBC_LDSO=$(UCLIBC_LDSO) \
- $(LDSO_CACHE_SUPPORT) \
-BUILD_CFLAGS-readelf.host := \
- -include $(top_srcdir)include/elf.h \
-
-
# Rules
utils_DIR := $(top_srcdir)utils
Modified: trunk/uClibc/utils/chroot_realpath.c
===================================================================
--- trunk/uClibc/utils/chroot_realpath.c 2009-02-09 21:25:15 UTC (rev 25280)
+++ trunk/uClibc/utils/chroot_realpath.c 2009-02-09 21:48:48 UTC (rev 25281)
@@ -20,24 +20,8 @@
* 2005/09/12: Dan Howell (modified from realpath.c to emulate chroot)
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
+#include "porting.h"
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <limits.h> /* for PATH_MAX */
-#include <sys/param.h> /* for MAXPATHLEN */
-#include <errno.h>
-#include <sys/stat.h> /* for S_IFLNK */
-
-#ifndef PATH_MAX
-#define PATH_MAX _POSIX_PATH_MAX
-#endif
-
#define MAX_READLINKS 32
char *chroot_realpath(const char *chroot, const char *path,
Modified: trunk/uClibc/utils/ldconfig.c
===================================================================
--- trunk/uClibc/utils/ldconfig.c 2009-02-09 21:25:15 UTC (rev 25280)
+++ trunk/uClibc/utils/ldconfig.c 2009-02-09 21:48:48 UTC (rev 25281)
@@ -26,20 +26,7 @@
* 2005/09/16: Dan Howell (modified for cross-development)
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <link.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include "bswap.h"
-#include "dl-defs.h"
+#include "porting.h"
#define BUFFER_SIZE 4096
@@ -72,20 +59,6 @@
char *___strtok = NULL;
-/* For SunOS */
-#ifndef PATH_MAX
-#include <limits.h>
-#define PATH_MAX _POSIX_PATH_MAX
-#endif
-
-/* For SunOS */
-#ifndef N_MAGIC
-#define N_MAGIC(exec) ((exec).a_magic & 0xffff)
-#endif
-
-#define EXIT_OK 0
-#define EXIT_FATAL 128
-
char *prog = NULL;
int debug = 0; /* debug mode */
int verbose = 0; /* verbose mode */
@@ -177,7 +150,7 @@
{
void *ptr;
if ((ptr = malloc(size)) == NULL)
- err(EXIT_FATAL, "out of memory");
+ err(EXIT_FAILURE, "out of memory");
return ptr;
}
@@ -185,7 +158,7 @@
{
char *ptr;
if ((ptr = strdup(str)) == NULL)
- err(EXIT_FATAL, "out of memory");
+ err(EXIT_FAILURE, "out of memory");
return ptr;
}
@@ -452,7 +425,7 @@
/* We need a writable copy of this string */
path = strdup(rawname);
if (!path) {
- err(EXIT_FATAL, "Out of memory!\n");
+ err(EXIT_FAILURE, "Out of memory!\n");
}
/* Eliminate all double //s */
path_n = path;
@@ -678,17 +651,17 @@
return;
if (!chroot_realpath(chroot_dir, cachefile, realcachefile))
- err(EXIT_FATAL, "can't resolve %s in chroot %s (%s)",
+ err(EXIT_FAILURE, "can't resolve %s in chroot %s (%s)",
cachefile, chroot_dir, strerror(errno));
sprintf(tempfile, "%s~", realcachefile);
if (unlink(tempfile) && errno != ENOENT)
- err(EXIT_FATAL, "can't unlink %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't unlink %s~ (%s)", cachefile,
strerror(errno));
if ((cachefd = creat(tempfile, 0644)) < 0)
- err(EXIT_FATAL, "can't create %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't create %s~ (%s)", cachefile,
strerror(errno));
if (byteswap) {
@@ -699,7 +672,7 @@
magic_ptr = &magic;
}
if (write(cachefd, magic_ptr, sizeof(header_t)) != sizeof(header_t))
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
strerror(errno));
for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next) {
@@ -717,31 +690,31 @@
}
if (write(cachefd, lib_ptr, sizeof(libentry_t)) !=
sizeof(libentry_t))
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
strerror(errno));
}
for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next) {
if ((size_t)write(cachefd, cur_lib->soname, strlen(cur_lib->soname) + 1)
!= strlen(cur_lib->soname) + 1)
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
strerror(errno));
if ((size_t)write(cachefd, cur_lib->libname, strlen(cur_lib->libname) + 1)
!= strlen(cur_lib->libname) + 1)
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
strerror(errno));
}
if (close(cachefd))
- err(EXIT_FATAL, "can't close %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't close %s~ (%s)", cachefile,
strerror(errno));
if (chmod(tempfile, 0644))
- err(EXIT_FATAL, "can't chmod %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't chmod %s~ (%s)", cachefile,
strerror(errno));
if (rename(tempfile, realcachefile))
- err(EXIT_FATAL, "can't rename %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't rename %s~ (%s)", cachefile,
strerror(errno));
}
@@ -756,22 +729,22 @@
char realcachefile[BUFFER_SIZE];
if (!chroot_realpath(chroot_dir, cachefile, realcachefile))
- err(EXIT_FATAL, "can't resolve %s in chroot %s (%s)",
+ err(EXIT_FAILURE, "can't resolve %s in chroot %s (%s)",
cachefile, chroot_dir, strerror(errno));
if (stat(realcachefile, &st) || (fd = open(realcachefile, O_RDONLY)) < 0)
- err(EXIT_FATAL, "can't read %s (%s)", cachefile, strerror(errno));
+ err(EXIT_FAILURE, "can't read %s (%s)", cachefile, strerror(errno));
c = mmap(0, st.st_size, PROT_READ, LDSO_CACHE_MMAP_FLAGS, fd, 0);
if (c == MAP_FAILED)
- err(EXIT_FATAL, "can't map %s (%s)", cachefile, strerror(errno));
+ err(EXIT_FAILURE, "can't map %s (%s)", cachefile, strerror(errno));
close(fd);
if (memcmp(((header_t *) c)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN))
- err(EXIT_FATAL, "%s cache corrupt", cachefile);
+ err(EXIT_FAILURE, "%s cache corrupt", cachefile);
if (memcmp(((header_t *) c)->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN))
- err(EXIT_FATAL, "wrong cache version - expected %s",
+ err(EXIT_FAILURE, "wrong cache version - expected %s",
LDSO_CACHE_VER);
header = (header_t *) c;
@@ -843,7 +816,7 @@
"\tlib ... :\tlibraries to link\n\n"
#endif
);
- exit(EXIT_FATAL);
+ exit(EXIT_FAILURE);
}
#define DIR_SEP ":, \t\n"
@@ -916,11 +889,11 @@
if (chroot_dir && *chroot_dir) {
if (chroot(chroot_dir) < 0) {
if (chdir(chroot_dir) < 0)
- err(EXIT_FATAL, "couldn't chroot to %s (%s)", chroot_dir, strerror(errno));
+ err(EXIT_FAILURE, "couldn't chroot to %s (%s)", chroot_dir, strerror(errno));
chroot_dir = ".";
} else {
if (chdir("/") < 0)
- err(EXIT_FATAL, "couldn't chdir to / (%s)", strerror(errno));
+ err(EXIT_FAILURE, "couldn't chdir to / (%s)", strerror(errno));
chroot_dir = NULL;
}
}
@@ -932,7 +905,7 @@
if (printcache) {
/* print the cache -- don't you trust me? */
cache_print();
- exit(EXIT_OK);
+ exit(EXIT_SUCCESS);
} else if (libmode) {
/* so you want to do things manually, eh? */
@@ -952,7 +925,7 @@
/* we'd better do a little bit of checking */
if ((so = is_shlib(dir, cp, &libtype, &islink, LIB_ANY)) == NULL)
- err(EXIT_FATAL, "%s%s%s is not a shared library",
+ err(EXIT_FAILURE, "%s%s%s is not a shared library",
dir, (*dir && strcmp(dir, "/")) ? "/" : "", cp);
/* so far, so good, maybe he knows what he's doing */
@@ -1005,5 +978,5 @@
cache_write();
}
- exit(EXIT_OK);
+ exit(EXIT_SUCCESS);
}
Modified: trunk/uClibc/utils/ldd.c
===================================================================
--- trunk/uClibc/utils/ldd.c 2009-02-09 21:25:15 UTC (rev 25280)
+++ trunk/uClibc/utils/ldd.c 2009-02-09 21:48:48 UTC (rev 25281)
@@ -13,26 +13,8 @@
* Licensed under GPLv2 or later
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
+#include "porting.h"
-#include "bswap.h"
-#include "link.h"
-#include "dl-defs.h"
-/* makefile will include elf.h for us */
-
-#ifdef DMALLOC
-#include <dmalloc.h>
-#endif
-
#if defined(__alpha__)
#define MATCH_MACHINE(x) (x == EM_ALPHA)
#define ELFCLASSM ELFCLASS64
@@ -134,16 +116,12 @@
# warning "You really should add a MATCH_MACHINE() macro for your architecture"
#endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_LITTLE
#define ELFDATAM ELFDATA2LSB
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_BIG
#define ELFDATAM ELFDATA2MSB
#endif
-#ifndef UCLIBC_RUNTIME_PREFIX
-# define UCLIBC_RUNTIME_PREFIX "/"
-#endif
-
struct library {
char *name;
int resolved;
@@ -247,15 +225,13 @@
/* Check if the target endianness matches the host's endianness */
byteswap = 0;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- if (ehdr->e_ident[5] == ELFDATA2MSB)
- byteswap = 1;
-#elif __BYTE_ORDER == __BIG_ENDIAN
- if (ehdr->e_ident[5] == ELFDATA2LSB)
- byteswap = 1;
-#else
-#error Unknown host byte order!
-#endif
+ if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_LITTLE) {
+ if (ehdr->e_ident[5] == ELFDATA2MSB)
+ byteswap = 1;
+ } else if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_BIG) {
+ if (ehdr->e_ident[5] == ELFDATA2LSB)
+ byteswap = 1;
+ }
/* Be very lazy, and only byteswap the stuff we use */
if (byteswap) {
Added: trunk/uClibc/utils/porting.h
===================================================================
--- trunk/uClibc/utils/porting.h (rev 0)
+++ trunk/uClibc/utils/porting.h 2009-02-09 21:48:48 UTC (rev 25281)
@@ -0,0 +1,57 @@
+/* Misc system-specific crap */
+
+#ifndef _PORTING_H_
+#define _PORTING_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <link.h>
+#include <sys/mman.h>
+/* makefile will include elf.h for us */
+
+#include "bswap.h"
+#include "dl-defs.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
+/* For SunOS */
+#ifndef PATH_MAX
+#define PATH_MAX _POSIX_PATH_MAX
+#endif
+
+#ifndef UCLIBC_RUNTIME_PREFIX
+# define UCLIBC_RUNTIME_PREFIX "/"
+#endif
+
+#define UCLIBC_ENDIAN_LITTLE 1234
+#define UCLIBC_ENDIAN_BIG 4321
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+# define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_LITTLE
+#elif __BYTE_ORDER == __BIG_ENDIAN
+# define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_BIG
+#else
+# error "Unknown host byte order!"
+#endif
+
+#endif
Modified: trunk/uClibc/utils/readelf.c
===================================================================
--- trunk/uClibc/utils/readelf.c 2009-02-09 21:25:15 UTC (rev 25280)
+++ trunk/uClibc/utils/readelf.c 2009-02-09 21:48:48 UTC (rev 25281)
@@ -13,20 +13,8 @@
* Licensed under GPLv2 or later
*/
+#include "porting.h"
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include "bswap.h"
-#include "link.h"
-/* makefile will include elf.h for us */
-
static int byteswap;
static __inline__ uint32_t byteswap32_to_host(uint32_t value)
{
@@ -103,15 +91,13 @@
/* Check if the target endianness matches the host's endianness */
byteswap = 0;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- if (ehdr->e_ident[5] == ELFDATA2MSB)
- byteswap = 1;
-#elif __BYTE_ORDER == __BIG_ENDIAN
- if (ehdr->e_ident[5] == ELFDATA2LSB)
- byteswap = 1;
-#else
-#error Unknown host byte order!
-#endif
+ if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_LITTLE) {
+ if (ehdr->e_ident[5] == ELFDATA2MSB)
+ byteswap = 1;
+ } else if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_BIG) {
+ if (ehdr->e_ident[5] == ELFDATA2LSB)
+ byteswap = 1;
+ }
/* Be very lazy, and only byteswap the stuff we use */
if (byteswap) {
ehdr->e_type = bswap_16(ehdr->e_type);
Modified: trunk/uClibc/utils/readsoname2.c
===================================================================
--- trunk/uClibc/utils/readsoname2.c 2009-02-09 21:25:15 UTC (rev 25280)
+++ trunk/uClibc/utils/readsoname2.c 2009-02-09 21:48:48 UTC (rev 25281)
@@ -35,13 +35,11 @@
if ((char *)(epnt + 1) > (char *)(header + st.st_size))
goto skip;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- byteswap = (epnt->e_ident[5] == ELFDATA2MSB) ? 1 : 0;
-#elif __BYTE_ORDER == __BIG_ENDIAN
- byteswap = (epnt->e_ident[5] == ELFDATA2LSB) ? 1 : 0;
-#else
-#error Unknown host byte order!
-#endif
+ if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_LITTLE)
+ byteswap = (epnt->e_ident[5] == ELFDATA2MSB) ? 1 : 0;
+ else if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_BIG)
+ byteswap = (epnt->e_ident[5] == ELFDATA2LSB) ? 1 : 0;
+
/* Be very lazy, and only byteswap the stuff we use */
if (byteswap == 1) {
epnt->e_phoff = bswap_32(epnt->e_phoff);
More information about the uClibc-cvs
mailing list