[PATCH] Bionic lacks setmntent, getmntent_r, endmntent; provide workarounds
Note: This commit subsumes a previous workaround (908d6b70, a0e17f7d) for the lack of getmntent_r in dietlibc. --- include/platform.h | 39 +++ libbb/platform.c| 47 +++ util-linux/mount.c | 12 util-linux/umount.c | 12 4 files changed, 86 insertions(+), 24 deletions(-) diff --git a/include/platform.h b/include/platform.h index df95945..aa7fddd 100644 --- a/include/platform.h +++ b/include/platform.h @@ -384,6 +384,11 @@ typedef unsigned smalluint; #define HAVE_UNLOCKED_LINE_OPS 1 #define HAVE_GETLINE 1 #define HAVE_XTABS 1 +#define HAVE_SETMNTENT 1 +#define HAVE_GETMNTENT 1 +#define HAVE_GETMNTENT_R 1 +#define HAVE_ADDMNTENT 1 +#define HAVE_ENDMNTENT 1 #define HAVE_MNTENT_H 1 #define HAVE_NET_ETHERNET_H 1 #define HAVE_SYS_STATFS_H 1 @@ -446,6 +451,7 @@ typedef unsigned smalluint; #if defined(__dietlibc__) # undef HAVE_STRCHRNUL +# undef HAVE_GETMNTENT_R #endif #if defined(__APPLE__) @@ -485,6 +491,11 @@ typedef unsigned smalluint; # undef HAVE_STRCHRNUL # undef HAVE_STRVERSCMP # undef HAVE_UNLOCKED_LINE_OPS +# undef HAVE_SETMNTENT +# undef HAVE_GETMNTENT +# undef HAVE_GETMNTENT_R +# undef HAVE_ADDMNTENT +# undef HAVE_ENDMNTENT # undef HAVE_NET_ETHERNET_H #endif @@ -561,4 +572,32 @@ extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC extern ssize_t getline(char **lineptr, size_t *n, FILE *stream) FAST_FUNC; #endif +#ifndef HAVE_SETMNTENT +# include /* for FILE */ +# define setmntent bb_setmntent +extern FILE * setmntent(const char *filename, const char *type); +#endif + +#ifndef HAVE_GETMNTENT +# include /* for FILE */ +extern struct mntent * getmntent(FILE *stream); +#endif + +#ifndef HAVE_GETMNTENT_R +# include /* for FILE */ +# define getmntent_r bb_getmntent_r +extern struct mntent * getmntent_r(FILE *streamp, struct mntent *mntbuf, char *buf, int buflen); +#endif + +#ifndef HAVE_ADDMNTENT +# include /* for FILE */ +extern int addmntent(FILE *stream, const struct mntent *mnt); +#endif + +#ifndef HAVE_ENDMNTENT +# include /* for FILE */ +# define endmntent bb_endmntent +extern int endmntent(FILE *streamp); +#endif + #endif diff --git a/libbb/platform.c b/libbb/platform.c index 8d90ca4..c6c2526 100644 --- a/libbb/platform.c +++ b/libbb/platform.c @@ -194,3 +194,50 @@ ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream) return len; } #endif + +#ifndef HAVE_SETMNTENT +FILE *setmntent(const char *filename, const char *type) +{ + return fopen(filename, type); +} +#endif + +#ifndef HAVE_GETMNTENT_R +# ifdef HAVE_GETMNTENT +struct mntent * getmntent_r(FILE *streamp, struct mntent *mntbuf, + char *buf UNUSED_PARAM, int buflen UNUSED_PARAM) +{ + struct mntent *ent = getmntent(streamp); + return ent ? memcpy(mntbuf, ent, sizeof *mntbuf) : NULL; +} +# else +struct mntent * getmntent_r(FILE *streamp, struct mntent *mntbuf, char *buf, int buflen) +{ + static const char delims[] = " \t"; + char *saveptr; + while (fgets(buf, buflen, streamp)) { + if ((mntbuf->mnt_fsname = strtok_r(buf, delims, &saveptr)) && + mntbuf->mnt_fsname[0] != '#' && + (mntbuf->mnt_dir = strtok_r(NULL, delims, &saveptr)) && + (mntbuf->mnt_type = strtok_r(NULL, delims, &saveptr)) && + (mntbuf->mnt_opts = strtok_r(NULL, delims, &saveptr))) { + mntbuf->mnt_passno = mntbuf->mnt_freq = 0; + if ((buf = strtok_r(NULL, delims, &saveptr))) { + mntbuf->mnt_freq = atoi(buf); + if ((buf = strtok_r(NULL, delims, &saveptr))) + mntbuf->mnt_passno = atoi(buf); + } + return mntbuf; + } + } + return NULL; +} +# endif +#endif + +#ifndef HAVE_ENDMNTENT +int endmntent(FILE *streamp) +{ + return fclose(streamp); +} +#endif diff --git a/util-linux/mount.c b/util-linux/mount.c index cb40c80..3d179a7 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -245,18 +245,6 @@ #endif -#if defined(__dietlibc__) -// 16.12.2006, Sampo Kellomaki (sa...@iki.fi) -// dietlibc-0.30 does not have implementation of getmntent_r() -static struct mntent *getmntent_r(FILE* stream, struct mntent* result, - char* buffer UNUSED_PARAM, int bufsize UNUSED_PARAM) -{ - struct mntent* ment = getmntent(stream); - return memcpy(result, ment, sizeof(*ment)); -} -#endif - - // Not real flags, but we want to be able to check for this. enum { MOUNT_USERS = (1 << 28) * ENABLE_DESKTOP, diff --git a/util-linux/umount.c b/util-linux/umount.c index 4c2e882..2afdf59 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c @@ -32,18 +32,6 @@ #include #include
[PATCH 1/2] Bionic lacks ttyname_r; provide a workaround
--- include/platform.h | 7 +++ libbb/missing_syscalls.c | 17 + 2 files changed, 24 insertions(+) diff --git a/include/platform.h b/include/platform.h index 8914d4a..8896a6b 100644 --- a/include/platform.h +++ b/include/platform.h @@ -368,6 +368,7 @@ typedef unsigned smalluint; #define HAVE_DPRINTF 1 #define HAVE_MEMRCHR 1 #define HAVE_MKDTEMP 1 +#define HAVE_TTYNAME_R 1 #define HAVE_PTSNAME_R 1 #define HAVE_SETBIT 1 #define HAVE_SIGHANDLER_T 1 @@ -480,6 +481,7 @@ typedef unsigned smalluint; #if defined(ANDROID) || defined(__ANDROID__) # undef HAVE_DPRINTF +# undef HAVE_TTYNAME_R # undef HAVE_GETLINE # undef HAVE_STPCPY # undef HAVE_MEMPCPY @@ -506,6 +508,11 @@ extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC; extern char *mkdtemp(char *template) FAST_FUNC; #endif +#ifndef HAVE_TTYNAME_R +#define ttyname_r bb_ttyname_r +extern int ttyname_r(int fd, char *buf, size_t buflen); +#endif + #ifndef HAVE_SETBIT # define setbit(a, b) ((a)[(b) >> 3] |= 1 << ((b) & 7)) # define clrbit(a, b) ((a)[(b) >> 3] &= ~(1 << ((b) & 7))) diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c index dd430e3..c768f11 100644 --- a/libbb/missing_syscalls.c +++ b/libbb/missing_syscalls.c @@ -40,3 +40,20 @@ int pivot_root(const char *new_root, const char *put_old) return syscall(__NR_pivot_root, new_root, put_old); } #endif + +#ifndef HAVE_TTYNAME_R +int ttyname_r(int fd, char *buf, size_t buflen) +{ + int r; + char path[32]; + if (!isatty(fd)) + return errno == EINVAL ? ENOTTY : errno; + sprintf(path, "/proc/self/fd/%d", fd); + if ((r = readlink(path, buf, buflen)) < 0) + return errno; + if (r >= buflen) + return ERANGE; + buf[r] = '\0'; + return 0; +} +#endif -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 2/2] Bionic lacks tcdrain; provide a workaround
--- libbb/missing_syscalls.c | 5 + 1 file changed, 5 insertions(+) diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c index c768f11..1e2507d 100644 --- a/libbb/missing_syscalls.c +++ b/libbb/missing_syscalls.c @@ -39,6 +39,11 @@ int pivot_root(const char *new_root, const char *put_old) { return syscall(__NR_pivot_root, new_root, put_old); } + +int tcdrain(int fd) +{ + return ioctl(fd, TCSBRK, 1); +} #endif #ifndef HAVE_TTYNAME_R -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 1/2] Bionic lacks ttyname_r; provide a workaround
On Fri, Apr 24, 2015 at 05:22:57PM -0400, Matt Whitlock wrote: > I think providing an alternative implementation of ttyname_r() in > missing_syscalls.c won't work. Busybox cannot be statically linked > when ttyname_r is defined in missing_syscalls.o: > > ld: error: > /usr/local/arm-linux-androideabi/bin/../sysroot/usr/lib/libc.a(stubs.o): > multiple definition of 'ttyname_r' > ld: libbb/lib.a(missing_syscalls.o): previous definition here This is only happening because another function from stubs.o is being pulled in. Passing -Wl,-t might be able to show the reason. But it's probably best to #define ttyname_r to something else when providing a fallback to avoid the problem. Rich ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH] Bionic lacks transparent LFS migrations; provide a workaround
This solves some of the problems arising from Bionic's off_t being 32 bits wide despite _FILE_OFFSET_BITS==64. See BusyBox bug #6908. Note that this doesn't solve all such problems since Bionic lacks 64-bit variants of many standard I/O functions: open, creat, lockf, posix_fadvise, posix_fallocate, truncate, sendfile, getrlimit, setrlimit, fopen, freopen, fseeko, ftello, fgetpos, fsetpos, mkstemp. --- include/platform.h | 19 +++ 1 file changed, 19 insertions(+) diff --git a/include/platform.h b/include/platform.h index 9893536..1744b3c 100644 --- a/include/platform.h +++ b/include/platform.h @@ -491,6 +491,25 @@ typedef unsigned smalluint; # undef HAVE_NET_ETHERNET_H #endif +/* Bionic system headers lack transparent LFS migrations. */ +#if defined(__BIONIC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 +/* from */ +# define lseek lseek64 +# define pread pread64 +# define pwrite pwrite64 +# define ftruncate ftruncate64 +/* from */ +# define off_t off64_t +# define ino_t ino64_t +# define blkcnt_t blkcnt64_t +# define fsblkcnt_t fsblkcnt64_t +# define fsfilcnt_t fsfilcnt64_t +typedef uint64_t ino_t; +typedef uint64_t blkcnt_t; +typedef uint64_t fsblkcnt_t; +typedef uint64_t fsfilcnt_t; +#endif + /* * Now, define prototypes for all the functions defined in platform.c * These must come after all the HAVE_* macros are defined (or not) -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 5/5] Bionic lacks transparent LFS migrations; provide a workaround
On Friday, 24 April 2015, at 4:12 am, Matt Whitlock wrote: > +#if defined(__BIONIC__) && _FILE_OFFSET_BITS == 64 The preprocessor needs to test whether _FILE_OFFSET_BITS is defined before using it in an expression. #if defined(__BIONIC__) && defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS == 64 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 1/2] Bionic lacks ttyname_r; provide a workaround
I think providing an alternative implementation of ttyname_r() in missing_syscalls.c won't work. Busybox cannot be statically linked when ttyname_r is defined in missing_syscalls.o: ld: error: /usr/local/arm-linux-androideabi/bin/../sysroot/usr/lib/libc.a(stubs.o): multiple definition of 'ttyname_r' ld: libbb/lib.a(missing_syscalls.o): previous definition here ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 1/2] Bionic lacks ttyname_r; provide a workaround
--- libbb/missing_syscalls.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c index dd430e3..e57c2de 100644 --- a/libbb/missing_syscalls.c +++ b/libbb/missing_syscalls.c @@ -39,4 +39,18 @@ int pivot_root(const char *new_root, const char *put_old) { return syscall(__NR_pivot_root, new_root, put_old); } + +int ttyname_r(int fd, char *buf, size_t buflen) { + int r; + char path[32]; + if (!isatty(fd)) + return errno == EINVAL ? ENOTTY : errno; + sprintf(path, "/proc/self/fd/%d", fd); + if ((r = readlink(path, buf, buflen)) < 0) + return errno; + if (r >= buflen) + return ERANGE; + buf[r] = '\0'; + return 0; +} #endif -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 2/2] Bionic lacks tcdrain; provide a workaround
--- libbb/missing_syscalls.c | 5 + 1 file changed, 5 insertions(+) diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c index e57c2de..0de3df9 100644 --- a/libbb/missing_syscalls.c +++ b/libbb/missing_syscalls.c @@ -40,6 +40,11 @@ int pivot_root(const char *new_root, const char *put_old) return syscall(__NR_pivot_root, new_root, put_old); } +int tcdrain(int fd) +{ + return ioctl(fd, TCSBRK, 1); +} + int ttyname_r(int fd, char *buf, size_t buflen) { int r; char path[32]; -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH 3/5] Bionic lacks ttyname_r; provide a workaround
On Friday, 24 April 2015, at 1:04 pm, walter harms wrote: > perhaps it is better to move the code to missing_syscalls.c ? > (this is a question) The reason I didn't put it there is that ttyname_r() is defined in Bionic, but it's a stub that prints out a diagnostic message at runtime and returns -1 unconditionally, thereby causing xmalloc_ttyname() to fail, even when the specified file descriptor does refer to a TTY. I'll provide an alternative patch that places the workaround in missing_syscalls.c since I can see good arguments for both ways. ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH] gzip: add support for compression levels 4-9
Add support for compression levels 4-9. function old new delta gzip_main191 306+115 usage_messages 40461 40504 +43 pack_gzip 19241907 -17 -- (add/remove: 0/0 grow/shrink: 2/1 up/down: 158/-17) Total: 141 bytes The rationale for this feature is that the current hardcoded 9 level is painfully slow with big files. Below are some examples when compressing a rootfs tarball (368.9M uncompressed) with different levels (gzip 1.6 compression time for comparison in parenthesis): compression timecompressed size Without the patch: 1m22.534s 152.0M With the patch, 9: 1m15.351s (1m7.419s)152.0M (old bb default level) 8: 0m46.763s (0m43.335s) 152.1M 7: 0m28.519s (0m27.076s) 152.4M 6: 0m22.960s (0m21.879s) 152.8M (gzip default level) 5: 0m16.058s (0m14.740s) 153.9M 4: 0m12.484s (0m11.167s) 156.4M If the compression level support is enabled, we make 6 the default as with gzip 1.6. Signed-off-by: Aaro Koskinen --- archival/gzip.c | 56 +++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/archival/gzip.c b/archival/gzip.c index bc1f9c6..e6161e2 100644 --- a/archival/gzip.c +++ b/archival/gzip.c @@ -62,14 +62,26 @@ aa: 85.1% -- replaced with aa.gz //config:1: larger buffers, larger hash-tables //config:2: larger buffers, largest hash-tables //config:Larger models may give slightly better compression +//config: +//config:config FEATURE_GZIP_LEVELS +//config: bool "Enable compression levels" +//config: default y +//config: depends on GZIP +//config: help +//config:Enable support for compression levels 4-9. The default level +//config:is 6 (without this option 9). If levels 1-3 are specified, 4 +//config:is used. //applet:IF_GZIP(APPLET(gzip, BB_DIR_BIN, BB_SUID_DROP)) //kbuild:lib-$(CONFIG_GZIP) += gzip.o //usage:#define gzip_trivial_usage -//usage: "[-cfd] [FILE]..." +//usage: "[-cfd" IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..." //usage:#define gzip_full_usage "\n\n" //usage: "Compress FILEs (or stdin)\n" +//usage:IF_FEATURE_GZIP_LEVELS( +//usage: "\n-1..9 Compression level" +//usage:) //usage: "\n -d Decompress" //usage: "\n -c Write to stdout" //usage: "\n -f Force" @@ -252,6 +264,8 @@ enum { * input file length plus MIN_LOOKAHEAD. */ +#ifndef ENABLE_FEATURE_GZIP_LEVELS + max_chain_length = 4096, /* To speed up deflation, hash chains are never searched beyond this length. * A higher limit improves compression ratio but degrades the speed. @@ -283,11 +297,23 @@ enum { * For deflate_fast() (levels <= 3) good is ignored and lazy has a different * meaning. */ +#endif /* ENABLE_FEATURE_GZIP_LEVELS */ }; struct globals { +#ifdef ENABLE_FEATURE_GZIP_LEVELS + unsigned _max_chain_length; + unsigned _max_lazy_match; + unsigned _good_match; + unsigned _nice_match; +#define max_chain_length (G1._max_chain_length) +#define max_lazy_match (G1._max_lazy_match) +#define good_match (G1._good_match) +#define nice_match (G1._nice_match) +#endif /* ENABLE_FEATURE_GZIP_LEVELS */ + lng block_start; /* window position at the beginning of the current output block. Gets @@ -2161,6 +2187,22 @@ int gzip_main(int argc UNUSED_PARAM, char **argv) #endif { unsigned opt; +#ifdef ENABLE_FEATURE_GZIP_LEVELS + unsigned level; + const struct { + unsigned char good; + unsigned char chain_shift; + unsigned short lazy; + unsigned short nice; + } gzip_level_config[6] = { + {4, 4, 4, 16}, /* Level 4 */ + {8, 5, 16, 32}, /* Level 5 */ + {8, 7, 16, 128}, /* Level 6 */ + {8, 8, 32, 128}, /* Level 7 */ + {32, 10, 128, 258}, /* Level 8 */ + {32, 12, 258, 258}, /* Level 9 */ + }; +#endif /* ENABLE_FEATURE_GZIP_LEVELS */ #if ENABLE_FEATURE_GZIP_LONG_OPTIONS applet_long_options = gzip_longopts; @@ -2171,6 +2213,11 @@ int gzip_main(int argc UNUSED_PARAM, char **argv) if (opt & 0x18) // -d and/or -t return gunzip_main(argc, argv); #endif +#ifdef ENABLE_FEATURE_GZIP_LEVELS + /* Map 1..3 to 4 and make 6 a default. */ + level = ffs(opt >> (4 + IF_GUNZIP(2)) & 0x1ff); + level = !level ? 6 : MAX(4, level); +#endif /* ENABLE_FEATURE_GZIP_LEVELS */ option_mas
Re: [PATCH 3/5] Bionic lacks ttyname_r; provide a workaround
Am 24.04.2015 10:12, schrieb Matt Whitlock: > --- > include/platform.h| 2 ++ > libbb/xfuncs_printf.c | 10 ++ > 2 files changed, 12 insertions(+) > > diff --git a/include/platform.h b/include/platform.h > index 8914d4a..9893536 100644 > --- a/include/platform.h > +++ b/include/platform.h > @@ -369,6 +369,7 @@ typedef unsigned smalluint; > #define HAVE_MEMRCHR 1 > #define HAVE_MKDTEMP 1 > #define HAVE_PTSNAME_R 1 > +#define HAVE_TTYNAME_R 1 > #define HAVE_SETBIT 1 > #define HAVE_SIGHANDLER_T 1 > #define HAVE_STPCPY 1 > @@ -481,6 +482,7 @@ typedef unsigned smalluint; > #if defined(ANDROID) || defined(__ANDROID__) > # undef HAVE_DPRINTF > # undef HAVE_GETLINE > +# undef HAVE_TTYNAME_R > # undef HAVE_STPCPY > # undef HAVE_MEMPCPY > # undef HAVE_STRCHRNUL > diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c > index e4ac6a0..bada57f 100644 > --- a/libbb/xfuncs_printf.c > +++ b/libbb/xfuncs_printf.c > @@ -569,9 +569,19 @@ int FAST_FUNC bb_xioctl(int fd, unsigned request, void > *argp) > char* FAST_FUNC xmalloc_ttyname(int fd) > { > char buf[128]; > +#ifdef HAVE_TTYNAME_R > int r = ttyname_r(fd, buf, sizeof(buf) - 1); > if (r) > return NULL; > +#else > + int r; > + if (!isatty(fd)) > + return NULL; > + sprintf(buf, "/proc/self/fd/%d", fd); > + if ((r = readlink(buf, buf, sizeof(buf) - 1)) < 0) > + return NULL; > + buf[r] = '\0'; > +#endif > return xstrdup(buf); > } > perhaps it is better to move the code to missing_syscalls.c ? (this is a question) re, wh ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 4/5] Bionic lacks tcdrain; provide a workaround
--- libbb/missing_syscalls.c | 5 + 1 file changed, 5 insertions(+) diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c index dd430e3..e3c1e92 100644 --- a/libbb/missing_syscalls.c +++ b/libbb/missing_syscalls.c @@ -39,4 +39,9 @@ int pivot_root(const char *new_root, const char *put_old) { return syscall(__NR_pivot_root, new_root, put_old); } + +int tcdrain(int fd) +{ + return ioctl(fd, TCSBRK, 1); +} #endif -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 1/5] bb_socklen_t must be signed int
BSD and POSIX specify socklen_t as int. Busybox should too, to avoid pointer signedness warnings. --- include/libbb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libbb.h b/include/libbb.h index f0ac1f5..dc0acd8 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -143,7 +143,7 @@ * (in case "is it defined already" detection above failed) */ # define socklen_t bb_socklen_t - typedef unsigned socklen_t; + typedef int socklen_t; # endif #endif #ifndef HAVE_CLEARENV -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 2/5] Bionic lacks mempcpy; enable existing workaround
--- include/platform.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/platform.h b/include/platform.h index df95945..8914d4a 100644 --- a/include/platform.h +++ b/include/platform.h @@ -482,6 +482,7 @@ typedef unsigned smalluint; # undef HAVE_DPRINTF # undef HAVE_GETLINE # undef HAVE_STPCPY +# undef HAVE_MEMPCPY # undef HAVE_STRCHRNUL # undef HAVE_STRVERSCMP # undef HAVE_UNLOCKED_LINE_OPS -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 3/5] Bionic lacks ttyname_r; provide a workaround
--- include/platform.h| 2 ++ libbb/xfuncs_printf.c | 10 ++ 2 files changed, 12 insertions(+) diff --git a/include/platform.h b/include/platform.h index 8914d4a..9893536 100644 --- a/include/platform.h +++ b/include/platform.h @@ -369,6 +369,7 @@ typedef unsigned smalluint; #define HAVE_MEMRCHR 1 #define HAVE_MKDTEMP 1 #define HAVE_PTSNAME_R 1 +#define HAVE_TTYNAME_R 1 #define HAVE_SETBIT 1 #define HAVE_SIGHANDLER_T 1 #define HAVE_STPCPY 1 @@ -481,6 +482,7 @@ typedef unsigned smalluint; #if defined(ANDROID) || defined(__ANDROID__) # undef HAVE_DPRINTF # undef HAVE_GETLINE +# undef HAVE_TTYNAME_R # undef HAVE_STPCPY # undef HAVE_MEMPCPY # undef HAVE_STRCHRNUL diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index e4ac6a0..bada57f 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c @@ -569,9 +569,19 @@ int FAST_FUNC bb_xioctl(int fd, unsigned request, void *argp) char* FAST_FUNC xmalloc_ttyname(int fd) { char buf[128]; +#ifdef HAVE_TTYNAME_R int r = ttyname_r(fd, buf, sizeof(buf) - 1); if (r) return NULL; +#else + int r; + if (!isatty(fd)) + return NULL; + sprintf(buf, "/proc/self/fd/%d", fd); + if ((r = readlink(buf, buf, sizeof(buf) - 1)) < 0) + return NULL; + buf[r] = '\0'; +#endif return xstrdup(buf); } -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
[PATCH 5/5] Bionic lacks transparent LFS migrations; provide a workaround
This solves some of the problems arising from Bionic's off_t being 32 bits wide despite _FILE_OFFSET_BITS==64. See BusyBox bug #6908. Note that this doesn't solve all such problems since Bionic lacks 64-bit variants of many standard I/O functions: open, creat, lockf, posix_fadvise, posix_fallocate, truncate, sendfile, getrlimit, setrlimit, fopen, freopen, fseeko, ftello, fgetpos, fsetpos, mkstemp. --- include/platform.h | 19 +++ 1 file changed, 19 insertions(+) diff --git a/include/platform.h b/include/platform.h index 9893536..4540e0a 100644 --- a/include/platform.h +++ b/include/platform.h @@ -491,6 +491,25 @@ typedef unsigned smalluint; # undef HAVE_NET_ETHERNET_H #endif +/* Bionic system headers lack transparent LFS migrations. */ +#if defined(__BIONIC__) && _FILE_OFFSET_BITS == 64 +/* from */ +# define lseek lseek64 +# define pread pread64 +# define pwrite pwrite64 +# define ftruncate ftruncate64 +/* from */ +# define off_t off64_t +# define ino_t ino64_t +# define blkcnt_t blkcnt64_t +# define fsblkcnt_t fsblkcnt64_t +# define fsfilcnt_t fsfilcnt64_t +typedef uint64_t ino_t; +typedef uint64_t blkcnt_t; +typedef uint64_t fsblkcnt_t; +typedef uint64_t fsfilcnt_t; +#endif + /* * Now, define prototypes for all the functions defined in platform.c * These must come after all the HAVE_* macros are defined (or not) -- 2.0.5 ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox