X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/ef38181605be2f7131bed9865d965300339389b5..1b4560fec66a6e7b2dff9aaa19095fb8423f69a0:/apt-pkg/contrib/cdromutl.cc diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index cf1c0c29b..afa01a562 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -10,6 +10,8 @@ ##################################################################### */ /*}}}*/ // Include Files /*{{{*/ +#include + #include #include #include @@ -17,18 +19,19 @@ #include #include -#include - #include -#include #include #include #include #include #include #include + +#include /*}}}*/ +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 @@ -119,8 +122,9 @@ bool MountCdrom(string Path, string DeviceName) if (Child == 0) { // Make all the fds /dev/null + int null_fd = open("/dev/null",O_RDWR); for (int I = 0; I != 3; I++) - dup2(open("/dev/null",O_RDWR),I); + dup2(null_fd, I); if (_config->Exists("Acquire::cdrom::"+Path+"::Mount") == true) { @@ -206,8 +210,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 +243,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 +261,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(); } - - + /*}}}*/