* [PATCH] Fix strings to work with > 2GB files again on 32-bit arches
@ 2004-10-11 20:21 Jakub Jelinek
2004-10-11 23:15 ` Alan Modra
2004-10-16 20:19 ` Aaron W. LaFramboise
0 siblings, 2 replies; 7+ messages in thread
From: Jakub Jelinek @ 2004-10-11 20:21 UTC (permalink / raw)
To: binutils
Hi!
2003-11-07 changes broke strings on arches with 32-bit off_t.
The following patch fixes this, although I'm not sure if the
! S_ISREG (st.st_mode) test shouldn't be killed as well
(I think it should be ok to run strings on say /dev/hda).
Maybe just strings_file in that case should avoid attempting
to open it as bfd.
2004-10-11 Jakub Jelinek <jakub@redhat.com>
* strings.c (statbuf): New typedef.
(file_stat): Define.
(strings_object_file): Avoid using get_file_size, instead do the
checks here, using file_stat.
* configure.in (HAVE_STAT64): New test.
* configure: Rebuilt.
* config.in: Rebuilt.
--- binutils/strings.c.jj 2004-06-15 17:16:04.000000000 +0200
+++ binutils/strings.c 2004-10-11 21:57:47.565716824 +0200
@@ -104,6 +104,13 @@ typedef off64_t file_off;
typedef off_t file_off;
#define file_open(s,m) fopen(s, m)
#endif
+#ifdef HAVE_STAT64
+typedef struct stat64 statbuf;
+#define file_stat(f,s) stat64(f, s)
+#else
+typedef struct stat statbuf;
+#define file_stat(f,s) stat(f, s)
+#endif
/* Radix for printing addresses (must be 8, 10 or 16). */
static int address_radix;
@@ -370,8 +377,22 @@ strings_object_file (const char *file)
static bfd_boolean
strings_file (char *file)
{
- if (get_file_size (file) < 1)
- return FALSE;
+ statbuf st;
+
+ if (file_stat (file, &st) < 0)
+ {
+ if (errno == ENOENT)
+ non_fatal (_("'%s': No such file"), file);
+ else
+ non_fatal (_("Warning: could not locate '%s'. reason: %s"),
+ file, strerror (errno));
+ return FALSE;
+ }
+ else if (! S_ISREG (st.st_mode))
+ {
+ non_fatal (_("Warning: '%s' is not an ordinary file"), file);
+ return FALSE;
+ }
/* If we weren't told to scan the whole file,
try to open it as an object file and only look at
--- binutils/config.in.jj 2004-09-19 16:26:42.000000000 +0200
+++ binutils/config.in 2004-10-11 22:08:55.323608130 +0200
@@ -166,6 +166,9 @@
/* Is fopen64 available? */
#undef HAVE_FOPEN64
+/* Is stat64 available? */
+#undef HAVE_STAT64
+
/* Enable LFS */
#undef _LARGEFILE64_SOURCE
--- binutils/configure.in.jj 2004-01-02 19:13:02.000000000 +0100
+++ binutils/configure.in 2004-10-11 22:07:15.000000000 +0200
@@ -118,10 +118,27 @@ AC_MSG_RESULT($bu_cv_have_fopen64)
if test "$bu_cv_have_fopen64" != no; then
AC_DEFINE([HAVE_FOPEN64], 1,
[Is fopen64 available?])
- if test "$bu_cv_have_fopen64" = "need -D_LARGEFILE64_SOURCE"; then
- AC_DEFINE([_LARGEFILE64_SOURCE], 1,
- [Enable LFS])
- fi
+fi
+AC_MSG_CHECKING([for stat64])
+AC_CACHE_VAL(bu_cv_have_stat64,
+[AC_TRY_LINK([#include <sys/stat.h>], [struct stat64 st; stat64 ("/tmp/foo", &st);],
+bu_cv_have_stat64=yes,
+[saved_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
+ AC_TRY_LINK([#include <sys/stat.h>], [struct stat64 st; stat64 ("/tmp/foo", &st);],
+bu_cv_have_stat64="need -D_LARGEFILE64_SOURCE",
+bu_cv_have_stat64=no)
+ CPPFLAGS=$saved_CPPFLAGS])])
+AC_MSG_RESULT($bu_cv_have_stat64)
+if test "$bu_cv_have_stat64" != no; then
+ AC_DEFINE([HAVE_STAT64], 1,
+ [Is stat64 available?])
+fi
+if test "$bu_cv_have_fopen64" = "need -D_LARGEFILE64_SOURCE" \
+ || test "$bu_cv_have_stat64" = "need -D_LARGEFILE64_SOURCE"; then
+ AC_DEFINE([_LARGEFILE64_SOURCE], 1,
+ [Enable LFS])
+ CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
fi
# Some systems have frexp only in -lm, not in -lc.
--- binutils/configure.jj 2004-09-19 16:26:43.000000000 +0200
+++ binutils/configure 2004-10-11 22:08:30.327031365 +0200
@@ -5035,12 +5035,66 @@ if test "$bu_cv_have_fopen64" != no; the
#define HAVE_FOPEN64 1
EOF
- if test "$bu_cv_have_fopen64" = "need -D_LARGEFILE64_SOURCE"; then
- cat >> confdefs.h <<\EOF
+fi
+echo $ac_n "checking for stat64""... $ac_c" 1>&6
+echo "configure:5054: checking for stat64" >&5
+if eval "test \"`echo '$''{'bu_cv_have_stat64'+set}'`\" = set"; then
+ echo $ac_n "(cached) $ac_c" 1>&6
+else
+ cat > conftest.$ac_ext <<EOF
+#line 5059 "configure"
+#include "confdefs.h"
+#include <sys/stat.h>
+int main() {
+struct stat64 st; stat64 ("/tmp/foo", &st);
+; return 0; }
+EOF
+if { (eval echo configure:5066: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+ rm -rf conftest*
+ bu_cv_have_stat64=yes
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ saved_CPPFLAGS=$CPPFLAGS
+ CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
+ cat > conftest.$ac_ext <<EOF
+#line 5076 "configure"
+#include "confdefs.h"
+#include <sys/stat.h>
+int main() {
+struct stat64 st; stat64 ("/tmp/foo", &st);
+; return 0; }
+EOF
+if { (eval echo configure:5083: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+ rm -rf conftest*
+ bu_cv_have_stat64="need -D_LARGEFILE64_SOURCE"
+else
+ echo "configure: failed program was:" >&5
+ cat conftest.$ac_ext >&5
+ rm -rf conftest*
+ bu_cv_have_stat64=no
+fi
+rm -f conftest*
+ CPPFLAGS=$saved_CPPFLAGS
+fi
+rm -f conftest*
+fi
+
+echo "$ac_t""$bu_cv_have_stat64" 1>&6
+if test "$bu_cv_have_stat64" != no; then
+ cat >> confdefs.h <<\EOF
+#define HAVE_STAT64 1
+EOF
+
+fi
+if test "$bu_cv_have_fopen64" = "need -D_LARGEFILE64_SOURCE" \
+ || test "$bu_cv_have_stat64" = "need -D_LARGEFILE64_SOURCE"; then
+ cat >> confdefs.h <<\EOF
#define _LARGEFILE64_SOURCE 1
EOF
- fi
+ CPPFLAGS="$CPPFLAGS -D_LARGEFILE64_SOURCE"
fi
# Some systems have frexp only in -lm, not in -lc.
Jakub
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix strings to work with > 2GB files again on 32-bit arches
2004-10-11 20:21 [PATCH] Fix strings to work with > 2GB files again on 32-bit arches Jakub Jelinek
@ 2004-10-11 23:15 ` Alan Modra
2004-10-12 5:49 ` Jakub Jelinek
2004-10-16 20:19 ` Aaron W. LaFramboise
1 sibling, 1 reply; 7+ messages in thread
From: Alan Modra @ 2004-10-11 23:15 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: binutils
On Mon, Oct 11, 2004 at 10:20:28PM +0200, Jakub Jelinek wrote:
> 2003-11-07 changes broke strings on arches with 32-bit off_t.
> The following patch fixes this, although I'm not sure if the
What about all the other uses of get_file_size? Shouldn't you be fixing
get_file_size instead?
--
Alan Modra
IBM OzLabs - Linux Technology Centre
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix strings to work with > 2GB files again on 32-bit arches
2004-10-11 23:15 ` Alan Modra
@ 2004-10-12 5:49 ` Jakub Jelinek
2004-10-13 13:54 ` Alan Modra
0 siblings, 1 reply; 7+ messages in thread
From: Jakub Jelinek @ 2004-10-12 5:49 UTC (permalink / raw)
To: binutils
On Tue, Oct 12, 2004 at 08:45:06AM +0930, Alan Modra wrote:
> On Mon, Oct 11, 2004 at 10:20:28PM +0200, Jakub Jelinek wrote:
> > 2003-11-07 changes broke strings on arches with 32-bit off_t.
> > The following patch fixes this, although I'm not sure if the
>
> What about all the other uses of get_file_size? Shouldn't you be fixing
> get_file_size instead?
All the other tools work with object files and handling there
> 2GB files would require more changes than just get_file_size.
strings works on all files and is ATM the only one using fopen64/etc.
Plus I really think strings should work also on devices, which get_file_size
refuses and it should work also on zero length files, which get_file_size
doesn't like either.
Jakub
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix strings to work with > 2GB files again on 32-bit arches
2004-10-12 5:49 ` Jakub Jelinek
@ 2004-10-13 13:54 ` Alan Modra
0 siblings, 0 replies; 7+ messages in thread
From: Alan Modra @ 2004-10-13 13:54 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: binutils
On Tue, Oct 12, 2004 at 01:49:06AM -0400, Jakub Jelinek wrote:
> On Tue, Oct 12, 2004 at 08:45:06AM +0930, Alan Modra wrote:
> > What about all the other uses of get_file_size? Shouldn't you be fixing
> > get_file_size instead?
>
> All the other tools work with object files and handling there
> > 2GB files would require more changes than just get_file_size.
> strings works on all files and is ATM the only one using fopen64/etc.
I see.
> Plus I really think strings should work also on devices, which get_file_size
> refuses and it should work also on zero length files, which get_file_size
> doesn't like either.
Yes. OK, I'm willing to pre-approve a patch to do that as well.
--
Alan Modra
IBM OzLabs - Linux Technology Centre
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix strings to work with > 2GB files again on 32-bit arches
2004-10-11 20:21 [PATCH] Fix strings to work with > 2GB files again on 32-bit arches Jakub Jelinek
2004-10-11 23:15 ` Alan Modra
@ 2004-10-16 20:19 ` Aaron W. LaFramboise
2004-10-18 13:45 ` Nick Clifton
1 sibling, 1 reply; 7+ messages in thread
From: Aaron W. LaFramboise @ 2004-10-16 20:19 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: binutils
[-- Attachment #1: Type: text/plain, Size: 505 bytes --]
Jakub Jelinek wrote:
> 2004-10-11 Jakub Jelinek <jakub@redhat.com>
>
> * strings.c (statbuf): New typedef.
> (file_stat): Define.
> (strings_object_file): Avoid using get_file_size, instead do the
> checks here, using file_stat.
> * configure.in (HAVE_STAT64): New test.
> * configure: Rebuilt.
> * config.in: Rebuilt.
This patch breaks i686-pc-mingw32 because struct stat isn't defined.
Including <sys/stat.h> fixes it.
I have a copyright assignment but no CVS access.
Aaron W. LaFramboise
[-- Attachment #2: binutils-head-20041016-stat.patch --]
[-- Type: text/plain, Size: 648 bytes --]
2004-10-16 Aaron W. LaFramboise <aaron98wiridge9@aaronwl.com>
* strings.c (<sys/stat.h>): Include.
Index: src/binutils/strings.c
===================================================================
RCS file: /cvs/src/src/binutils/strings.c,v
retrieving revision 1.24
diff -c -3 -p -r1.24 strings.c
*** src/binutils/strings.c 13 Oct 2004 14:33:51 -0000 1.24
--- src/binutils/strings.c 16 Oct 2004 20:15:58 -0000
***************
*** 67,72 ****
--- 67,73 ----
#include "bucomm.h"
#include "libiberty.h"
#include "safe-ctype.h"
+ #include <sys/stat.h>
/* Some platforms need to put stdin into binary mode, to read
binary files. */
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix strings to work with > 2GB files again on 32-bit arches
2004-10-16 20:19 ` Aaron W. LaFramboise
@ 2004-10-18 13:45 ` Nick Clifton
2004-10-18 13:47 ` Jakub Jelinek
0 siblings, 1 reply; 7+ messages in thread
From: Nick Clifton @ 2004-10-18 13:45 UTC (permalink / raw)
To: Aaron W. LaFramboise; +Cc: Jakub Jelinek, binutils
Hi Aaron,
>>2004-10-11 Jakub Jelinek <jakub@redhat.com>
>>
>> * strings.c (statbuf): New typedef.
>> (file_stat): Define.
>> (strings_object_file): Avoid using get_file_size, instead do the
>> checks here, using file_stat.
>> * configure.in (HAVE_STAT64): New test.
>> * configure: Rebuilt.
>> * config.in: Rebuilt.
> This patch breaks i686-pc-mingw32 because struct stat isn't defined.
> Including <sys/stat.h> fixes it.
>
> I have a copyright assignment but no CVS access.
No worries - I have checked your patch in.
Cheers
Nick
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix strings to work with > 2GB files again on 32-bit arches
2004-10-18 13:45 ` Nick Clifton
@ 2004-10-18 13:47 ` Jakub Jelinek
0 siblings, 0 replies; 7+ messages in thread
From: Jakub Jelinek @ 2004-10-18 13:47 UTC (permalink / raw)
To: Nick Clifton; +Cc: Aaron W. LaFramboise, binutils
On Mon, Oct 18, 2004 at 02:50:46PM +0100, Nick Clifton wrote:
> Hi Aaron,
>
> >>2004-10-11 Jakub Jelinek <jakub@redhat.com>
> >>
> >> * strings.c (statbuf): New typedef.
> >> (file_stat): Define.
> >> (strings_object_file): Avoid using get_file_size, instead do the
> >> checks here, using file_stat.
> >> * configure.in (HAVE_STAT64): New test.
> >> * configure: Rebuilt.
> >> * config.in: Rebuilt.
>
> >This patch breaks i686-pc-mingw32 because struct stat isn't defined.
> >Including <sys/stat.h> fixes it.
> >
> >I have a copyright assignment but no CVS access.
>
> No worries - I have checked your patch in.
Sorry about that. It works for me on Linux, as fcntl.h includes there
sys/stat.h (which POSIX allows).
Jakub
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2004-10-18 13:47 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-11 20:21 [PATCH] Fix strings to work with > 2GB files again on 32-bit arches Jakub Jelinek
2004-10-11 23:15 ` Alan Modra
2004-10-12 5:49 ` Jakub Jelinek
2004-10-13 13:54 ` Alan Modra
2004-10-16 20:19 ` Aaron W. LaFramboise
2004-10-18 13:45 ` Nick Clifton
2004-10-18 13:47 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).