]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/cdromutl.cc
- add a ReadLine method
[apt.git] / apt-pkg / contrib / cdromutl.cc
index cf1c0c29bf02edaa476988f680f029701892df00..187f6bd5997eb96af56a0b050137094d0d881d69 100644 (file)
@@ -10,6 +10,8 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
+#include<config.h>
+
 #include <apt-pkg/cdromutl.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/md5.h>
 #include <apt-pkg/configuration.h>
 #include <apt-pkg/strutl.h>
 
-#include <apti18n.h>
-    
 #include <sys/wait.h>
-#include <sys/errno.h>
 #include <sys/statvfs.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <unistd.h>
 #include <stdio.h>
+
+#include <apti18n.h>
                                                                        /*}}}*/
 
+using std::string;
+
 // IsMounted - Returns true if the mount point is mounted              /*{{{*/
 // ---------------------------------------------------------------------
 /* This is a simple algorithm that should always work, we stat the mount point
@@ -206,8 +209,11 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
       Hash.Add(Dir->d_name);
    };
    
-   if (chdir(StartDir.c_str()) != 0)
-      return _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
+   if (chdir(StartDir.c_str()) != 0) {
+      _error->Errno("chdir",_("Unable to change to %s"),StartDir.c_str());
+      closedir(D);
+      return false;
+   }
    closedir(D);
    
    // Some stats from the fsys
@@ -236,8 +242,8 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version)
 }
                                                                        /*}}}*/
 
-// FindMountPointForDevice - Find mountpoint for the given device      /*{{{*/
-char* FindMountPointForDevice(const char *devnode)
+// FindMountPointForDevice - Find mountpoint for the given device      /*{{{*/
+string FindMountPointForDevice(const char *devnode)
 {
    char buf[255];
    char *out[10];
@@ -254,14 +260,18 @@ char* FindMountPointForDevice(const char *devnode)
          while ( fgets(buf, sizeof(buf), f) != NULL) {
             if (strncmp(buf, devnode, strlen(devnode)) == 0) {
                if(TokSplitString(' ', buf, out, 10))
-                  return strdup(out[1]);
+               {
+                  fclose(f);
+                  // unescape the \0XXX chars in the path
+                  string mount_point = out[1];
+                  return DeEscapeString(mount_point);
+               }
             }
          }
          fclose(f);
       }
    }
    
-   return NULL;
+   return string();
 }
-
-
+                                                                       /*}}}*/