]> granicus.if.org Git - strace/blobdiff - file.c
Fix signed/unsigned problems
[strace] / file.c
diff --git a/file.c b/file.c
index f1c8f3ab69a0c97f91f5b57cf9dd445d5a206ac2..bfb12ca30a3cfdb528690e8909f6d70e408ba275 100644 (file)
--- a/file.c
+++ b/file.c
@@ -107,11 +107,17 @@ struct stat {
 #    define off_t off_t
 #    define loff_t loff_t
 #  endif
+#  ifdef HPPA  /* asm-parisc/stat.h defines stat64 */
+#    undef stat64
+#  endif
 #  define stat libc_stat
 #  define stat64 libc_stat64
 #  include <sys/stat.h>
 #  undef stat
 #  undef stat64
+#  ifdef HPPA
+#    define stat64 hpux_stat64
+#  endif
 #else
 #  include <sys/stat.h>
 #endif
@@ -132,6 +138,22 @@ struct stat {
 #include <sys/stat.h>
 #endif
 
+#if HAVE_LONG_LONG_OFF_T
+/*
+ * Ugly hacks for systems that have typedef long long off_t
+ */
+
+#define stat64 stat
+#define HAVE_STAT64 1  /* Ugly hack */
+
+#define        sys_stat64      sys_stat
+#define sys_fstat64    sys_fstat
+#define sys_lstat64    sys_lstat
+#define sys_lseek64    sys_lseek
+#define sys_truncate64 sys_truncate
+#define sys_ftruncate64        sys_ftruncate
+#endif
+
 #ifdef MAJOR_IN_SYSMACROS
 #include <sys/sysmacros.h>
 #endif
@@ -351,7 +373,7 @@ static struct xlat whence[] = {
        { 0,            NULL            },
 };
 
-#ifndef FREEBSD
+#ifndef HAVE_LONG_LONG_OFF_T
 int
 sys_lseek(tcp)
 struct tcb *tcp;
@@ -382,11 +404,11 @@ struct tcb *tcp;
        if (tcp->u_arg[4] == SEEK_SET)
            tprintf("%ld, %llu, ", tcp->u_arg[0],
                    (((long long int) tcp->u_arg[1]) << 32
-                    | (unsigned long long) tcp->u_arg[2]));
+                    | (unsigned long long) (unsigned) tcp->u_arg[2]));
        else
            tprintf("%ld, %lld, ", tcp->u_arg[0],
                    (((long long int) tcp->u_arg[1]) << 32
-                    | (unsigned long long) tcp->u_arg[2]));
+                    | (unsigned long long) (unsigned) tcp->u_arg[2]));
     }
     else {
        long long int off;
@@ -400,7 +422,7 @@ struct tcb *tcp;
 }
 #endif
 
-#if _LFS64_LARGEFILE || FREEBSD
+#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
 int
 sys_lseek64 (tcp)
 struct tcb *tcp;
@@ -408,7 +430,7 @@ struct tcb *tcp;
        if (entering(tcp)) {
                long long offset;
                ALIGN64 (tcp, 1);       /* FreeBSD aligns off_t args */
-               offset = get64(tcp->u_arg [1], tcp->u_arg[2]);
+               offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
                if (tcp->u_arg[3] == SEEK_SET)
                        tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
                else
@@ -419,7 +441,7 @@ struct tcb *tcp;
 }
 #endif
 
-#ifndef FREEBSD
+#ifndef HAVE_LONG_LONG_OFF_T
 int
 sys_truncate(tcp)
 struct tcb *tcp;
@@ -432,7 +454,7 @@ struct tcb *tcp;
 }
 #endif
 
-#if _LFS64_LARGEFILE || FREEBSD
+#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
 int
 sys_truncate64(tcp)
 struct tcb *tcp;
@@ -440,13 +462,13 @@ struct tcb *tcp;
        if (entering(tcp)) {
                ALIGN64 (tcp, 1);
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", %llu", get64(tcp->u_arg[1],tcp->u_arg[2]));
+               tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
        }
        return 0;
 }
 #endif
 
-#ifndef FREEBSD
+#ifndef HAVE_LONG_LONG_OFF_T
 int
 sys_ftruncate(tcp)
 struct tcb *tcp;
@@ -458,7 +480,7 @@ struct tcb *tcp;
 }
 #endif
 
-#if _LFS64_LARGEFILE || FREEBSD
+#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
 int
 sys_ftruncate64(tcp)
 struct tcb *tcp;
@@ -466,7 +488,7 @@ struct tcb *tcp;
        if (entering(tcp)) {
                ALIGN64 (tcp, 1);
                tprintf("%ld, %llu", tcp->u_arg[0],
-                       get64(tcp->u_arg[1] ,tcp->u_arg[2]));
+                       LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
        }
        return 0;
 }
@@ -608,8 +630,8 @@ long addr;
 }
 #endif /* LINUXSPARC */
 
-#ifdef FREEBSD
 static struct xlat fileflags[] = {
+#ifdef FREEBSD
        { UF_NODUMP,    "UF_NODUMP"     },
        { UF_IMMUTABLE, "UF_IMMUTABLE"  },
        { UF_APPEND,    "UF_APPEND"     },
@@ -619,9 +641,18 @@ static struct xlat fileflags[] = {
        { SF_IMMUTABLE, "SF_IMMUTABLE"  },
        { SF_APPEND,    "SF_APPEND"     },
        { SF_NOUNLINK,  "SF_NOUNLINK"   },
+#elif UNIXWARE >= 2
+#ifdef         _S_ISMLD
+       { _S_ISMLD,     "_S_ISMLD"      },
+#endif
+#ifdef         _S_ISMOUNTED
+       { _S_ISMOUNTED, "_S_ISMOUNTED"  },
+#endif
+#endif
        { 0,            NULL            },
 };
 
+#ifdef FREEBSD
 int
 sys_chflags(tcp)
 struct tcb *tcp;
@@ -652,6 +683,7 @@ struct tcb *tcp;
 }
 #endif
 
