]> git.saurik.com Git - apt.git/blobdiff - cmdline/apt-cache.cc
* Use isatty rather than ttyname for checking if stdin ...
[apt.git] / cmdline / apt-cache.cc
index df68f78333c80c6f125ac5a3c13ef7a11afea2de..1933f60c640343275a9a015cb3bf340903adee49 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: apt-cache.cc,v 1.64 2003/05/15 09:39:38 piefel Exp $
+// $Id: apt-cache.cc,v 1.68 2003/11/19 23:50:51 mdz Exp $
 /* ######################################################################
    
    apt-cache - Manages the cache files
@@ -1195,7 +1195,7 @@ bool DisplayRecord(pkgCache::VerIterator V)
    Buffer[V.FileList()->Size] = '\n';
    if (PkgF.Seek(V.FileList()->Offset) == false ||
        PkgF.Read(Buffer,V.FileList()->Size) == false ||
-       write(STDOUT_FILENO,Buffer,V.FileList()->Size+1) != V.FileList()->Size+1)
+       fwrite(Buffer,1,V.FileList()->Size+1,stdout) < V.FileList()->Size+1)
    {
       delete [] Buffer;
       return false;
@@ -1344,6 +1344,8 @@ bool ShowPackage(CommandLine &CmdL)
 {   
    pkgCache &Cache = *GCache;
    pkgDepCache::Policy Plcy;
+
+   unsigned found = 0;
    
    for (const char **I = CmdL.FileList + 1; *I != 0; I++)
    {
@@ -1354,6 +1356,8 @@ bool ShowPackage(CommandLine &CmdL)
         continue;
       }
 
+      ++found;
+
       // Find the proper version to use.
       if (_config->FindB("APT::Cache::AllVersions","true") == true)
       {
@@ -1373,7 +1377,10 @@ bool ShowPackage(CommandLine &CmdL)
            return false;
       }      
    }
-   return true;
+
+   if (found > 0)
+        return true;
+   return _error->Error(_("No packages found"));
 }
                                                                        /*}}}*/
 // ShowPkgNames - Show package names                                   /*{{{*/
@@ -1574,6 +1581,9 @@ bool ShowHelp(CommandLine &Cmd)
    ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
            COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
    
+   if (_config->FindB("version") == true)
+     return true;
+
    cout << 
     _("Usage: apt-cache [options] command\n"
       "       apt-cache [options] add file1 [file2 ...]\n"
@@ -1687,7 +1697,7 @@ int main(int argc,const char *argv[])
    }
    
    // Deal with stdout not being a tty
-   if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1)
+   if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
       _config->Set("quiet","1");
 
    if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)