nsFileSpecOS2.cpp revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is
* John Fairhurst, <john_fairhurst@iname.com>.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Henry Sobotka <sobotka@axess.com>
* replaced nsFileSpec::Execute implementation with system() call
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK *****
*
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM described herein are
* Copyright (c) International Business Machines
* Corporation, 2000
*
* Modifications to Mozilla code or documentation
* identified per MPL Section 3.3
*
* Date Modified by Description of modification
* 03/23/2000 IBM Corp. Fixed bug where 2 char or less profile names treated as drive letters.
* 06/20/2000 IBM Corp. Make it more like Windows version.
*/
#define INCL_DOSERRORS
#define INCL_DOS
#define INCL_WINWORKPLACE
#include <os2.h>
#ifdef XP_OS2_VACPP
#include <direct.h>
#endif
#include <limits.h>
#include <ctype.h>
#include <io.h>
//----------------------------------------------------------------------------------------
// Canonify, make absolute, and check whether directories exist. This
// takes a (possibly relative) native path and converts it into a
// fully qualified native path.
//----------------------------------------------------------------------------------------
{
return;
"This smells like a Unix path. Native path expected! "
"Please fix.");
if (inMakeDirs)
{
const int mode = 0700;
}
errno = 0;
*buffer = '\0';
#ifdef XP_OS2
// Strip off any trailing backslash UNLESS it's the backslash that
// comes after "X:". Note also that "\" is valid. Sheesh.
//
{
lastchar = '\0';
}
DosQueryPathInfo( (char*) ioPath,
#else
#endif
if (canonicalPath)
{
if (canonicalPath[0] == '\0')
return;
#ifdef XP_OS2
// If we removed that backslash, add it back onto the fullpath
if (removedBackslash)
#endif
}
} // nsFileSpecHelpers::Canonify
//----------------------------------------------------------------------------------------
// 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.
return;
// Strip initial slash for an absolute path
if (*src == '/') {
if (!src[1]) {
// allocate new string by copying from ioPath[1]
return;
}
// Since it was an absolute path, check for the drive letter
*colonPointer = ':';
// allocate new string by copying from ioPath[1]
}
if (*src) {
// Convert '/' to '\'.
while (*++src)
{
if (*src == '/')
*src = '\\';
}
}
} // nsFileSpecHelpers::UnixToNative
//----------------------------------------------------------------------------------------
// 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.
//----------------------------------------------------------------------------------------
{
return;
// Convert the drive-letter separator, if present
else
// Convert '\' to '/'
{
#ifdef XP_OS2
// OS2TODO - implement equivalent of IsDBCSLeadByte
#else
{
cp++;
continue;
}
#endif
if (*cp == '\\')
*cp = '/';
}
// Add the slash in front.
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// NS_ASSERTION(0, "nsFileSpec is unsupported - use nsIFile!");
*this = inPath;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::operator =
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
*this = inSpec;
} // nsFilePath::nsFilePath
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFilePath::operator =
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::SetLeafName
//----------------------------------------------------------------------------------------
char* nsFileSpec::GetLeafName() const
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::GetLeafName
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
} // nsFileSpec::Exists
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
else
outStamp = 0;
} // nsFileSpec::GetModDate
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
return 0;
} // nsFileSpec::GetFileSize
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
#ifdef XP_OS2
#else
#endif
} // nsFileSpec::IsFile
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
#ifdef XP_OS2
#else
#endif
} // nsFileSpec::IsDirectory
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
{
#ifdef XP_OS2
&fs3,
sizeof fs3);
if(!rc)
#else
if (FILE_ATTRIBUTE_HIDDEN & attr)
#endif
}
return hidden;
}
// nsFileSpec::IsHidden
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
#ifdef XP_OS2
return PR_FALSE; // No symlinks on OS/2
#else
// Get a pointer to the IShellLink interface.
{
// Get a pointer to the IPersistFile interface.
{
// Ensure that the string is Unicode.
// Load the shortcut.
{
}
// Release the pointer to the IPersistFile interface.
}
// Release the pointer to the IShellLink interface.
}
return isSymlink;
#endif
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
#ifdef XP_OS2
return NS_OK; // no symlinks on OS/2
#else
if (Exists())
return NS_OK;
// Get a pointer to the IShellLink interface.
{
// Get a pointer to the IPersistFile interface.
{
// Ensure that the string is Unicode.
// Load the shortcut.
{
// Resolve the link.
{
// Get the path to the link target.
{
// Here we modify the nsFileSpec;
}
}
}
else {
// It wasn't a shortcut. Oh well. Leave it like it was.
hres = 0;
}
// Release the pointer to the IPersistFile interface.
}
// Release the pointer to the IShellLink interface.
}
return NS_OK;
return NS_FILE_FAILURE;
#endif
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (cp++)
} // nsFileSpec::GetParent
//----------------------------------------------------------------------------------------
void nsFileSpec::operator += (const char* inRelativePath)
//----------------------------------------------------------------------------------------
{
return;
mPath += "x";
else
mPath += "\\x";
// If it's a (unix) relative path, make it native
} // nsFileSpec::operator +=
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// Note that mPath is canonical!
#ifdef XP_OS2
// OS2TODO - vacpp complains about mkdir but PR_MkDir should be ok?
#else
mkdir(nsNSPRPath(*this));
#endif
} // nsFileSpec::CreateDirectory
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (IsDirectory())
{
if (inRecursive)
{
{
}
}
#ifdef XP_OS2
// OS2TODO - vacpp complains if use rmdir but PR_RmDir should be ok?
PR_RmDir(nsNSPRPath(*this));
#else
rmdir(nsNSPRPath(*this));
#endif
}
{
remove(nsNSPRPath(*this));
}
} // nsFileSpec::Delete
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (IsDirectory())
{
{
}
{
if (child.IsDirectory())
{
tmpDirSpec += leafname;
}
else
{
}
}
}
{
{
}
}
} // nsFileSpec::RecursiveCopy
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
#ifdef XP_OS2
&hFile,
0,
NULL);
return NS_FILE_FAILURE;
else
goto error;
#else
// Leave it to Microsoft to open an existing file with a function
// named "CreateFile".
NULL,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
return NS_FILE_FAILURE;
// Seek to new, desired end of file
if (status == 0xffffffff)
goto error;
// Truncate file at current cursor position
if (!SetEndOfFile(hFile))
goto error;
if (!CloseHandle(hFile))
return NS_FILE_FAILURE;
#endif
return NS_OK;
#ifdef XP_OS2
#else
#endif
return NS_FILE_FAILURE;
} // nsFileSpec::Truncate
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// This function should not be used to move a file on disk.
return NS_FILE_FAILURE;
{
// Could not rename, set back to the original.
return NS_FILE_FAILURE;
}
return NS_OK;
} // nsFileSpec::Rename
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// We can only copy into a directory, and (for now) can not copy entire directories
{
char *leafname = GetLeafName();
destPath += "\\";
// CopyFile returns non-zero if succeeds
#ifdef XP_OS2
else
#else
#endif
if (copyOK)
return NS_OK;
}
return NS_FILE_FAILURE;
} // nsFileSpec::CopyToDir
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
// We can only copy into a directory, and (for now) can not copy entire directories
{
char *leafname = GetLeafName();
destPath += "\\";
{
*this = inNewParentDirectory + GetLeafName();
return NS_OK;
}
}
return NS_FILE_FAILURE;
} // nsFileSpec::MoveToDir
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (!IsDirectory())
{
#ifdef XP_OS2
{
}
return result;
#else
if (execResult > 31)
return NS_OK;
#endif
}
return NS_FILE_FAILURE;
} // nsFileSpec::Execute
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
sizeof(fsAllocate));
}
return nBytes;
}
//========================================================================================
// nsDirectoryIterator
//========================================================================================
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
mCurrent += "dummy";
mStarting += "dummy";
++(*this);
} // nsDirectoryIterator::nsDirectoryIterator
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
{
if (mDir)
} // nsDirectoryIterator::nsDirectoryIterator
//----------------------------------------------------------------------------------------
nsDirectoryIterator& nsDirectoryIterator::operator ++ ()
//----------------------------------------------------------------------------------------
{
if (!mDir)
return *this;
if (entry)
{
if (mResoveSymLinks)
{
}
}
return *this;
} // nsDirectoryIterator::operator ++
//----------------------------------------------------------------------------------------
nsDirectoryIterator& nsDirectoryIterator::operator -- ()
//----------------------------------------------------------------------------------------
{
return ++(*this); // can't do it backwards.
} // nsDirectoryIterator::operator --