]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/fileutl.cc
Merge branch 'debian/sid' into debian/experimental
[apt.git] / apt-pkg / contrib / fileutl.cc
index c7c60e00eca6c70ccd0864d9d27da4ac0ece4923..02b30dc1f17ce3abd401ddb731a91b7a71eadbcd 100644 (file)
        #include <bzlib.h>
 #endif
 #ifdef HAVE_LZMA
-       #include <stdint.h>
        #include <lzma.h>
 #endif
-
-#ifdef WORDS_BIGENDIAN
-#include <inttypes.h>
-#endif
+#include <endian.h>
+#include <stdint.h>
 
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -855,6 +852,27 @@ bool ExecWait(pid_t Pid,const char *Name,bool Reap)
 }
                                                                        /*}}}*/
 
+
+// StartsWithGPGClearTextSignature - Check if a file is Pgp/GPG clearsigned     /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool StartsWithGPGClearTextSignature(string const &FileName)
+{
+   static const char* SIGMSG = "-----BEGIN PGP SIGNED MESSAGE-----\n";
+   char buffer[strlen(SIGMSG)+1];
+   FILE* gpg = fopen(FileName.c_str(), "r");
+   if (gpg == NULL)
+      return false;
+
+   char const * const test = fgets(buffer, sizeof(buffer), gpg);
+   fclose(gpg);
+   if (test == NULL || strcmp(buffer, SIGMSG) != 0)
+      return false;
+
+   return true;
+}
+
+
 class FileFdPrivate {                                                  /*{{{*/
        public:
 #ifdef HAVE_ZLIB
@@ -1896,19 +1914,13 @@ unsigned long long FileFd::Size()
          FileFdErrno("lseek","Unable to seek to end of gzipped file");
          return 0;
        }
-       size = 0;
+       uint32_t size = 0;
        if (read(iFd, &size, 4) != 4)
        {
          FileFdErrno("read","Unable to read original size of gzipped file");
          return 0;
        }
-
-#ifdef WORDS_BIGENDIAN
-       uint32_t tmp_size = size;
-       uint8_t const * const p = (uint8_t const * const) &tmp_size;
-       tmp_size = (p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0];
-       size = tmp_size;
-#endif
+       size = le32toh(size);
 
        if (lseek(iFd, oldPos, SEEK_SET) < 0)
        {