+#ifndef HAVE_LONG_LONG_OFF_T
 static void
 realprintstat(tcp, statbuf)
 struct tcb *tcp;
@@ -695,17 +727,28 @@ struct stat *statbuf;
     if (!abbrev(tcp)) {
            tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
            tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
-#ifndef FREEBSD
-           tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
-#else /* FREEBSD */
-           tprintf("st_ctime=%s, ", sprinttime(statbuf->st_ctime));
-           tprintf("st_flags=");
-           if (statbuf->st_flags) {
-                   printflags(fileflags, statbuf->st_flags);
-           } else
-                   tprintf("0");
-           tprintf(", st_gen=%u}", statbuf->st_gen);
-#endif /* FREEBSD */
+           tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
+#if HAVE_ST_FLAGS
+               tprintf(", st_flags=");
+               if (statbuf->st_flags) {
+                       printflags(fileflags, statbuf->st_flags);
+               } else
+                       tprintf("0");
+#endif
+#if HAVE_ST_ACLCNT
+               tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
+#endif
+#if HAVE_ST_LEVEL
+               tprintf(", st_level=%ld", statbuf->st_level);
+#endif
+#if HAVE_ST_FSTYPE
+               tprintf(", st_fstype=%.*s",
+                       (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
+#endif
+#if HAVE_ST_GEN
+               tprintf(", st_gen=%u", statbuf->st_gen);
+#endif
+               tprintf("}");
     }
     else
            tprintf("...}");
@@ -741,6 +784,7 @@ long addr;
 
        realprintstat(tcp, &statbuf);
 }
+#endif /* !HAVE_LONG_LONG_OFF_T */
 
 #ifdef HAVE_STAT64
 static void
@@ -817,14 +861,35 @@ long addr;
        if (!abbrev(tcp)) {
                tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
                tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
-               tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
+               tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
+#if HAVE_ST_FLAGS
+               tprintf(", st_flags=");
+               if (statbuf.st_flags) {
+                       printflags(fileflags, statbuf.st_flags);
+               } else
+                       tprintf("0");
+#endif
+#if HAVE_ST_ACLCNT
+               tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
+#endif
+#if HAVE_ST_LEVEL
+               tprintf(", st_level=%ld", statbuf.st_level);
+#endif
+#if HAVE_ST_FSTYPE
+               tprintf(", st_fstype=%.*s",
+                       (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
+#endif
+#if HAVE_ST_GEN
+               tprintf(", st_gen=%u", statbuf.st_gen);
+#endif
+               tprintf("}");
        }
        else
                tprintf("...}");
 }
 #endif /* HAVE_STAT64 */
 
-#if defined(linux) && !defined(IA64)
+#if defined(linux) && !defined(IA64) && !defined(HPPA)
 static void
 convertoldstat(oldbuf, newbuf)
 const struct __old_kernel_stat *oldbuf;
@@ -879,7 +944,7 @@ long addr;
 }
 #endif /* linux && !IA64 */
 
-
+#ifndef HAVE_LONG_LONG_OFF_T
 int
 sys_stat(tcp)
 struct tcb *tcp;
@@ -892,6 +957,7 @@ struct tcb *tcp;
        }
        return 0;
 }
+#endif
 
 int
 sys_stat64(tcp)
@@ -911,7 +977,7 @@ struct tcb *tcp;
 }
 
 #ifdef linux
-# if !defined(IA64)
+# if !defined(IA64) && !defined(HPPA)
 int
 sys_oldstat(tcp)
 struct tcb *tcp;
@@ -924,9 +990,10 @@ struct tcb *tcp;
        }
        return 0;
 }
-# endif /* !IA64 */
+# endif /* !IA64 && !HPPA*/
 #endif /* linux */
 
+#ifndef HAVE_LONG_LONG_OFF_T
 int
 sys_fstat(tcp)
 struct tcb *tcp;
@@ -938,6 +1005,7 @@ struct tcb *tcp;
        }
        return 0;
 }
+#endif
 
 int
 sys_fstat64(tcp)
@@ -956,7 +1024,7 @@ struct tcb *tcp;
 }
 
 #ifdef linux
-# if !defined(IA64)
+# if !defined(IA64) && !defined(HPPA)
 int
 sys_oldfstat(tcp)
 struct tcb *tcp;
@@ -968,9 +1036,10 @@ struct tcb *tcp;
        }
        return 0;
 }
-# endif /* !IA64 */
+# endif /* !IA64 && !HPPA*/
 #endif
 
+#ifndef HAVE_LONG_LONG_OFF_T
 int
 sys_lstat(tcp)
 struct tcb *tcp;
@@ -983,6 +1052,7 @@ struct tcb *tcp;
        }
        return 0;
 }
+#endif
 
 int
 sys_lstat64(tcp)
@@ -1002,7 +1072,7 @@ struct tcb *tcp;
 }
 
 #ifdef linux
-# if !defined(IA64)
+# if !defined(IA64) && !defined(HPPA)
 int
 sys_oldlstat(tcp)
 struct tcb *tcp;
@@ -1015,7 +1085,7 @@ struct tcb *tcp;
        }
        return 0;
 }
-# endif /* !IA64 */
+# endif /* !IA64 && !HPPA */
 #endif