[uClibc] fstat and fstat64

Simon Posnjak sposnjak at gmail.com
Thu Jun 2 13:47:42 UTC 2005

Hi all,

Yesterday I reported that I am having problems with sqlite3 (3.2.1)
and uclibc (0.9.27). Today I did a bit of investigating and found that
the problem is connected to fstat function.

The code in question is:
-From sqlite:
int sqlite3OsFileSize(OsFile *id, i64 *pSize){
  struct stat buf;

  if( fstat(id->h, &buf)!=0 ){
    return SQLITE_IOERR;
  *pSize = buf.st_size;
  return SQLITE_OK;

-From uclibc:
int stat64(const char *file_name, struct stat64 *buf)
        int result;
        struct kernel_stat64 kbuf;

        result = __syscall_stat64(file_name, &kbuf);
        if (result == 0) {
                __xstat64_conv(&kbuf, buf);
        return result;

I get a segfault after the fstat call.

I went through the code with the debugger and found that the size of
struct stat buf and struct stat64 *buf is not the same:

[simonp at matilda trunk]$ /usr/local/gdb-cris/bin/cris-gdb
GNU gdb 6.2.50_20041012
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i386-linux --target=cris"...
(gdb) br sqlite3OsFileSize
Breakpoint 1 at 0x88b46: file src/os_unix.c, line 811.
(gdb) target remote
Remote debugging using
0x00080080 in _start ()
(gdb) c

Breakpoint 1, sqlite3OsFileSize (id=0xfe434, pSize=0x9fffa1fc) at
811       assert( id->isOpen );
(gdb) list
806     /*
807     ** Determine the current size of a file in bytes
808     */
809     int sqlite3OsFileSize(OsFile *id, i64 *pSize){
810       struct stat buf;
811       assert( id->isOpen );
812       SimulateIOError(SQLITE_IOERR);
813       printf ("sqlite3OsFileSize: %i\n", sizeof(struct stat));
814       if( fstat(id->h, &buf)!=0 ){
815         return SQLITE_IOERR;
(gdb) n
813       printf ("sqlite3OsFileSize: %i\n", sizeof(struct stat));
(gdb) n
814       if( fstat(id->h, &buf)!=0 ){
(gdb) print sizeof(buf)
$1 = 92
(gdb) s
fstat64 (fd=3, buf=0x9fffa18c) at fstat64.c:28
28              result = __syscall_fstat64(fd, &kbuf);
(gdb) list
23      int fstat64(int fd, struct stat64 *buf)
24      {
25              int result;
26              struct kernel_stat64 kbuf;
28              result = __syscall_fstat64(fd, &kbuf);
29              if (result == 0) {
30                      __xstat64_conv(&kbuf, buf);
31              }
32              return result;
(gdb) print sizeof(*buf)
$2 = 96

I think that the problem is some have connected to header files but I
can not pin it down. Any ideas what the problem could be?

Regards Simon

More information about the uClibc mailing list