//---------------------------------------------------------------------------------------- void nsFileSpecHelpers::Canonify(nsSimpleCharString& ioPath, PRBool inMakeDirs) // Canonify, make absolute, and check whether directories exist. This // takes a (possibly relative) native path and converts it into a // fully qualified native path. //---------------------------------------------------------------------------------------- { if (ioPath.IsEmpty()) return; NS_ASSERTION(strchr((const char*)ioPath, '/') == 0, "This smells like a Unix path. Native path expected! " "Please fix."); if (inMakeDirs) { const int mode = 0755; nsSimpleCharString unixStylePath = ioPath; nsFileSpecHelpers::NativeToUnix(unixStylePath); nsFileSpecHelpers::MakeAllDirectories((const char*)unixStylePath, mode); } char buffer[_MAX_PATH]; errno = 0; *buffer = '\0'; char* canonicalPath = _fullpath(buffer, ioPath, _MAX_PATH); if (canonicalPath) { NS_ASSERTION( canonicalPath[0] != '\0', "Uh oh...couldn't convert" ); if (canonicalPath[0] == '\0') return; } ioPath = canonicalPath; } // nsFileSpecHelpers::Canonify
//---------------------------------------------------------------------------------------- void nsFileSpecHelpers::NativeToUnix(nsSimpleCharString& ioPath) // This just does string manipulation. It doesn't check reality, or canonify, or // anything. The unix path is longer, so we can't do it in place. //---------------------------------------------------------------------------------------- { if (ioPath.IsEmpty()) return; // Convert the drive-letter separator, if present nsSimpleCharString temp("/"); char* cp = (char*)ioPath + 1; if (strstr(cp, ":\\") == cp) *cp = '|'; // absolute path else if (cp[0] == '\\') // unc path cp--; else temp[0] = '\0'; // relative path // Convert '\' to '/' for (; *cp; cp++) { if(IsDBCSLeadByte(*cp) && *(cp+1) != nsnull) { cp++; continue; } if (*cp == '\\') *cp = '/'; } // Add the slash in front. temp += ioPath; ioPath = temp; }
//---------------------------------------------------------------------------------------- void nsFileSpecHelpers::Canonify(nsSimpleCharString& ioPath, PRBool inMakeDirs) // Canonify, make absolute, and check whether directories exist //---------------------------------------------------------------------------------------- { if (ioPath.IsEmpty()) return; if (inMakeDirs) { const mode_t mode = 0755; nsFileSpecHelpers::MakeAllDirectories((const char*)ioPath, mode); } errno = 0; // needed? if (ioPath[0] != '/') { // the ioPath that was passed in is relative. We must cat it to the cwd. char buffer[MAXPATHLEN]; (void) getcwd(buffer, MAXPATHLEN); strcat(buffer, "/"); strcat(buffer, ioPath); ioPath = buffer; } } // nsFileSpecHelpers::Canonify
//---------------------------------------------------------------------------------------- void nsFileSpecHelpers::Canonify(nsSimpleCharString& ioPath, PRBool inMakeDirs) // Canonify, make absolute, and check whether directories exist //---------------------------------------------------------------------------------------- { if (ioPath.IsEmpty()) return; if (inMakeDirs) { const mode_t mode = 0700; nsFileSpecHelpers::MakeAllDirectories((const char*)ioPath, mode); } char buffer[MAXPATHLEN]; errno = 0; *buffer = '\0'; BEntry e((const char *)ioPath, true); BPath p; e.GetPath(&p); ioPath = p.Path(); } // nsFileSpecHelpers::Canonify
//---------------------------------------------------------------------------------------- void nsFileSpecHelpers::UnixToNative(nsSimpleCharString& ioPath) // This just does string manipulation. It doesn't check reality, or canonify, or // anything //---------------------------------------------------------------------------------------- { // Allow for relative or absolute. We can do this in place, because the // native path is never longer. if (ioPath.IsEmpty()) return; // Strip initial slash for an absolute path char* src = (char*)ioPath; if (*src == '/') { if (!src[1]) { // allocate new string by copying from ioPath[1] nsSimpleCharString temp = src + 1; ioPath = temp; return; } // Since it was an absolute path, check for the drive letter char* colonPointer = src + 2; if (strstr(src, "|/") == colonPointer) *colonPointer = ':'; // allocate new string by copying from ioPath[1] nsSimpleCharString temp = src + 1; ioPath = temp; } // Convert '/' to '\'. (Must check EVERY character: consider UNC path // case.) for (src = (char*)ioPath; *src; ++src) { if (*src == '/') *src = '\\'; } } // nsFileSpecHelpers::UnixToNative