version 1.26, 2003/03/18 20:59:36
|
version 1.55.22.2, 2013/09/18 06:29:20
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%LICENSE//////////////////////////////////////////////////////////////// |
// |
|
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
|
// The Open Group, Tivoli Systems |
|
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// Licensed to The Open Group (TOG) under one or more contributor license |
// of this software and associated documentation files (the "Software"), to |
// agreements. Refer to the OpenPegasusNOTICE.txt file distributed with |
// deal in the Software without restriction, including without limitation the |
// this work for additional information regarding copyright ownership. |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// Each contributor licenses this file to you under the OpenPegasus Open |
// sell copies of the Software, and to permit persons to whom the Software is |
// Source License; you may not use this file except in compliance with the |
// furnished to do so, subject to the following conditions: |
// License. |
// | // |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// Permission is hereby granted, free of charge, to any person obtaining a |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// copy of this software and associated documentation files (the "Software"), |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
// to deal in the Software without restriction, including without limitation |
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
// and/or sell copies of the Software, and to permit persons to whom the |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
// Software is furnished to do so, subject to the following conditions: |
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
// | // |
//============================================================================== |
// The above copyright notice and this permission notice shall be included |
|
// in all copies or substantial portions of the Software. |
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
// | // |
// Modified By: |
////////////////////////////////////////////////////////////////////////// |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/String.h> | #include <Pegasus/Common/String.h> |
|
#include <Pegasus/Common/Buffer.h> |
#include <Pegasus/Common/ArrayInternal.h> | #include <Pegasus/Common/ArrayInternal.h> |
#include <Pegasus/Common/InternalException.h> | #include <Pegasus/Common/InternalException.h> |
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
#include <Pegasus/Common/Linkage.h> | #include <Pegasus/Common/Linkage.h> |
#include <fstream> | #include <fstream> |
|
#include <cstdio> |
|
#include <Pegasus/Common/Buffer.h> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
|
*/ | */ |
static Boolean removeFileNoCase(const String& path); | static Boolean removeFileNoCase(const String& path); |
| |
|
/** Produces an array of filenames that match the given pattern under |
|
the directory given by path. The pattern is limited to asterisks |
|
only. Examples: "*.txt", "hello*world.c". Returns true on success. |
|
Return false if the base diretory does not exist or cannot be |
|
accessed. |
|
*/ |
|
static Boolean glob( |
|
const String& path, |
|
const String& pattern, |
|
Array<String>& filenames); |
|
|
/** Loads contents of the file into the array. Note that the file is | /** Loads contents of the file into the array. Note that the file is |
opened using binary mode (newline sequences are not expanded to | opened using binary mode (newline sequences are not expanded to |
carriage-return-line-feed sequences on Windows). | carriage-return-line-feed sequences on Windows). |
|
|
@exception CannotOpenFile | @exception CannotOpenFile |
*/ | */ |
static void loadFileToMemory( | static void loadFileToMemory( |
Array<Sint8>& array, |
Buffer& array, |
const String& fileName); | const String& fileName); |
| |
/** Determines whether two files have exactly the same content. | /** Determines whether two files have exactly the same content. |
|
|
const String& path1, | const String& path1, |
const String& path2); | const String& path2); |
| |
/** Renames a file. |
/** |
@param oldPath old name of file. |
Renames a file. If the new name refers to an existing file, it is |
@param newPath new name of file. |
removed and replaced with the renamed file. The rename operation is |
@return true on success. |
performed atomically. |
|
@param oldPath A String containing the name of the file to rename. |
|
@param newPath A String containing the name to which to rename the file. |
|
@return A Boolean indicating whether the rename operation was |
|
successful. |
*/ | */ |
static Boolean renameFile( | static Boolean renameFile( |
const String& oldPath, | const String& oldPath, |
const String& newPath); | const String& newPath); |
| |
/** Same as rename file except that the case of the file referred to | /** Same as rename file except that the case of the file referred to |
by oldPath is ignored. |
by oldPath is ignored. The case resolution of the oldPath is |
|
performed prior to the atomic rename operation. |
*/ | */ |
static Boolean renameFileNoCase( | static Boolean renameFileNoCase( |
const String& oldPath, | const String& oldPath, |
|
|
*/ | */ |
static String extractFilePath(const String& path); | static String extractFilePath(const String& path); |
| |
|
/** Changes file permissions on the given file. |
|
@param path path of the file. |
|
@param mode the bit-wise inclusive OR of the values for the |
|
desired permissions. |
|
@return true on success, false on error and errno is set appropriately. |
|
*/ |
|
static Boolean changeFilePermissions(const String& path, mode_t mode); |
|
|
|
/** |
|
Return OS path specific delimiter. |
|
|
|
@return delimiter specific to the platform |
|
*/ |
|
static String getPathDelimiter(); |
|
|
|
/** |
|
Returns the absolute pathname for the specified filename. |
|
|
|
@param paths directories seperated by an OS specific delimiter to search |
|
@param filename filename to search for in the paths |
|
|
|
@return the full absolute pathname to the found filename or an empty |
|
string on failure. |
|
*/ |
|
static String getAbsoluteFileName( |
|
const String& paths, |
|
const String& filename); |
|
|
|
|
|
//#ifdef PEGASUS_ENABLE_PROTOCOL_WEB |
|
// /** |
|
// Returns the absolute filename for the given one. |
|
// |
|
// @param filename filename to resolve absolute path of |
|
// @return the full absolute pathname to the found filename or an empty |
|
// string on failure. |
|
// */ |
|
// static String getAbsoluteFileName( |
|
// const String& filename); |
|
//#endif |
|
|
|
|
|
/** |
|
Convert a library name to its corresponding file name by adding the |
|
appropriate prefix and suffix. |
|
|
|
@param libraryName The name of the library for which to build the file |
|
name. |
|
@return The file name corresponding to the specified library name. |
|
*/ |
|
static String buildLibraryFileName(const String &libraryName); |
|
|
|
/** |
|
Returns the platform-specific file name extension for dynamic |
|
libraries. |
|
|
|
@return the platform-specific file name extension for dynamic |
|
libraries. |
|
*/ |
|
static String getDynamicLibraryExtension(); |
|
|
|
static Boolean changeFileOwner( |
|
const String& fileName, |
|
const String& userName); |
|
|
|
/** |
|
Flushes the data from the iostream buffers to the OS buffers and |
|
then flushes the data from the OS buffers to the disk. |
|
|
|
This will avoid the possible data loss in case of an OS crash when |
|
OS filesystem commit directory-level changes immediately while |
|
file-level changes remain cached (e.g. HP-UX). |
|
|
|
@param fstream. The iostream that we want to flush data. |
|
*/ |
|
static void syncWithDirectoryUpdates(PEGASUS_STD(fstream)&); |
|
|
private: | private: |
| |
FileSystem() { } | FileSystem() { } |
|
|
return !!os; | return !!os; |
} | } |
| |
|
inline String FileSystem::getPathDelimiter() |
|
{ |
|
#if defined(PEGASUS_OS_TYPE_WINDOWS) |
|
return String(";"); |
|
#else |
|
return String(":"); |
|
#endif |
|
} |
|
|
/** Get the next line from the input file. | /** Get the next line from the input file. |
*/ | */ |
PEGASUS_COMMON_LINKAGE Boolean GetLine(PEGASUS_STD(istream)& is, String& line); |
PEGASUS_COMMON_LINKAGE Boolean GetLine(PEGASUS_STD(istream)& is, Buffer& line); |
|
|
|
inline Boolean GetLine(PEGASUS_STD(istream)& is, String& line) |
|
{ |
|
Buffer lineBuffer; |
|
Boolean result = GetLine(is, lineBuffer); |
|
line = String(lineBuffer.getData(), lineBuffer.size()); |
|
return result; |
|
} |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
| |