--- a/browser/confvars.sh
+++ b/browser/confvars.sh
@@ -42,11 +42,10 @@ MOZ_PHOENIX=1
MOZ_ENABLE_LIBXUL=1
MOZ_STATIC_BUILD_UNSUPPORTED=1
MOZ_PLACES=1
# always enabled for form history
MOZ_MORKREADER=1
MOZ_SAFE_BROWSING=1
MOZ_APP_VERSION=$FIREFOX_VERSION
-MOZ_NO_XPCOM_OBSOLETE=1
MOZ_EXTENSIONS_DEFAULT=" gnomevfs reporter"
# MOZ_APP_DISPLAYNAME will be set by branding/configure.sh
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -156,17 +156,16 @@ MOZ_PLACES = @MOZ_PLACES@
MOZ_PLACES_BOOKMARKS = @MOZ_PLACES_BOOKMARKS@
MOZ_STORAGE = @MOZ_STORAGE@
MOZ_SAFE_BROWSING = @MOZ_SAFE_BROWSING@
MOZ_FASTSTART = @MOZ_FASTSTART@
MOZ_URL_CLASSIFIER = @MOZ_URL_CLASSIFIER@
MOZ_ZIPWRITER = @MOZ_ZIPWRITER@
MOZ_MORK = @MOZ_MORK@
MOZ_MORKREADER = @MOZ_MORKREADER@
-MOZ_NO_XPCOM_OBSOLETE = @MOZ_NO_XPCOM_OBSOLETE@
MOZ_NO_FAST_LOAD = @MOZ_NO_FAST_LOAD@
MOZ_OGG = @MOZ_OGG@
MOZ_SYDNEYAUDIO = @MOZ_SYDNEYAUDIO@
MOZ_WAVE = @MOZ_WAVE@
MOZ_MEDIA = @MOZ_MEDIA@
NS_PRINTING = @NS_PRINTING@
MOZ_CRASHREPORTER = @MOZ_CRASHREPORTER@
MOZ_HELP_VIEWER = @MOZ_HELP_VIEWER@
@@ -471,17 +470,16 @@ NSPR_LIBS = @NSPR_LIBS@
NSS_CONFIG = @NSS_CONFIG@
NSS_CFLAGS = @NSS_CFLAGS@
NSS_LIBS = @NSS_LIBS@
NSS_DEP_LIBS = @NSS_DEP_LIBS@
NSS_DISABLE_DBM = @NSS_DISABLE_DBM@
XPCOM_GLUE_LDOPTS = @XPCOM_GLUE_LDOPTS@
XPCOM_STANDALONE_GLUE_LDOPTS = @XPCOM_STANDALONE_GLUE_LDOPTS@
-MOZ_XPCOM_OBSOLETE_LIBS = @MOZ_XPCOM_OBSOLETE_LIBS@
USE_DEPENDENT_LIBS = @USE_DEPENDENT_LIBS@
# UNIX98 iconv support
LIBICONV = @LIBICONV@
# MKSHLIB_FORCE_ALL is used to force the linker to include all object
# files present in an archive. MKSHLIB_UNFORCE_ALL reverts the linker
--- a/config/config.mk
+++ b/config/config.mk
@@ -418,17 +418,16 @@ endif
# Force XPCOM/widget/gfx methods to be _declspec(dllexport) when we're
# building libxul libraries
ifdef MOZ_ENABLE_LIBXUL
ifdef LIBXUL_LIBRARY
DEFINES += \
-D_IMPL_NS_COM \
-DEXPORT_XPT_API \
-DEXPORT_XPTC_API \
- -D_IMPL_NS_COM_OBSOLETE \
-D_IMPL_NS_GFX \
-D_IMPL_NS_WIDGET \
-DIMPL_XREAPI \
-DIMPL_NS_NET \
-DIMPL_THEBES \
$(NULL)
ifndef MOZ_NATIVE_ZLIB
@@ -717,17 +716,17 @@ else
WIN32_EXE_LDFLAGS += -SUBSYSTEM:WINDOWS
endif
endif
endif
endif
# Flags needed to link against the component library
ifdef MOZ_COMPONENTLIB
-MOZ_COMPONENTLIB_EXTRA_DSO_LIBS = mozcomps xpcom_compat
+MOZ_COMPONENTLIB_EXTRA_DSO_LIBS = mozcomps
# Tell the linker where NSS is, if we're building crypto
ifeq ($(OS_ARCH),Darwin)
ifeq (,$(findstring crypto,$(MOZ_META_COMPONENTS)))
MOZ_COMPONENTLIB_EXTRA_LIBS = $(foreach library, $(patsubst -l%, $(LIB_PREFIX)%$(DLL_SUFFIX), $(filter -l%, $(NSS_LIBS))), -dylib_file @executable_path/$(library):$(DIST)/bin/$(library))
endif
endif
endif
--- a/config/static-config.mk
+++ b/config/static-config.mk
@@ -98,21 +98,16 @@ ifdef MOZ_SYDNEYAUDIO
ifeq ($(OS_ARCH),Linux)
STATIC_EXTRA_LIBS += $(MOZ_ALSA_LIBS)
endif
endif
# Component Makefile always brings in this.
# STATIC_EXTRA_LIBS += $(TK_LIBS)
-# Some random modules require this
-ifndef MOZ_NO_XPCOM_OBSOLETE
-STATIC_EXTRA_LIBS += $(MOZ_XPCOM_OBSOLETE_LIBS)
-endif
-
ifeq ($(OS_ARCH),WINNT)
STATIC_EXTRA_LIBS += $(call EXPAND_LIBNAME,comctl32 comdlg32 uuid shell32 ole32 oleaut32 version winspool imm32)
# XXX temporary workaround until link ordering issue is solved
ifdef GNU_CC
STATIC_EXTRA_LIBS += $(call EXPAND_LIBNAME,winmm wsock32 gdi32)
endif
STATIC_EXTRA_LIBS += $(call EXPAND_LIBNAME, usp10)
endif
--- a/configure.in
+++ b/configure.in
@@ -1068,17 +1068,16 @@ MOZ_FIX_LINK_PATHS='-Wl,-rpath-link,$(LI
XPCOM_FROZEN_LDOPTS='-L$(LIBXUL_DIST)/bin -lxpcom'
LIBXUL_LIBS='$(XPCOM_FROZEN_LDOPTS) -lxul'
XPCOM_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) $(XPCOM_FROZEN_LDOPTS)'
XPCOM_STANDALONE_GLUE_LDOPTS='$(LIBXUL_DIST)/lib/$(LIB_PREFIX)xpcomglue.$(LIB_SUFFIX)'
MOZ_FS_LAYOUT=unix
MOZ_COMPONENT_NSPR_LIBS='-L$(LIBXUL_DIST)/bin $(NSPR_LIBS)'
-MOZ_XPCOM_OBSOLETE_LIBS='-L$(LIBXUL_DIST)/lib -lxpcom_compat'
USE_DEPENDENT_LIBS=1
_PLATFORM_DEFAULT_TOOLKIT=cairo-gtk2
MOZ_ENABLE_POSTSCRIPT=1
if test -n "$CROSS_COMPILE"; then
@@ -2034,17 +2033,16 @@ case "$target" in
MKSHLIB_FORCE_ALL=
MKSHLIB_UNFORCE_ALL=
MOZ_COMPONENT_NSPR_LIBS='$(NSPR_LIBS)'
MOZ_COMPONENT_NSPR_LIBS='$(NSPR_LIBS)'
MOZ_DEBUG_FLAGS='-Zi'
MOZ_DEBUG_LDFLAGS='-DEBUG -DEBUGTYPE:CV'
MOZ_FIX_LINK_PATHS=
MOZ_JS_LIBS='$(LIBXUL_DIST)/lib/js$(MOZ_BITS)$(VERSION_NUMBER).lib'
- MOZ_XPCOM_OBSOLETE_LIBS='$(LIBXUL_DIST)/lib/xpcom_compat.lib'
OBJ_SUFFIX=obj
RANLIB='echo not_ranlib'
STRIP='echo not_strip'
TARGET_NSPR_MDCPUCFG='\"md/_wince.cfg\"'
UNZIP=unzip
XARGS=xargs
XPCOM_FROZEN_LDOPTS='$(LIBXUL_DIST)/lib/xpcom.lib'
ZIP=zip
@@ -2145,17 +2143,16 @@ case "$target" in
WARNINGS_AS_ERRORS='-WX'
MOZ_OPTIMIZE_FLAGS='-O1'
MOZ_JS_LIBS='$(LIBXUL_DIST)/lib/js$(MOZ_BITS)$(VERSION_NUMBER).lib'
MOZ_FIX_LINK_PATHS=
DYNAMIC_XPCOM_LIBS='$(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xpcom_core.lib'
XPCOM_FROZEN_LDOPTS='$(LIBXUL_DIST)/lib/xpcom.lib'
LIBXUL_LIBS='$(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xul.lib'
MOZ_COMPONENT_NSPR_LIBS='$(NSPR_LIBS)'
- MOZ_XPCOM_OBSOLETE_LIBS='$(LIBXUL_DIST)/lib/xpcom_compat.lib'
if test $_MSC_VER -ge 1400; then
LDFLAGS="$LDFLAGS -NXCOMPAT -SAFESEH"
dnl For profile-guided optimization
PROFILE_GEN_CFLAGS="-GL"
PROFILE_GEN_LDFLAGS="-LTCG:PGINSTRUMENT"
dnl XXX: PGO builds can fail with warnings treated as errors,
dnl specifically "no profile data available" appears to be
dnl treated as an error sometimes. This might be a consequence
@@ -2445,17 +2442,16 @@ case "$target" in
BIN_FLAGS='-Zlinker /ST:0x100000'
IMPLIB='emximp -o'
FILTER='emxexp -o'
LDFLAGS='-Zmap'
WARNINGS_AS_ERRORS='-Werror'
MOZ_DEBUG_FLAGS="-g -fno-inline"
MOZ_OPTIMIZE_FLAGS="-O2"
MOZ_OPTIMIZE_LDFLAGS="-s -Zlinker /EXEPACK:2 -Zlinker /PACKCODE -Zlinker /PACKDATA"
- MOZ_XPCOM_OBSOLETE_LIBS='-L$(LIBXUL_DIST)/lib $(LIBXUL_DIST)/lib/xpcomct.lib'
DYNAMIC_XPCOM_LIBS='-L$(LIBXUL_DIST)/lib $(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xpcomcor.lib'
LIBXUL_LIBS='-L$(LIBXUL_DIST)/lib $(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xul.lib'
TARGET_MD_ARCH=os2
_PLATFORM_DEFAULT_TOOLKIT="cairo-os2"
MOZ_ENABLE_POSTSCRIPT=
RC=rc.exe
RCFLAGS='-n'
MOZ_USER_DIR="Mozilla"
@@ -4491,17 +4487,16 @@ MOZ_JAVAXPCOM=
MOZ_JSDEBUGGER=1
MOZ_JSLOADER=1
MOZ_MATHML=1
MOZ_MORK=1
MOZ_MORKREADER=
MOZ_AUTH_EXTENSION=1
MOZ_NO_ACTIVEX_SUPPORT=1
MOZ_NO_INSPECTOR_APIS=
-MOZ_NO_XPCOM_OBSOLETE=
MOZ_NO_FAST_LOAD=
MOZ_OGG=1
MOZ_SYDNEYAUDIO=
MOZ_WAVE=1
MOZ_MEDIA=
MOZ_PERMISSIONS=1
MOZ_PLACES=
MOZ_PLAINTEXT_EDITOR_ONLY=
@@ -4608,17 +4603,16 @@ basic)
MOZ_IMG_ENCODERS_DEFAULT=
MOZ_IMG_ENCODERS=
MOZ_INSTALLER=
MOZ_JSDEBUGGER=
MOZ_MATHML=
MOZ_AUTH_EXTENSION=
MOZ_NO_ACTIVEX_SUPPORT=1
MOZ_NO_INSPECTOR_APIS=1
- MOZ_NO_XPCOM_OBSOLETE=1
MOZ_NO_FAST_LOAD=1
MOZ_PLAINTEXT_EDITOR_ONLY=1
# MOZ_PLUGINS=
MOZ_PREF_EXTENSIONS=
MOZ_PROFILELOCKING=
MOZ_SPELLCHECK=
MOZ_SVG=
MOZ_UNIVERSALCHARDET=
@@ -4650,17 +4644,16 @@ minimal)
MOZ_IMG_ENCODERS_DEFAULT=
MOZ_IMG_ENCODERS=
MOZ_INSTALLER=
MOZ_JSDEBUGGER=
MOZ_MATHML=
MOZ_AUTH_EXTENSION=
MOZ_NO_ACTIVEX_SUPPORT=1
MOZ_NO_INSPECTOR_APIS=1
- MOZ_NO_XPCOM_OBSOLETE=1
MOZ_NO_FAST_LOAD=1
MOZ_PLAINTEXT_EDITOR_ONLY=1
MOZ_PLUGINS=
MOZ_PREF_EXTENSIONS=
MOZ_PROFILELOCKING=
MOZ_SPELLCHECK=
MOZ_STORAGE=1
MOZ_PLACES=
@@ -5465,28 +5458,16 @@ MOZ_ARG_ENABLE_BOOL(plaintext-editor-onl
[ --enable-plaintext-editor-only
Allow only plaintext editing],
MOZ_PLAINTEXT_EDITOR_ONLY=1,
MOZ_PLAINTEXT_EDITOR_ONLY= )
dnl Note the #define is MOZILLA, not MOZ, for compat with the Mac build.
AC_SUBST(MOZ_PLAINTEXT_EDITOR_ONLY)
dnl ========================================================
-dnl = Drop XPCOM Obsolete library
-dnl ========================================================
-MOZ_ARG_DISABLE_BOOL(xpcom-obsolete,
-[ --disable-xpcom-obsolete Disable XPCOM Obsolete Library],
- MOZ_NO_XPCOM_OBSOLETE=1,
- MOZ_NO_XPCOM_OBSOLETE=)
-
-if test -n "$MOZ_NO_XPCOM_OBSOLETE"; then
- AC_DEFINE(MOZ_NO_XPCOM_OBSOLETE)
-fi
-
-dnl ========================================================
dnl = Disable Fast Load
dnl ========================================================
MOZ_ARG_DISABLE_BOOL(xpcom-fastload,
[ --disable-xpcom-fastload Disable XPCOM fastload support],
MOZ_NO_FAST_LOAD=1,
MOZ_NO_FAST_LOAD=)
AC_SUBST(MOZ_NO_FAST_LOAD)
@@ -5837,21 +5818,16 @@ if test `echo "$MOZ_EXTENSIONS" | grep -
MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|java||g'`
fi
if test `echo "$MOZ_EXTENSIONS" | grep -c spellcheck` -ne 0; then
AC_MSG_WARN([spellcheck is no longer an extension.])
MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|spellcheck||g'`
fi
-if test -n "$MOZ_NO_XPCOM_OBSOLETE" && test `echo "$MOZ_EXTENSIONS" | grep -c sroaming` -ne 0; then
- AC_MSG_WARN([Cannot currently build sroaming without xpcom obsolete -- bug 249343. Removing sroaming from MOZ_EXTENSIONS.])
- MOZ_EXTENSIONS=`echo $MOZ_EXTENSIONS | sed -e 's|sroaming||'`
-fi
-
dnl Remove dupes
MOZ_EXTENSIONS=`${PERL} ${srcdir}/build/unix/uniq.pl ${MOZ_EXTENSIONS}`
dnl Ensure every extension exists, to avoid mostly-inscrutable error messages
dnl when trying to build a non-existent extension.
for extension in $MOZ_EXTENSIONS; do
if test ! -d "${srcdir}/extensions/${extension}"; then
AC_MSG_ERROR([Unrecognized extension provided to --enable-extensions: ${extension}.])
@@ -7975,17 +7951,16 @@ AC_SUBST(MOZ_DEBUG_DISABLE_DEFS)
AC_SUBST(MOZ_DEBUG_FLAGS)
AC_SUBST(MOZ_DEBUG_LDFLAGS)
AC_SUBST(WARNINGS_AS_ERRORS)
AC_SUBST(MOZ_DBGRINFO_MODULES)
AC_SUBST(MOZ_EXTENSIONS)
AC_SUBST(MOZ_IMG_DECODERS)
AC_SUBST(MOZ_IMG_ENCODERS)
AC_SUBST(MOZ_JSDEBUGGER)
-AC_SUBST(MOZ_NO_XPCOM_OBSOLETE)
AC_SUBST(MOZ_PLUGINS)
AC_SUBST(ENABLE_EAZEL_PROFILER)
AC_SUBST(EAZEL_PROFILER_CFLAGS)
AC_SUBST(EAZEL_PROFILER_LIBS)
AC_SUBST(GC_LEAK_DETECTOR)
AC_SUBST(MOZ_LOG_REFCNT)
AC_SUBST(MOZ_LEAKY)
AC_SUBST(MOZ_JPROF)
@@ -8034,17 +8009,16 @@ AC_SUBST(MOZ_USER_DIR)
AC_SUBST(MOZ_CRASHREPORTER)
AC_SUBST(ENABLE_STRIP)
AC_SUBST(PKG_SKIP_STRIP)
AC_SUBST(USE_ELF_DYNSTR_GC)
AC_SUBST(INCREMENTAL_LINKER)
AC_SUBST(MOZ_COMPONENTS_VERSION_SCRIPT_LDFLAGS)
AC_SUBST(MOZ_COMPONENT_NSPR_LIBS)
-AC_SUBST(MOZ_XPCOM_OBSOLETE_LIBS)
AC_SUBST(MOZ_FIX_LINK_PATHS)
AC_SUBST(XPCOM_LIBS)
AC_SUBST(XPCOM_FROZEN_LDOPTS)
AC_SUBST(XPCOM_GLUE_LDOPTS)
AC_SUBST(XPCOM_STANDALONE_GLUE_LDOPTS)
AC_SUBST(USE_DEPENDENT_LIBS)
--- a/embedding/config/basebrowser-mac-macho
+++ b/embedding/config/basebrowser-mac-macho
@@ -24,19 +24,16 @@ libplds4.dylib
libmozjs.dylib
;
; XPCOM:
;
libxpcom.dylib
libxpcom_core.dylib
-libxpcom_compat.dylib
-components/libxpcom_compat_c.dylib
-components/xpcom_obsolete.xpt
;
; Components: (need to trim fat)
;
; appshell
components/libnsappshell.dylib
--- a/embedding/config/basebrowser-qnx
+++ b/embedding/config/basebrowser-qnx
@@ -29,19 +29,16 @@ libmozjs.so
libxpcom.so
libxpcom_core.so
components/xpcom_base.xpt
components/xpcom_components.xpt
components/xpcom_ds.xpt
components/xpcom_io.xpt
components/xpcom_threads.xpt
components/xpcom_xpti.xpt
-libxpcom_compat.so
-components/libxpcom_compat_c.so
-components/xpcom_obsolete.xpt
; xpconnect
components/libxpconnect.so
components/xpconnect.xpt
;
; XP widgets/graphics
;
--- a/embedding/config/basebrowser-unix
+++ b/embedding/config/basebrowser-unix
@@ -29,19 +29,16 @@ libmozjs.so
libxpcom.so
libxpcom_core.so
components/xpcom_base.xpt
components/xpcom_components.xpt
components/xpcom_ds.xpt
components/xpcom_io.xpt
components/xpcom_threads.xpt
components/xpcom_xpti.xpt
-libxpcom_compat.so
-components/libxpcom_compat_c.so
-components/xpcom_obsolete.xpt
; xpconnect
components/libxpconnect.so
components/xpconnect.xpt
;
; XP widgets/graphics
;
--- a/embedding/config/basebrowser-win
+++ b/embedding/config/basebrowser-win
@@ -41,28 +41,25 @@ plds4.dll
;
js3250.dll
;
; XPCOM:
;
xpcom.dll
xpcom_core.dll
-xpcom_compat.dll
-components\xpcom_compat_c.dll
components\xpcom_base.xpt
components\xpcom_components.xpt
components\xpcom_ds.xpt
components\xpcom_io.xpt
components\xpcom_nativeapp.xpt
components\xpcom_thread.xpt
components\xpcom_xpti.xpt
components\mozreg.dll
;components\mozreg.xpt
-components\xpcom_obsolete.xpt
; required prefs files
greprefs\*
; xpconnect
components\xpc3250.dll
components\xpconnect.xpt
--- a/js/src/config/config.mk
+++ b/js/src/config/config.mk
@@ -418,17 +418,16 @@ endif
# Force XPCOM/widget/gfx methods to be _declspec(dllexport) when we're
# building libxul libraries
ifdef MOZ_ENABLE_LIBXUL
ifdef LIBXUL_LIBRARY
DEFINES += \
-D_IMPL_NS_COM \
-DEXPORT_XPT_API \
-DEXPORT_XPTC_API \
- -D_IMPL_NS_COM_OBSOLETE \
-D_IMPL_NS_GFX \
-D_IMPL_NS_WIDGET \
-DIMPL_XREAPI \
-DIMPL_NS_NET \
-DIMPL_THEBES \
$(NULL)
ifndef MOZ_NATIVE_ZLIB
@@ -717,17 +716,17 @@ else
WIN32_EXE_LDFLAGS += -SUBSYSTEM:WINDOWS
endif
endif
endif
endif
# Flags needed to link against the component library
ifdef MOZ_COMPONENTLIB
-MOZ_COMPONENTLIB_EXTRA_DSO_LIBS = mozcomps xpcom_compat
+MOZ_COMPONENTLIB_EXTRA_DSO_LIBS = mozcomps
# Tell the linker where NSS is, if we're building crypto
ifeq ($(OS_ARCH),Darwin)
ifeq (,$(findstring crypto,$(MOZ_META_COMPONENTS)))
MOZ_COMPONENTLIB_EXTRA_LIBS = $(foreach library, $(patsubst -l%, $(LIB_PREFIX)%$(DLL_SUFFIX), $(filter -l%, $(NSS_LIBS))), -dylib_file @executable_path/$(library):$(DIST)/bin/$(library))
endif
endif
endif
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -872,17 +872,16 @@ WIN_TOP_SRC=
MOZ_USER_DIR=".mozilla"
HOST_AR='$(AR)'
HOST_AR_FLAGS='$(AR_FLAGS)'
MOZ_JS_LIBS='-L$(libdir) -lmozjs'
MOZ_FIX_LINK_PATHS='-Wl,-rpath-link,$(LIBXUL_DIST)/bin -Wl,-rpath-link,$(PREFIX)/lib'
MOZ_COMPONENT_NSPR_LIBS='-L$(LIBXUL_DIST)/bin $(NSPR_LIBS)'
-MOZ_XPCOM_OBSOLETE_LIBS='-L$(LIBXUL_DIST)/lib -lxpcom_compat'
USE_DEPENDENT_LIBS=1
_PLATFORM_DEFAULT_TOOLKIT=cairo-gtk2
MOZ_ENABLE_POSTSCRIPT=1
if test -n "$CROSS_COMPILE"; then
@@ -1832,17 +1831,16 @@ case "$target" in
MKSHLIB_FORCE_ALL=
MKSHLIB_UNFORCE_ALL=
MOZ_COMPONENT_NSPR_LIBS='$(NSPR_LIBS)'
MOZ_COMPONENT_NSPR_LIBS='$(NSPR_LIBS)'
MOZ_DEBUG_FLAGS='-Zi'
MOZ_DEBUG_LDFLAGS='-DEBUG -DEBUGTYPE:CV'
MOZ_FIX_LINK_PATHS=
MOZ_JS_LIBS='$(libdir)/js$(MOZ_BITS)$(VERSION_NUMBER).lib'
- MOZ_XPCOM_OBSOLETE_LIBS='$(LIBXUL_DIST)/lib/xpcom_compat.lib'
OBJ_SUFFIX=obj
RANLIB='echo not_ranlib'
STRIP='echo not_strip'
TARGET_NSPR_MDCPUCFG='\"md/_wince.cfg\"'
UNZIP=unzip
XARGS=xargs
XPCOM_FROZEN_LDOPTS='$(LIBXUL_DIST)/lib/xpcom.lib'
ZIP=zip
@@ -1957,17 +1955,16 @@ case "$target" in
WARNINGS_AS_ERRORS='-WX'
MOZ_OPTIMIZE_FLAGS='-O1'
MOZ_JS_LIBS='$(libdir)/js$(MOZ_BITS)$(VERSION_NUMBER).lib'
MOZ_FIX_LINK_PATHS=
DYNAMIC_XPCOM_LIBS='$(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xpcom_core.lib'
XPCOM_FROZEN_LDOPTS='$(LIBXUL_DIST)/lib/xpcom.lib'
LIBXUL_LIBS='$(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xul.lib'
MOZ_COMPONENT_NSPR_LIBS='$(NSPR_LIBS)'
- MOZ_XPCOM_OBSOLETE_LIBS='$(LIBXUL_DIST)/lib/xpcom_compat.lib'
if test $_MSC_VER -ge 1400; then
LDFLAGS="$LDFLAGS -NXCOMPAT -SAFESEH"
dnl For profile-guided optimization
PROFILE_GEN_CFLAGS="-GL"
PROFILE_GEN_LDFLAGS="-LTCG:PGINSTRUMENT"
dnl XXX: PGO builds can fail with warnings treated as errors,
dnl specifically "no profile data available" appears to be
dnl treated as an error sometimes. This might be a consequence
@@ -2172,17 +2169,16 @@ case "$target" in
BIN_FLAGS='-Zlinker /ST:0x100000'
IMPLIB='emximp -o'
FILTER='emxexp -o'
LDFLAGS='-Zmap'
WARNINGS_AS_ERRORS='-Werror'
MOZ_DEBUG_FLAGS="-g -fno-inline"
MOZ_OPTIMIZE_FLAGS="-O2"
MOZ_OPTIMIZE_LDFLAGS="-s -Zlinker /EXEPACK:2 -Zlinker /PACKCODE -Zlinker /PACKDATA"
- MOZ_XPCOM_OBSOLETE_LIBS='-L$(LIBXUL_DIST)/lib $(LIBXUL_DIST)/lib/xpcomct.lib'
DYNAMIC_XPCOM_LIBS='-L$(LIBXUL_DIST)/lib $(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xpcomcor.lib'
LIBXUL_LIBS='-L$(LIBXUL_DIST)/lib $(LIBXUL_DIST)/lib/xpcom.lib $(LIBXUL_DIST)/lib/xul.lib'
TARGET_MD_ARCH=os2
_PLATFORM_DEFAULT_TOOLKIT="cairo-os2"
MOZ_ENABLE_POSTSCRIPT=
RC=rc.exe
RCFLAGS='-n'
MOZ_USER_DIR="Mozilla"
--- a/modules/libpref/src/Makefile.in
+++ b/modules/libpref/src/Makefile.in
@@ -48,20 +48,16 @@ EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsPrefModule
ifeq ($(OS_ARCH)$(MOZ_ENABLE_LIBXUL),WINNT)
LIBRARY_NAME = xppref$(MOZ_BITS)
endif
GRE_MODULE = 1
LIBXUL_LIBRARY = 1
-
-ifndef MOZ_NO_XPCOM_OBSOLETE
-endif
-
include $(topsrcdir)/config/config.mk
CPPSRCS = nsPref.cpp \
nsPrefBranch.cpp \
nsPrefService.cpp \
nsPrefsFactory.cpp \
prefapi.cpp \
prefread.cpp \
--- a/modules/libpref/src/nsPref.cpp
+++ b/modules/libpref/src/nsPref.cpp
@@ -55,20 +55,16 @@
#include "nsIPrefBranchInternal.h"
#include "nsIFactory.h"
#include "nsIComponentManager.h"
#include "nsIObserver.h"
#include "nsCOMPtr.h"
#include "nsMemory.h"
#include "prefapi.h"
-#ifndef MOZ_NO_XPCOM_OBSOLETE
-#include "nsIFileSpec.h"
-#endif
-
#include "nsString.h"
#include "nsILocalFile.h"
#include "nsIPrefBranch.h"
#include "nsIPrefLocalizedString.h"
#include "nsISecurityPref.h"
#include "nsIPrefService.h"
#include "nsISupportsPrimitives.h"
#include "nsWeakReference.h"
@@ -495,44 +491,22 @@ NS_IMETHODIMP nsPref::GetDefaultLocalize
rv = theString->ToString(_retval);
}
return rv;
}
NS_IMETHODIMP nsPref::GetFilePref(const char *pref, nsIFileSpec **_retval)
{
-#ifdef MOZ_NO_XPCOM_OBSOLETE
return NS_ERROR_NOT_IMPLEMENTED;
-#else
- nsresult rv;
-
- nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(mPrefService, &rv);
- if (NS_SUCCEEDED(rv))
- rv = prefBranch->GetComplexValue(pref, NS_GET_IID(nsIFileSpec), (void **)_retval);
- return rv;
-#endif
}
NS_IMETHODIMP nsPref::SetFilePref(const char *pref, nsIFileSpec *value, PRBool setDefault)
{
-#ifdef MOZ_NO_XPCOM_OBSOLETE
return NS_ERROR_NOT_IMPLEMENTED;
-#else
- nsresult rv;
-
- if (setDefault) {
- rv = mDefaultBranch->SetComplexValue(pref, NS_GET_IID(nsIFileSpec), value);
- } else {
- nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(mPrefService, &rv);
- if (NS_SUCCEEDED(rv))
- rv = prefBranch->SetComplexValue(pref, NS_GET_IID(nsIFileSpec), value);
- }
- return rv;
-#endif
}
NS_IMETHODIMP nsPref::GetFileXPref(const char *pref, nsILocalFile **_retval)
{
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefBranch = do_QueryInterface(mPrefService, &rv);
if (NS_SUCCEEDED(rv))
--- a/modules/libpref/src/nsPrefBranch.cpp
+++ b/modules/libpref/src/nsPrefBranch.cpp
@@ -47,20 +47,16 @@
#include "nsReadableUtils.h"
#include "nsXPIDLString.h"
#include "nsIStringBundle.h"
#include "prefapi.h"
#include "prmem.h"
#include "pldhash.h"
#include "nsPrefsCID.h"
-#ifndef MOZ_NO_XPCOM_OBSOLETE
-#include "nsIFileSpec.h" // this should be removed eventually
-#endif
-
#include "plstr.h"
#include "nsCRT.h"
#include "prefapi_private_data.h"
// Definitions
struct EnumerateData {
const char *parent;
@@ -347,39 +343,16 @@ NS_IMETHODIMP nsPrefBranch::GetComplexVa
NS_ADDREF(temp);
*_retval = (void *)temp;
return NS_OK;
}
}
return rv;
}
- // This is deprecated and you should not be using it
-#ifndef MOZ_NO_XPCOM_OBSOLETE
- if (aType.Equals(NS_GET_IID(nsIFileSpec))) {
- nsCOMPtr<nsIFileSpec> file(do_CreateInstance(NS_FILESPEC_CONTRACTID, &rv));
-
- if (NS_SUCCEEDED(rv)) {
- nsIFileSpec *temp = file;
- PRBool valid;
-
- file->SetPersistentDescriptorString(utf8String); // only returns NS_OK
- file->IsValid(&valid);
- if (!valid) {
- /* if the string wasn't a valid persistent descriptor, it might be a valid native path */
- file->SetNativePath(utf8String);
- }
- NS_ADDREF(temp);
- *_retval = (void *)temp;
- return NS_OK;
- }
- return rv;
- }
-#endif
-
NS_WARNING("nsPrefBranch::GetComplexValue - Unsupported interface type");
return NS_NOINTERFACE;
}
NS_IMETHODIMP nsPrefBranch::SetComplexValue(const char *aPrefName, const nsIID & aType, nsISupports *aValue)
{
nsresult rv = NS_NOINTERFACE;
@@ -452,32 +425,16 @@ NS_IMETHODIMP nsPrefBranch::SetComplexVa
rv = theString->GetData(getter_Copies(wideString));
if (NS_SUCCEEDED(rv)) {
rv = SetCharPref(aPrefName, NS_ConvertUTF16toUTF8(wideString).get());
}
}
return rv;
}
-#ifndef MOZ_NO_XPCOM_OBSOLETE
- // This is deprecated and you should not be using it
- if (aType.Equals(NS_GET_IID(nsIFileSpec))) {
- nsCOMPtr<nsIFileSpec> file = do_QueryInterface(aValue);
- if (!file)
- return NS_NOINTERFACE;
- nsXPIDLCString descriptorString;
-
- rv = file->GetPersistentDescriptorString(getter_Copies(descriptorString));
- if (NS_SUCCEEDED(rv)) {
- rv = SetCharPref(aPrefName, descriptorString);
- }
- return rv;
- }
-#endif
-
NS_WARNING("nsPrefBranch::SetComplexValue - Unsupported interface type");
return NS_NOINTERFACE;
}
NS_IMETHODIMP nsPrefBranch::ClearUserPref(const char *aPrefName)
{
const char *pref;
nsresult rv;
--- a/netwerk/build.mk
+++ b/netwerk/build.mk
@@ -61,25 +61,21 @@ endif
# the offline cache uses mozStorage
ifdef MOZ_STORAGE
tier_necko_dirs += storage/public
endif
# these are only in the necko tier because libpref needs it
ifndef WINCE
-ifneq (1_,$(MOZ_NO_XPCOM_OBSOLETE)_$(MOZ_XPINSTALL))
+ifneq (,$(MOZ_XPINSTALL))
tier_necko_dirs += modules/libreg
endif
endif
-ifndef MOZ_NO_XPCOM_OBSOLETE
-tier_necko_dirs += xpcom/obsolete
-endif
-
tier_necko_dirs += \
modules/libpref \
intl \
netwerk \
$(NULL)
ifdef MOZ_AUTH_EXTENSION
tier_necko_dirs += extensions/auth
--- a/netwerk/confvars.sh
+++ b/netwerk/confvars.sh
@@ -34,10 +34,9 @@
# 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 *****
MOZ_APP_NAME=mozilla
MOZ_EXTENSIONS_DEFAULT=""
MOZ_APP_VERSION=$MOZILLA_VERSION
-MOZ_NO_XPCOM_OBSOLETE=1
MOZ_XPINSTALL=
--- a/toolkit/toolkit-makefiles.sh
+++ b/toolkit/toolkit-makefiles.sh
@@ -559,21 +559,16 @@ MAKEFILES_xpcom="
xpcom/threads/Makefile
xpcom/tools/Makefile
xpcom/tools/registry/Makefile
xpcom/stub/Makefile
xpcom/windbgdlg/Makefile
xpcom/system/Makefile
"
-MAKEFILES_xpcom_obsolete="
- xpcom/obsolete/Makefile
- xpcom/obsolete/component/Makefile
-"
-
MAKEFILES_xpcom_tests="
xpcom/tests/Makefile
xpcom/tests/dynamic/Makefile
xpcom/tests/services/Makefile
xpcom/tests/windows/Makefile
xpcom/tests/static-checker/Makefile
"
@@ -677,17 +672,16 @@ MAKEFILES_xulapp="
toolkit/crashreporter/google-breakpad/src/common/mac/Makefile
toolkit/crashreporter/google-breakpad/src/common/mac/dwarf/Makefile
toolkit/crashreporter/google-breakpad/src/common/solaris/Makefile
toolkit/crashreporter/google-breakpad/src/common/windows/Makefile
toolkit/crashreporter/google-breakpad/src/tools/linux/dump_syms/Makefile
toolkit/crashreporter/google-breakpad/src/tools/mac/dump_syms/Makefile
toolkit/crashreporter/google-breakpad/src/tools/solaris/dump_syms/Makefile
toolkit/content/Makefile
- toolkit/obsolete/Makefile
toolkit/components/alerts/Makefile
toolkit/components/alerts/public/Makefile
toolkit/components/alerts/src/Makefile
toolkit/components/alerts/src/mac/Makefile
toolkit/components/alerts/src/mac/growl/Makefile
toolkit/components/apppicker/Makefile
toolkit/components/autocomplete/Makefile
toolkit/components/autocomplete/public/Makefile
@@ -866,17 +860,16 @@ add_makefiles "
$MAKEFILES_sun_java
$MAKEFILES_caps
$MAKEFILES_chrome
$MAKEFILES_view
$MAKEFILES_docshell
$MAKEFILES_webshell
$MAKEFILES_widget
$MAKEFILES_xpcom
- $MAKEFILES_xpcom_obsolete
$MAKEFILES_xpcom_tests
$MAKEFILES_xpinstall
$MAKEFILES_xpfe
$MAKEFILES_embedding
$MAKEFILES_xulapp
$MAKEFILES_libpr0n
$MAKEFILES_accessible
$MAKEFILES_zlib
deleted file mode 100644
--- a/xpcom/obsolete/Makefile.in
+++ /dev/null
@@ -1,122 +0,0 @@
-#
-# ***** 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
-# http://www.mozilla.org/MPL/
-#
-# 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 mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Netscape Communications Corporation.
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#
-# 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 *****
-
-DEPTH = ../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE = xpcom_obsolete
-LIBRARY_NAME = xpcom_compat
-ifneq (,$(filter-out WINNT WINCE,$(OS_ARCH)))
-SHORT_LIBNAME = xpcomct
-endif
-
-GRE_MODULE = 1
-LIBXUL_LIBRARY = 1
-
-DIRS = component
-
-
-CPPSRCS = \
- nsFileSpec.cpp \
- nsFileStream.cpp \
- nsIFileStream.cpp \
- nsFileSpecImpl.cpp \
- $(NULL)
-
-ifeq (,$(filter-out WINNT WINCE OS2,$(OS_ARCH)))
-ifndef MOZ_ENABLE_LIBXUL
-CPPSRCS += dlldeps-obs.cpp
-endif
-endif
-
-EXPORTS = \
- xpcomobsolete.h \
- nsFileSpec.h \
- nsFileStream.h \
- nsIFileStream.h \
- nsIRegistryUtils.h \
- $(NULL)
-
-LOCAL_INCLUDES = \
- -I.. \
- -I$(srcdir)/../io \
- $(NULL)
-
-XPIDLSRCS = nsIFileSpec.idl \
- nsIRegistry.idl \
- $(NULL)
-
-# Force use of PIC
-FORCE_USE_PIC = 1
-
-# due to symbol conflicts on win32, this needs to be shared
-ifndef MOZ_ENABLE_LIBXUL
-FORCE_SHARED_LIB = 1
-endif
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += -D_IMPL_NS_COM_OBSOLETE
-
-EXTRA_DSO_LDOPTS += \
- $(DEPTH)/modules/libreg/src/$(LIB_PREFIX)mozreg_s.$(LIB_SUFFIX) \
- $(MOZ_COMPONENT_LIBS) \
- $(NULL)
-
-ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
-CXXFLAGS += $(TK_CFLAGS)
-EXTRA_DSO_LDOPTS += $(TK_LIBS)
-endif
-
-ifeq ($(OS_ARCH),BeOS)
-EXTRA_DSO_LDOPTS += -lbe
-endif
-
-ifeq ($(OS_ARCH),WINNT)
-EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME, shell32 ole32)
-ifneq (,$(MOZ_DEBUG)$(NS_TRACE_MALLOC))
-EXTRA_DSO_LDOPTS += $(call EXPAND_LIBNAME, imagehlp)
-endif
-ifdef GNU_CXX
-DSO_LDOPTS += -Wl,--export-all-symbols
-endif
-endif # WINNT
-
deleted file mode 100644
--- a/xpcom/obsolete/component/Makefile.in
+++ /dev/null
@@ -1,79 +0,0 @@
-#
-# ***** 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
-# http://www.mozilla.org/MPL/
-#
-# 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 mozilla.org code.
-#
-# The Initial Developer of the Original Code is
-# Netscape Communications Corporation.
-# Portions created by the Initial Developer are Copyright (C) 1998
-# the Initial Developer. All Rights Reserved.
-#
-# Contributor(s):
-#
-# 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 *****
-
-DEPTH = ../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(DEPTH)/config/autoconf.mk
-
-MODULE = xpcom_compat_c
-MODULE_NAME = xpcomObsoleteModule
-LIBRARY_NAME = xpcom_compat_c
-ifneq ($(OS_ARCH),WINNT)
-SHORT_LIBNAME = xpcomctc
-endif
-
-EXPORT_LIBRARY = 1
-IS_COMPONENT = 1
-GRE_MODULE = 1
-LIBXUL_LIBRARY = 1
-
-
-CPPSRCS = \
- nsXPCOMObsolete.cpp \
- nsRegistry.cpp \
- $(NULL)
-
-
-LOCAL_INCLUDES = \
- -I$(srcdir)/../ \
- $(NULL)
-
-EXTRA_DSO_LDOPTS += \
- $(DEPTH)/modules/libreg/src/$(LIB_PREFIX)mozreg_s.$(LIB_SUFFIX) \
- $(MOZ_COMPONENT_LIBS) \
- $(MOZ_XPCOM_OBSOLETE_LIBS) \
- $(NULL)
-
-include $(topsrcdir)/config/rules.mk
-
-ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
-CXXFLAGS += $(TK_CFLAGS)
-EXTRA_DSO_LDOPTS += $(TK_LIBS)
-endif
deleted file mode 100644
--- a/xpcom/obsolete/component/nsRegistry.cpp
+++ /dev/null
@@ -1,2019 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * 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 ***** */
-
-#ifdef MOZ_LOGGING
-#define FORCE_PR_LOG /* Allow logging in the release build */
-#endif
-
-#include "nsIGenericFactory.h"
-
-#include "nsRegistry.h"
-#include "nsIEnumerator.h"
-#include "nsDirectoryService.h"
-#include "nsDirectoryServiceDefs.h"
-#include "nsAppDirectoryServiceDefs.h"
-#include "NSReg.h"
-#include "prmem.h"
-#include "prlock.h"
-#include "prlog.h"
-#include "prprf.h"
-#include "nsCRT.h"
-#include "nsMemory.h"
-
-#include "nsCOMPtr.h"
-#include "nsILocalFile.h"
-#include "nsIServiceManager.h"
-#include "nsTextFormatter.h"
-
-#ifdef XP_BEOS
-#include <FindDirectory.h>
-#include <Path.h>
-#endif
-
-/* extra locking for the paranoid */
-/* #define EXTRA_THREADSAFE */
-#ifndef EXTRA_THREADSAFE
-#define PR_Lock(x) (void)0
-#define PR_Unlock(x) (void)0
-#endif
-
-// Logging of debug output
-extern NS_COM PRLogModuleInfo *nsComponentManagerLog;
-
-PRUnichar widestrFormat[] = { PRUnichar('%'),PRUnichar('s'),PRUnichar(0)};
-
-/*-------------------------------- nsRegistry ----------------------------------
-| This class implements the nsIRegistry interface using the functions |
-| provided by libreg (as declared in mozilla/modules/libreg/include/NSReg.h). |
-| |
-| Since that interface is designed to match the libreg function, this class |
-| is implemented with each member function being a simple wrapper for the |
-| corresponding libreg function. |
-| |
-| #define EXTRA_THREADSAFE if you are worried about libreg thread safety. |
-| It should not be necessary, but I'll leave in the code for the paranoid. |
-------------------------------------------------------------------------------*/
-
-#define NS_MOZILLA_DIR_PERMISSION 00700
-
-#include "nsRegistry.h"
-/*
-struct nsRegistry : public nsIRegistry {
- // This class implements the nsISupports interface functions.
- NS_DECL_ISUPPORTS
-
- // This class implements the nsIRegistry interface functions.
- NS_DECL_NSIREGISTRY
-
- // ctor/dtor
- nsRegistry();
-
-private:
- ~nsRegistry();
-
-protected:
- HREG mReg; // Registry handle.
-#ifdef EXTRA_THREADSAFE
- PRLock *mregLock; // libreg isn't threadsafe. Use locks to synchronize.
-#endif
- char *mCurRegFile; // these are to prevent open from opening the registry again
- nsWellKnownRegistry mCurRegID;
-
- NS_IMETHOD Close();
-}; // nsRegistry
-*/
-
-#include "nsIFactory.h"
-/*----------------------------- nsRegistryFactory ------------------------------
-| Class factory for nsRegistry objects. |
-------------------------------------------------------------------------------*/
-struct nsRegistryFactory : public nsIFactory {
- // This class implements the nsISupports interface functions.
- NS_DECL_ISUPPORTS
-
- // nsIFactory methods
- NS_IMETHOD CreateInstance(nsISupports *,const nsIID &,void **);
- NS_IMETHOD LockFactory(PRBool aLock);
-
- // ctor
- nsRegistryFactory();
-};
-
-
-/*--------------------------- nsRegSubtreeEnumerator ---------------------------
-| This class implements the nsIEnumerator interface and is used to implement |
-| the nsRegistry EnumerateSubtrees and EnumerateAllSubtrees functions. |
-------------------------------------------------------------------------------*/
-struct nsRegSubtreeEnumerator : public nsIRegistryEnumerator {
- // This class implements the nsISupports interface functions.
- NS_DECL_ISUPPORTS
-
- // This class implements the nsIEnumerator interface functions.
- NS_DECL_NSIENUMERATOR
-
- // And our magic behind-the-back fast-path thing.
- NS_DECL_NSIREGISTRYENUMERATOR
-
- // ctor/dtor
- nsRegSubtreeEnumerator( HREG hReg, RKEY rKey, PRBool all );
- // virtual dtor since subclasses call our Release()
- virtual ~nsRegSubtreeEnumerator();
-
-protected:
- NS_IMETHOD advance(); // Implementation file; does appropriate NR_RegEnum call.
- HREG mReg; // Handle to registry we're affiliated with.
- RKEY mKey; // Base key being enumerated.
- char mName[MAXREGPATHLEN]; // The name of the current key which is in mNext
- REGENUM mEnum; // Corresponding libreg "enumerator".
- REGENUM mNext; // Lookahead value.
- PRUint32 mStyle; // Style (indicates all or some);
- PRBool mDone; // Done flag.
-#ifdef EXTRA_THREADSAFE
- PRLock *mregLock;
-#endif
-}; // nsRegSubtreeEnumerator
-
-
-/*--------------------------- nsRegValueEnumerator -----------------------------
-| This class is a variation on nsRegSubtreeEnumerator that allocates |
-| nsRegistryValue objects rather than nsRegistryNode objects. It also |
-| overrides certain functions to make sure the "value" oriented libreg |
-| functions used rather than the subtree oriented ones. |
-------------------------------------------------------------------------------*/
-struct nsRegValueEnumerator : public nsRegSubtreeEnumerator {
- // Override CurrentItem to allocate nsRegistryValue objects.
- NS_IMETHOD CurrentItem( nsISupports **result );
-
- // Override advance() to use proper NR_RegEnumEntries.
- NS_IMETHOD advance();
-
- // ctor/dtor
- nsRegValueEnumerator( HREG hReg, RKEY rKey );
-}; // nsRegValueEnumerator
-
-/*------------------------------ nsRegistryNode --------------------------------
-| This class implements the nsIRegistryNode interface. Instances are |
-| allocated by nsRegSubtreeEnumerator::CurrentItem. |
-------------------------------------------------------------------------------*/
-struct nsRegistryNode : public nsIRegistryNode {
- // This class implements the nsISupports interface functions.
- NS_DECL_ISUPPORTS
-
- // This class implements the nsIRegistryNode interface functions.
- NS_DECL_NSIREGISTRYNODE
-
- // ctor
- nsRegistryNode( HREG hReg, char *name, RKEY childKey );
-
-private:
- ~nsRegistryNode();
-
-protected:
- HREG mReg; // Handle to registry this node is part of.
- char mName[MAXREGPATHLEN]; // Buffer to hold name.
- RKEY mChildKey; // Key corresponding to mName
-#ifdef EXTRA_THREADSAFE
- PRLock *mregLock;
-#endif
-}; // nsRegistryNode
-
-
-/*------------------------------ nsRegistryValue -------------------------------
-| This class implements the nsIRegistryValue interface. Instances are |
-| allocated by nsRegValueEnumerator::CurrentItem. |
-------------------------------------------------------------------------------*/
-struct nsRegistryValue : public nsIRegistryValue {
- // This class implements the nsISupports interface functions.
- NS_DECL_ISUPPORTS
-
- // This class implements the nsIRegistryValue interface functions.
- NS_DECL_NSIREGISTRYVALUE
-
- // ctor
- nsRegistryValue( HREG hReg, RKEY key, REGENUM slot );
-
-private:
- ~nsRegistryValue();
-
-protected:
- nsresult getInfo(); // Get registry info.
- HREG mReg; // Handle to registry this node is part of.
- RKEY mKey; // Key this node is under.
- REGENUM mEnum; // Copy of corresponding content of parent enumerator.
- REGINFO mInfo; // Value info.
- char mName[MAXREGNAMELEN]; // Buffer to hold name.
- REGERR mErr; // XXX This causes this class to be NON THREAD SAFE
-#ifdef EXTRA_THREADSAFE
- PRLock *mregLock;
-#endif
-}; // nsRegistryValue
-
-
-/*----------------------------- regerr2nsresult --------------------------------
-| This utility function maps a REGERR value to a corresponding nsresult |
-| error code. |
-------------------------------------------------------------------------------*/
-static nsresult regerr2nsresult( REGERR err ) {
- nsresult rv = NS_ERROR_UNEXPECTED;
- switch( err ) {
- case REGERR_OK:
- rv = NS_OK;
- break;
-
- case REGERR_FAIL:
- rv = NS_ERROR_FAILURE;
- break;
-
- case REGERR_NOMORE:
- rv = NS_ERROR_REG_NO_MORE;
- break;
-
- case REGERR_NOFIND:
- rv = NS_ERROR_REG_NOT_FOUND;
- break;
-
- case REGERR_PARAM:
- case REGERR_BADTYPE:
- case REGERR_BADNAME:
- rv = NS_ERROR_INVALID_ARG;
- break;
-
- case REGERR_NOFILE:
- rv = NS_ERROR_REG_NOFILE;
- break;
-
- case REGERR_MEMORY:
- rv = NS_ERROR_OUT_OF_MEMORY;
- break;
-
- case REGERR_BUFTOOSMALL:
- rv = NS_ERROR_REG_BUFFER_TOO_SMALL;
- break;
-
- case REGERR_NAMETOOLONG:
- rv = NS_ERROR_REG_NAME_TOO_LONG;
- break;
-
- case REGERR_NOPATH:
- rv = NS_ERROR_REG_NO_PATH;
- break;
-
- case REGERR_READONLY:
- rv = NS_ERROR_REG_READ_ONLY;
- break;
-
- case REGERR_BADUTF8:
- rv = NS_ERROR_REG_BAD_UTF8;
- break;
-
- }
- return rv;
-}
-
-/*----------------------------- reginfo2DataType -------------------------------
-| This utility function converts the type field in the REGINFO structure to |
-| the corresponding nsIRegistry::DataType value. |
-------------------------------------------------------------------------------*/
-static void reginfo2DataType( const REGINFO &in, PRUint32 &out ) {
- // Transfer information, based on entry type.
- switch( in.entryType ) {
- case REGTYPE_ENTRY_STRING_UTF:
- out = nsIRegistry::String;
- //out.length = in.entryLength;
- break;
-
- case REGTYPE_ENTRY_INT32_ARRAY:
- out = nsIRegistry::Int32;
- // Convert length in bytes to array dimension.
- //out.length = in.entryLength / sizeof(PRInt32);
- break;
-
- case REGTYPE_ENTRY_BYTES:
- out = nsIRegistry::Bytes;
- //out.length = in.entryLength;
- break;
-
- case REGTYPE_ENTRY_FILE:
- out = nsIRegistry::File;
- //out.length = in.entryLength;
- break;
- }
-}
-
-/*----------------------------- reginfo2DataType -------------------------------
-| This utility function converts the length field in the REGINFO structure to |
-| the proper units (if type==Int32 array, we divide by sizeof(PRInt32)). |
-------------------------------------------------------------------------------*/
-static void reginfo2Length( const REGINFO &in, PRUint32 &out ) {
- // Transfer information, based on entry type.
- switch( in.entryType ) {
- case REGTYPE_ENTRY_STRING_UTF:
- out = in.entryLength;
- break;
-
- case REGTYPE_ENTRY_INT32_ARRAY:
- // Convert length in bytes to array dimension.
- out = in.entryLength / sizeof(PRInt32);
- break;
-
- case REGTYPE_ENTRY_BYTES:
- out = in.entryLength;
- break;
-
- case REGTYPE_ENTRY_FILE:
- out = in.entryLength;
- break;
- }
-}
-
-/*------------------------ nsISupports Implementation --------------------------
-| This code generates the implementation of the nsISupports member functions |
-| for each class implemented in this file. |
-------------------------------------------------------------------------------*/
-NS_IMPL_THREADSAFE_ISUPPORTS2(nsRegistry, nsIRegistry, nsIRegistryGetter)
-NS_IMPL_ISUPPORTS2( nsRegSubtreeEnumerator, nsIEnumerator,
- nsIRegistryEnumerator)
-NS_IMPL_ISUPPORTS1( nsRegistryNode, nsIRegistryNode )
-NS_IMPL_ISUPPORTS1( nsRegistryValue, nsIRegistryValue )
-
-/*-------------------------- nsRegistry::nsRegistry ----------------------------
-| Vanilla nsRegistry constructor. |
-------------------------------------------------------------------------------*/
-nsRegistry::nsRegistry()
- : mReg(0), mCurRegID(0) {
-#ifdef EXTRA_THREADSAFE
- mregLock = PR_NewLock();
-#endif
- NR_StartupRegistry();
- return;
-}
-
-/*------------------------- nsRegistry::~nsRegistry ----------------------------
-| The dtor closes the registry file(if open). |
-------------------------------------------------------------------------------*/
-nsRegistry::~nsRegistry() {
- if( mReg ) {
- Close();
- }
-#ifdef EXTRA_THREADSAFE
- if (mregLock) {
- PR_DestroyLock(mregLock);
- }
-#endif
- NR_ShutdownRegistry();
- return;
-}
-
-/*----------------------------- nsRegistry::Open -------------------------------
-| If the argument is null, delegate to OpenDefault, else open the registry |
-| file. We first check to see if a registry file is already open and close |
-| it if so. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::Open( nsIFile *regFile ) {
- REGERR err = REGERR_OK;
-
- // Check for default.
- if( !regFile ) {
- return OpenWellKnownRegistry(nsIRegistry::ApplicationRegistry);
- }
-
- nsCAutoString regPath;
- nsresult rv = regFile->GetNativePath(regPath);
- if (NS_FAILED(rv)) return rv;
-
-#ifdef DEBUG_dp
- printf("nsRegistry: Opening registry %s\n", regPath.get());
-#endif /* DEBUG_dp */
-
- if (mCurRegID != nsIRegistry::None && mCurRegID != nsIRegistry::ApplicationCustomRegistry)
- {
- // Can't open another registry without closing explictly.
- return NS_ERROR_INVALID_ARG;
- }
-
- // Do we have an open registry ?
- if (mCurRegID != nsIRegistry::None)
- {
- PRBool equals;
- if (mCurRegFile && NS_SUCCEEDED(mCurRegFile->Equals(regFile, &equals)) && equals)
- {
- // The right one is already open
- return NS_OK;
- }
- else
- {
- // Opening a new registry without closing an already open one.
- // This is an error.
- return NS_ERROR_FAILURE;
- }
- }
-
- // Open specified registry.
- PR_Lock(mregLock);
- err = NR_RegOpen(const_cast<char*>(regPath.get()), &mReg);
- PR_Unlock(mregLock);
-
- mCurRegID = nsIRegistry::ApplicationCustomRegistry;
-
- // No error checking for no mem. Trust me.
- if (NS_FAILED(regFile->Clone(getter_AddRefs(mCurRegFile))))
- mCurRegFile = nsnull; // not fatal
-
- // Convert the result.
- return regerr2nsresult( err );
-}
-
-static void
-EnsureDefaultRegistryDirectory() {
-#if defined(XP_UNIX) && !defined(XP_MACOSX)
- // Create ~/.mozilla as that is the default place for the registry file
-
- /* The default registry on the unix system is $HOME/.mozilla/registry per
- * vr_findGlobalRegName(). vr_findRegFile() will create the registry file
- * if it doesn't exist. But it won't create directories.
- *
- * Hence we need to create the directory if it doesn't exist already.
- *
- * Why create it here as opposed to the app ?
- * ------------------------------------------
- * The app cannot create the directory in main() as most of the registry
- * and initialization happens due to use of static variables.
- * And we don't want to be dependent on the order in which
- * these static stuff happen.
- *
- * Permission for the $HOME/.mozilla will be Read,Write,Execute
- * for user only. Nothing to group and others.
- */
- char *home = getenv("HOME");
- if (home != NULL)
- {
- char dotMozillaDir[1024];
- PR_snprintf(dotMozillaDir, sizeof(dotMozillaDir),
- "%s/" MOZ_USER_DIR, home);
- if (PR_Access(dotMozillaDir, PR_ACCESS_EXISTS) != PR_SUCCESS)
- {
- PR_MkDir(dotMozillaDir, NS_MOZILLA_DIR_PERMISSION);
- PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
- ("nsComponentManager: Creating Directory %s", dotMozillaDir));
- }
- }
-#endif /* XP_UNIX */
-
-#ifdef XP_BEOS
- BPath p;
- const char *settings = "/boot/home/config/settings";
- if(find_directory(B_USER_SETTINGS_DIRECTORY, &p) == B_OK)
- settings = p.Path();
- char settingsMozillaDir[1024];
- PR_snprintf(settingsMozillaDir, sizeof(settingsMozillaDir),
- "%s/" MOZ_USER_DIR, settings);
- if (PR_Access(settingsMozillaDir, PR_ACCESS_EXISTS) != PR_SUCCESS) {
- PR_MkDir(settingsMozillaDir, NS_MOZILLA_DIR_PERMISSION);
- PR_LOG(nsComponentManagerLog, PR_LOG_ALWAYS,
- ("nsComponentManager: Creating Directory %s", settingsMozillaDir));
- }
-#endif
-}
-
-/*----------------------------- nsRegistry::OpenWellKnownRegistry --------------
-| Takes a registry id and maps that to a file name for opening. We first check |
-| to see if a registry file is already open and close it if so. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::OpenWellKnownRegistry( nsWellKnownRegistry regid )
-{
- REGERR err = REGERR_OK;
-
- if (mCurRegID != nsIRegistry::None && mCurRegID != regid)
- {
- // Can't open another registry without closing explictly.
- return NS_ERROR_INVALID_ARG;
- }
-
- if (mCurRegID == regid)
- {
- // Already opened.
- return NS_OK;
- }
-
- nsresult rv;
- nsCOMPtr<nsIFile> registryLocation;
-
- PRBool foundReg = PR_FALSE;
- nsCAutoString regFile;
-
- switch ( (nsWellKnownRegistry) regid ) {
- case ApplicationComponentRegistry:
- NS_WARNING("ApplicationComponentRegistry is unsupported!");
- break;
- case ApplicationRegistry:
- {
- EnsureDefaultRegistryDirectory();
- nsCOMPtr<nsIProperties> directoryService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
- if (NS_FAILED(rv)) return rv;
- directoryService->Get(NS_APP_APPLICATION_REGISTRY_FILE, NS_GET_IID(nsIFile),
- getter_AddRefs(registryLocation));
-
- if (registryLocation)
- {
- foundReg = PR_TRUE;
- rv = registryLocation->GetNativePath(regFile); // dougt fix...
- // dveditz needs to fix his registry so that I can pass an
- // nsIFile interface and not hack
- if (NS_FAILED(rv))
- return rv;
- }
- }
- break;
-
- default:
- break;
- }
-
- if (foundReg == PR_FALSE) {
- return NS_ERROR_REG_BADTYPE;
- }
-
-#ifdef DEBUG_dp
- printf("nsRegistry: Opening std registry %s\n", regFile.get());
-#endif /* DEBUG_dp */
-
- PR_Lock(mregLock);
- err = NR_RegOpen(const_cast<char*>(regFile.get()), &mReg );
- PR_Unlock(mregLock);
-
- // Store the registry that was opened for optimizing future opens.
- mCurRegID = regid;
-
- // Convert the result.
- return regerr2nsresult( err );
-}
-
-#if 0
-/*-------------------------- nsRegistry::OpenDefault ---------------------------
-| Open the "default" registry; in the case of this libreg-based implementation |
-| that is done by passing a null file name pointer to NR_RegOpen. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::OpenDefault() {
- return OpenWellKnownRegistry(nsIRegistry::ApplicationRegistry);
-}
-#endif
-
-/*----------------------------- nsRegistry::Close ------------------------------
-| Tests the mReg handle and if non-null, closes the registry via NR_RegClose. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::Close() {
- REGERR err = REGERR_OK;
- if( mReg ) {
- PR_Lock(mregLock);
- err = NR_RegClose( mReg );
- PR_Unlock(mregLock);
- mReg = 0;
- mCurRegFile = nsnull;
- mCurRegID = 0;
- }
- return regerr2nsresult( err );
-}
-
-/*----------------------------- nsRegistry::Flush ------------------------------
-| Flushes the registry via NR_RegFlush. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::Flush() {
- REGERR err = REGERR_FAIL;
- if( mReg ) {
- PR_Lock(mregLock);
- err = NR_RegFlush( mReg );
- PR_Unlock(mregLock);
- }
- return regerr2nsresult( err );
-}
-
-/*----------------------------- nsRegistry::IsOpen -----------------------------
-| Tests the mReg handle and returns whether the registry is open or not. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::IsOpen( PRBool *result ) {
- *result = ( mReg != 0 );
- return NS_OK;
-}
-
-
-/*--------------------------- nsRegistry::AddKey -------------------------------
-| Add a key into the registry or find an existing one. This is generally used |
-| instead of GetKey unless it's an error for the key not to exist already i
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::AddKey( nsRegistryKey baseKey, const PRUnichar *keyname, nsRegistryKey *_retval)
-{
- if ( !keyname )
- return NS_ERROR_NULL_POINTER;
-
- return AddSubtree( baseKey, NS_ConvertUTF16toUTF8(keyname).get(), _retval );
-}
-
-/*--------------------------- nsRegistry::GetKey -------------------------------
-| returns the nsRegistryKey associated with a given node in the registry |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetKey(nsRegistryKey baseKey, const PRUnichar *keyname, nsRegistryKey *_retval)
-{
- if ( !keyname || !_retval )
- return NS_ERROR_NULL_POINTER;
-
- return GetSubtree( baseKey, NS_ConvertUTF16toUTF8(keyname).get(), _retval );
-}
-
-/*--------------------------- nsRegistry::RemoveKey ----------------------------
-| Delete a key from the registry |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::RemoveKey(nsRegistryKey baseKey, const PRUnichar *keyname)
-{
- if ( !keyname )
- return NS_ERROR_NULL_POINTER;
-
- return RemoveSubtree( baseKey, NS_ConvertUTF16toUTF8(keyname).get() );
-}
-
-NS_IMETHODIMP nsRegistry::GetString(nsRegistryKey baseKey, const PRUnichar *valname, PRUnichar **_retval)
-{
- // Make sure caller gave us place for result.
- if ( !valname || !_retval )
- return NS_ERROR_NULL_POINTER;
-
- // initialize the return value
- *_retval = nsnull;
- nsXPIDLCString tmpstr;
-
- nsresult rv = GetStringUTF8( baseKey, NS_ConvertUTF16toUTF8(valname).get(), getter_Copies(tmpstr) );
-
- if (NS_SUCCEEDED(rv))
- {
- *_retval = nsTextFormatter::smprintf( widestrFormat, tmpstr.get() );
- if ( *_retval == nsnull )
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
-
- return rv;
-}
-
-NS_IMETHODIMP nsRegistry::SetString(nsRegistryKey baseKey, const PRUnichar *valname, const PRUnichar *value)
-{
- if ( !valname || ! value )
- return NS_ERROR_NULL_POINTER;
-
- return SetStringUTF8( baseKey,
- NS_ConvertUTF16toUTF8(valname).get(),
- NS_ConvertUTF16toUTF8(value).get() );
-}
-
-/*--------------------------- nsRegistry::GetString ----------------------------
-| First, look for the entry using GetValueInfo. If found, and it's a string, |
-| allocate space for it and fetch the value. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetStringUTF8( nsRegistryKey baseKey, const char *path, char **result ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
-
- // Make sure caller gave us place for result.
- if ( !result )
- return NS_ERROR_NULL_POINTER;
-
- char regStr[MAXREGPATHLEN];
-
- // initialize the return value
- *result = 0;
-
- // Attempt to get string into our fixed buffer
- PR_Lock(mregLock);
- err = NR_RegGetEntryString( mReg,(RKEY)baseKey,(char*)path, regStr,
- sizeof(regStr) );
- PR_Unlock(mregLock);
-
- if ( err == REGERR_OK )
- {
- *result = nsCRT::strdup(regStr);
- if (!*result)
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- else if ( err == REGERR_BUFTOOSMALL )
- {
- // find the real size and malloc it
- PRUint32 length;
- rv = GetValueLength( baseKey, path, &length );
- // See if that worked.
- if( rv == NS_OK )
- {
- *result =(char*)nsMemory::Alloc( length + 1 );
- if( *result )
- {
- // Get string from registry into result buffer.
- PR_Lock(mregLock);
- err = NR_RegGetEntryString( mReg,(RKEY)baseKey,(char*)path, *result, length+1 );
- PR_Unlock(mregLock);
-
- // Convert status.
- rv = regerr2nsresult( err );
- if ( rv != NS_OK )
- {
- // Didn't get result, free buffer
- nsCRT::free( *result );
- *result = 0;
- }
- }
- else
- {
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- }
- }
- else
- {
- // Convert status.
- rv = regerr2nsresult( err );
- NS_ASSERTION(NS_FAILED(rv), "returning success code on failure");
- }
-
- return rv;
-}
-
-NS_IMETHODIMP
-nsRegistry::GetStringUTF8IntoBuffer( nsRegistryKey baseKey, const char *path,
- char *buf, PRUint32 *length )
-{
- REGERR err = REGERR_OK;
-
- // Attempt to get string into our fixed buffer
- PR_Lock(mregLock);
- err = NR_RegGetEntryString( mReg,(RKEY)baseKey,(char*)path, buf, *length );
- PR_Unlock(mregLock);
-
- // Convert status.
- nsresult rv = regerr2nsresult( err );
-
- if (rv == NS_ERROR_REG_BUFFER_TOO_SMALL) {
- // fill length with the actual length
- nsresult rv1 = GetValueLength( baseKey, path, length );
- if(NS_FAILED(rv1))
- return rv1;
- }
-
- return rv;
-}
-
-/*--------------------------- nsRegistry::SetString ----------------------------
-| Simply sets the registry contents using NR_RegSetEntryString. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::SetStringUTF8( nsRegistryKey baseKey, const char *path, const char *value ) {
- REGERR err = REGERR_OK;
- // Set the contents.
- PR_Lock(mregLock);
- err = NR_RegSetEntryString( mReg,(RKEY)baseKey,(char*)path,(char*)value );
- PR_Unlock(mregLock);
- // Convert result.
- return regerr2nsresult( err );
-}
-
-/*---------------------------- nsRegistry::GetBytesUTF8 ------------------------------
-| This function is just shorthand for fetching a char array. We |
-| implement it "manually" using NR_RegGetEntry |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetBytesUTF8( nsRegistryKey baseKey, const char *path, PRUint32* length, PRUint8** result) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
-
- if ( !result )
- return NS_ERROR_NULL_POINTER;
-
- char regStr[MAXREGPATHLEN];
-
- // initialize the return value
- *length = 0;
- *result = 0;
-
- // Get info about the requested entry.
- PRUint32 type;
- rv = GetValueType( baseKey, path, &type );
- // See if that worked.
- if( rv == NS_OK )
- {
- // Make sure the entry is an PRInt8 array.
- if( type == Bytes )
- {
- // Attempt to get string into our fixed buffer
- PR_Lock(mregLock);
- uint32 length2 = sizeof regStr;
- err = NR_RegGetEntry( mReg,(RKEY)baseKey,const_cast<char*>(path), regStr, &length2);
- PR_Unlock(mregLock);
-
- if ( err == REGERR_OK )
- {
- *length = length2;
- *result = (PRUint8*)(nsCRT::strdup(regStr));
- if (!*result)
- {
- rv = NS_ERROR_OUT_OF_MEMORY;
- *length = 0;
- }
- else
- {
- *length = length2;
- }
- }
- else if ( err == REGERR_BUFTOOSMALL )
- {
- // find the real size and malloc it
- rv = GetValueLength( baseKey, path, length );
- // See if that worked.
- if( rv == NS_OK )
- {
- *result = reinterpret_cast<PRUint8*>(nsMemory::Alloc( *length ));
- if( *result )
- {
- // Get bytes from registry into result field.
- PR_Lock(mregLock);
- length2 = *length;
- err = NR_RegGetEntry( mReg,(RKEY)baseKey,const_cast<char*>(path), *result, &length2);
- *length = length2;
- PR_Unlock(mregLock);
- // Convert status.
- rv = regerr2nsresult( err );
- if ( rv != NS_OK )
- {
- // Didn't get result, free buffer
- nsCRT::free( reinterpret_cast<char*>(*result) );
- *result = 0;
- *length = 0;
- }
- }
- else
- {
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- }
- }
- }
- else
- {
- // They asked for the wrong type of value.
- rv = NS_ERROR_REG_BADTYPE;
- }
- }
- return rv;
-}
-
-NS_IMETHODIMP
-nsRegistry::GetBytesUTF8IntoBuffer( nsRegistryKey baseKey, const char *path,
- PRUint8 *buf, PRUint32* length )
-{
- REGERR err = REGERR_OK;
-
- // Get info about the requested entry.
- PRUint32 type;
- nsresult rv = GetValueType( baseKey, path, &type );
- // See if that worked.
- if(NS_FAILED(rv))
- return rv;
- // Make sure we are dealing with bytes
- if (type != Bytes)
- return NS_ERROR_REG_BADTYPE;
-
- // Attempt to get bytes into our fixed buffer
- PR_Lock(mregLock);
- err = NR_RegGetEntry( mReg,(RKEY)baseKey,const_cast<char*>(path),
- buf, (uint32 *)length );
- PR_Unlock(mregLock);
-
- rv = regerr2nsresult(rv);
-
- if (rv == NS_ERROR_REG_BUFFER_TOO_SMALL) {
- // fill length with the actual length
- nsresult rv1 = GetValueLength( baseKey, path, length );
- if(NS_FAILED(rv1))
- return rv1;
- }
-
-
- return rv;
-}
-
-/*---------------------------- nsRegistry::GetInt ------------------------------
-| This function is just shorthand for fetching a 1-element PRInt32 array. We |
-| implement it "manually" using NR_RegGetEntry |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetInt( nsRegistryKey baseKey, const char *path, PRInt32 *result ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
-
- // Make sure caller gave us place for result.
- if( result ) {
- // Get info about the requested entry.
- PRUint32 type;
- rv = GetValueType( baseKey, path, &type );
- // See if that worked.
- if( rv == NS_OK ) {
- // Make sure the entry is an PRInt32 array.
- if( type == Int32 ) {
- uint32 len = sizeof *result;
- // Get int from registry into result field.
- PR_Lock(mregLock);
- err = NR_RegGetEntry( mReg,(RKEY)baseKey,(char*)path, result, &len );
- PR_Unlock(mregLock);
- // Convert status.
- rv = regerr2nsresult( err );
- } else {
- // They asked for the wrong type of value.
- rv = NS_ERROR_REG_BADTYPE;
- }
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-
-/*---------------------------- nsRegistry::GetLongLong--------------------------
-| This function is just shorthand for fetching a 1-element PRInt64 array. We |
-| implement it "manually" using NR_RegGetEntry |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetLongLong( nsRegistryKey baseKey, const char *path, PRInt64 *result ) {
- REGERR err = REGERR_OK;
-
- PR_Lock(mregLock);
-
- uint32 length = sizeof(PRInt64);
- err = NR_RegGetEntry( mReg,(RKEY)baseKey,(char*)path,(void*)result,&length);
-
- PR_Unlock(mregLock);
-
- // Convert status.
- return regerr2nsresult( err );
-}
-/*---------------------------- nsRegistry::SetBytesUTF8 ------------------------------
-| Write out the value as a char array, using NR_RegSetEntry. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::SetBytesUTF8( nsRegistryKey baseKey, const char *path, PRUint32 length, PRUint8* value) {
- REGERR err = REGERR_OK;
- // Set the contents.
- PR_Lock(mregLock);
- err = NR_RegSetEntry( mReg,
- (RKEY)baseKey,
- (char*)path,
- REGTYPE_ENTRY_BYTES,
- (char*)value,
- length);
- PR_Unlock(mregLock);
- // Convert result.
- return regerr2nsresult( err );
-}
-
-/*---------------------------- nsRegistry::SetInt ------------------------------
-| Write out the value as a one-element PRInt32 array, using NR_RegSetEntry. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::SetInt( nsRegistryKey baseKey, const char *path, PRInt32 value ) {
- REGERR err = REGERR_OK;
- // Set the contents.
- PR_Lock(mregLock);
- err = NR_RegSetEntry( mReg,
- (RKEY)baseKey,
- (char*)path,
- REGTYPE_ENTRY_INT32_ARRAY,
- &value,
- sizeof value );
- PR_Unlock(mregLock);
- // Convert result.
- return regerr2nsresult( err );
-}
-
-
-
-/*---------------------------- nsRegistry::SetLongLong---------------------------
-| Write out the value as a one-element PRInt64 array, using NR_RegSetEntry. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::SetLongLong( nsRegistryKey baseKey, const char *path, PRInt64* value ) {
- REGERR err = REGERR_OK;
- // Set the contents.
- PR_Lock(mregLock);
-
- err = NR_RegSetEntry( mReg,
- (RKEY)baseKey,
- (char*)path,
- REGTYPE_ENTRY_BYTES,
- (void*)value,
- sizeof(PRInt64) );
-
- PR_Unlock(mregLock);
- // Convert result.
- return regerr2nsresult( err );
-}
-
-/*-------------------------- nsRegistry::AddSubtree ----------------------------
-| Add a new registry subkey with the specified name, using NR_RegAddKey. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::AddSubtree( nsRegistryKey baseKey, const char *path, nsRegistryKey *result ) {
- REGERR err = REGERR_OK;
- // Add the subkey.
- PR_Lock(mregLock);
- err = NR_RegAddKey( mReg,(RKEY)baseKey,(char*)path,(RKEY*)result );
- PR_Unlock(mregLock);
- // Convert result.
- return regerr2nsresult( err );
-}
-
-/*-------------------------- nsRegistry::AddSubtreeRaw--------------------------
-| Add a new registry subkey with the specified name, using NR_RegAddKeyRaw |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::AddSubtreeRaw( nsRegistryKey baseKey, const char *path, nsRegistryKey *result ) {
- REGERR err = REGERR_OK;
- // Add the subkey.
- PR_Lock(mregLock);
- err = NR_RegAddKeyRaw( mReg,(RKEY)baseKey,(char*)path,(RKEY*)result );
- PR_Unlock(mregLock);
- // Convert result.
- return regerr2nsresult( err );
-}
-
-
-/*------------------------- nsRegistry::RemoveSubtree --------------------------
-| Deletes the subtree at a given location using NR_RegDeleteKey. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::RemoveSubtree( nsRegistryKey baseKey, const char *path ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
-
- // libreg doesn't delete keys if there are subkeys under the key
- // Hence we have to recurse through to delete the subtree
-
- RKEY key;
-
- PR_Lock(mregLock);
- err = NR_RegGetKey(mReg, baseKey, (char *)path, &key);
- PR_Unlock(mregLock);
- if (err != REGERR_OK)
- {
- rv = regerr2nsresult( err );
- return rv;
- }
-
- // Now recurse through and delete all keys under hierarchy
-
- char subkeyname[MAXREGPATHLEN+1];
- REGENUM state = 0;
- subkeyname[0] = '\0';
- while (NR_RegEnumSubkeys(mReg, key, &state, subkeyname, sizeof(subkeyname),
- REGENUM_NORMAL) == REGERR_OK)
- {
-#ifdef DEBUG_dp
- printf("...recursing into %s\n", subkeyname);
-#endif /* DEBUG_dp */
- // Even though this is not a "Raw" API the subkeys may still, in fact,
- // *be* raw. Since we're recursively deleting this will work either way.
- // If we were guaranteed none would be raw then a depth-first enumeration
- // would be much more efficient.
- err = RemoveSubtreeRaw(key, subkeyname);
- if (err != REGERR_OK) break;
- }
-
- // If success in deleting all subkeys, delete this key too
- if (err == REGERR_OK)
- {
-#ifdef DEBUG_dp
- printf("...deleting %s\n", path);
-#endif /* DEBUG_dp */
- PR_Lock(mregLock);
- err = NR_RegDeleteKey(mReg, baseKey, (char *)path);
- PR_Unlock(mregLock);
- }
-
- // Convert result.
- rv = regerr2nsresult( err );
- return rv;
-}
-
-
-/*------------------------- nsRegistry::RemoveSubtreeRaw -----------------------
-| Deletes the subtree at a given location using NR_RegDeleteKeyRaw |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::RemoveSubtreeRaw( nsRegistryKey baseKey, const char *keyname ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
-
- // libreg doesn't delete keys if there are subkeys under the key
- // Hence we have to recurse through to delete the subtree
-
- RKEY key;
- char subkeyname[MAXREGPATHLEN+1];
- int n = sizeof(subkeyname);
- REGENUM state = 0;
-
- PR_Lock(mregLock);
- err = NR_RegGetKeyRaw(mReg, baseKey, (char *)keyname, &key);
- PR_Unlock(mregLock);
- if (err != REGERR_OK)
- {
- rv = regerr2nsresult( err );
- return rv;
- }
-
- // Now recurse through and delete all keys under hierarchy
-
- subkeyname[0] = '\0';
- while (NR_RegEnumSubkeys(mReg, key, &state, subkeyname, n, REGENUM_NORMAL) == REGERR_OK)
- {
-#ifdef DEBUG_dp
- printf("...recursing into %s\n", subkeyname);
-#endif /* DEBUG_dp */
- err = RemoveSubtreeRaw(key, subkeyname);
- if (err != REGERR_OK) break;
- }
-
- // If success in deleting all subkeys, delete this key too
- if (err == REGERR_OK)
- {
-#ifdef DEBUG_dp
- printf("...deleting %s\n", keyname);
-#endif /* DEBUG_dp */
- PR_Lock(mregLock);
- err = NR_RegDeleteKeyRaw(mReg, baseKey, (char *)keyname);
- PR_Unlock(mregLock);
- }
-
- // Convert result.
- rv = regerr2nsresult( err );
- return rv;
-}
-/*-------------------------- nsRegistry::GetSubtree ----------------------------
-| Returns a nsRegistryKey(RKEY) for a given key/path. The key is |
-| obtained using NR_RegGetKey. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetSubtree( nsRegistryKey baseKey, const char *path, nsRegistryKey *result ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
- // Make sure we have a place for the result.
- if( result ) {
- // Get key.
- PR_Lock(mregLock);
- err = NR_RegGetKey( mReg,(RKEY)baseKey,(char*)path,(RKEY*)result );
- PR_Unlock(mregLock);
- // Convert result.
- rv = regerr2nsresult( err );
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*-------------------------- nsRegistry::GetSubtreeRaw--------------------------
-| Returns a nsRegistryKey(RKEY) for a given key/path. The key is |
-| obtained using NR_RegGetKeyRaw. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetSubtreeRaw( nsRegistryKey baseKey, const char *path, nsRegistryKey *result ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
- // Make sure we have a place for the result.
- if( result ) {
- // Get key.
- PR_Lock(mregLock);
- err = NR_RegGetKeyRaw( mReg,(RKEY)baseKey,(char*)path,(RKEY*)result );
- PR_Unlock(mregLock);
- // Convert result.
- rv = regerr2nsresult( err );
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-
-/*----------------------- nsRegistry::EnumerateSubtrees ------------------------
-| Allocate a nsRegSubtreeEnumerator object and return it to the caller. |
-| We construct the enumerator using the registry handle from this registry |
-| object, the user-specified registry key, and indicate that we don't want |
-| to recurse down subtrees. No libreg functions are invoked at this point |
-|(that will happen when the enumerator member functions are called). |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::EnumerateSubtrees( nsRegistryKey baseKey, nsIEnumerator **result ) {
- nsresult rv = NS_OK;
- // Make sure we have a place to put the result.
- if( result ) {
- *result = new nsRegSubtreeEnumerator( mReg,(RKEY)baseKey, PR_FALSE );
- // Check for success.
- if( *result ) {
- // Bump refcnt on behalf of caller.
- NS_ADDREF(*result);
- } else {
- // Unable to allocate space for the enumerator object.
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*--------------------- nsRegistry::EnumerateAllSubtrees -----------------------
-| Same as EnumerateSubtrees but we pass PR_TRUE to request that the |
-| enumerator object descend subtrees when it is used. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::EnumerateAllSubtrees( nsRegistryKey baseKey, nsIEnumerator **result ) {
- nsresult rv = NS_OK;
- // Make sure we have a place to put the result.
- if( result ) {
- *result = new nsRegSubtreeEnumerator( mReg,(RKEY)baseKey, PR_TRUE );
- // Check for success.
- if( *result ) {
- // Bump refcnt on behalf of caller.
- NS_ADDREF(*result);
- } else {
- // Unable to allocate space for the enumerator object.
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*------------------------- nsRegistry::GetValueType ---------------------------
-| Gets the type from the registry using the NR_GetEntryInfo libreg API. |
-| The result is transferred to the PRUint32 value passed in (with conversion |
-| to the appropriate nsIRegistry::DataType value). |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetValueType( nsRegistryKey baseKey, const char *path, PRUint32 *result ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
- // Make sure we have a place to put the result.
- if( result ) {
- // Get registry info into local structure.
- REGINFO info = { sizeof info, 0, 0 };
- PR_Lock(mregLock);
- err = NR_RegGetEntryInfo( mReg,(RKEY)baseKey,(char*)path, &info );
- PR_Unlock(mregLock);
- if( err == REGERR_OK ) {
- // Copy info to user's result value.
- reginfo2DataType( info, *result );
- } else {
- rv = regerr2nsresult( err );
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*------------------------ nsRegistry::GetValueLength --------------------------
-| Gets the registry value info via NR_RegGetEntryInfo. The length is |
-| converted to the proper "units" via reginfo2Length. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetValueLength( nsRegistryKey baseKey, const char *path, PRUint32 *result ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
- // Make sure we have a place to put the result.
- if( result ) {
- // Get registry info into local structure.
- REGINFO info = { sizeof info, 0, 0 };
- PR_Lock(mregLock);
- err = NR_RegGetEntryInfo( mReg,(RKEY)baseKey,(char*)path, &info );
- PR_Unlock(mregLock);
- if( err == REGERR_OK ) {
- // Copy info to user's result value.
- reginfo2Length( info, *result );
- } else {
- rv = regerr2nsresult( err );
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*-------------------------- nsRegistry::DeleteValue ---------------------------
-| Remove the registry value with the specified name |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::DeleteValue( nsRegistryKey baseKey, const char *path)
-{
- REGERR err = REGERR_OK;
- // Delete the value
- PR_Lock(mregLock);
- err = NR_RegDeleteEntry( mReg,(RKEY)baseKey,(char*)path );
- PR_Unlock(mregLock);
- // Convert result.
- return regerr2nsresult( err );
-}
-
-/*------------------------ nsRegistry::EnumerateValues -------------------------
-| Allocates and returns an instance of nsRegValueEnumerator constructed in |
-| a similar fashion as the nsRegSubtreeEnumerator is allocated/returned by |
-| EnumerateSubtrees. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::EnumerateValues( nsRegistryKey baseKey, nsIEnumerator **result ) {
- nsresult rv = NS_OK;
- // Make sure we have a place to put the result.
- if( result ) {
- *result = new nsRegValueEnumerator( mReg,(RKEY)baseKey );
- // Check for success.
- if( *result ) {
- // Bump refcnt on behalf of caller.
- NS_ADDREF(*result);
- } else {
- // Unable to allocate space for the enumerator object.
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*---------------------- nsRegistry::GetCurrentUserName ------------------------
-| Simple wrapper for NR_RegGetUsername. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::GetCurrentUserName( char **result ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
- // Make sure we have a place to put the result.
- if( result ) {
- // Get the user name.
- PR_Lock(mregLock);
- err = NR_RegGetUsername( result );
- PR_Unlock(mregLock);
- // Convert the result.
- rv = regerr2nsresult( err );
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*---------------------- nsRegistry::SetCurrentUserName ------------------------
-| Simple wrapper for NR_RegSetUsername. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::SetCurrentUserName( const char *name ) {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
- // Set the user name.
- PR_Lock(mregLock);
- err = NR_RegSetUsername( name );
- PR_Unlock(mregLock);
- // Convert result.
- rv = regerr2nsresult( err );
- return rv;
-}
-
-/*----------------------------- nsRegistry::Pack -------------------------------
-| Simple wrapper for NR_RegPack. We don't set up any callback. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::Pack() {
- nsresult rv = NS_OK;
- REGERR err = REGERR_OK;
- // Pack the registry.
- PR_Lock(mregLock);
- err = NR_RegPack( mReg, 0, 0 );
- PR_Unlock(mregLock);
- // Convert result.
- rv = regerr2nsresult( err );
- return rv;
-}
-
-/*----------------------------- nsRegistry::EscapeKey -------------------------------
-| Escape a binary key so that the registry works OK, since it expects UTF8
-| with no slashes or control characters. This is probably better than raw.
-| If no escaping is required, then the method is successful and a null is
-| returned, indicating that the caller should use the original string.
-------------------------------------------------------------------------------*/
-static const char sEscapeKeyHex[] = "0123456789abcdef0123456789ABCDEF";
-NS_IMETHODIMP nsRegistry::EscapeKey(PRUint8* key, PRUint32 termination, PRUint32* length, PRUint8** escaped)
-{
- nsresult rv = NS_OK;
- char* value = (char*)key;
- char* b = value;
- char* e = b + *length;
- int escapees = 0;
- while (b < e) // Count characters outside legal range or slash
- {
- int c = *b++;
- if (c <= ' '
- || c > '~'
- || c == '/'
- || c == '%')
- {
- escapees++;
- }
- }
- if (escapees == 0) // If no escapees, then no results
- {
- *length = 0;
- *escaped = nsnull;
- return NS_OK;
- }
- // New length includes two extra chars for escapees.
- *length += escapees * 2;
- *escaped = (PRUint8*)nsMemory::Alloc(*length + termination);
- if (*escaped == nsnull)
- {
- *length = 0;
- *escaped = nsnull;
- return NS_ERROR_OUT_OF_MEMORY;
- }
- char* n = (char*)*escaped;
- b = value;
- while (escapees && b < e)
- {
- char c = *b++;
- if (c < ' '
- || c > '~'
- || c == '/'
- || c == '%')
- {
- *(n++) = '%';
- *(n++) = sEscapeKeyHex[ 0xF & (c >> 4) ];
- *(n++) = sEscapeKeyHex[ 0xF & c ];
- escapees--;
- }
- else
- {
- *(n++) = c;
- }
- }
- e += termination;
- if (b < e)
- {
- strncpy(n, b, e - b);
- }
- return rv;
-}
-
-/*----------------------------- nsRegistry::UnescapeKey -------------------------------
-| Unscape a binary key so that the registry works OK, since it expects UTF8
-| with no slashes or control characters. This is probably better than raw.
-| If no escaping is required, then the method is successful and a null is
-| returned, indicating that the caller should use the original string.
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistry::UnescapeKey(PRUint8* escaped, PRUint32 termination, PRUint32* length, PRUint8** key)
-{
- nsresult rv = NS_OK;
- char* value = (char*)escaped;
- char* b = value;
- char* e = b + *length;
- int escapees = 0;
- while (b < e) // Count characters outside legal range or slash
- {
- if (*b++ == '%')
- {
- escapees++;
- }
- }
- if (escapees == 0) // If no escapees, then no results
- {
- *length = 0;
- *key = nsnull;
- return NS_OK;
- }
- // New length includes two extra chars for escapees.
- *length -= escapees * 2;
- *key = (PRUint8*)nsMemory::Alloc(*length + termination);
- if (*key == nsnull)
- {
- *length = 0;
- *key = nsnull;
- return NS_ERROR_OUT_OF_MEMORY;
- }
- char* n = (char*)*key;
- b = value;
- while (escapees && b < e)
- {
- char c = *(b++);
- if (c == '%')
- {
- if (e - b >= 2)
- {
- const char* c1 = strchr(sEscapeKeyHex, *(b++));
- const char* c2 = strchr(sEscapeKeyHex, *(b++));
- if (c1 != nsnull
- && c2 != nsnull)
- {
- *(n++) = ((c2 - sEscapeKeyHex) & 0xF)
- | (((c1 - sEscapeKeyHex) & 0xF) << 4);
- }
- else
- {
- escapees = -1;
- }
- }
- else
- {
- escapees = -1;
- }
- escapees--;
- }
- else
- {
- *(n++) = c;
- }
- }
- if (escapees < 0)
- {
- nsMemory::Free(*key);
- *length = 0;
- *key = nsnull;
- return NS_ERROR_INVALID_ARG;
- }
- e += termination;
- if (b < e)
- {
- strncpy(n, b, e - b);
- }
- return rv;
-}
-
-
-/*-------------- nsRegistry::SetBufferSize-------------------------------------
-| Sets the size of the file used for the registry's buffer size. |
-------------------------------------------------------------------------------*/
-int nsRegistry::SetBufferSize( int bufsize )
-{
- int newSize;
- // set the file buffer size
- PR_Lock(mregLock);
- newSize = NR_RegSetBufferSize( mReg, bufsize );
- PR_Unlock(mregLock);
- return newSize;
-}
-
-
-/*-------------- nsRegSubtreeEnumerator::nsRegSubtreeEnumerator ----------------
-| The ctor simply stashes all the information that will be needed to enumerate |
-| the subkeys. |
-------------------------------------------------------------------------------*/
-nsRegSubtreeEnumerator::nsRegSubtreeEnumerator( HREG hReg, RKEY rKey, PRBool all )
- : mReg( hReg ), mKey( rKey ), mEnum( 0 ), mNext( 0 ),
- mStyle( all ? REGENUM_DESCEND : REGENUM_CHILDREN ), mDone( PR_FALSE ) {
-
- mName[0] = '\0';
-
-#ifdef EXTRA_THREADSAFE
- // Create a registry lock
- mregLock = PR_NewLock();
-#endif
- return;
-}
-
-nsRegSubtreeEnumerator::~nsRegSubtreeEnumerator()
-{
-#ifdef EXTRA_THREADSAFE
- if (mregLock) {
- PR_DestroyLock(mregLock);
- }
-#endif
-}
-
-/*----------------------- nsRegSubtreeEnumerator::First ------------------------
-| Set mEnum to 0; this will cause the next NR_RegEnum call to go to |
-| the beginning. We then do a Next() call in order to do a "lookahead" to |
-| properly detect an empty list (i.e., set the mDone flag). |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP
-nsRegSubtreeEnumerator::First() {
- nsresult rv = NS_OK;
- // Reset "done" flag.
- mDone = PR_FALSE;
- // Clear Name
- mName[0] = '\0';
- // Go to beginning.
- mEnum = mNext = 0;
- // Lookahead so mDone flag gets set for empty list.
- rv = Next();
- return rv;
-}
-
-/*----------------------- nsRegSubtreeEnumerator::Next -------------------------
-| First, we check if we've already advanced to the end by checking the mDone |
-| flag. |
-| |
-| We advance mEnum to the next enumeration value which is in the mNext |
-| lookahead buffer. We must then call advance to lookahead and properly set |
-| the isDone flag. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP
-nsRegSubtreeEnumerator::Next() {
- nsresult rv = NS_OK;
- // Check for at end.
- if ( !mDone ) {
- // Advance to next spot.
- mEnum = mNext;
- // Lookahead so mDone is properly set (and to update mNext).
- rv = advance();
- } else {
- // Set result accordingly.
- rv = regerr2nsresult( REGERR_NOMORE );
- }
- return rv;
-}
-
-/*---------------------- nsRegSubtreeEnumerator::advance -----------------------
-| Advance mNext to next subkey using NR_RegEnumSubkeys. We set mDone if |
-| there are no more subkeys. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegSubtreeEnumerator::advance() {
- REGERR err = REGERR_OK;
- PR_Lock(mregLock);
- err = NR_RegEnumSubkeys( mReg, mKey, &mNext, mName, sizeof mName, mStyle );
- // See if we ran off end.
- if( err == REGERR_NOMORE ) {
- // Remember we've run off end.
- mDone = PR_TRUE;
- }
- PR_Unlock(mregLock);
- // Convert result.
- nsresult rv = regerr2nsresult( err );
- return rv;
-}
-
-/*-------------------- nsRegSubtreeEnumerator::CurrentItem ---------------------
-| Allocates and returns a new instance of class nsRegistryNode. The node |
-| object will hold the curent mEnum value so it can obtain its name from |
-| the registry when asked. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP
-nsRegSubtreeEnumerator::CurrentItem( nsISupports **result) {
- nsresult rv = NS_OK;
- // Make sure there is a place to put the result.
- if( result ) {
- *result = new nsRegistryNode( mReg, mName, (RKEY) mNext );
- if( *result ) {
- NS_ADDREF(*result);
- } else {
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*--------------nsRegSubtreeEnumerator::CurrentItemInPlaceUTF8-----------------
-| An ugly name for an ugly function. Hands back a shared pointer to the |
-| name (encoded as UTF-8), and the subkey identifier. |
------------------------------------------------------------------------------*/
-NS_IMETHODIMP
-nsRegSubtreeEnumerator::CurrentItemInPlaceUTF8( nsRegistryKey *childKey ,
- const char **name )
-{
- *childKey = mNext;
- /* [shared] */
- *name = mName;
- return NS_OK;
-}
-
-/*---------------------- nsRegSubtreeEnumerator::IsDone ------------------------
-| Simply return mDone. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP
-nsRegSubtreeEnumerator::IsDone() {
- nsresult rv = mDone ? NS_OK : NS_ENUMERATOR_FALSE;
- return rv;
-}
-
-
-/*---------------- nsRegValueEnumerator::nsRegValueEnumerator ------------------
-| Delegates everything to the base class constructor. |
-------------------------------------------------------------------------------*/
-nsRegValueEnumerator::nsRegValueEnumerator( HREG hReg, RKEY rKey )
- : nsRegSubtreeEnumerator( hReg, rKey, PR_FALSE ) {
- return;
-}
-
-
-/*--------------------- nsRegValueEnumerator::CurrentItem ----------------------
-| As the nsRegSubtreeEnumerator counterpart, but allocates an object of |
-| class nsRegistryValue. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP
-nsRegValueEnumerator::CurrentItem( nsISupports **result ) {
- nsresult rv = NS_OK;
- // Make sure there is a place to put the result.
- if( result ) {
- *result = new nsRegistryValue( mReg, mKey, mEnum );
- if( *result ) {
- NS_ADDREF(*result);
- } else {
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*----------------------- nsRegValueEnumerator::advance ------------------------
-| Advance mNext to next subkey using NR_RegEnumEntries. We set mDone if |
-| there are no more entries. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegValueEnumerator::advance() {
- REGERR err = REGERR_OK;
- char name[MAXREGNAMELEN];
- PRUint32 len = sizeof name;
- REGINFO info = { sizeof info, 0, 0 };
- PR_Lock(mregLock);
- err = NR_RegEnumEntries( mReg, mKey, &mNext, name, len, &info );
- // See if we ran off end.
- if( err == REGERR_NOMORE ) {
- // Remember we've run off end.
- mDone = PR_TRUE;
- }
- PR_Unlock(mregLock);
- // Convert result.
- nsresult rv = regerr2nsresult( err );
- return rv;
-}
-
-
-/*---------------------- nsRegistryNode::nsRegistryNode ------------------------
-| Store the arguments in the corresponding data members and initialize |
-| the other data members. We defer the libreg calls till we're asked for |
-| our name. We use mErr==-1 to indicate we haven't fetched the name yet. |
-------------------------------------------------------------------------------*/
-nsRegistryNode::nsRegistryNode( HREG hReg, char *name, RKEY childKey )
- : mReg( hReg ), mChildKey( childKey ) {
-
- PR_ASSERT(name != nsnull);
- strcpy(mName, name);
-
-#ifdef EXTRA_THREADSAFE
- mregLock = PR_NewLock();
-#endif
-
- return;
-}
-
-nsRegistryNode::~nsRegistryNode()
-{
-#ifdef EXTRA_THREADSAFE
- if (mregLock) {
- PR_DestroyLock(mregLock);
- }
-#endif
-}
-
-/*-------------------------- nsRegistryNode::GetName ---------------------------
-| If we haven't fetched it yet, get the name of the corresponding subkey now, |
-| using NR_RegEnumSubkeys. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistryNode::GetName( PRUnichar **result ) {
- if (result == nsnull) return NS_ERROR_NULL_POINTER;
- // Make sure there is a place to put the result.
- *result = nsTextFormatter::smprintf( widestrFormat, mName );
- if ( !*result ) return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-/*-------------------------- nsRegistryNode::GetNameUTF8 -----------------------
-| If we haven't fetched it yet, get the name of the corresponding subkey now, |
-| using NR_RegEnumSubkeys. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistryNode::GetNameUTF8( char **result ) {
- if (result == nsnull) return NS_ERROR_NULL_POINTER;
- // Make sure there is a place to put the result.
- *result = nsCRT::strdup( mName );
- if ( !*result ) return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-/*-------------------------- nsRegistryNode::GetKey ----------------------------
-| Get the subkey corresponding to this node |
-| using NR_RegEnumSubkeys. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistryNode::GetKey( nsRegistryKey *r_key ) {
- nsresult rv = NS_OK;
- if (r_key == nsnull) return NS_ERROR_NULL_POINTER;
- *r_key = mChildKey;
- return rv;
-}
-
-
-
-/*--------------------- nsRegistryValue::nsRegistryValue -----------------------
-| Implemented the same way as the nsRegistryNode ctor. |
-------------------------------------------------------------------------------*/
-nsRegistryValue::nsRegistryValue( HREG hReg, RKEY key, REGENUM slot )
- : mReg( hReg ), mKey( key ), mEnum( slot ), mErr( -1 ) {
-#ifdef EXTRA_THREADSAFE
- mregLock = PR_NewLock();
-#endif
- mInfo.size = sizeof(REGINFO);
-}
-
-nsRegistryValue::~nsRegistryValue()
-{
-#ifdef EXTRA_THREADSAFE
- if (mregLock) {
- PR_DestroyLock(mregLock);
- }
-#endif
-}
-
-/*------------------------- nsRegistryValue::GetName ---------------------------
-| See nsRegistryNode::GetName; we use NR_RegEnumEntries in this case. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistryValue::GetName( PRUnichar **result ) {
- nsresult rv = NS_OK;
- // Make sure we have a place to put the result.
- if( result ) {
- // Ensure we've got the info we need.
- rv = getInfo();
- if( rv == NS_OK || rv == NS_ERROR_REG_NO_MORE ) {
- // worked, return actual result.
- *result = nsTextFormatter::smprintf( widestrFormat, mName );
- if ( *result ) {
- rv = NS_OK;
- } else {
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*------------------------- nsRegistryValue::GetNameUTF8 -----------------------
-| See nsRegistryNode::GetName; we use NR_RegEnumEntries in this case. |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistryValue::GetNameUTF8( char **result ) {
- nsresult rv = NS_OK;
- // Make sure we have a place to put the result.
- if( result ) {
- // Ensure we've got the info we need.
- rv = getInfo();
- if( rv == NS_OK || rv == NS_ERROR_REG_NO_MORE ) {
- // worked, return actual result.
- *result = nsCRT::strdup( mName );
- if ( *result ) {
- rv = NS_OK;
- } else {
- rv = NS_ERROR_OUT_OF_MEMORY;
- }
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*----------------------- nsRegistryValue::GetType ------------------------
-| We test if we've got the info already. If not, we git it by calling |
-| getInfo. We calculate the result by converting the REGINFO type field to |
-| a nsIRegistry::DataType value (using reginfo2DataType). |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistryValue::GetType( PRUint32 *result ) {
- nsresult rv = NS_OK;
- // Make sure we have room for th result.
- if( result ) {
- // Make sure we've got the info we need.
- rv = getInfo();
- // Check if it worked.
- if( rv == NS_OK ) {
- // Convert result from REGINFO to nsIRegistry::ValueInfo.
- reginfo2DataType( mInfo, *result );
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*---------------------- nsRegistryValue::GetLength -----------------------
-| We test if we've got the info already. If not, we git it by calling |
-| getInfo. We calculate the result by converting the REGINFO type field to |
-| a nsIRegistry::DataType value (using reginfo2Length). |
-------------------------------------------------------------------------------*/
-NS_IMETHODIMP nsRegistryValue::GetLength( PRUint32 *result ) {
- nsresult rv = NS_OK;
- // Make sure we have room for th result.
- if( result ) {
- // Make sure we've got the info we need.
- rv = getInfo();
- // Check if it worked.
- if( rv == NS_OK ) {
- // Convert result from REGINFO to length.
- reginfo2Length( mInfo, *result );
- }
- } else {
- rv = NS_ERROR_NULL_POINTER;
- }
- return rv;
-}
-
-/*------------------------- nsRegistryValue::getInfo ---------------------------
-| Call NR_RegEnumEntries to set the mInfo/mName data members. |
-------------------------------------------------------------------------------*/
-nsresult nsRegistryValue::getInfo() {
- nsresult rv = NS_OK;
- // Test whether we haven't tried to get it yet.
- if( mErr == -1 ) {
- REGENUM temp = mEnum;
- // Get name and info.
- PR_Lock(mregLock);
- mErr = NR_RegEnumEntries( mReg, mKey, &temp, mName, sizeof mName, &mInfo );
- // Convert result.
- rv = regerr2nsresult( mErr );
- PR_Unlock(mregLock);
- }
- return rv;
-}
-
-
-nsRegistryFactory::nsRegistryFactory() {
-}
-
-NS_IMPL_ISUPPORTS1(nsRegistryFactory, nsIFactory)
-
-NS_IMETHODIMP
-nsRegistryFactory::CreateInstance(nsISupports *aOuter,
- const nsIID &aIID,
- void **aResult) {
- nsresult rv = NS_OK;
- nsRegistry* newRegistry;
-
- if(aResult == nsnull) {
- return NS_ERROR_NULL_POINTER;
- } else {
- *aResult = nsnull;
- }
-
- if(0 != aOuter) {
- return NS_ERROR_NO_AGGREGATION;
- }
-
- NS_NEWXPCOM(newRegistry, nsRegistry);
-
- if(newRegistry == nsnull) {
- return NS_ERROR_OUT_OF_MEMORY;
- }
-
- NS_ADDREF(newRegistry);
- rv = newRegistry->QueryInterface(aIID, aResult);
- NS_RELEASE(newRegistry);
-
- return rv;
-}
-
-nsresult
-nsRegistryFactory::LockFactory(PRBool aLock)
-{
- // Not implemented in simplest case.
- return NS_OK;
-}
-
-// This is a temporary hack; needs work to support dynamic binding
-// via nsComponentManager and support for multiple factories per DLL.
-extern "C" NS_EXPORT nsresult
-NS_RegistryGetFactory(nsIFactory** aFactory ) {
- nsresult rv = NS_OK;
-
- if( aFactory == 0 ) {
- return NS_ERROR_NULL_POINTER;
- } else {
- *aFactory = 0;
- }
-
- nsIFactory* inst = new nsRegistryFactory();
- if(0 == inst) {
- rv = NS_ERROR_OUT_OF_MEMORY;
- } else {
- NS_ADDREF(inst);
- *aFactory = inst;
- }
-
- return rv;
-}
deleted file mode 100644
--- a/xpcom/obsolete/component/nsRegistry.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Edward Kandrot <kandrot@netscape.com>
- *
- * 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 ***** */
-
-
-#ifndef nsRegistry_h__
-#define nsRegistry_h__
-
-#include "nsIRegistry.h"
-#include "NSReg.h"
-#include "nsIFile.h"
-#include "nsCOMPtr.h"
-
-struct nsRegistry : public nsIRegistry, nsIRegistryGetter {
- // This class implements the nsISupports interface functions.
- NS_DECL_ISUPPORTS
-
- // This class implements the nsIRegistry interface functions.
- NS_DECL_NSIREGISTRY
-
- // Fast registry getters
- NS_DECL_NSIREGISTRYGETTER
-
- int SetBufferSize( int bufsize ); // changes the file buffer size for this registry
-
- // ctor/dtor
- nsRegistry();
-
-private:
- ~nsRegistry();
-
-protected:
- HREG mReg; // Registry handle.
-#ifdef EXTRA_THREADSAFE
- PRLock *mregLock; // libreg isn't threadsafe. Use locks to synchronize.
-#endif
- nsCOMPtr<nsIFile> mCurRegFile; // these are to prevent open from opening the registry again
- nsWellKnownRegistry mCurRegID;
-
- NS_IMETHOD Close();
-}; // nsRegistry
-
-#endif
deleted file mode 100644
--- a/xpcom/obsolete/component/nsXPCOMObsolete.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * 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 ***** */
-
-#include "nsXPCOM.h"
-#include "nsIGenericFactory.h"
-
-#include "nsFileSpecImpl.h"
-#include "nsRegistry.h"
-
-#define COMPONENT(NAME, Ctor) \
- { NS_##NAME##_CLASSNAME, NS_##NAME##_CID, NS_##NAME##_CONTRACTID, Ctor }
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegistry)
-
-static const nsModuleComponentInfo components[] =
-{
- COMPONENT(FILESPEC, nsFileSpecImpl::Create),
- COMPONENT(DIRECTORYITERATOR, nsDirectoryIteratorImpl::Create),
- COMPONENT(REGISTRY, nsRegistryConstructor),
-};
-
-NS_IMPL_NSGETMODULE(xpcomObsoleteModule, components)
-
deleted file mode 100644
--- a/xpcom/obsolete/dlldeps-obs.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 2003
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * 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 ***** */
-
-// Force references to all of the symbols that we want exported from
-// the dll that are located in the .lib files we link with
-
-#include "nsFileSpec.h"
-#include "NSReg.h"
-
-void XXXNeverCalled_obsolete()
-{
- nsFileURL(NULL);
- nsFileSpec s;
-
- NR_RegSetBufferSize(NULL, 0);
-}
deleted file mode 100644
--- a/xpcom/obsolete/nsFileSpec.cpp
+++ /dev/null
@@ -1,1246 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * 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 ***** */
-
-#include "nsFileSpec.h"
-
-#include "nsDebug.h"
-#include "nsEscape.h"
-#include "nsMemory.h"
-
-#include "prtypes.h"
-#include "plstr.h"
-#include "plbase64.h"
-#include "prmem.h"
-
-#include "nsCOMPtr.h"
-#include "nsIServiceManager.h"
-#include "nsILocalFile.h"
-
-#include <string.h>
-#include <stdio.h>
-
-#if defined(XP_WIN)
-#include <mbstring.h>
-#endif
-
-#ifdef XP_OS2
-extern unsigned char* _mbsrchr( const unsigned char*, int);
-#endif
-
-// return pointer to last instance of the given separator
-static inline char *GetLastSeparator(const char *str, char sep)
-{
-#if defined(XP_WIN) || defined(XP_OS2)
- return (char*) _mbsrchr((const unsigned char *) str, sep);
-#else
- return (char*) strrchr(str, sep);
-#endif
-}
-
-#ifdef XP_MACOSX
-#include <sys/stat.h>
-#include <Aliases.h>
-#include <TextUtils.h>
-#endif
-
-//========================================================================================
-// class nsSimpleCharString
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsSimpleCharString::nsSimpleCharString()
-//----------------------------------------------------------------------------------------
-: mData(nsnull)
-{
-
-} // nsSimpleCharString::nsSimpleCharString
-
-//----------------------------------------------------------------------------------------
-nsSimpleCharString::nsSimpleCharString(const char* inString)
-//----------------------------------------------------------------------------------------
-: mData(nsnull)
-{
- if (inString)
- CopyFrom(inString, strlen(inString));
-} // nsSimpleCharString::nsSimpleCharString
-
-//----------------------------------------------------------------------------------------
-nsSimpleCharString::nsSimpleCharString(const nsString& inString)
-//----------------------------------------------------------------------------------------
-: mData(nsnull)
-{
- *this = inString;
-} // nsSimpleCharString::nsSimpleCharString
-
-//----------------------------------------------------------------------------------------
-nsSimpleCharString::nsSimpleCharString(const nsSimpleCharString& inOther)
-//----------------------------------------------------------------------------------------
-{
- mData = inOther.mData;
- AddRefData();
-} // nsSimpleCharString::nsSimpleCharString
-
-//----------------------------------------------------------------------------------------
-nsSimpleCharString::nsSimpleCharString(const char* inData, PRUint32 inLength)
-//----------------------------------------------------------------------------------------
-: mData(nsnull)
-{
- CopyFrom(inData, inLength);
-} // nsSimpleCharString::nsSimpleCharString
-
-//----------------------------------------------------------------------------------------
-nsSimpleCharString::~nsSimpleCharString()
-//----------------------------------------------------------------------------------------
-{
- ReleaseData();
-} // nsSimpleCharString::nsSimpleCharString
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::operator = (const char* inString)
-//----------------------------------------------------------------------------------------
-{
- if (inString)
- CopyFrom(inString, strlen(inString));
- else
- SetToEmpty();
-} // nsSimpleCharString::operator =
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::operator = (const nsString& inString)
-//----------------------------------------------------------------------------------------
-{
- PRUint32 len = inString.Length();
- ReallocData(len);
- if (!mData)
- return;
- nsFixedCString dataString(mData->mString, len + 1);
- LossyCopyUTF16toASCII(inString, dataString);
- NS_ASSERTION(dataString.get() == mData->mString, "buffer too small");
-} // nsSimpleCharString::operator =
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::operator = (const nsSimpleCharString& inOther)
-//----------------------------------------------------------------------------------------
-{
- if (mData == inOther.mData)
- return;
- ReleaseData();
- mData = inOther.mData;
- AddRefData();
-} // nsSimpleCharString::operator =
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::operator += (const char* inOther)
-//----------------------------------------------------------------------------------------
-{
- if (!inOther)
- return;
- int newLength = Length() + strlen(inOther);
- ReallocData(newLength);
- strcat(mData->mString, inOther);
-} // nsSimpleCharString::operator =
-
-//----------------------------------------------------------------------------------------
-nsSimpleCharString nsSimpleCharString::operator + (const char* inOther) const
-//----------------------------------------------------------------------------------------
-{
- nsSimpleCharString result(*this);
- result += inOther;
- return result;
-} // nsSimpleCharString::operator =
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::Catenate(const char* inString1, const char* inString2)
-//----------------------------------------------------------------------------------------
-{
- if (!inString2)
- {
- *this += inString1;
- return;
- }
- int newLength = Length() + strlen(inString1) + strlen(inString2);
- ReallocData(newLength);
- strcat(mData->mString, inString1);
- strcat(mData->mString, inString2);
-} // nsSimpleCharString::operator =
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::CopyFrom(const char* inData, PRUint32 inLength)
-//----------------------------------------------------------------------------------------
-{
- if (!inData)
- return;
- ReallocData(inLength);
- if (!mData)
- return;
- if (inLength != 0) {
- memcpy(mData->mString, inData, inLength);
- }
- mData->mString[inLength] = '\0';
-} // nsSimpleCharString::CopyFrom
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::SetToEmpty()
-//----------------------------------------------------------------------------------------
-{
- ReleaseData();
-} // nsSimpleCharString::SetToEmpty
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::Unescape()
-//----------------------------------------------------------------------------------------
-{
- if (!mData)
- return;
- ReallocData(mData->mLength);
- if (!mData)
- return;
- nsUnescape(mData->mString);
- mData->mLength = strlen(mData->mString);
-} // nsSimpleCharString::Unescape
-
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::AddRefData()
-//----------------------------------------------------------------------------------------
-{
- if (mData)
- ++mData->mRefCount;
-} // nsSimpleCharString::AddRefData
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::ReleaseData()
-//----------------------------------------------------------------------------------------
-{
- if (!mData)
- return;
- NS_ASSERTION(mData->mRefCount > 0, "String deleted too many times!");
- if (--mData->mRefCount == 0)
- PR_Free(mData);
- mData = nsnull;
-} // nsSimpleCharString::ReleaseData
-
-//----------------------------------------------------------------------------------------
-inline PRUint32 CalculateAllocLength(PRUint32 logicalLength)
-// Round up to the next multiple of 256.
-//----------------------------------------------------------------------------------------
-{
- return ((1 + (logicalLength >> 8)) << 8);
-}
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::ReallocData(PRUint32 inLength)
-// Reallocate mData to a new length. Since this presumably precedes a change to the string,
-// we want to detach ourselves if the data is shared by another string, even if the length
-// requested would not otherwise require a reallocation.
-//----------------------------------------------------------------------------------------
-{
- PRUint32 newAllocLength = CalculateAllocLength(inLength);
- PRUint32 oldAllocLength = CalculateAllocLength(Length());
- if (mData)
- {
- NS_ASSERTION(mData->mRefCount > 0, "String deleted too many times!");
- if (mData->mRefCount == 1)
- {
- // We are the sole owner, so just change its length, if necessary.
- if (newAllocLength > oldAllocLength)
- mData = (Data*)PR_Realloc(mData, newAllocLength + sizeof(Data));
- mData->mLength = inLength;
- mData->mString[inLength] = '\0'; // we may be truncating
- return;
- }
- }
- PRUint32 copyLength = Length();
- if (inLength < copyLength)
- copyLength = inLength;
- Data* newData = (Data*)PR_Malloc(newAllocLength + sizeof(Data));
- // If data was already allocated when we get to here, then we are cloning the data
- // from a shared pointer.
- if (mData)
- {
- memcpy(newData, mData, sizeof(Data) + copyLength);
- mData->mRefCount--; // Say goodbye
- }
- else
- newData->mString[0] = '\0';
-
- mData = newData;
- mData->mRefCount = 1;
- mData->mLength = inLength;
-} // nsSimpleCharString::ReleaseData
-
-
-//========================================================================================
-NS_NAMESPACE nsFileSpecHelpers
-//========================================================================================
-{
- enum
- { kMaxFilenameLength = 31 // should work on Macintosh, Unix, and Win32.
- , kMaxAltDigitLength = 5
- , kMaxCoreLeafNameLength = (kMaxFilenameLength - (kMaxAltDigitLength + 1))
- };
- NS_NAMESPACE_PROTOTYPE void Canonify(nsSimpleCharString& ioPath, PRBool inMakeDirs);
- NS_NAMESPACE_PROTOTYPE void MakeAllDirectories(const char* inPath, int mode);
-#if defined(XP_WIN) || defined(XP_OS2)
- NS_NAMESPACE_PROTOTYPE void NativeToUnix(nsSimpleCharString& ioPath);
- NS_NAMESPACE_PROTOTYPE void UnixToNative(nsSimpleCharString& ioPath);
-#endif
-} NS_NAMESPACE_END
-
-//----------------------------------------------------------------------------------------
-nsresult ns_file_convert_result(PRInt32 nativeErr)
-//----------------------------------------------------------------------------------------
-{
- return nativeErr ?
- NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES,((nativeErr)&0xFFFF))
- : NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-void nsSimpleCharString::LeafReplace(char inSeparator, const char* inLeafName)
-//----------------------------------------------------------------------------------------
-{
- // Find the existing leaf name
- if (IsEmpty())
- return;
- if (!inLeafName)
- {
- SetToEmpty();
- return;
- }
- char* chars = mData->mString;
- char* lastSeparator = GetLastSeparator(chars, inSeparator);
- int oldLength = Length();
- PRBool trailingSeparator = (lastSeparator + 1 == chars + oldLength);
- if (trailingSeparator)
- {
- char savedCh = *lastSeparator;
- char *savedLastSeparator = lastSeparator;
- *lastSeparator = '\0';
- lastSeparator = GetLastSeparator(chars, inSeparator);
- *savedLastSeparator = savedCh;
- }
- if (lastSeparator)
- lastSeparator++; // point at the trailing string
- else
- lastSeparator = chars; // the full monty
-
- PRUint32 savedLastSeparatorOffset = (lastSeparator - chars);
- int newLength =
- (lastSeparator - chars) + strlen(inLeafName) + (trailingSeparator != 0);
- ReallocData(newLength);
-
- chars = mData->mString; // it might have moved.
- chars[savedLastSeparatorOffset] = '\0'; // strip the current leaf name
-
- strcat(chars, inLeafName);
- if (trailingSeparator)
- {
- // If the original ended in a slash, then the new one should, too.
- char sepStr[2] = "/";
- *sepStr = inSeparator;
- strcat(chars, sepStr);
- }
-} // nsSimpleCharString::LeafReplace
-
-//----------------------------------------------------------------------------------------
-char* nsSimpleCharString::GetLeaf(char inSeparator) const
-// Returns a pointer to an allocated string representing the leaf.
-//----------------------------------------------------------------------------------------
-{
- if (IsEmpty())
- return nsnull;
-
- char* chars = mData->mString;
- const char* lastSeparator = GetLastSeparator(chars, inSeparator);
- // If there was no separator, then return a copy of our path.
- if (!lastSeparator)
- return nsCRT::strdup(*this);
-
- // So there's at least one separator. What's just after it?
- // If the separator was not the last character, return the trailing string.
- const char* leafPointer = lastSeparator + 1;
- if (*leafPointer)
- return nsCRT::strdup(leafPointer);
-
- // So now, separator was the last character. Poke in a null instead.
- *(char*)lastSeparator = '\0'; // Should use const_cast, but Unix has old compiler.
- leafPointer = GetLastSeparator(chars, inSeparator);
- char* result = leafPointer ? nsCRT::strdup(++leafPointer) : nsCRT::strdup(chars);
- // Restore the poked null before returning.
- *(char*)lastSeparator = inSeparator;
-#if defined(XP_WIN) || defined(XP_OS2)
- // If it's a drive letter use the colon notation.
- if (!leafPointer && result[1] == '|' && result[2] == 0)
- result[1] = ':';
-#endif
- return result;
-} // nsSimpleCharString::GetLeaf
-
-#if (defined(XP_UNIX) || defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS))
-
-//----------------------------------------------------------------------------------------
-void nsFileSpecHelpers::MakeAllDirectories(const char* inPath, int mode)
-// Make the path a valid one by creating all the intermediate directories. Does NOT
-// make the leaf into a directory. This should be a unix path.
-//----------------------------------------------------------------------------------------
-{
- if (!inPath)
- return;
-
- char* pathCopy = nsCRT::strdup( inPath );
- if (!pathCopy)
- return;
-
- const char kSeparator = '/'; // I repeat: this should be a unix-style path.
- const int kSkipFirst = 1;
-
-#if defined(XP_WIN) || defined(XP_OS2)
- // Either this is a relative path, or we ensure that it has
- // a drive letter specifier.
- NS_ASSERTION( pathCopy[0] != '/' || (pathCopy[1] && (pathCopy[2] == '|' || pathCopy[2] == '/')),
- "Not a UNC path and no drive letter!" );
-#endif
- char* currentStart = pathCopy;
- char* currentEnd = strchr(currentStart + kSkipFirst, kSeparator);
- if (currentEnd)
- {
- nsFileSpec spec;
- *currentEnd = '\0';
-
-#if defined(XP_WIN) || defined(XP_OS2)
- /*
- if we have a drive letter path, we must make sure that the inital path has a '/' on it, or
- Canonify will turn "/c|" into a path relative to the running executable.
- */
- if (pathCopy[0] == '/' && pathCopy[1] && pathCopy[2] == '|')
- {
- char* startDir = (char*)PR_Malloc(strlen(pathCopy) + 2);
- strcpy(startDir, pathCopy);
- strcat(startDir, "/");
-
- spec = nsFilePath(startDir, PR_FALSE);
-
- PR_Free(startDir);
- }
- else
- {
- // move after server name and share name in UNC path
- if (pathCopy[0] == '/' &&
- currentEnd == currentStart+kSkipFirst)
- {
- *currentEnd = '/';
- currentStart = strchr(pathCopy+2, kSeparator);
- currentStart = strchr(currentStart+1, kSeparator);
- currentEnd = strchr(currentStart+1, kSeparator);
- if (currentEnd)
- *currentEnd = '\0';
- }
- spec = nsFilePath(pathCopy, PR_FALSE);
- }
-#else
- spec = nsFilePath(pathCopy, PR_FALSE);
-#endif
- do
- {
- // If the node doesn't exist, and it is not the initial node in a full path,
- // then make a directory (We cannot make the initial (volume) node).
- if (!spec.Exists() && *currentStart != kSeparator)
- spec.CreateDirectory(mode);
-
- currentStart = ++currentEnd;
- currentEnd = strchr(currentStart, kSeparator);
- if (!currentEnd)
- break;
-
- *currentEnd = '\0';
-
- spec += currentStart; // "lengthen" the path, adding the next node.
- } while (currentEnd);
- }
- nsCRT::free(pathCopy);
-} // nsFileSpecHelpers::MakeAllDirectories
-
-#endif // XP_UNIX || XP_WIN || XP_OS2 || XP_BEOS
-
-#if defined(XP_WIN)
-#include "nsFileSpecWin.cpp" // Windows-specific implementations
-#elif defined(XP_BEOS)
-#include "nsFileSpecBeOS.cpp" // BeOS-specific implementations
-#elif defined(XP_UNIX)
-#include "nsFileSpecUnix.cpp" // Unix-specific implementations
-#elif defined(XP_OS2)
-#include "nsFileSpecOS2.cpp" // OS/2-specific implementations
-#endif
-
-//========================================================================================
-// nsFileURL implementation
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsFileURL::nsFileURL(const char* inString, PRBool inCreateDirs)
-//----------------------------------------------------------------------------------------
-{
- if (!inString)
- return;
- NS_ASSERTION(strstr(inString, kFileURLPrefix) == inString, "Not a URL!");
- // Make canonical and absolute. Since it's a parameter to this constructor,
- // inString is escaped. We want to make an nsFilePath, which requires
- // an unescaped string.
- nsSimpleCharString unescapedPath(inString + kFileURLPrefixLength);
- unescapedPath.Unescape();
- nsFilePath path(unescapedPath, inCreateDirs);
- *this = path;
-} // nsFileURL::nsFileURL
-
-//----------------------------------------------------------------------------------------
-nsFileURL::nsFileURL(const nsString& inString, PRBool inCreateDirs)
-//----------------------------------------------------------------------------------------
-{
- NS_LossyConvertUTF16toASCII cstring(inString);
- if (!inString.Length())
- return;
- NS_ASSERTION(strstr(cstring.get(), kFileURLPrefix) == cstring.get(),
- "Not a URL!");
- // Make canonical and absolute. Since it's a parameter to this constructor,
- // inString is escaped. We want to make an nsFilePath, which requires
- // an unescaped string.
- nsSimpleCharString unescapedPath(cstring.get() + kFileURLPrefixLength);
- unescapedPath.Unescape();
- nsFilePath path(unescapedPath, inCreateDirs);
- *this = path;
-} // nsFileURL::nsFileURL
-
-//----------------------------------------------------------------------------------------
-nsFileURL::nsFileURL(const nsFileURL& inOther)
-//----------------------------------------------------------------------------------------
-: mURL(inOther.mURL)
-{
-} // nsFileURL::nsFileURL
-
-//----------------------------------------------------------------------------------------
-nsFileURL::nsFileURL(const nsFilePath& inOther)
-//----------------------------------------------------------------------------------------
-{
- *this = inOther;
-} // nsFileURL::nsFileURL
-
-//----------------------------------------------------------------------------------------
-nsFileURL::nsFileURL(const nsFileSpec& inOther)
-//----------------------------------------------------------------------------------------
-{
- *this = inOther;
-} // nsFileURL::nsFileURL
-
-//----------------------------------------------------------------------------------------
-nsFileURL::~nsFileURL()
-//----------------------------------------------------------------------------------------
-{
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileURL::operator = (const char* inString)
-//----------------------------------------------------------------------------------------
-{
- // XXX is this called by nsFileSpecImpl.cpp::SetURLString?
- // if so, there's a bug...
-
- mURL = inString;
- NS_ASSERTION(strstr(inString, kFileURLPrefix) == inString, "Not a URL!");
-} // nsFileURL::operator =
-
-//----------------------------------------------------------------------------------------
-void nsFileURL::operator +=(const char* inRelativeUnixPath)
-//----------------------------------------------------------------------------------------
-{
- char* escapedPath = nsEscape(inRelativeUnixPath, url_Path);
- mURL += escapedPath;
- nsCRT::free(escapedPath);
-} // nsFileURL::operator +=
-
-//----------------------------------------------------------------------------------------
-nsFileURL nsFileURL::operator +(const char* inRelativeUnixPath) const
-//----------------------------------------------------------------------------------------
-{
- nsFileURL result(*this);
- result += inRelativeUnixPath;
- return result;
-} // nsFileURL::operator +
-
-//----------------------------------------------------------------------------------------
-void nsFileURL::operator = (const nsFileURL& inOther)
-//----------------------------------------------------------------------------------------
-{
- mURL = inOther.mURL;
-} // nsFileURL::operator =
-
-//----------------------------------------------------------------------------------------
-void nsFileURL::operator = (const nsFilePath& inOther)
-//----------------------------------------------------------------------------------------
-{
- mURL = kFileURLPrefix;
- char* original = (char*)(const char*)inOther; // we shall modify, but restore.
- if (!original || !*original) return;
-#if defined(XP_WIN) || defined(XP_OS2)
- // because we don't want to escape the '|' character, change it to a letter.
- // Note that a UNC path will not have a '|' character.
- char oldchar = original[2];
- original[2] = 'x';
- char* escapedPath = nsEscape(original, url_Path);
- original[2] = escapedPath[2] = oldchar; // restore it
-#else
- char* escapedPath = nsEscape(original, url_Path);
-#endif
- if (escapedPath)
- mURL += escapedPath;
- nsCRT::free(escapedPath);
-} // nsFileURL::operator =
-
-//----------------------------------------------------------------------------------------
-void nsFileURL::operator = (const nsFileSpec& inOther)
-//----------------------------------------------------------------------------------------
-{
- *this = nsFilePath(inOther);
- if (mURL[mURL.Length() - 1] != '/' && inOther.IsDirectory())
- mURL += "/";
-} // nsFileURL::operator =
-
-
-//========================================================================================
-// nsFilePath implementation
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsFilePath::nsFilePath(const nsFilePath& inPath)
-//----------------------------------------------------------------------------------------
- : mPath(inPath.mPath)
-{
-}
-
-//----------------------------------------------------------------------------------------
-nsFilePath::nsFilePath(const char* inString, PRBool inCreateDirs)
-//----------------------------------------------------------------------------------------
-: mPath(inString)
-{
- if (mPath.IsEmpty())
- return;
-
- NS_ASSERTION(strstr(inString, kFileURLPrefix) != inString, "URL passed as path");
-
-#if defined(XP_WIN) || defined(XP_OS2)
- nsFileSpecHelpers::UnixToNative(mPath);
-#endif
- // Make canonical and absolute.
- nsFileSpecHelpers::Canonify(mPath, inCreateDirs);
-#if defined(XP_WIN) || defined(XP_OS2)
- // Assert native path is of one of these forms:
- // - regular: X:\some\path
- // - UNC: \\some_machine\some\path
- NS_ASSERTION( mPath[1] == ':' || (mPath[0] == '\\' && mPath[1] == '\\'),
- "unexpected canonical path" );
- nsFileSpecHelpers::NativeToUnix(mPath);
-#endif
-}
-
-//----------------------------------------------------------------------------------------
-nsFilePath::nsFilePath(const nsString& inString, PRBool inCreateDirs)
-//----------------------------------------------------------------------------------------
-: mPath(inString)
-{
- if (mPath.IsEmpty())
- return;
-
- NS_ASSERTION(strstr((const char*)mPath, kFileURLPrefix) != (const char*)mPath, "URL passed as path");
-#if defined(XP_WIN) || defined(XP_OS2)
- nsFileSpecHelpers::UnixToNative(mPath);
-#endif
- // Make canonical and absolute.
- nsFileSpecHelpers::Canonify(mPath, inCreateDirs);
-#if defined(XP_WIN) || defined(XP_OS2)
- NS_ASSERTION( mPath[1] == ':' || (mPath[0] == '\\' && mPath[1] == '\\'),
- "unexpected canonical path" );
- nsFileSpecHelpers::NativeToUnix(mPath);
-#endif
-}
-
-//----------------------------------------------------------------------------------------
-nsFilePath::nsFilePath(const nsFileURL& inOther)
-//----------------------------------------------------------------------------------------
-{
- mPath = (const char*)inOther.mURL + kFileURLPrefixLength;
- mPath.Unescape();
-}
-
-#if (defined XP_UNIX || defined XP_BEOS)
-//----------------------------------------------------------------------------------------
-nsFilePath::nsFilePath(const nsFileSpec& inOther)
-//----------------------------------------------------------------------------------------
-: mPath(inOther.mPath)
-{
-}
-#endif // XP_UNIX || XP_BEOS
-
-//----------------------------------------------------------------------------------------
-nsFilePath::~nsFilePath()
-//----------------------------------------------------------------------------------------
-{
-}
-
-#if (defined XP_UNIX || defined XP_BEOS)
-//----------------------------------------------------------------------------------------
-void nsFilePath::operator = (const nsFileSpec& inOther)
-//----------------------------------------------------------------------------------------
-{
- // XXX bug here, again if.
-
- mPath = inOther.mPath;
-}
-#endif // XP_UNIX
-
-//----------------------------------------------------------------------------------------
-void nsFilePath::operator = (const char* inString)
-//----------------------------------------------------------------------------------------
-{
-
- NS_ASSERTION(strstr(inString, kFileURLPrefix) != inString, "URL passed as path");
- mPath = inString;
- if (mPath.IsEmpty())
- return;
-#if defined(XP_WIN) || defined(XP_OS2)
- nsFileSpecHelpers::UnixToNative(mPath);
-#endif
- // Make canonical and absolute.
- nsFileSpecHelpers::Canonify(mPath, PR_FALSE /* XXX? */);
-#if defined(XP_WIN) || defined(XP_OS2)
- nsFileSpecHelpers::NativeToUnix(mPath);
-#endif
-}
-
-//----------------------------------------------------------------------------------------
-void nsFilePath::operator = (const nsFileURL& inOther)
-//----------------------------------------------------------------------------------------
-{
- mPath = (const char*)nsFilePath(inOther);
-}
-
-//----------------------------------------------------------------------------------------
-void nsFilePath::operator = (const nsFilePath& inOther)
-//----------------------------------------------------------------------------------------
-{
- mPath = inOther.mPath;
-}
-
-//----------------------------------------------------------------------------------------
-void nsFilePath::operator +=(const char* inRelativeUnixPath)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inRelativeUnixPath, "Attempt append relative path with null path");
-
- char* escapedPath = nsEscape(inRelativeUnixPath, url_Path);
- mPath += escapedPath;
- nsCRT::free(escapedPath);
-} // nsFilePath::operator +=
-
-//----------------------------------------------------------------------------------------
-nsFilePath nsFilePath::operator +(const char* inRelativeUnixPath) const
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inRelativeUnixPath, "Attempt append relative path with null path");
-
- nsFilePath resultPath(*this);
- resultPath += inRelativeUnixPath;
- return resultPath;
-} // nsFilePath::operator +
-
-
-//========================================================================================
-// nsFileSpec implementation
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec()
-//----------------------------------------------------------------------------------------
-: mError(NS_OK) // XXX shouldn't this be NS_ERROR_NOT_INITIALIZED?
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::Clear()
-//----------------------------------------------------------------------------------------
-{
- mPath.SetToEmpty();
- mError = NS_ERROR_NOT_INITIALIZED;
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpec::~nsFileSpec()
-//----------------------------------------------------------------------------------------
-{
- // mPath cleans itself up
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec(const nsPersistentFileDescriptor& inDescriptor)
-//----------------------------------------------------------------------------------------
-{
- *this = inDescriptor;
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec(const nsFileURL& inURL)
-//----------------------------------------------------------------------------------------
-{
- *this = nsFilePath(inURL); // convert to unix path first
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::MakeUnique(const char* inSuggestedLeafName, PRBool inCreateFile)
-//----------------------------------------------------------------------------------------
-{
- if (inSuggestedLeafName && *inSuggestedLeafName)
- SetLeafName(inSuggestedLeafName);
- MakeUnique(inCreateFile);
-} // nsFileSpec::MakeUnique
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::MakeUnique(PRBool inCreateFile)
-//----------------------------------------------------------------------------------------
-{
- // XXX: updated path starts empty. In case of error this will cause
- // any callers to fail badly, but that seems better than letting them
- // re-use the default name which has failed to be unique.
- nsCAutoString path;
- nsCOMPtr<nsILocalFile> localFile;
- NS_NewNativeLocalFile(nsDependentCString(*this), PR_TRUE, getter_AddRefs(localFile));
- if (localFile)
- {
- nsresult rv;
-
- if (inCreateFile)
- rv = localFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
- else
- rv = localFile->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700);
-
- if (NS_SUCCEEDED(rv))
- localFile->GetNativePath(path);
- }
-
- NS_ASSERTION(!path.IsEmpty(), "MakeUnique() failed!");
- *this = path.get(); // reset the filepath to point to the unique location
-
-} // nsFileSpec::MakeUnique
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator = (const nsFileURL& inURL)
-//----------------------------------------------------------------------------------------
-{
- *this = nsFilePath(inURL); // convert to unix path first
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator = (const nsPersistentFileDescriptor& inDescriptor)
-//----------------------------------------------------------------------------------------
-{
-
- nsCAutoString data;
- inDescriptor.GetData(data);
-
-#ifdef XP_MACOSX
- // Decode descriptor into a Handle (which is actually an AliasHandle)
- char* decodedData = PL_Base64Decode(data.get(), data.Length(), nsnull);
- Handle aliasH = nsnull;
- mError = NS_FILE_RESULT(::PtrToHand(decodedData, &aliasH, (data.Length() * 3) / 4));
- PR_Free(decodedData);
- if (NS_FAILED(mError))
- return; // not enough memory?
-
- Boolean changed;
- FSRef fileRef;
- mError = NS_FILE_RESULT(::FSResolveAlias(nsnull, (AliasHandle)aliasH, &fileRef, &changed));
- ::DisposeHandle(aliasH);
-
- UInt8 pathBuf[PATH_MAX];
- mError = NS_FILE_RESULT(::FSRefMakePath(&fileRef, pathBuf, PATH_MAX));
- if (NS_FAILED(mError))
- return;
- mPath = (const char*)pathBuf;
-#else
- mPath = data.get();
- mError = NS_OK;
-#endif
-}
-
-//========================================================================================
-// UNIX & WIN nsFileSpec implementation
-//========================================================================================
-
-#if (defined XP_UNIX || defined XP_BEOS)
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec(const nsFilePath& inPath)
-//----------------------------------------------------------------------------------------
-: mPath((const char*)inPath)
-, mError(NS_OK)
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator = (const nsFilePath& inPath)
-//----------------------------------------------------------------------------------------
-{
- mPath = (const char*)inPath;
- mError = NS_OK;
-}
-#endif // XP_UNIX || XP_BEOS
-
-#if (defined(XP_UNIX) || defined(XP_WIN) || defined(XP_OS2) || defined(XP_BEOS))
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec(const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
-: mPath(inSpec.mPath)
-, mError(NS_OK)
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec(const char* inString, PRBool inCreateDirs)
-//----------------------------------------------------------------------------------------
-: mPath(inString)
-, mError(NS_OK)
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
- // Make canonical and absolute.
- nsFileSpecHelpers::Canonify(mPath, inCreateDirs);
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec(const nsString& inString, PRBool inCreateDirs)
-//----------------------------------------------------------------------------------------
-: mPath(inString)
-, mError(NS_OK)
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
- // Make canonical and absolute.
- nsFileSpecHelpers::Canonify(mPath, inCreateDirs);
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator = (const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
-{
- mPath = inSpec.mPath;
- mError = inSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator = (const char* inString)
-//----------------------------------------------------------------------------------------
-{
- mPath = inString;
- // Make canonical and absolute.
- nsFileSpecHelpers::Canonify(mPath, PR_FALSE /* XXX? */);
- mError = NS_OK;
-}
-#endif // XP_UNIX,XP_WIN,XP_OS2,XP_BEOS
-
-//----------------------------------------------------------------------------------------
-nsFileSpec nsFileSpec::operator + (const char* inRelativePath) const
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inRelativePath, "Attempt to append name with a null string");
-
- nsFileSpec resultSpec = *this;
- resultSpec += inRelativePath;
- return resultSpec;
-} // nsFileSpec::operator +
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::operator == (const nsFileSpec& inOther) const
-//----------------------------------------------------------------------------------------
-{
- PRBool amEmpty = mPath.IsEmpty();
- PRBool heEmpty = inOther.mPath.IsEmpty();
- if (amEmpty) // we're the same if he's empty...
- return heEmpty;
- if (heEmpty) // ('cuz I'm not...)
- return PR_FALSE;
-
- nsSimpleCharString str = mPath;
- nsSimpleCharString inStr = inOther.mPath;
-
- // Length() is size of buffer, not length of string
- PRUint32 strLast = str.Length() - 1, inLast = inStr.Length() - 1;
-#if defined(XP_WIN) || defined(XP_OS2)
-#define DIR_SEPARATOR '\\' // XXX doesn't NSPR have this?
- /* windows does not care about case. */
-#ifdef XP_OS2
-#define DIR_STRCMP strcmp
-#else
-#define DIR_STRCMP _stricmp
-#endif
-#else
-#define DIR_SEPARATOR '/'
-#if defined(VMS)
-#define DIR_STRCMP strcasecmp
-#else
-#define DIR_STRCMP strcmp
-#endif
-#endif
- if(str[strLast] == DIR_SEPARATOR)
- str[strLast] = '\0';
-
- if(inStr[inLast] == DIR_SEPARATOR)
- inStr[inLast] = '\0';
-
- if (DIR_STRCMP(str, inStr) == 0)
- return PR_TRUE;
-#undef DIR_SEPARATOR
-#undef DIR_STRCMP
- return PR_FALSE;
-}
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::operator != (const nsFileSpec& inOther) const
-//----------------------------------------------------------------------------------------
-{
- return (! (*this == inOther) );
-}
-
-//----------------------------------------------------------------------------------------
-// This is the only automatic conversion to const char*
-// that is provided, and it allows the
-// path to be "passed" to NSPR file routines. This practice
-// is VERY EVIL and should only be used to support legacy
-// code. Using it guarantees bugs on Macintosh. The path is NOT allocated, so do
-// not even think of deleting (or freeing) it.
-const char* nsFileSpec::GetCString() const
-//----------------------------------------------------------------------------------------
-{
- return mPath;
-}
-
-//----------------------------------------------------------------------------------------
-// Is our spec a child of the provided parent?
-PRBool nsFileSpec::IsChildOf(nsFileSpec &possibleParent)
-//----------------------------------------------------------------------------------------
-{
- nsFileSpec iter = *this, parent;
-#ifdef DEBUG
- int depth = 0;
-#endif
- while (1) {
-#ifdef DEBUG
- // sanity
- NS_ASSERTION(depth < 100, "IsChildOf has lost its little mind");
- if (depth > 100)
- return PR_FALSE;
-#endif
- if (iter == possibleParent)
- return PR_TRUE;
-
- iter.GetParent(parent); // shouldn't this be an error on parent?
- if (iter.Failed())
- return PR_FALSE;
-
- if (iter == parent) // hit bottom
- return PR_FALSE;
-
- iter = parent;
-#ifdef DEBUG
- depth++;
-#endif
- }
-
- // not reached, but I bet some compiler will whine
- return PR_FALSE;
-}
-
-
-//========================================================================================
-// class nsPersistentFileDescriptor
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsPersistentFileDescriptor::nsPersistentFileDescriptor(const nsPersistentFileDescriptor& inDesc)
-//----------------------------------------------------------------------------------------
- : mDescriptorString(inDesc.mDescriptorString)
-{
-} // nsPersistentFileDescriptor::nsPersistentFileDescriptor
-
-//----------------------------------------------------------------------------------------
-void nsPersistentFileDescriptor::operator = (const nsPersistentFileDescriptor& inDesc)
-//----------------------------------------------------------------------------------------
-{
- mDescriptorString = inDesc.mDescriptorString;
-} // nsPersistentFileDescriptor::operator =
-
-//----------------------------------------------------------------------------------------
-nsPersistentFileDescriptor::nsPersistentFileDescriptor(const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
-{
- *this = inSpec;
-} // nsPersistentFileDescriptor::nsPersistentFileDescriptor
-
-//----------------------------------------------------------------------------------------
-void nsPersistentFileDescriptor::operator = (const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
-{
-#ifdef XP_MACOSX
- if (inSpec.Error())
- return;
-
- FSRef fileRef;
- Boolean isDir;
- OSErr err = ::FSPathMakeRef((const UInt8*)inSpec.GetCString(), &fileRef, &isDir);
- if (err != noErr)
- return;
-
- AliasHandle aliasH;
- err = ::FSNewAlias(nsnull, &fileRef, &aliasH);
- if (err != noErr)
- return;
-
- PRUint32 bytes = ::GetHandleSize((Handle) aliasH);
- ::HLock((Handle)aliasH);
- char* buf = PL_Base64Encode((const char*)*aliasH, bytes, nsnull);
- ::DisposeHandle((Handle) aliasH);
-
- mDescriptorString = buf;
- PR_Free(buf);
-#else
- mDescriptorString = inSpec.GetCString();
-#endif // XP_MACOSX
-} // nsPersistentFileDescriptor::operator =
-
-//----------------------------------------------------------------------------------------
-nsPersistentFileDescriptor::~nsPersistentFileDescriptor()
-//----------------------------------------------------------------------------------------
-{
-} // nsPersistentFileDescriptor::~nsPersistentFileDescriptor
-
-//----------------------------------------------------------------------------------------
-void nsPersistentFileDescriptor::GetData(nsAFlatCString& outData) const
-//----------------------------------------------------------------------------------------
-{
- outData.Assign(mDescriptorString, mDescriptorString.Length());
-}
-
-//----------------------------------------------------------------------------------------
-void nsPersistentFileDescriptor::SetData(const nsAFlatCString& inData)
-//----------------------------------------------------------------------------------------
-{
- mDescriptorString.CopyFrom(inData.get(), inData.Length());
-}
-
-//----------------------------------------------------------------------------------------
-void nsPersistentFileDescriptor::SetData(const char* inData, PRInt32 inSize)
-//----------------------------------------------------------------------------------------
-{
- mDescriptorString.CopyFrom(inData, inSize);
-}
-
-//========================================================================================
-// class nsNSPRPath
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsNSPRPath::operator const char*() const
-// NSPR expects a UNIX path on unix and Macintosh, but a native path on windows. NSPR
-// cannot be changed, so we have to do the dirty work.
-//----------------------------------------------------------------------------------------
-{
-#if defined(XP_WIN) || defined(XP_OS2)
- if (!modifiedNSPRPath)
- {
- // If this is the first call, initialize modifiedNSPRPath. Start by cloning
- // mFilePath, but strip the leading separator, if present
- const char* unixPath = (const char*)mFilePath;
- if (!unixPath)
- return nsnull;
-
- ((nsNSPRPath*)this)->modifiedNSPRPath
- = nsCRT::strdup(*unixPath == '/' ? unixPath + 1: unixPath);
-
- // Replace the bar
- if (modifiedNSPRPath[1] == '|')
- modifiedNSPRPath[1] = ':';
-
- // Remove the ending separator only if it is not the last separator
- int len = strlen(modifiedNSPRPath);
- if (modifiedNSPRPath[len - 1 ] == '/' && modifiedNSPRPath[len - 2 ] != ':')
- modifiedNSPRPath[len - 1 ] = '\0';
- }
- return modifiedNSPRPath;
-#else
- return (const char*)mFilePath;
-#endif
-}
-
-//----------------------------------------------------------------------------------------
-nsNSPRPath::~nsNSPRPath()
-//----------------------------------------------------------------------------------------
-{
-#if defined(XP_WIN) || defined(XP_OS2)
- if (modifiedNSPRPath)
- nsCRT::free(modifiedNSPRPath);
-#endif
-}
-
-
-nsresult
-NS_FileSpecToIFile(nsFileSpec* fileSpec, nsILocalFile* *result)
-{
- nsresult rv;
-
- nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
-
- if (!file) return NS_ERROR_FAILURE;
-
- rv = file->InitWithNativePath(nsDependentCString(fileSpec->GetNativePathCString()));
-
- if (NS_FAILED(rv)) return rv;
-
- *result = file;
- NS_ADDREF(*result);
- return NS_OK;
-}
-
-
-
-
deleted file mode 100644
--- a/xpcom/obsolete/nsFileSpec.h
+++ /dev/null
@@ -1,707 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * 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 ***** */
-
-
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- THESE CLASSES ARE DEPRECATED AND UNSUPPORTED! USE |nsIFile| and |nsILocalFile|.
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-
-
-
-
-
-
-
-
-
-// First checked in on 98/11/20 by John R. McMullen in the wrong directory.
-// Checked in again 98/12/04.
-// Polished version 98/12/08.
-
-//========================================================================================
-//
-// Classes defined:
-//
-// nsFilePath, nsFileURL, nsFileSpec, nsPersistentFileDescriptor
-// nsDirectoryIterator.
-//
-// Q. How should I represent files at run time?
-// A. Use nsFileSpec. Using char* will lose information on some platforms.
-//
-// Q. Then what are nsFilePath and nsFileURL for?
-// A. Only when you need a char* parameter for legacy code.
-//
-// Q. How should I represent files in a persistent way (eg, in a disk file)?
-// A. Use nsPersistentFileDescriptor. Convert to and from nsFileSpec at run time.
-//
-// This suite provides the following services:
-//
-// 1. Encapsulates all platform-specific file details, so that files can be
-// described correctly without any platform #ifdefs
-//
-// 2. Type safety. This will fix the problems that used to occur because people
-// confused file paths. They used to use const char*, which could mean three
-// or four different things. Bugs were introduced as people coded, right up
-// to the moment Communicator 4.5 shipped.
-//
-// 3. Used in conjunction with nsFileStream.h (q.v.), this supports all the power
-// and readability of the ansi stream syntax.
-//
-// Basic example:
-//
-// nsFilePath myPath("/Development/iotest.txt");
-//
-// nsOutputFileStream testStream(nsFileSpec(myPath));
-// testStream << "Hello World" << nsEndl;
-//
-// 4. Handy methods for manipulating file specifiers safely, e.g. MakeUnique(),
-// SetLeafName(), Exists().
-//
-// 5. Easy cross-conversion.
-//
-// Examples:
-//
-// Initialize a URL from a string
-//
-// nsFileURL fileURL("file:///Development/MPW/MPW%20Shell");
-//
-// Initialize a Unix-style path from a URL
-//
-// nsFilePath filePath(fileURL);
-//
-// Initialize a file spec from a URL
-//
-// nsFileSpec fileSpec(fileURL);
-//
-// Make the spec unique.
-//
-// fileSpec.MakeUnique();
-//
-// Assign the spec to a URL (causing conversion)
-//
-// fileURL = fileSpec;
-//
-// Assign a unix path using a string
-//
-// filePath = "/Development/MPW/SysErrs.err";
-//
-// Assign to a file spec using a unix path (causing conversion).
-//
-// fileSpec = filePath;
-//
-// Make this unique.
-//
-// fileSpec.MakeUnique();
-//
-// 6. Fixes a bug that have been there for a long time, and
-// is inevitable if you use NSPR alone, where files are described as paths.
-//
-// The problem affects platforms (Macintosh) in which a path does not fully
-// specify a file, because two volumes can have the same name. This
-// is solved by holding a "private" native file spec inside the
-// nsFilePath and nsFileURL classes, which is used when appropriate.
-//
-//========================================================================================
-
-#ifndef _FILESPEC_H_
-#define _FILESPEC_H_
-
-#include "xpcomobsolete.h"
-#include "nsError.h"
-#include "nsString.h"
-#include "nsReadableUtils.h"
-#include "nsCRT.h"
-#include "prtypes.h"
-
-//========================================================================================
-// Compiler-specific macros, as needed
-//========================================================================================
-#if !defined(NS_USING_NAMESPACE) && (defined(__MWERKS__) || defined(_MSC_VER))
-#define NS_USING_NAMESPACE
-#endif
-
-#ifdef NS_USING_NAMESPACE
-
-#define NS_NAMESPACE_PROTOTYPE
-#define NS_NAMESPACE namespace
-#define NS_NAMESPACE_END
-#define NS_EXPLICIT explicit
-#else
-
-#define NS_NAMESPACE_PROTOTYPE static
-#define NS_NAMESPACE struct
-#define NS_NAMESPACE_END ;
-#define NS_EXPLICIT
-
-#endif
-//=========================== End Compiler-specific macros ===============================
-
-#include "nsILocalFile.h"
-#include "nsCOMPtr.h"
-
-#if defined(XP_UNIX) || defined(XP_BEOS)
-#include <dirent.h>
-#elif defined(XP_WIN)
-
-// This clashes with some of the Win32 system headers (specifically,
-// winbase.h). Hopefully they'll have been included first; else we may
-// have problems. We could include winbase.h before doing this;
-// unfortunately, it'd bring in too much crap and'd slow stuff down
-// more than it's worth doing.
-#ifdef CreateDirectory
-#undef CreateDirectory
-#endif
-
-#include "prio.h"
-#elif defined(XP_OS2)
-#define INCL_DOS
-#define INCL_DOSERRORS
-#define INCL_WIN
-#define INCL_GPI
-#include <os2.h>
-#include "prio.h"
-#endif
-
-//========================================================================================
-// Here are the allowable ways to describe a file.
-//========================================================================================
-
-class nsFileSpec; // Preferred. For i/o use nsInputFileStream, nsOutputFileStream
-class nsFilePath;
-class nsFileURL;
-class nsNSPRPath; // This can be passed to NSPR file I/O routines, if you must.
-class nsPersistentFileDescriptor; // Used for storage across program launches.
-
-#define kFileURLPrefix "file://"
-#define kFileURLPrefixLength (7)
-
-class nsOutputStream;
-class nsInputStream;
-class nsIOutputStream;
-class nsIInputStream;
-class nsOutputFileStream;
-class nsInputFileStream;
-class nsOutputConsoleStream;
-
-class nsIUnicodeEncoder;
-class nsIUnicodeDecoder;
-
-//========================================================================================
-// Conversion of native file errors to nsresult values. These are really only for use
-// in the file module, clients of this interface shouldn't really need them.
-// Error results returned from this interface have, in the low-order 16 bits,
-// native errors that are masked to 16 bits. Assumption: a native error of 0 is success
-// on all platforms. Note the way we define this using an inline function. This
-// avoids multiple evaluation if people go NS_FILE_RESULT(function_call()).
-#define NS_FILE_RESULT(x) ns_file_convert_result((PRInt32)x)
-nsresult ns_file_convert_result(PRInt32 nativeErr);
-#define NS_FILE_FAILURE NS_FILE_RESULT(-1)
-
-//========================================================================================
-class nsSimpleCharString
-// An envelope for char*: reference counted. Used internally by all the nsFileSpec
-// classes below.
-//========================================================================================
-{
-public:
- nsSimpleCharString();
- nsSimpleCharString(const char*);
- nsSimpleCharString(const nsString&);
- nsSimpleCharString(const nsSimpleCharString&);
- nsSimpleCharString(const char* inData, PRUint32 inLength);
-
- ~nsSimpleCharString();
-
- void operator = (const char*);
- void operator = (const nsString&);
- void operator = (const nsSimpleCharString&);
-
- operator const char*() const { return mData ? mData->mString : 0; }
- operator char* ()
- {
- ReallocData(Length()); // requires detaching if shared...
- return mData ? mData->mString : 0;
- }
- PRBool operator == (const char*);
- PRBool operator == (const nsString&);
- PRBool operator == (const nsSimpleCharString&);
-
- void operator += (const char* inString);
- nsSimpleCharString operator + (const char* inString) const;
-
- char operator [](int i) const { return mData ? mData->mString[i] : '\0'; }
- char& operator [](int i)
- {
- if (i >= (int)Length())
- ReallocData((PRUint32)i + 1);
- return mData->mString[i]; // caveat appelator
- }
- char& operator [](unsigned int i) { return (*this)[(int)i]; }
-
- void Catenate(const char* inString1, const char* inString2);
-
- void SetToEmpty();
- PRBool IsEmpty() const { return Length() == 0; }
-
- PRUint32 Length() const { return mData ? mData->mLength : 0; }
- void SetLength(PRUint32 inLength) { ReallocData(inLength); }
- void CopyFrom(const char* inData, PRUint32 inLength);
- void LeafReplace(char inSeparator, const char* inLeafName);
- char* GetLeaf(char inSeparator) const; // use PR_Free()
- void Unescape();
-
-protected:
-
- void AddRefData();
- void ReleaseData();
- void ReallocData(PRUint32 inLength);
-
- //--------------------------------------------------
- // Data
- //--------------------------------------------------
-
-protected:
-
- struct Data {
- int mRefCount;
- PRUint32 mLength;
- char mString[1];
- };
- Data* mData;
-}; // class nsSimpleCharString
-
-//========================================================================================
-class NS_COM_OBSOLETE nsFileSpec
-// This is whatever each platform really prefers to describe files as. Declared first
-// because the other two types have an embedded nsFileSpec object.
-//========================================================================================
-{
- public:
- nsFileSpec();
-
- // These two methods take *native* file paths.
- NS_EXPLICIT nsFileSpec(const char* inNativePath, PRBool inCreateDirs = PR_FALSE);
- NS_EXPLICIT nsFileSpec(const nsString& inNativePath, PRBool inCreateDirs = PR_FALSE);
-
-
- NS_EXPLICIT nsFileSpec(const nsFilePath& inPath);
- NS_EXPLICIT nsFileSpec(const nsFileURL& inURL);
- nsFileSpec(const nsFileSpec& inPath);
- virtual ~nsFileSpec();
-
- // These two operands take *native* file paths.
- void operator = (const char* inNativePath);
-
- void operator = (const nsFilePath& inPath);
- void operator = (const nsFileURL& inURL);
- void operator = (const nsFileSpec& inOther);
- void operator = (const nsPersistentFileDescriptor& inOther);
-
- PRBool operator ==(const nsFileSpec& inOther) const;
- PRBool operator !=(const nsFileSpec& inOther) const;
-
-
- // Returns a native path, and allows the
- // path to be "passed" to legacy code. This practice
- // is VERY EVIL and should only be used to support legacy
- // code. Using it guarantees bugs on Macintosh.
- // The path is cached and freed by the nsFileSpec destructor
- // so do not delete (or free) it. See also nsNSPRPath below,
- // if you really must pass a string to PR_OpenFile().
- // Doing so will introduce two automatic bugs.
- const char* GetCString() const;
-
- // Same as GetCString (please read the comments).
- // Do not try to free this!
- operator const char* () const { return GetCString(); }
-
- // Same as GetCString (please read the comments).
- // Do not try to free this!
- const char* GetNativePathCString() const { return GetCString(); }
-
- PRBool IsChildOf(nsFileSpec &possibleParent);
-
- PRBool Valid() const { return NS_SUCCEEDED(Error()); }
- nsresult Error() const
- {
- if (mPath.IsEmpty() && NS_SUCCEEDED(mError))
- ((nsFileSpec*)this)->mError = NS_ERROR_NOT_INITIALIZED;
- return mError;
- }
- PRBool Failed() const { return (PRBool)NS_FAILED(Error()); }
-
- //--------------------------------------------------
- // Queries and path algebra. These do not modify the disk.
- //--------------------------------------------------
-
- char* GetLeafName() const; // Allocated. Use nsCRT::free().
- // inLeafName can be a relative path, so this allows
- // one kind of concatenation of "paths".
- void SetLeafName(const char* inLeafName);
-
- // Return the filespec of the parent directory. Used
- // in conjunction with GetLeafName(), this lets you
- // parse a path into a list of node names. Beware,
- // however, that the top node is still not a name,
- // but a spec. Volumes on Macintosh can have identical
- // names. Perhaps could be used for an operator --() ?
- void GetParent(nsFileSpec& outSpec) const;
-
-
- // ie nsFileSpec::TimeStamp. This is 32 bits now,
- // but might change, eg, to a 64-bit class. So use the
- // typedef, and use a streaming operator to convert
- // to a string, so that your code won't break. It's
- // none of your business what the number means. Don't
- // rely on the implementation.
- typedef PRUint32 TimeStamp;
-
- // This will return different values on different
- // platforms, even for the same file (eg, on a server).
- // But if the platform is constant, it will increase after
- // every file modification.
- void GetModDate(TimeStamp& outStamp) const;
-
- PRBool ModDateChanged(const TimeStamp& oldStamp) const
- {
- TimeStamp newStamp;
- GetModDate(newStamp);
- return newStamp != oldStamp;
- }
-
- PRUint32 GetFileSize() const;
- PRInt64 GetDiskSpaceAvailable() const;
-
- nsFileSpec operator + (const char* inRelativeUnixPath) const;
-
- // Concatenate the relative path to this directory.
- // Used for constructing the filespec of a descendant.
- // This must be a directory for this to work. This differs
- // from SetLeafName(), since the latter will work
- // starting with a sibling of the directory and throws
- // away its leaf information, whereas this one assumes
- // this is a directory, and the relative path starts
- // "below" this.
- void operator += (const char* inRelativeUnixPath);
-
-
-
- PRBool IsDirectory() const; // More stringent than Exists()
- PRBool IsFile() const; // More stringent than Exists()
- PRBool Exists() const;
-
- PRBool IsHidden() const;
-
- PRBool IsSymlink() const;
-
- //--------------------------------------------------
- // Creation and deletion of objects. These can modify the disk.
- //--------------------------------------------------
-
- // For security reasons, these create the file.
- void MakeUnique(PRBool inCreateFile = PR_TRUE);
- void MakeUnique(const char* inSuggestedLeafName, PRBool inCreateFile = PR_TRUE);
-
- // Called for the spec of an alias. Modifies the spec to
- // point to the original. Sets mError.
- nsresult ResolveSymlink(PRBool& wasSymlink);
-
- void CreateDirectory(int mode = 0775 /* for unix */);
- void CreateDir(int mode = 0775) { CreateDirectory(mode); }
- // workaround for yet another VC++ bug with long identifiers.
- void Delete(PRBool inRecursive) const;
- nsresult Truncate(PRInt32 aNewLength) const;
- void RecursiveCopy(nsFileSpec newDir) const;
-
- nsresult Rename(const char* inNewName); // not const: gets updated
- nsresult CopyToDir(const nsFileSpec& inNewParentDirectory) const;
- nsresult MoveToDir(const nsFileSpec& inNewParentDirectory);
- nsresult Execute(const char* args) const;
-
- protected:
-
- //--------------------------------------------------
- // Data
- //--------------------------------------------------
-
- protected:
-
- // Clear the nsFileSpec contents, resetting it
- // to the uninitialized state;
- void Clear();
-
- friend class nsFilePath;
- friend class nsFileURL;
- friend class nsDirectoryIterator;
-
- nsSimpleCharString mPath;
- nsresult mError;
-
-private:
- NS_EXPLICIT nsFileSpec(const nsPersistentFileDescriptor& inURL);
-
-}; // class nsFileSpec
-
-// FOR HISTORICAL REASONS:
-
-typedef nsFileSpec nsNativeFileSpec;
-
-//========================================================================================
-class NS_COM_OBSOLETE nsFileURL
-// This is an escaped string that looks like "file:///foo/bar/mumble%20fish". Since URLs
-// are the standard way of doing things in mozilla, this allows a string constructor,
-// which just stashes the string with no conversion.
-//========================================================================================
-{
- public:
- nsFileURL(const nsFileURL& inURL);
- NS_EXPLICIT nsFileURL(const char* inURLString, PRBool inCreateDirs = PR_FALSE);
- NS_EXPLICIT nsFileURL(const nsString& inURLString, PRBool inCreateDirs = PR_FALSE);
- NS_EXPLICIT nsFileURL(const nsFilePath& inPath);
- NS_EXPLICIT nsFileURL(const nsFileSpec& inPath);
- virtual ~nsFileURL();
-
-// nsString GetString() const { return mPath; }
- // may be needed for implementation reasons,
- // but should not provide a conversion constructor.
-
- void operator = (const nsFileURL& inURL);
- void operator = (const char* inURLString);
- void operator = (const nsString& inURLString)
- {
- *this = NS_LossyConvertUTF16toASCII(inURLString).get();
- }
- void operator = (const nsFilePath& inOther);
- void operator = (const nsFileSpec& inOther);
-
- void operator +=(const char* inRelativeUnixPath);
- nsFileURL operator +(const char* inRelativeUnixPath) const;
- operator const char* () const { return (const char*)mURL; } // deprecated.
- const char* GetURLString() const { return (const char*)mURL; }
- // Not allocated, so don't free it.
- const char* GetAsString() const { return (const char*)mURL; }
- // Not allocated, so don't free it.
-
- //--------------------------------------------------
- // Data
- //--------------------------------------------------
-
- protected:
- friend class nsFilePath; // to allow construction of nsFilePath
- nsSimpleCharString mURL;
-}; // class nsFileURL
-
-//========================================================================================
-class NS_COM_OBSOLETE nsFilePath
-// This is a string that looks like "/foo/bar/mumble fish". Same as nsFileURL, but
-// without the "file:// prefix", and NOT %20 ENCODED! Strings passed in must be
-// valid unix-style paths in this format.
-//========================================================================================
-{
- public:
- nsFilePath(const nsFilePath& inPath);
- NS_EXPLICIT nsFilePath(const char* inUnixPathString, PRBool inCreateDirs = PR_FALSE);
- NS_EXPLICIT nsFilePath(const nsString& inUnixPathString, PRBool inCreateDirs = PR_FALSE);
- NS_EXPLICIT nsFilePath(const nsFileURL& inURL);
- NS_EXPLICIT nsFilePath(const nsFileSpec& inPath);
- virtual ~nsFilePath();
-
-
- operator const char* () const { return mPath; }
- // This will return a UNIX string. If you
- // need a string that can be passed into
- // NSPR, take a look at the nsNSPRPath class.
-
- void operator = (const nsFilePath& inPath);
- void operator = (const char* inUnixPathString);
- void operator = (const nsString& inUnixPathString)
- {
- *this = NS_LossyConvertUTF16toASCII(inUnixPathString).get();
- }
- void operator = (const nsFileURL& inURL);
- void operator = (const nsFileSpec& inOther);
-
- void operator +=(const char* inRelativeUnixPath);
- nsFilePath operator +(const char* inRelativeUnixPath) const;
-
- //--------------------------------------------------
- // Data
- //--------------------------------------------------
-
- private:
-
- nsSimpleCharString mPath;
-}; // class nsFilePath
-
-//========================================================================================
-class nsPersistentFileDescriptor
-// To save information about a file's location in another file, initialize
-// one of these from your nsFileSpec, and then write this out to your output stream.
-// To retrieve the info, create one of these, read its value from an input stream.
-// and then make an nsFileSpec from it.
-//========================================================================================
-{
- public:
- nsPersistentFileDescriptor() {}
- // For use prior to reading in from a stream
- nsPersistentFileDescriptor(const nsPersistentFileDescriptor& inEncodedData);
- virtual ~nsPersistentFileDescriptor();
- void operator = (const nsPersistentFileDescriptor& inEncodedData);
-
- // Conversions
- NS_EXPLICIT nsPersistentFileDescriptor(const nsFileSpec& inSpec);
- void operator = (const nsFileSpec& inSpec);
-
- // The following four functions are declared here (as friends). Their implementations
- // are in mozilla/base/src/nsFileSpecStreaming.cpp.
-
- friend nsresult Read(nsIInputStream* aStream, nsPersistentFileDescriptor&);
- friend nsresult Write(nsIOutputStream* aStream, const nsPersistentFileDescriptor&);
- // writes the data to a file
- friend NS_COM_OBSOLETE nsInputStream& operator >> (nsInputStream&, nsPersistentFileDescriptor&);
- // reads the data from a file
- friend NS_COM_OBSOLETE nsOutputStream& operator << (nsOutputStream&, const nsPersistentFileDescriptor&);
- // writes the data to a file
- friend class nsFileSpec;
-
- void GetData(nsAFlatCString& outData) const;
- void SetData(const nsAFlatCString& inData);
- void SetData(const char* inData, PRInt32 inSize);
-
- //--------------------------------------------------
- // Data
- //--------------------------------------------------
-
- protected:
-
- nsSimpleCharString mDescriptorString;
-
-}; // class nsPersistentFileDescriptor
-
-//========================================================================================
-class NS_COM_OBSOLETE nsDirectoryIterator
-// Example:
-//
-// nsFileSpec parentDir(...); // directory over whose children we shall iterate
-// for (nsDirectoryIterator i(parentDir, PR_FALSE); i.Exists(); i++)
-// {
-// // do something with i.Spec()
-// }
-//
-// - or -
-//
-// for (nsDirectoryIterator i(parentDir, PR_TRUE); i.Exists(); i--)
-// {
-// // do something with i.Spec()
-// }
-// This one passed the PR_TRUE flag which will resolve any symlink encountered.
-//========================================================================================
-{
- public:
- nsDirectoryIterator( const nsFileSpec& parent,
- PRBool resoveSymLinks);
- virtual ~nsDirectoryIterator();
- PRBool Exists() const { return mExists; }
- nsDirectoryIterator& operator ++(); // moves to the next item, if any.
- nsDirectoryIterator& operator ++(int) { return ++(*this); } // post-increment.
- nsDirectoryIterator& operator --(); // moves to the previous item, if any.
- nsDirectoryIterator& operator --(int) { return --(*this); } // post-decrement.
- operator nsFileSpec&() { return mCurrent; }
-
- nsFileSpec& Spec() { return mCurrent; }
-
- //--------------------------------------------------
- // Data
- //--------------------------------------------------
-
- private:
-
- nsFileSpec mCurrent;
- PRBool mExists;
- PRBool mResoveSymLinks;
-
-#if (defined(XP_UNIX) || defined(XP_BEOS) || defined (XP_WIN) || defined(XP_OS2))
- nsFileSpec mStarting;
-#endif
-
-#if defined(XP_UNIX) || defined(XP_BEOS)
- DIR* mDir;
-#elif defined(XP_WIN) || defined(XP_OS2)
- PRDir* mDir; // XXX why not use PRDir for Unix too?
-#endif
-}; // class nsDirectoryIterator
-
-//========================================================================================
-class NS_COM_OBSOLETE nsNSPRPath
-// This class will allow you to pass any one of the nsFile* classes directly into NSPR
-// without the need to worry about whether you have the right kind of filepath or not.
-// It will also take care of cleaning up any allocated memory.
-//========================================================================================
-{
-public:
- NS_EXPLICIT nsNSPRPath(const nsFileSpec& inSpec)
- : mFilePath(inSpec), modifiedNSPRPath(nsnull) {}
- NS_EXPLICIT nsNSPRPath(const nsFileURL& inURL)
- : mFilePath(inURL), modifiedNSPRPath(nsnull) {}
- NS_EXPLICIT nsNSPRPath(const nsFilePath& inUnixPath)
- : mFilePath(inUnixPath), modifiedNSPRPath(nsnull) {}
-
- virtual ~nsNSPRPath();
-
- operator const char*() const;
- // Returns the path
- // that NSPR file routines expect on each platform.
- // Concerning constness, this can modify
- // modifiedNSPRPath, but it's really just "mutable".
-
- //--------------------------------------------------
- // Data
- //--------------------------------------------------
-
-private:
-
- nsFilePath mFilePath;
- char* modifiedNSPRPath; // Currently used only on XP_WIN,XP_OS2
-}; // class nsNSPRPath
-
-
-NS_COM_OBSOLETE nsresult NS_FileSpecToIFile(nsFileSpec* fileSpec, nsILocalFile* *result);
-
-#endif // _FILESPEC_H_
deleted file mode 100644
--- a/xpcom/obsolete/nsFileSpecBeOS.cpp
+++ /dev/null
@@ -1,547 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * 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 file is included by nsFileSpec.cpp, and includes the Unix-specific
-// implementations.
-
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <errno.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <limits.h>
-#include "nsError.h"
-#include "prio.h" /* for PR_Rename */
-
-// BeOS specific headers
-#include <Entry.h>
-#include <Path.h>
-#include <Volume.h>
-
-//----------------------------------------------------------------------------------------
-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 nsFileSpec::SetLeafName(const char* inLeafName)
-//----------------------------------------------------------------------------------------
-{
- mPath.LeafReplace('/', inLeafName);
-} // nsFileSpec::SetLeafName
-
-//----------------------------------------------------------------------------------------
-char* nsFileSpec::GetLeafName() const
-//----------------------------------------------------------------------------------------
-{
- return mPath.GetLeaf('/');
-} // nsFileSpec::GetLeafName
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::Exists() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && 0 == stat(mPath, &st);
-} // nsFileSpec::Exists
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::GetModDate(TimeStamp& outStamp) const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(mPath, &st) == 0)
- outStamp = st.st_mtime;
- else
- outStamp = 0;
-} // nsFileSpec::GetModDate
-
-//----------------------------------------------------------------------------------------
-PRUint32 nsFileSpec::GetFileSize() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(mPath, &st) == 0)
- return (PRUint32)st.st_size;
- return 0;
-} // nsFileSpec::GetFileSize
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsFile() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && stat(mPath, &st) == 0 && S_ISREG(st.st_mode);
-} // nsFileSpec::IsFile
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsDirectory() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && 0 == stat(mPath, &st) && S_ISDIR(st.st_mode);
-} // nsFileSpec::IsDirectory
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsHidden() const
-//----------------------------------------------------------------------------------------
-{
- PRBool hidden = PR_TRUE;
- char *leafname = GetLeafName();
- if (nsnull != leafname)
- {
- if ((!strcmp(leafname, ".")) || (!strcmp(leafname, "..")))
- {
- hidden = PR_FALSE;
- }
- nsCRT::free(leafname);
- }
- return hidden;
-} // nsFileSpec::IsHidden
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsSymlink() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(mPath, &st) == 0 && S_ISLNK(st.st_mode))
- return PR_TRUE;
-
- return PR_FALSE;
-} // nsFileSpec::IsSymlink
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::ResolveSymlink(PRBool& wasAliased)
-//----------------------------------------------------------------------------------------
-{
- wasAliased = PR_FALSE;
-
- char resolvedPath[MAXPATHLEN];
- int charCount = readlink(mPath, (char*)&resolvedPath, MAXPATHLEN);
- if (0 < charCount)
- {
- if (MAXPATHLEN > charCount)
- resolvedPath[charCount] = '\0';
-
- wasAliased = PR_TRUE;
- /* if it's not an absolute path,
- replace the leaf with what got resolved */
- if (resolvedPath[0] != '/') {
- SetLeafName(resolvedPath);
- }
- else {
- mPath = (char*)resolvedPath;
- }
-
- BEntry e((const char *)mPath, true); // traverse symlink
- BPath p;
- status_t err;
- err = e.GetPath(&p);
- NS_ASSERTION(err == B_OK, "realpath failed");
-
- const char* canonicalPath = p.Path();
- if(err == B_OK)
- mPath = (char*)canonicalPath;
- else
- return NS_ERROR_FAILURE;
- }
- return NS_OK;
-} // nsFileSpec::ResolveSymlink
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::GetParent(nsFileSpec& outSpec) const
-//----------------------------------------------------------------------------------------
-{
- outSpec.mPath = mPath;
- char* chars = (char*)outSpec.mPath;
- chars[outSpec.mPath.Length() - 1] = '\0'; // avoid trailing separator, if any
- char* cp = strrchr(chars, '/');
- if (cp++)
- outSpec.mPath.SetLength(cp - chars); // truncate.
-} // nsFileSpec::GetParent
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator += (const char* inRelativePath)
-//----------------------------------------------------------------------------------------
-{
- if (!inRelativePath || mPath.IsEmpty())
- return;
-
- char endChar = mPath[(int)(strlen(mPath) - 1)];
- if (endChar == '/')
- mPath += "x";
- else
- mPath += "/x";
- SetLeafName(inRelativePath);
-} // nsFileSpec::operator +=
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::CreateDirectory(int mode)
-//----------------------------------------------------------------------------------------
-{
- // Note that mPath is canonical!
- if (mPath.IsEmpty())
- return;
- mkdir(mPath, mode);
-} // nsFileSpec::CreateDirectory
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::Delete(PRBool inRecursive) const
-// To check if this worked, call Exists() afterwards, see?
-//----------------------------------------------------------------------------------------
-{
- if (IsDirectory())
- {
- if (inRecursive)
- {
- for (nsDirectoryIterator i(*this, PR_FALSE); i.Exists(); i++)
- {
- nsFileSpec& child = (nsFileSpec&)i;
- child.Delete(inRecursive);
- }
- }
- rmdir(mPath);
- }
- else if (!mPath.IsEmpty())
- remove(mPath);
-} // nsFileSpec::Delete
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::RecursiveCopy(nsFileSpec newDir) const
-//----------------------------------------------------------------------------------------
-{
- if (IsDirectory())
- {
- if (!(newDir.Exists()))
- {
- newDir.CreateDirectory();
- }
-
- for (nsDirectoryIterator i(*this, PR_FALSE); i.Exists(); i++)
- {
- nsFileSpec& child = (nsFileSpec&)i;
-
- if (child.IsDirectory())
- {
- nsFileSpec tmpDirSpec(newDir);
-
- char *leafname = child.GetLeafName();
- tmpDirSpec += leafname;
- nsCRT::free(leafname);
-
- child.RecursiveCopy(tmpDirSpec);
- }
- else
- {
- child.RecursiveCopy(newDir);
- }
- }
- }
- else if (!mPath.IsEmpty())
- {
- nsFileSpec& filePath = (nsFileSpec&) *this;
-
- if (!(newDir.Exists()))
- {
- newDir.CreateDirectory();
- }
-
- filePath.CopyToDir(newDir);
- }
-} // nsFileSpec::RecursiveCopy
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Truncate(PRInt32 offset) const
-//----------------------------------------------------------------------------------------
-{
- char* Path = nsCRT::strdup(mPath);
-
- int rv = truncate(Path, offset) ;
-
- nsCRT::free(Path) ;
-
- if(!rv)
- return NS_OK ;
- else
- return NS_ERROR_FAILURE ;
-} // nsFileSpec::Truncate
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Rename(const char* inNewName)
-//----------------------------------------------------------------------------------------
-{
- // This function should not be used to move a file on disk.
- if (mPath.IsEmpty() || strchr(inNewName, '/'))
- return NS_FILE_FAILURE;
-
- char* oldPath = nsCRT::strdup(mPath);
-
- SetLeafName(inNewName);
-
- if (PR_Rename(oldPath, mPath) != NS_OK)
- {
- // Could not rename, set back to the original.
- mPath = oldPath;
- return NS_FILE_FAILURE;
- }
-
- nsCRT::free(oldPath);
-
- return NS_OK;
-} // nsFileSpec::Rename
-
-//----------------------------------------------------------------------------------------
-static int CrudeFileCopy(const char* in, const char* out)
-//----------------------------------------------------------------------------------------
-{
- struct stat in_stat;
- int stat_result = -1;
-
- char buf [1024];
- FILE *ifp, *ofp;
- int rbytes, wbytes;
-
- if (!in || !out)
- return -1;
-
- stat_result = stat (in, &in_stat);
-
- ifp = fopen (in, "r");
- if (!ifp)
- {
- return -1;
- }
-
- ofp = fopen (out, "w");
- if (!ofp)
- {
- fclose (ifp);
- return -1;
- }
-
- while ((rbytes = fread (buf, 1, sizeof(buf), ifp)) > 0)
- {
- while (rbytes > 0)
- {
- if ( (wbytes = fwrite (buf, 1, rbytes, ofp)) < 0 )
- {
- fclose (ofp);
- fclose (ifp);
- unlink(out);
- return -1;
- }
- rbytes -= wbytes;
- }
- }
- fclose (ofp);
- fclose (ifp);
-
- if (stat_result == 0)
- chmod (out, in_stat.st_mode & 0777);
-
- return 0;
-} // nsFileSpec::Rename
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::CopyToDir(const nsFileSpec& inParentDirectory) const
-//----------------------------------------------------------------------------------------
-{
- // We can only copy into a directory, and (for now) can not copy entire directories
- nsresult result = NS_FILE_FAILURE;
-
- if (inParentDirectory.IsDirectory() && (! IsDirectory() ) )
- {
- char *leafname = GetLeafName();
- nsSimpleCharString destPath(inParentDirectory.GetCString());
- destPath += "/";
- destPath += leafname;
- nsCRT::free(leafname);
- result = NS_FILE_RESULT(CrudeFileCopy(GetCString(), destPath));
- }
- return result;
-} // nsFileSpec::CopyToDir
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::MoveToDir(const nsFileSpec& inNewParentDirectory)
-//----------------------------------------------------------------------------------------
-{
- // We can only copy into a directory, and (for now) can not copy entire directories
- nsresult result = NS_FILE_FAILURE;
-
- if (inNewParentDirectory.IsDirectory() && !IsDirectory())
- {
- char *leafname = GetLeafName();
- nsSimpleCharString destPath(inNewParentDirectory.GetCString());
- destPath += "/";
- destPath += leafname;
- nsCRT::free(leafname);
-
- result = NS_FILE_RESULT(CrudeFileCopy(GetCString(), (const char*)destPath));
- if (result == NS_OK)
- {
- // cast to fix const-ness
- ((nsFileSpec*)this)->Delete(PR_FALSE);
-
- *this = inNewParentDirectory + GetLeafName();
- }
- }
- return result;
-}
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Execute(const char* inArgs ) const
-//----------------------------------------------------------------------------------------
-{
- nsresult result = NS_FILE_FAILURE;
-
- if (!mPath.IsEmpty() && !IsDirectory())
- {
- nsSimpleCharString fileNameWithArgs = mPath + " " + inArgs;
- result = NS_FILE_RESULT(system(fileNameWithArgs));
- }
-
- return result;
-
-} // nsFileSpec::Execute
-
-//----------------------------------------------------------------------------------------
-PRInt64 nsFileSpec::GetDiskSpaceAvailable() const
-//----------------------------------------------------------------------------------------
-{
- char curdir [MAXPATHLEN];
- if (!mPath || !*mPath)
- {
- (void) getcwd(curdir, MAXPATHLEN);
- if (!curdir)
- return ULONGLONG_MAX; /* hope for the best as we did in cheddar */
- }
- else
- sprintf(curdir, "%.200s", (const char*)mPath);
-
- BEntry e(curdir);
- if(e.InitCheck() != B_OK)
- return ULONGLONG_MAX; /* hope for the best as we did in cheddar */
- entry_ref ref;
- e.GetRef(&ref);
- BVolume v(ref.device);
-
-#ifdef DEBUG_DISK_SPACE
- printf("DiskSpaceAvailable: %d bytes\n", space);
-#endif
- return v.FreeBytes();
-} // nsFileSpec::GetDiskSpace()
-
-//========================================================================================
-// nsDirectoryIterator
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator::nsDirectoryIterator(
- const nsFileSpec& inDirectory
-, PRBool resolveSymlinks)
-//----------------------------------------------------------------------------------------
- : mCurrent(inDirectory)
- , mStarting(inDirectory)
- , mExists(PR_FALSE)
- , mDir(nsnull)
- , mResoveSymLinks(resolveSymlinks)
-{
- mStarting += "sysygy"; // save off the starting directory
- mCurrent += "sysygy"; // prepare the path for SetLeafName
- mDir = opendir((const char*)nsFilePath(inDirectory));
- ++(*this);
-} // nsDirectoryIterator::nsDirectoryIterator
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator::~nsDirectoryIterator()
-//----------------------------------------------------------------------------------------
-{
- if (mDir)
- closedir(mDir);
-} // nsDirectoryIterator::nsDirectoryIterator
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator& nsDirectoryIterator::operator ++ ()
-//----------------------------------------------------------------------------------------
-{
- mExists = PR_FALSE;
- if (!mDir)
- return *this;
- char* dot = ".";
- char* dotdot = "..";
- struct dirent* entry = readdir(mDir);
- if (entry && strcmp(entry->d_name, dot) == 0)
- entry = readdir(mDir);
- if (entry && strcmp(entry->d_name, dotdot) == 0)
- entry = readdir(mDir);
- if (entry)
- {
- mExists = PR_TRUE;
- mCurrent = mStarting; // restore mCurrent to be the starting directory. ResolveSymlink() may have taken us to another directory
- mCurrent.SetLeafName(entry->d_name);
- if (mResoveSymLinks)
- {
- PRBool ignore;
- mCurrent.ResolveSymlink(ignore);
- }
- }
- return *this;
-} // nsDirectoryIterator::operator ++
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator& nsDirectoryIterator::operator -- ()
-//----------------------------------------------------------------------------------------
-{
- return ++(*this); // can't do it backwards.
-} // nsDirectoryIterator::operator --
deleted file mode 100644
--- a/xpcom/obsolete/nsFileSpecImpl.cpp
+++ /dev/null
@@ -1,895 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Pierre Phaneuf <pp@ludusdesign.com>
- *
- * 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 ***** */
-
-#include "nsFileSpecImpl.h"// Always first, to ensure that it compiles alone.
-
-#include "nsIFileStream.h"
-#include "nsFileStream.h"
-
-#include "nsILocalFile.h"
-#include "nsNativeCharsetUtils.h"
-
-#include "prmem.h"
-
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsFileSpecImpl, nsIFileSpec)
-
-#ifdef NS_DEBUG
-#define TEST_OUT_PTR(p) \
- if (!(p)) \
- return NS_ERROR_NULL_POINTER;
-#else
-#define TEST_OUT_PTR(p)
-#endif
-
-//----------------------------------------------------------------------------------------
-nsFileSpecImpl::nsFileSpecImpl()
-//----------------------------------------------------------------------------------------
- : mInputStream(nsnull)
- , mOutputStream(nsnull)
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
-
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpecImpl::nsFileSpecImpl(const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
- : mFileSpec(inSpec)
- , mInputStream(nsnull)
- , mOutputStream(nsnull)
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
-
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpecImpl::~nsFileSpecImpl()
-//----------------------------------------------------------------------------------------
-{
- CloseStream();
-}
-
-//----------------------------------------------------------------------------------------
-/* static */
-nsresult nsFileSpecImpl::MakeInterface(const nsFileSpec& inSpec, nsIFileSpec** result)
-//----------------------------------------------------------------------------------------
-{
- nsFileSpecImpl* it = new nsFileSpecImpl(inSpec);
- if (!it)
- return NS_ERROR_OUT_OF_MEMORY;
- return it->QueryInterface(NS_GET_IID(nsIFileSpec), (void **) result);
-} // nsFileSpecImpl::MakeInterface
-
-#define FILESPEC(ifilespec) ((nsFileSpecImpl*)ifilespec)->mFileSpec
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::FromFileSpec(const nsIFileSpec *original)
-//----------------------------------------------------------------------------------------
-{
- if (original) {
- nsresult rv = ((nsIFileSpec *)original)->GetFileSpec( &mFileSpec);
- if (NS_SUCCEEDED( rv))
- return mFileSpec.Error();
- else
- return( rv);
- }
- else
- return( NS_ERROR_FAILURE);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::IsChildOf(nsIFileSpec *possibleParent,
- PRBool *_retval)
-{
- *_retval = mFileSpec.IsChildOf(FILESPEC(possibleParent));
- return mFileSpec.Error();
-}
-//----------------------------------------------------------------------------------------
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetURLString(char * *aURLString)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aURLString)
- if (mFileSpec.Failed())
- return mFileSpec.Error();
- nsFileURL url(mFileSpec);
- *aURLString = nsCRT::strdup(url.GetURLString());
- if (!*aURLString)
- return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-} // nsFileSpecImpl::GetURLString
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::SetURLString(const char * aURLString)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec = nsFileURL(aURLString);
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetUnixStyleFilePath(char * *aUnixStyleFilePath)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aUnixStyleFilePath)
- if (mFileSpec.Failed())
- return mFileSpec.Error();
- nsFilePath path(mFileSpec);
- *aUnixStyleFilePath = nsCRT::strdup((const char*) path);
- if (!*aUnixStyleFilePath)
- return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::SetUnixStyleFilePath(const char * aUnixStyleFilePath)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec = nsFilePath(aUnixStyleFilePath);
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetPersistentDescriptorString(char * *aPersistentDescriptorString)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aPersistentDescriptorString)
- if (mFileSpec.Failed())
- return mFileSpec.Error();
- nsPersistentFileDescriptor desc(mFileSpec);
- nsCAutoString data;
- desc.GetData(data);
- *aPersistentDescriptorString = ToNewCString(data);
- if (!*aPersistentDescriptorString)
- return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::SetPersistentDescriptorString(const char * aPersistentDescriptorString)
-//----------------------------------------------------------------------------------------
-{
- nsPersistentFileDescriptor desc(mFileSpec);
- desc.SetData(nsDependentCString(aPersistentDescriptorString));
- mFileSpec = desc;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetNativePath(char * *aNativePath)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aNativePath)
- if (mFileSpec.Failed())
- return mFileSpec.Error();
- *aNativePath = nsCRT::strdup(mFileSpec.GetNativePathCString());
- if (!*aNativePath)
- return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::SetNativePath(const char * aNativePath)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec = aNativePath;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetUnicodePath(nsAString & aUnicodePath)
-//----------------------------------------------------------------------------------------
-{
- nsCAutoString native;
- native = mFileSpec.GetNativePathCString();
- NS_CopyNativeToUnicode(native, aUnicodePath);
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::SetUnicodePath(const nsAString & aUnicodePath)
-//----------------------------------------------------------------------------------------
-{
- nsCAutoString native;
-
- NS_CopyUnicodeToNative(aUnicodePath, native);
- mFileSpec = native.get();
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetNSPRPath(char * *aNSPRPath)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aNSPRPath)
- if (mFileSpec.Failed())
- return mFileSpec.Error();
- nsNSPRPath path(mFileSpec);
- *aNSPRPath = nsCRT::strdup((const char*) path);
- if (!*aNSPRPath)
- return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Error()
-//----------------------------------------------------------------------------------------
-{
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::IsValid(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = mFileSpec.Valid();
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Failed(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- *_retval = mFileSpec.Failed();
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetLeafName(char * *aLeafName)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aLeafName)
- *aLeafName = mFileSpec.GetLeafName();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::SetLeafName(const char * aLeafName)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec.SetLeafName(aLeafName);
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetParent(nsIFileSpec * *aParent)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aParent)
- nsFileSpec parent;
- mFileSpec.GetParent(parent);
- return MakeInterface(parent, aParent);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::MakeUnique()
-//----------------------------------------------------------------------------------------
-{
- mFileSpec.MakeUnique();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::MakeUniqueWithSuggestedName(const char *suggestedName)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec.MakeUnique(suggestedName);
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::MakeUniqueDir()
-//----------------------------------------------------------------------------------------
-{
- mFileSpec.MakeUnique(PR_FALSE);
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::MakeUniqueDirWithSuggestedName(const char *suggestedName)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec.MakeUnique(suggestedName, PR_FALSE);
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetModDate(PRUint32 *aModDate)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aModDate)
- nsFileSpec::TimeStamp stamp;
- mFileSpec.GetModDate(stamp);
- *aModDate = stamp;
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::ModDateChanged(PRUint32 oldStamp, PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = mFileSpec.ModDateChanged(oldStamp);
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::IsDirectory(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = mFileSpec.IsDirectory();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::IsFile(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = mFileSpec.IsFile();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Exists(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = mFileSpec.Exists();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::IsHidden(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = mFileSpec.IsHidden();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::IsSymlink(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = mFileSpec.IsSymlink();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::ResolveSymlink()
-//----------------------------------------------------------------------------------------
-{
- PRBool ignore;
- return mFileSpec.ResolveSymlink(ignore);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetFileSize(PRUint32 *aFileSize)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aFileSize)
- *aFileSize = mFileSpec.GetFileSize();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aDiskSpaceAvailable)
- *aDiskSpaceAvailable = mFileSpec.GetDiskSpaceAvailable();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::AppendRelativeUnixPath(const char *relativePath)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec += relativePath;
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Touch()
-//----------------------------------------------------------------------------------------
-{
- // create an empty file, like the UNIX touch command.
- nsresult rv;
- rv = OpenStreamForWriting();
- if (NS_FAILED(rv)) return rv;
- rv = CloseStream();
- return rv;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::CreateDir()
-//----------------------------------------------------------------------------------------
-{
- mFileSpec.CreateDir();
- return mFileSpec.Error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Delete(PRBool aRecursive)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec.Delete(aRecursive);
- return mFileSpec.Error();
-}
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Truncate(PRInt32 aNewLength)
-//----------------------------------------------------------------------------------------
-{
- return mFileSpec.Truncate(aNewLength);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Rename(const char *newLeafName)
-//----------------------------------------------------------------------------------------
-{
- return mFileSpec.Rename(newLeafName);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::CopyToDir(const nsIFileSpec *newParentDir)
-//----------------------------------------------------------------------------------------
-{
- return mFileSpec.CopyToDir(FILESPEC(newParentDir));
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::MoveToDir(const nsIFileSpec *newParentDir)
-//----------------------------------------------------------------------------------------
-{
- return mFileSpec.MoveToDir(FILESPEC(newParentDir));
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Execute(const char *args)
-//----------------------------------------------------------------------------------------
-{
- return mFileSpec.Execute(args);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::OpenStreamForReading()
-//----------------------------------------------------------------------------------------
-{
- if (mInputStream || mOutputStream)
- return NS_ERROR_FAILURE;
- return NS_NewTypicalInputFileStream((nsISupports**)&mInputStream, mFileSpec);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::OpenStreamForWriting()
-//----------------------------------------------------------------------------------------
-{
- if (mInputStream || mOutputStream)
- return NS_ERROR_FAILURE;
- return NS_NewTypicalOutputFileStream((nsISupports**)&mOutputStream, mFileSpec);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::OpenStreamForReadingAndWriting()
-//----------------------------------------------------------------------------------------
-{
- if (mInputStream || mOutputStream)
- return NS_ERROR_FAILURE;
- nsresult result = NS_NewTypicalInputFileStream((nsISupports**)&mInputStream, mFileSpec);
- if (NS_SUCCEEDED(result))
- result = NS_NewTypicalOutputFileStream((nsISupports**)&mOutputStream, mFileSpec);
- return result;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::CloseStream()
-//----------------------------------------------------------------------------------------
-{
- NS_IF_RELEASE(mInputStream);
- NS_IF_RELEASE(mOutputStream);
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::IsStreamOpen(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = (mInputStream || mOutputStream);
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetInputStream(nsIInputStream** _retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- if (!mInputStream) {
- nsresult rv = OpenStreamForReading();
- if (NS_FAILED(rv)) return rv;
- }
- *_retval = mInputStream;
- NS_IF_ADDREF(mInputStream);
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetOutputStream(nsIOutputStream** _retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- if (!mOutputStream) {
- nsresult rv = OpenStreamForWriting();
- if (NS_FAILED(rv)) return rv;
- }
- *_retval = mOutputStream;
- NS_IF_ADDREF(mOutputStream);
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::SetFileContents(const char* inString)
-//----------------------------------------------------------------------------------------
-{
- nsresult rv = OpenStreamForWriting();
- if (NS_FAILED(rv)) return rv;
- PRInt32 count;
- rv = Write(inString, PL_strlen(inString), &count);
- nsresult rv2 = CloseStream();
- return NS_FAILED(rv) ? rv : rv2;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetFileContents(char** _retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- *_retval = nsnull;
- nsresult rv = OpenStreamForReading();
- if (NS_FAILED(rv)) return rv;
- PRInt32 theSize;
- rv = GetFileSize((PRUint32*)&theSize);
- if (NS_SUCCEEDED(rv))
- rv = Read(_retval, theSize, &theSize);
- if (NS_SUCCEEDED(rv))
- (*_retval)[theSize] = 0;
- nsresult rv2 = CloseStream();
- return NS_FAILED(rv) ? rv : rv2;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::GetFileSpec(nsFileSpec *aFileSpec)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(aFileSpec)
- *aFileSpec = mFileSpec;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Equals(nsIFileSpec *spec, PRBool *result)
-//----------------------------------------------------------------------------------------
-{
- nsresult rv;
-
- if (!result || !spec) return NS_ERROR_NULL_POINTER;
-
- nsFileSpec otherSpec;
-
- rv = spec->GetFileSpec(&otherSpec);
- if (NS_FAILED(rv)) return rv;
-
- if (mFileSpec == otherSpec) {
- *result = PR_TRUE;
- }
- else {
- *result = PR_FALSE;
- }
-
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::SetFromFileSpec(const nsFileSpec& aFileSpec)
-//----------------------------------------------------------------------------------------
-{
- mFileSpec = aFileSpec;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Eof(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- if (!mInputStream)
- return NS_ERROR_NULL_POINTER;
- nsInputFileStream s(mInputStream);
- *_retval = s.eof();
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Read(char** buffer, PRInt32 requestedCount, PRInt32 *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- TEST_OUT_PTR(buffer)
- if (!mInputStream) {
- nsresult rv = OpenStreamForReading();
- if (NS_FAILED(rv)) return rv;
- }
- if (!*buffer)
- *buffer = (char*)PR_Malloc(requestedCount + 1);
- if (!mInputStream)
- return NS_ERROR_NULL_POINTER;
- nsInputFileStream s(mInputStream);
- *_retval = s.read(*buffer, requestedCount);
- return s.error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::ReadLine(char** line, PRInt32 bufferSize, PRBool *wasTruncated)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(wasTruncated)
- TEST_OUT_PTR(line)
- if (!mInputStream) {
- nsresult rv = OpenStreamForReading();
- if (NS_FAILED(rv)) return rv;
- }
- if (!*line)
- *line = (char*)PR_Malloc(bufferSize + 1);
- if (!mInputStream)
- return NS_ERROR_NULL_POINTER;
- nsInputFileStream s(mInputStream);
- *wasTruncated = !s.readline(*line, bufferSize);
- return s.error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Write(const char * data, PRInt32 requestedCount, PRInt32 *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- //if (!mOutputStream)
- // return NS_ERROR_NULL_POINTER;
- if (!mOutputStream) {
- nsresult rv = OpenStreamForWriting();
- if (NS_FAILED(rv))
- return rv;
- }
- nsOutputFileStream s(mOutputStream);
- *_retval = s.write(data, requestedCount);
- return s.error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Flush()
-//----------------------------------------------------------------------------------------
-{
- if (!mOutputStream)
- return NS_ERROR_NULL_POINTER;
- nsOutputFileStream s(mOutputStream);
- s.flush();
- return s.error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Seek(PRInt32 offset)
-//----------------------------------------------------------------------------------------
-{
- nsresult result = NS_OK;
- if (mOutputStream)
- {
- nsOutputFileStream os(mOutputStream);
- os.seek(offset);
- result = os.error();
- }
- if (NS_SUCCEEDED(result) && mInputStream)
- {
- nsInputFileStream is(mInputStream);
- is.seek(offset);
- result = is.error();
- }
- return result;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Tell(PRInt32 *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- if (!mInputStream)
- return NS_ERROR_NULL_POINTER;
- nsInputFileStream s(mInputStream);
- *_retval = s.tell();
- return s.error();
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::EndLine()
-//----------------------------------------------------------------------------------------
-{
- nsOutputFileStream s(mOutputStream);
- s << nsEndl;
- return s.error();
-}
-
-NS_IMPL_ISUPPORTS1(nsDirectoryIteratorImpl, nsIDirectoryIterator)
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIteratorImpl::nsDirectoryIteratorImpl()
-//----------------------------------------------------------------------------------------
- : mDirectoryIterator(nsnull)
-{
-}
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIteratorImpl::~nsDirectoryIteratorImpl()
-//----------------------------------------------------------------------------------------
-{
- delete mDirectoryIterator;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsDirectoryIteratorImpl::Init(nsIFileSpec *parent, PRBool resolveSymlink)
-//----------------------------------------------------------------------------------------
-{
- delete mDirectoryIterator;
- mDirectoryIterator = new nsDirectoryIterator(FILESPEC(parent), resolveSymlink);
- if (!mDirectoryIterator)
- return NS_ERROR_OUT_OF_MEMORY;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsDirectoryIteratorImpl::Exists(PRBool *_retval)
-//----------------------------------------------------------------------------------------
-{
- TEST_OUT_PTR(_retval)
- if (!mDirectoryIterator)
- return NS_ERROR_NULL_POINTER;
- *_retval = mDirectoryIterator->Exists();
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsDirectoryIteratorImpl::Next()
-//----------------------------------------------------------------------------------------
-{
- if (!mDirectoryIterator)
- return NS_ERROR_NULL_POINTER;
- (*mDirectoryIterator)++;
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsDirectoryIteratorImpl::GetCurrentSpec(nsIFileSpec * *aCurrentSpec)
-//----------------------------------------------------------------------------------------
-{
- if (!mDirectoryIterator)
- return NS_ERROR_NULL_POINTER;
- return nsFileSpecImpl::MakeInterface(mDirectoryIterator->Spec(), aCurrentSpec);
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsDirectoryIteratorImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aIFileSpec)
-//----------------------------------------------------------------------------------------
-{
- if (aIFileSpec == NULL)
- return NS_ERROR_NULL_POINTER;
-
- nsDirectoryIteratorImpl* it = new nsDirectoryIteratorImpl;
- if (!it)
- return NS_ERROR_OUT_OF_MEMORY;
-
- nsresult rv = it->QueryInterface(aIID, aIFileSpec);
- if (NS_FAILED(rv))
- {
- delete it;
- return rv;
- }
- return rv;
-}
-
-//----------------------------------------------------------------------------------------
-NS_IMETHODIMP nsFileSpecImpl::Create(nsISupports* outer, const nsIID& aIID, void* *aIFileSpec)
-//----------------------------------------------------------------------------------------
-{
- if (aIFileSpec == NULL)
- return NS_ERROR_NULL_POINTER;
-
- nsFileSpecImpl* it = new nsFileSpecImpl;
- if (!it)
- return NS_ERROR_OUT_OF_MEMORY;
-
- nsresult rv = it->QueryInterface(aIID, aIFileSpec);
- if (NS_FAILED(rv))
- {
- delete it;
- return rv;
- }
- return rv;
-}
-
-//----------------------------------------------------------------------------------------
-nsresult NS_NewFileSpecWithSpec(const nsFileSpec& aSrcFileSpec, nsIFileSpec **result)
-//----------------------------------------------------------------------------------------
-{
- if (!result)
- return NS_ERROR_NULL_POINTER;
-
- return nsFileSpecImpl::MakeInterface(aSrcFileSpec, result);
-}
-
-//----------------------------------------------------------------------------------------
-nsresult NS_NewFileSpec(nsIFileSpec** result)
-//----------------------------------------------------------------------------------------
-{
- return nsFileSpecImpl::Create(nsnull, NS_GET_IID(nsIFileSpec), (void**)result);
-}
-
-//----------------------------------------------------------------------------------------
-nsresult NS_NewFileSpecFromIFile(nsIFile *aFile, nsIFileSpec **result)
-//----------------------------------------------------------------------------------------
-{
- nsresult rv = nsFileSpecImpl::Create(nsnull, NS_GET_IID(nsIFileSpec), (void**)result);
- if (NS_FAILED(rv)) return rv;
-
- nsCAutoString path;
- rv = aFile->GetNativePath(path);
- if (NS_FAILED(rv)) return rv;
-
- rv = (*result)->SetNativePath(path.get());
- if (NS_FAILED(rv))
- NS_RELEASE(*result);
- return rv;
-}
-
-//----------------------------------------------------------------------------------------
-nsresult NS_NewDirectoryIterator(nsIDirectoryIterator** result)
-//----------------------------------------------------------------------------------------
-{
- return nsDirectoryIteratorImpl::Create(nsnull, NS_GET_IID(nsIDirectoryIterator), (void**)result);
-}
deleted file mode 100644
--- a/xpcom/obsolete/nsFileSpecImpl.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * 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 ***** */
-
-#ifndef _FILESPECIMPL_H_
-#define _FILESPECIMPL_H_
-
-#include "nscore.h"
-#include "nsIFileSpec.h"
-#include "nsFileSpec.h"
-
-//========================================================================================
-class NS_COM_OBSOLETE nsFileSpecImpl
-//========================================================================================
- : public nsIFileSpec
-{
-
- public:
-
- NS_DECL_ISUPPORTS
-
- NS_DECL_NSIFILESPEC
-
- //----------------------
- // COM Cruft
- //----------------------
-
- static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aIFileSpec);
-
- //----------------------
- // Implementation
- //----------------------
-
- nsFileSpecImpl();
- nsFileSpecImpl(const nsFileSpec& inSpec);
- static nsresult MakeInterface(const nsFileSpec& inSpec, nsIFileSpec** outSpec);
-
- //----------------------
- // Data
- //----------------------
-
- nsFileSpec mFileSpec;
- nsIInputStream* mInputStream;
- nsIOutputStream* mOutputStream;
-
-private:
- ~nsFileSpecImpl();
-}; // class nsFileSpecImpl
-
-//========================================================================================
-class NS_COM_OBSOLETE nsDirectoryIteratorImpl
-//========================================================================================
- : public nsIDirectoryIterator
-{
-
-public:
-
- nsDirectoryIteratorImpl();
-
- NS_DECL_ISUPPORTS
-
- NS_IMETHOD Init(nsIFileSpec *parent, PRBool resolveSymlink);
-
- NS_IMETHOD Exists(PRBool *_retval);
-
- NS_IMETHOD Next();
-
- NS_IMETHOD GetCurrentSpec(nsIFileSpec * *aCurrentSpec);
-
- //----------------------
- // COM Cruft
- //----------------------
-
- static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aIFileSpec);
-
-private:
- ~nsDirectoryIteratorImpl();
-
-protected:
- nsDirectoryIterator* mDirectoryIterator;
-}; // class nsDirectoryIteratorImpl
-
-#endif // _FILESPECIMPL_H_
deleted file mode 100644
--- a/xpcom/obsolete/nsFileSpecOS2.cpp
+++ /dev/null
@@ -1,826 +0,0 @@
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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>
- * 00/01/06: general review and update against Win/Unix versions;
- * 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>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <limits.h>
-#include <ctype.h>
-#include <io.h>
-
-//----------------------------------------------------------------------------------------
-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 = 0700;
- nsSimpleCharString unixStylePath = ioPath;
- nsFileSpecHelpers::NativeToUnix(unixStylePath);
- nsFileSpecHelpers::MakeAllDirectories((const char*)unixStylePath, mode);
- }
- char buffer[_MAX_PATH];
- errno = 0;
- *buffer = '\0';
-#ifdef XP_OS2
- PRBool removedBackslash = PR_FALSE;
- PRUint32 lenstr = ioPath.Length();
- char &lastchar = ioPath[lenstr -1];
-
- // Strip off any trailing backslash UNLESS it's the backslash that
- // comes after "X:". Note also that "\" is valid. Sheesh.
- //
- if( lastchar == '\\' && (lenstr != 3 || ioPath[1] != ':') && lenstr != 1)
- {
- lastchar = '\0';
- removedBackslash = PR_TRUE;
- }
-
- char canonicalPath[CCHMAXPATH] = "";
-
- DosQueryPathInfo( (char*) ioPath,
- FIL_QUERYFULLNAME,
- canonicalPath,
- CCHMAXPATH);
-#else
- char* canonicalPath = _fullpath(buffer, ioPath, _MAX_PATH);
-#endif
-
- if (canonicalPath)
- {
- NS_ASSERTION( canonicalPath[0] != '\0', "Uh oh...couldn't convert" );
- if (canonicalPath[0] == '\0')
- return;
-#ifdef XP_OS2
- // If we removed that backslash, add it back onto the fullpath
- if (removedBackslash)
- strcat( canonicalPath, "\\");
-#endif
- }
- ioPath = canonicalPath;
-} // 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;
- }
-
- src = (char*)ioPath;
-
- if (*src) {
- // Convert '/' to '\'.
- while (*++src)
- {
- if (*src == '/')
- *src = '\\';
- }
- }
-} // nsFileSpecHelpers::UnixToNative
-
-//----------------------------------------------------------------------------------------
-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
- temp[0] = '\0'; // relative path
-
- // Convert '\' to '/'
- for (; *cp; cp++)
- {
-#ifdef XP_OS2
- // OS2TODO - implement equivalent of IsDBCSLeadByte
-#else
- if(IsDBCSLeadByte(*cp) && *(cp+1) != nsnull)
- {
- cp++;
- continue;
- }
-#endif
- if (*cp == '\\')
- *cp = '/';
- }
- // Add the slash in front.
- temp += ioPath;
- ioPath = temp;
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec(const nsFilePath& inPath)
-//----------------------------------------------------------------------------------------
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
- *this = inPath;
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator = (const nsFilePath& inPath)
-//----------------------------------------------------------------------------------------
-{
- mPath = (const char*)inPath;
- nsFileSpecHelpers::UnixToNative(mPath);
- mError = NS_OK;
-} // nsFileSpec::operator =
-
-//----------------------------------------------------------------------------------------
-nsFilePath::nsFilePath(const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
-{
- *this = inSpec;
-} // nsFilePath::nsFilePath
-
-//----------------------------------------------------------------------------------------
-void nsFilePath::operator = (const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
-{
- mPath = inSpec.mPath;
- nsFileSpecHelpers::NativeToUnix(mPath);
-} // nsFilePath::operator =
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::SetLeafName(const char* inLeafName)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inLeafName, "Attempt to SetLeafName with a null string");
- mPath.LeafReplace('\\', inLeafName);
-} // nsFileSpec::SetLeafName
-
-//----------------------------------------------------------------------------------------
-char* nsFileSpec::GetLeafName() const
-//----------------------------------------------------------------------------------------
-{
- return mPath.GetLeaf('\\');
-} // nsFileSpec::GetLeafName
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::Exists() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st);
-} // nsFileSpec::Exists
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::GetModDate(TimeStamp& outStamp) const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(nsNSPRPath(*this), &st) == 0)
- outStamp = st.st_mtime;
- else
- outStamp = 0;
-} // nsFileSpec::GetModDate
-
-//----------------------------------------------------------------------------------------
-PRUint32 nsFileSpec::GetFileSize() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(nsNSPRPath(*this), &st) == 0)
- return (PRUint32)st.st_size;
- return 0;
-} // nsFileSpec::GetFileSize
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsFile() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
-#ifdef XP_OS2
- return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && ( S_IFREG & st.st_mode);
-#else
- return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && (_S_IFREG & st.st_mode);
-#endif
-} // nsFileSpec::IsFile
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsDirectory() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
-#ifdef XP_OS2
- return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && ( S_IFDIR & st.st_mode);
-#else
- return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && (_S_IFDIR & st.st_mode);
-#endif
-} // nsFileSpec::IsDirectory
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsHidden() const
-//----------------------------------------------------------------------------------------
-{
- PRBool hidden = PR_FALSE;
- if (!mPath.IsEmpty())
- {
-#ifdef XP_OS2
- FILESTATUS3 fs3;
- APIRET rc;
-
- rc = DosQueryPathInfo( mPath,
- FIL_STANDARD,
- &fs3,
- sizeof fs3);
- if(!rc)
- hidden = fs3.attrFile & FILE_HIDDEN ? PR_TRUE : PR_FALSE;
-#else
- DWORD attr = GetFileAttributes(mPath);
- if (FILE_ATTRIBUTE_HIDDEN & attr)
- hidden = PR_TRUE;
-#endif
- }
- return hidden;
-}
-// nsFileSpec::IsHidden
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsSymlink() const
-//----------------------------------------------------------------------------------------
-{
-#ifdef XP_OS2
- return PR_FALSE; // No symlinks on OS/2
-#else
- HRESULT hres;
- IShellLink* psl;
-
- PRBool isSymlink = PR_FALSE;
-
- CoInitialize(NULL);
- // Get a pointer to the IShellLink interface.
- hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
- if (SUCCEEDED(hres))
- {
- IPersistFile* ppf;
-
- // Get a pointer to the IPersistFile interface.
- hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
-
- if (SUCCEEDED(hres))
- {
- WORD wsz[MAX_PATH];
- // Ensure that the string is Unicode.
- MultiByteToWideChar(CP_ACP, 0, mPath, -1, wsz, MAX_PATH);
-
- // Load the shortcut.
- hres = ppf->Load(wsz, STGM_READ);
- if (SUCCEEDED(hres))
- {
- isSymlink = PR_TRUE;
- }
-
- // Release the pointer to the IPersistFile interface.
- ppf->Release();
- }
-
- // Release the pointer to the IShellLink interface.
- psl->Release();
- }
-
- CoUninitialize();
-
- return isSymlink;
-#endif
-}
-
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::ResolveSymlink(PRBool& wasSymlink)
-//----------------------------------------------------------------------------------------
-{
-#ifdef XP_OS2
- return NS_OK; // no symlinks on OS/2
-#else
- wasSymlink = PR_FALSE; // assume failure
-
- if (Exists())
- return NS_OK;
-
-
- HRESULT hres;
- IShellLink* psl;
-
- CoInitialize(NULL);
-
- // Get a pointer to the IShellLink interface.
- hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
- if (SUCCEEDED(hres))
- {
- IPersistFile* ppf;
-
- // Get a pointer to the IPersistFile interface.
- hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
-
- if (SUCCEEDED(hres))
- {
- WORD wsz[MAX_PATH];
- // Ensure that the string is Unicode.
- MultiByteToWideChar(CP_ACP, 0, mPath, -1, wsz, MAX_PATH);
-
- // Load the shortcut.
- hres = ppf->Load(wsz, STGM_READ);
- if (SUCCEEDED(hres))
- {
- wasSymlink = PR_TRUE;
-
- // Resolve the link.
- hres = psl->Resolve(nsnull, SLR_NO_UI );
- if (SUCCEEDED(hres))
- {
- char szGotPath[MAX_PATH];
- WIN32_FIND_DATA wfd;
-
- // Get the path to the link target.
- hres = psl->GetPath( szGotPath, MAX_PATH, &wfd, SLGP_UNCPRIORITY );
-
- if (SUCCEEDED(hres))
- {
- // Here we modify the nsFileSpec;
- mPath = szGotPath;
- mError = NS_OK;
- }
- }
- }
- else {
- // It wasn't a shortcut. Oh well. Leave it like it was.
- hres = 0;
- }
-
- // Release the pointer to the IPersistFile interface.
- ppf->Release();
- }
- // Release the pointer to the IShellLink interface.
- psl->Release();
- }
-
- CoUninitialize();
-
- if (SUCCEEDED(hres))
- return NS_OK;
-
- return NS_FILE_FAILURE;
-#endif
-}
-
-
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::GetParent(nsFileSpec& outSpec) const
-//----------------------------------------------------------------------------------------
-{
- outSpec.mPath = mPath;
- char* chars = (char*)outSpec.mPath;
- chars[outSpec.mPath.Length() - 1] = '\0'; // avoid trailing separator, if any
- char* cp = strrchr(chars, '\\');
- if (cp++)
- outSpec.mPath.SetLength(cp - chars); // truncate.
-} // nsFileSpec::GetParent
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator += (const char* inRelativePath)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inRelativePath, "Attempt to do += with a null string");
-
- if (!inRelativePath || mPath.IsEmpty())
- return;
-
- if (mPath[mPath.Length() - 1] == '\\')
- mPath += "x";
- else
- mPath += "\\x";
-
- // If it's a (unix) relative path, make it native
- nsSimpleCharString dosPath = inRelativePath;
- nsFileSpecHelpers::UnixToNative(dosPath);
- SetLeafName(dosPath);
-} // nsFileSpec::operator +=
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::CreateDirectory(int /*mode*/)
-//----------------------------------------------------------------------------------------
-{
- // Note that mPath is canonical!
- if (!mPath.IsEmpty())
- mkdir(nsNSPRPath(*this));
-} // nsFileSpec::CreateDirectory
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::Delete(PRBool inRecursive) const
-//----------------------------------------------------------------------------------------
-{
- if (IsDirectory())
- {
- if (inRecursive)
- {
- for (nsDirectoryIterator i(*this, PR_FALSE); i.Exists(); i++)
- {
- nsFileSpec& child = i.Spec();
- child.Delete(inRecursive);
- }
- }
- rmdir(nsNSPRPath(*this));
- }
- else if (!mPath.IsEmpty())
- {
- remove(nsNSPRPath(*this));
- }
-} // nsFileSpec::Delete
-
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::RecursiveCopy(nsFileSpec newDir) const
-//----------------------------------------------------------------------------------------
-{
- if (IsDirectory())
- {
- if (!(newDir.Exists()))
- {
- newDir.CreateDirectory();
- }
-
- for (nsDirectoryIterator i(*this, PR_FALSE); i.Exists(); i++)
- {
- nsFileSpec& child = i.Spec();
-
- if (child.IsDirectory())
- {
- nsFileSpec tmpDirSpec(newDir);
-
- char *leafname = child.GetLeafName();
- tmpDirSpec += leafname;
- nsCRT::free(leafname);
-
- child.RecursiveCopy(tmpDirSpec);
- }
- else
- {
- child.RecursiveCopy(newDir);
- }
- }
- }
- else if (!mPath.IsEmpty())
- {
- nsFileSpec& filePath = (nsFileSpec&) *this;
-
- if (!(newDir.Exists()))
- {
- newDir.CreateDirectory();
- }
-
- filePath.CopyToDir(newDir);
- }
-} // nsFileSpec::RecursiveCopy
-
-//----------------------------------------------------------------------------------------
-nsresult
-nsFileSpec::Truncate(PRInt32 aNewFileLength) const
-//----------------------------------------------------------------------------------------
-{
-#ifdef XP_OS2
- APIRET rc;
- HFILE hFile;
- ULONG actionTaken;
-
- rc = DosOpen(mPath,
- &hFile,
- &actionTaken,
- 0,
- FILE_NORMAL,
- OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
- OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE,
- NULL);
-
- if (rc != NO_ERROR)
- return NS_FILE_FAILURE;
-
- rc = DosSetFileSize(hFile, aNewFileLength);
-
- if (rc == NO_ERROR)
- DosClose(hFile);
- else
- goto error;
-#else
- DWORD status;
- HANDLE hFile;
-
- // Leave it to Microsoft to open an existing file with a function
- // named "CreateFile".
- hFile = CreateFile(mPath,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- return NS_FILE_FAILURE;
-
- // Seek to new, desired end of file
- status = SetFilePointer(hFile, aNewFileLength, NULL, FILE_BEGIN);
- 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;
-
- error:
-#ifdef XP_OS2
- DosClose(hFile);
-#else
- CloseHandle(hFile);
-#endif
- return NS_FILE_FAILURE;
-
-} // nsFileSpec::Truncate
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Rename(const char* inNewName)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inNewName, "Attempt to Rename with a null string");
-
- // This function should not be used to move a file on disk.
- if (strchr(inNewName, '/'))
- return NS_FILE_FAILURE;
-
- char* oldPath = nsCRT::strdup(mPath);
-
- SetLeafName(inNewName);
-
- if (PR_Rename(oldPath, mPath) != NS_OK)
- {
- // Could not rename, set back to the original.
- mPath = oldPath;
- return NS_FILE_FAILURE;
- }
-
- nsCRT::free(oldPath);
-
- return NS_OK;
-} // nsFileSpec::Rename
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::CopyToDir(const nsFileSpec& inParentDirectory) const
-//----------------------------------------------------------------------------------------
-{
- // We can only copy into a directory, and (for now) can not copy entire directories
- if (inParentDirectory.IsDirectory() && (! IsDirectory() ) )
- {
- char *leafname = GetLeafName();
- nsSimpleCharString destPath(inParentDirectory.GetCString());
- destPath += "\\";
- destPath += leafname;
- nsCRT::free(leafname);
-
- // CopyFile returns non-zero if succeeds
-#ifdef XP_OS2
- APIRET rc;
- PRBool copyOK;
-
- rc = DosCopy(GetCString(), (PSZ)destPath, DCPY_EXISTING);
-
- if (rc == NO_ERROR)
- copyOK = PR_TRUE;
- else
- copyOK = PR_FALSE;
-#else
- int copyOK = CopyFile(GetCString(), destPath, PR_TRUE);
-#endif
- if (copyOK)
- return NS_OK;
- }
- return NS_FILE_FAILURE;
-} // nsFileSpec::CopyToDir
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::MoveToDir(const nsFileSpec& inNewParentDirectory)
-//----------------------------------------------------------------------------------------
-{
- // We can only copy into a directory, and (for now) can not copy entire directories
- if (inNewParentDirectory.IsDirectory() && (! IsDirectory() ) )
- {
- char *leafname = GetLeafName();
- nsSimpleCharString destPath(inNewParentDirectory.GetCString());
- destPath += "\\";
- destPath += leafname;
- nsCRT::free(leafname);
-
- if (DosMove(GetCString(), destPath) == NO_ERROR)
- {
- *this = inNewParentDirectory + GetLeafName();
- return NS_OK;
- }
-
- }
- return NS_FILE_FAILURE;
-} // nsFileSpec::MoveToDir
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Execute(const char* inArgs ) const
-//----------------------------------------------------------------------------------------
-{
- if (!IsDirectory())
- {
-#ifdef XP_OS2
- nsresult result = NS_FILE_FAILURE;
-
- if (!mPath.IsEmpty())
- {
- nsSimpleCharString fileNameWithArgs = mPath + " " + inArgs;
- result = NS_FILE_RESULT(system(fileNameWithArgs));
- }
- return result;
-#else
- nsSimpleCharString fileNameWithArgs = "\"";
- fileNameWithArgs += mPath + "\" " + inArgs;
- int execResult = WinExec( fileNameWithArgs, SW_NORMAL );
- if (execResult > 31)
- return NS_OK;
-#endif
- }
- return NS_FILE_FAILURE;
-} // nsFileSpec::Execute
-
-
-//----------------------------------------------------------------------------------------
-PRInt64 nsFileSpec::GetDiskSpaceAvailable() const
-//----------------------------------------------------------------------------------------
-{
- PRInt64 nBytes = 0;
- ULONG ulDriveNo = toupper(mPath[0]) + 1 - 'A';
- FSALLOCATE fsAllocate;
- APIRET rc = DosQueryFSInfo(ulDriveNo,
- FSIL_ALLOC,
- &fsAllocate,
- sizeof(fsAllocate));
-
- if (rc == NO_ERROR) {
- nBytes = fsAllocate.cUnitAvail;
- nBytes *= fsAllocate.cSectorUnit;
- nBytes *= fsAllocate.cbSector;
- }
-
- return nBytes;
-}
-
-
-
-//========================================================================================
-// nsDirectoryIterator
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator::nsDirectoryIterator(const nsFileSpec& inDirectory, PRBool resolveSymlink)
-//----------------------------------------------------------------------------------------
- : mCurrent(inDirectory)
- , mDir(nsnull)
- , mStarting(inDirectory)
- , mExists(PR_FALSE)
- , mResoveSymLinks(resolveSymlink)
-{
- mDir = PR_OpenDir(inDirectory);
- mCurrent += "dummy";
- mStarting += "dummy";
- ++(*this);
-} // nsDirectoryIterator::nsDirectoryIterator
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator::~nsDirectoryIterator()
-//----------------------------------------------------------------------------------------
-{
- if (mDir)
- PR_CloseDir(mDir);
-} // nsDirectoryIterator::nsDirectoryIterator
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator& nsDirectoryIterator::operator ++ ()
-//----------------------------------------------------------------------------------------
-{
- mExists = PR_FALSE;
- if (!mDir)
- return *this;
- PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH); // Ignore '.' && '..'
- if (entry)
- {
- mExists = PR_TRUE;
- mCurrent = mStarting;
- mCurrent.SetLeafName(entry->name);
- if (mResoveSymLinks)
- {
- PRBool ignore;
- mCurrent.ResolveSymlink(ignore);
- }
- }
- return *this;
-} // nsDirectoryIterator::operator ++
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator& nsDirectoryIterator::operator -- ()
-//----------------------------------------------------------------------------------------
-{
- return ++(*this); // can't do it backwards.
-} // nsDirectoryIterator::operator --
-
deleted file mode 100644
--- a/xpcom/obsolete/nsFileSpecUnix.cpp
+++ /dev/null
@@ -1,777 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Henry Sobotka <sobotka@axess.com>
- * William Bonnet <wbonnet@on-x.com>
- *
- * 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 file is included by nsFileSpec.cpp, and includes the Unix-specific
-// implementations.
-
-#include <sys/stat.h>
-#include <sys/param.h>
-#include <errno.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <limits.h>
-#include "xpcom-private.h"
-#include "nsError.h"
-#include "prio.h" /* for PR_Rename */
-#include "nsTArray.h"
-
-#if defined(_SCO_DS)
-#define _SVID3 /* for statvfs.h */
-#endif
-
-#ifdef HAVE_SYS_STATVFS_H
-#include <sys/statvfs.h>
-#endif
-
-#ifdef HAVE_SYS_VFS_H
-#include <sys/vfs.h>
-#endif
-
-#ifdef HAVE_SYS_STATFS_H
-#include <sys/statfs.h>
-#endif
-
-#ifdef HAVE_SYS_MOUNT_H
-#include <sys/mount.h>
-#undef Free
-#endif
-
-#ifdef HAVE_STATVFS
-#define STATFS statvfs
-#else
-#define STATFS statfs
-#endif
-
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024 /* Guessing this is okay. Works for SCO. */
-#endif
-
-#if defined(__QNX__)
-#include <unix.h> /* for realpath */
-#define f_bavail f_bfree
-extern "C" int truncate(const char *, off_t);
-#endif
-
-#if defined(SUNOS4)
-extern "C" int statfs(char *, struct statfs *);
-#endif
-
-#if defined(OSF1)
-extern "C" int statvfs(const char *, struct statvfs *);
-#endif
-
-#ifdef XP_MACOSX
-static void CopyUTF8toUTF16NFC(const nsACString& aSrc, nsAString& aResult);
-#endif
-
-//----------------------------------------------------------------------------------------
-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 nsFileSpec::SetLeafName(const char* inLeafName)
-//----------------------------------------------------------------------------------------
-{
- mPath.LeafReplace('/', inLeafName);
-} // nsFileSpec::SetLeafName
-
-//----------------------------------------------------------------------------------------
-char* nsFileSpec::GetLeafName() const
-//----------------------------------------------------------------------------------------
-{
-#ifndef XP_MACOSX
- return mPath.GetLeaf('/');
-#else
- char *name = mPath.GetLeaf('/');
- if (!name || !*name)
- return name;
- nsAutoString nameInNFC;
- CopyUTF8toUTF16NFC(nsDependentCString(name), nameInNFC);
- nsCRT::free(name);
- return nsCRT::strdup(NS_ConvertUTF16toUTF8(nameInNFC).get());
-#endif
-} // nsFileSpec::GetLeafName
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::Exists() const
-//----------------------------------------------------------------------------------------
-{
- return !mPath.IsEmpty() && 0 == access(mPath, F_OK);
-} // nsFileSpec::Exists
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::GetModDate(TimeStamp& outStamp) const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(mPath, &st) == 0)
- outStamp = st.st_mtime;
- else
- outStamp = 0;
-} // nsFileSpec::GetModDate
-
-//----------------------------------------------------------------------------------------
-PRUint32 nsFileSpec::GetFileSize() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(mPath, &st) == 0)
- return (PRUint32)st.st_size;
- return 0;
-} // nsFileSpec::GetFileSize
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsFile() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && stat(mPath, &st) == 0 && S_ISREG(st.st_mode);
-} // nsFileSpec::IsFile
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsDirectory() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && 0 == stat(mPath, &st) && S_ISDIR(st.st_mode);
-} // nsFileSpec::IsDirectory
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsHidden() const
-//----------------------------------------------------------------------------------------
-{
- PRBool hidden = PR_FALSE;
- char *leafname = GetLeafName();
- if (nsnull != leafname)
- {
- // rjc: don't return ".", "..", or any file/directory that begins with a "."
-
- /* if ((!strcmp(leafname, ".")) || (!strcmp(leafname, ".."))) */
- if (leafname[0] == '.')
- {
- hidden = PR_TRUE;
- }
- nsCRT::free(leafname);
- }
- return hidden;
-} // nsFileSpec::IsHidden
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsSymlink() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(mPath, &st) == 0 && S_ISLNK(st.st_mode))
- return PR_TRUE;
-
- return PR_FALSE;
-} // nsFileSpec::IsSymlink
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::ResolveSymlink(PRBool& wasAliased)
-//----------------------------------------------------------------------------------------
-{
- wasAliased = PR_FALSE;
-
- char resolvedPath[MAXPATHLEN];
- int charCount = readlink(mPath, (char*)&resolvedPath, MAXPATHLEN);
- if (0 < charCount)
- {
- if (MAXPATHLEN > charCount)
- resolvedPath[charCount] = '\0';
-
- wasAliased = PR_TRUE;
-
- /* if it's not an absolute path,
- replace the leaf with what got resolved */
- if (resolvedPath[0] != '/') {
- SetLeafName(resolvedPath);
- }
- else {
- mPath = (char*)&resolvedPath;
- }
-
- char* canonicalPath = realpath((const char *)mPath, resolvedPath);
- NS_ASSERTION(canonicalPath, "realpath failed");
- if (canonicalPath) {
- mPath = (char*)&resolvedPath;
- }
- else {
- return NS_ERROR_FAILURE;
- }
- }
-
- return NS_OK;
-} // nsFileSpec::ResolveSymlink
-
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::GetParent(nsFileSpec& outSpec) const
-//----------------------------------------------------------------------------------------
-{
- outSpec.mPath = mPath;
- char* chars = (char*)outSpec.mPath;
- chars[outSpec.mPath.Length() - 1] = '\0'; // avoid trailing separator, if any
- char* cp = strrchr(chars, '/');
- if (cp++)
- outSpec.mPath.SetLength(cp - chars); // truncate.
-} // nsFileSpec::GetParent
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator += (const char* inRelativePath)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inRelativePath, "Attempt to do += with a null string");
-
- if (!inRelativePath || mPath.IsEmpty())
- return;
-
- char endChar = mPath[(int)(strlen(mPath) - 1)];
- if (endChar == '/')
- mPath += "x";
- else
- mPath += "/x";
- SetLeafName(inRelativePath);
-} // nsFileSpec::operator +=
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::CreateDirectory(int mode)
-//----------------------------------------------------------------------------------------
-{
- // Note that mPath is canonical!
- if (mPath.IsEmpty())
- return;
- mkdir(mPath, mode);
-} // nsFileSpec::CreateDirectory
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::Delete(PRBool inRecursive) const
-// To check if this worked, call Exists() afterwards, see?
-//----------------------------------------------------------------------------------------
-{
- if (IsDirectory())
- {
- if (inRecursive)
- {
- for (nsDirectoryIterator i(*this, PR_FALSE); i.Exists(); i++)
- {
- nsFileSpec& child = (nsFileSpec&)i;
- child.Delete(inRecursive);
- }
- }
- rmdir(mPath);
- }
- else if (!mPath.IsEmpty())
- remove(mPath);
-} // nsFileSpec::Delete
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::RecursiveCopy(nsFileSpec newDir) const
-//----------------------------------------------------------------------------------------
-{
- if (IsDirectory())
- {
- if (!(newDir.Exists()))
- {
- newDir.CreateDirectory();
- }
-
- for (nsDirectoryIterator i(*this, PR_FALSE); i.Exists(); i++)
- {
- nsFileSpec& child = (nsFileSpec&)i;
-
- if (child.IsDirectory())
- {
- nsFileSpec tmpDirSpec(newDir);
-
- char *leafname = child.GetLeafName();
- tmpDirSpec += leafname;
- nsCRT::free(leafname);
-
- child.RecursiveCopy(tmpDirSpec);
- }
- else
- {
- child.RecursiveCopy(newDir);
- }
- }
- }
- else if (!mPath.IsEmpty())
- {
- nsFileSpec& filePath = (nsFileSpec&) *this;
-
- if (!(newDir.Exists()))
- {
- newDir.CreateDirectory();
- }
-
- filePath.CopyToDir(newDir);
- }
-} // nsFileSpec::RecursiveCopy
-
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Truncate(PRInt32 offset) const
-//----------------------------------------------------------------------------------------
-{
- char* Path = nsCRT::strdup(mPath);
-
- int rv = truncate(Path, offset) ;
-
- nsCRT::free(Path) ;
-
- if(!rv)
- return NS_OK ;
- else
- return NS_ERROR_FAILURE ;
-} // nsFileSpec::Truncate
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Rename(const char* inNewName)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inNewName, "Attempt to Rename with a null string");
-
- // This function should not be used to move a file on disk.
- if (mPath.IsEmpty() || strchr(inNewName, '/'))
- return NS_FILE_FAILURE;
-
- char* oldPath = nsCRT::strdup(mPath);
-
- SetLeafName(inNewName);
-
- if (PR_Rename(oldPath, mPath) != NS_OK)
- {
- // Could not rename, set back to the original.
- mPath = oldPath;
- nsCRT::free(oldPath);
- return NS_FILE_FAILURE;
- }
-
- nsCRT::free(oldPath);
-
- return NS_OK;
-} // nsFileSpec::Rename
-
-//----------------------------------------------------------------------------------------
-static int CrudeFileCopy_DoCopy(PRFileDesc * pFileDescIn, PRFileDesc * pFileDescOut, char * pBuf, long bufferSize)
-//----------------------------------------------------------------------------------------
-{
- PRInt32 rbytes, wbytes; // Number of bytes read and written in copy loop
-
- // Copy loop
- //
- // If EOF is reached and no data is available, PR_Read returns 0. A negative
- // return value means an error occured
- rbytes = PR_Read(pFileDescIn, pBuf, bufferSize);
- if (rbytes < 0) // Test if read was unsuccessfull
- { // Error case
- return -1; // Return an error
- }
-
- while (rbytes > 0) // While there is data to copy
- {
- // Data buffer size is only 1K ! fwrite function is able to write it in
- // one call. According to the man page fwrite returns a number of elements
- // written if an error occured. Thus there is no need to handle this case
- // as a normal case. Written data cannot be smaller than rbytes.
- wbytes = PR_Write(pFileDescOut, pBuf, rbytes); // Copy data to output file
- if (wbytes != rbytes) // Test if all data was written
- { // No this an error
- return -1; // Return an error
- }
-
- // Write is done, we try to get more data
- rbytes = PR_Read(pFileDescIn, pBuf, bufferSize);
- if (rbytes < 0) // Test if read was unsuccessful
- { // Error case
- return -1; // Return an error
- }
- }
-
- return 0; // Still here ? ok so it worked :)
-} // nsFileSpec::CrudeFileCopy_DoCopy
-
-//----------------------------------------------------------------------------------------
-static int CrudeFileCopy(const char* in, const char* out)
-//----------------------------------------------------------------------------------------
-{
- char buf[1024]; // Used as buffer for the copy loop
- PRInt32 rbytes, wbytes; // Number of bytes read and written in copy loop
- struct stat in_stat; // Stores informations from the stat syscall
- int stat_result = -1, ret;
- PRFileDesc * pFileDescIn, * pFileDescOut; // Src and dest pointers
-
- // Check if the pointers to filenames are valid
- NS_ASSERTION(in && out, "CrudeFileCopy should be called with pointers to filenames...");
-
- // Check if the pointers are the same, if so, no need to copy A to A
- if (in == out)
- return 0;
-
- // Check if content of the pointers are the sames, if so, no need to copy A to A
- if (strcmp(in,out) == 0)
- return 0;
-
- // Retrieve the 'in' file attributes
- stat_result = stat(in, &in_stat);
- if(stat_result != 0)
- {
- // test if stat failed, it can happen if the file does not exist, is not
- // readable or is not available ( can happen with NFS mounts )
- return -1; // Return an error
- }
-
- // Open the input file for binary read
- pFileDescIn = PR_Open(in, PR_RDONLY, 0444);
- if (pFileDescIn == 0)
- {
- return -1; // Open failed, return an error
- }
-
- // Open the output file for binary write
- pFileDescOut = PR_Open(out, PR_WRONLY | PR_CREATE_FILE, 0600);
- if (pFileDescOut == 0)
- {
- // Open failed, need to close input file, then return an error
- PR_Close(pFileDescOut); // Close the output file
- return -1; // Open failed, return an error
- }
-
- // Copy the data
- if (CrudeFileCopy_DoCopy(pFileDescIn, pFileDescOut, buf, sizeof(buf)) != 0)
- { // Error case
- PR_Close(pFileDescOut); // Close output file
- PR_Close(pFileDescIn); // Close input file
- PR_Delete(out); // Destroy output file
- return -1; // Return an error
- }
-
- // There is no need for error handling here. This should have worked, but even
- // if it fails, the data are now copied to destination, thus there is no need
- // for the function to fail on the input file error
- PR_Close(pFileDescIn);
-
- // It is better to call fsync and test return code before exiting to be sure
- // data are actually written on disk. Data loss can happen with NFS mounts
- if (PR_Sync(pFileDescOut) != PR_SUCCESS)
- { // Test if the fsync function succeeded
- PR_Close(pFileDescOut); // Close output file
- PR_Delete(out); // Destroy output file
- return -1; // Return an error
- }
-
- // Copy is done, close both file
- if (PR_Close(pFileDescOut) != PR_SUCCESS) // Close output file
- { // Output file was not closed :(
- PR_Delete(out); // Destroy output file
- return -1; // Return an error
- }
-
- ret = chmod(out, in_stat.st_mode & 0777); // Set the new file file mode
- if (ret != 0) // Test if the chmod function succeeded
- {
- PR_Delete(out); // Destroy output file
- return -1; // Return an error
- }
-
- return 0; // Still here ? ok so it worked :)
-} // nsFileSpec::CrudeFileCopy
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::CopyToDir(const nsFileSpec& inParentDirectory) const
-//----------------------------------------------------------------------------------------
-{
- // We can only copy into a directory, and (for now) can not copy entire directories
- nsresult result = NS_FILE_FAILURE;
-
- if (inParentDirectory.IsDirectory() && (! IsDirectory() ) )
- {
- char *leafname = GetLeafName();
- nsSimpleCharString destPath(inParentDirectory.GetCString());
- destPath += "/";
- destPath += leafname;
- nsCRT::free(leafname);
- result = NS_FILE_RESULT(CrudeFileCopy(GetCString(), destPath));
- }
- return result;
-} // nsFileSpec::CopyToDir
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::MoveToDir(const nsFileSpec& inNewParentDirectory)
-//----------------------------------------------------------------------------------------
-{
- // We can only copy into a directory, and (for now) can not copy entire directories
- nsresult result = NS_FILE_FAILURE;
-
- if (inNewParentDirectory.IsDirectory() && !IsDirectory())
- {
- char *leafname = GetLeafName();
- nsSimpleCharString destPath(inNewParentDirectory.GetCString());
- destPath += "/";
- destPath += leafname;
- nsCRT::free(leafname);
-
- result = NS_FILE_RESULT(CrudeFileCopy(GetCString(), (const char*)destPath));
- if (result == NS_OK)
- {
- // cast to fix const-ness
- ((nsFileSpec*)this)->Delete(PR_FALSE);
-
- *this = inNewParentDirectory + GetLeafName();
- }
- }
- return result;
-}
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Execute(const char* inArgs ) const
-//----------------------------------------------------------------------------------------
-{
- nsresult result = NS_FILE_FAILURE;
-
- if (!mPath.IsEmpty() && !IsDirectory())
- {
- nsSimpleCharString fileNameWithArgs = mPath + " " + inArgs;
- result = NS_FILE_RESULT(system(fileNameWithArgs));
- }
-
- return result;
-
-} // nsFileSpec::Execute
-
-//----------------------------------------------------------------------------------------
-PRInt64 nsFileSpec::GetDiskSpaceAvailable() const
-//----------------------------------------------------------------------------------------
-{
- PRInt64 bytes; /* XXX dougt needs to fix this */
- LL_I2L(bytes , LONG_MAX); // initialize to all the space in the world?
-
-
-#if defined(HAVE_SYS_STATFS_H) || defined(HAVE_SYS_STATVFS_H)
-
- char curdir [MAXPATHLEN];
- if (mPath.IsEmpty())
- {
- (void) getcwd(curdir, MAXPATHLEN);
- if (!curdir)
- return bytes; /* hope for the best as we did in cheddar */
- }
- else
- sprintf(curdir, "%.200s", (const char*)mPath);
-
- struct STATFS fs_buf;
-#if defined(__QNX__) && !defined(HAVE_STATVFS) /* Maybe this should be handled differently? */
- if (STATFS(curdir, &fs_buf, 0, 0) < 0)
-#else
- if (STATFS(curdir, &fs_buf) < 0)
-#endif
- return bytes; /* hope for the best as we did in cheddar */
-
-#ifdef DEBUG_DISK_SPACE
- printf("DiskSpaceAvailable: %d bytes\n",
- fs_buf.f_bsize * (fs_buf.f_bavail - 1));
-#endif
-
- PRInt64 bsize,bavail;
- LL_I2L( bsize, fs_buf.f_bsize );
- LL_I2L( bavail, fs_buf.f_bavail - 1 );
- LL_MUL( bytes, bsize, bavail );
- return bytes;
-
-#else
- /*
- ** This platform doesn't have statfs or statvfs, so we don't have much
- ** choice but to "hope for the best as we did in cheddar".
- */
- return bytes;
-#endif /* HAVE_SYS_STATFS_H or HAVE_SYS_STATVFS_H */
-
-} // nsFileSpec::GetDiskSpace()
-
-//========================================================================================
-// nsDirectoryIterator
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator::nsDirectoryIterator(const nsFileSpec& inDirectory, PRBool resolveSymLinks)
-//----------------------------------------------------------------------------------------
- : mCurrent(inDirectory)
- , mExists(PR_FALSE)
- , mResoveSymLinks(resolveSymLinks)
- , mStarting(inDirectory)
- , mDir(nsnull)
-
-{
- mStarting += "sysygy"; // save off the starting directory
- mCurrent += "sysygy"; // prepare the path for SetLeafName
- mDir = opendir((const char*)nsFilePath(inDirectory));
- ++(*this);
-} // nsDirectoryIterator::nsDirectoryIterator
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator::~nsDirectoryIterator()
-//----------------------------------------------------------------------------------------
-{
- if (mDir)
- closedir(mDir);
-} // nsDirectoryIterator::nsDirectoryIterator
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator& nsDirectoryIterator::operator ++ ()
-//----------------------------------------------------------------------------------------
-{
- mExists = PR_FALSE;
- if (!mDir)
- return *this;
- const char dot[] = ".";
- const char dotdot[] = "..";
- struct dirent* entry = readdir(mDir);
- if (entry && strcmp(entry->d_name, dot) == 0)
- entry = readdir(mDir);
- if (entry && strcmp(entry->d_name, dotdot) == 0)
- entry = readdir(mDir);
- if (entry)
- {
- mExists = PR_TRUE;
- mCurrent = mStarting; // restore mCurrent to be the starting directory. ResolveSymlink() may have taken us to another directory
- mCurrent.SetLeafName(entry->d_name);
- if (mResoveSymLinks)
- {
- PRBool ignore;
- mCurrent.ResolveSymlink(ignore);
- }
- }
- return *this;
-} // nsDirectoryIterator::operator ++
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator& nsDirectoryIterator::operator -- ()
-//----------------------------------------------------------------------------------------
-{
- return ++(*this); // can't do it backwards.
-} // nsDirectoryIterator::operator --
-
-// Convert a UTF-8 string to a UTF-16 string while normalizing to
-// Normalization Form C (composed Unicode). We need this because
-// Mac OS X file system uses NFD (Normalization Form D : decomposed Unicode)
-// while most other OS', server-side programs usually expect NFC.
-
-#ifdef XP_MACOSX
-typedef void (*UnicodeNormalizer) (CFMutableStringRef, CFStringNormalizationForm);
-static void CopyUTF8toUTF16NFC(const nsACString& aSrc, nsAString& aResult)
-{
- static PRBool sChecked = PR_FALSE;
- static UnicodeNormalizer sUnicodeNormalizer = NULL;
-
- // CFStringNormalize was not introduced until Mac OS 10.2
- if (!sChecked) {
- CFBundleRef carbonBundle =
- CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"));
- if (carbonBundle)
- sUnicodeNormalizer = (UnicodeNormalizer)
- ::CFBundleGetFunctionPointerForName(carbonBundle,
- CFSTR("CFStringNormalize"));
- sChecked = PR_TRUE;
- }
-
- if (!sUnicodeNormalizer) { // OS X 10.1 or earlier
- CopyUTF8toUTF16(aSrc, aResult);
- return;
- }
-
- const nsAFlatCString &inFlatSrc = PromiseFlatCString(aSrc);
-
- // The number of 16bit code units in a UTF-16 string will never be
- // larger than the number of bytes in the corresponding UTF-8 string.
- CFMutableStringRef inStr =
- ::CFStringCreateMutable(NULL, inFlatSrc.Length());
-
- if (!inStr) {
- CopyUTF8toUTF16(aSrc, aResult);
- return;
- }
-
- ::CFStringAppendCString(inStr, inFlatSrc.get(), kCFStringEncodingUTF8);
-
- sUnicodeNormalizer(inStr, kCFStringNormalizationFormC);
-
- CFIndex length = CFStringGetLength(inStr);
- const UniChar* chars = CFStringGetCharactersPtr(inStr);
-
- if (chars)
- aResult.Assign(chars, length);
- else {
- nsAutoTArray<UniChar, 512> buffer;
- if (buffer.SetLength(length)) {
- CFStringGetCharacters(inStr, CFRangeMake(0, length), buffer.Elements());
- aResult.Assign(buffer.Elements(), length);
- }
- else
- CopyUTF8toUTF16(aSrc, aResult);
- }
- CFRelease(inStr);
-}
-#endif
deleted file mode 100644
--- a/xpcom/obsolete/nsFileSpecWin.cpp
+++ /dev/null
@@ -1,779 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Masayuki Nakano <masayuki@d-toybox.com>
- *
- * 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 file is included by nsFileSpec.cp, and includes the Windows-specific
-// implementations.
-
-#include <sys/stat.h>
-#include <direct.h>
-#include <limits.h>
-#include <stdlib.h>
-#include "prio.h"
-#include "nsError.h"
-
-#include <windows.h>
-#include <mbstring.h>
-
-#if (_MSC_VER == 1100) || defined(__GNUC__)
-#define INITGUID
-#include <objbase.h>
-DEFINE_OLEGUID(IID_IPersistFile, 0x0000010BL, 0, 0);
-#endif
-
-#include <shlobj.h>
-#include <shellapi.h>
-#include <shlguid.h>
-
-#ifndef WINCE
-#ifdef UNICODE
-#define CreateDirectoryW CreateDirectory
-#else
-#define CreateDirectoryA CreateDirectory
-#endif
-#endif
-
-//----------------------------------------------------------------------------------------
-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::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
-
-//----------------------------------------------------------------------------------------
-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;
-}
-
-//----------------------------------------------------------------------------------------
-nsFileSpec::nsFileSpec(const nsFilePath& inPath)
-//----------------------------------------------------------------------------------------
-{
-// NS_ERROR("nsFileSpec is unsupported - use nsIFile!");
- *this = inPath;
-}
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator = (const nsFilePath& inPath)
-//----------------------------------------------------------------------------------------
-{
- mPath = (const char*)inPath;
- nsFileSpecHelpers::UnixToNative(mPath);
- mError = NS_OK;
-} // nsFileSpec::operator =
-
-//----------------------------------------------------------------------------------------
-nsFilePath::nsFilePath(const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
-{
- *this = inSpec;
-} // nsFilePath::nsFilePath
-
-//----------------------------------------------------------------------------------------
-void nsFilePath::operator = (const nsFileSpec& inSpec)
-//----------------------------------------------------------------------------------------
-{
- mPath = inSpec.mPath;
- nsFileSpecHelpers::NativeToUnix(mPath);
-} // nsFilePath::operator =
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::SetLeafName(const char* inLeafName)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inLeafName, "Attempt to SetLeafName with a null string");
- mPath.LeafReplace('\\', inLeafName);
-} // nsFileSpec::SetLeafName
-
-//----------------------------------------------------------------------------------------
-char* nsFileSpec::GetLeafName() const
-//----------------------------------------------------------------------------------------
-{
- return mPath.GetLeaf('\\');
-} // nsFileSpec::GetLeafName
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::Exists() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st);
-} // nsFileSpec::Exists
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::GetModDate(TimeStamp& outStamp) const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(nsNSPRPath(*this), &st) == 0)
- outStamp = st.st_mtime;
- else
- outStamp = 0;
-} // nsFileSpec::GetModDate
-
-//----------------------------------------------------------------------------------------
-PRUint32 nsFileSpec::GetFileSize() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- if (!mPath.IsEmpty() && stat(nsNSPRPath(*this), &st) == 0)
- return (PRUint32)st.st_size;
- return 0;
-} // nsFileSpec::GetFileSize
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsFile() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && (_S_IFREG & st.st_mode);
-} // nsFileSpec::IsFile
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsDirectory() const
-//----------------------------------------------------------------------------------------
-{
- struct stat st;
- return !mPath.IsEmpty() && 0 == stat(nsNSPRPath(*this), &st) && (_S_IFDIR & st.st_mode);
-} // nsFileSpec::IsDirectory
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsHidden() const
-//----------------------------------------------------------------------------------------
-{
- PRBool hidden = PR_FALSE;
- if (!mPath.IsEmpty())
- {
- DWORD attr = GetFileAttributes(mPath);
- if (FILE_ATTRIBUTE_HIDDEN & attr)
- hidden = PR_TRUE;
- }
- return hidden;
-}
-// nsFileSpec::IsHidden
-
-//----------------------------------------------------------------------------------------
-PRBool nsFileSpec::IsSymlink() const
-//----------------------------------------------------------------------------------------
-{
- HRESULT hres;
- IShellLink* psl;
-
- PRBool isSymlink = PR_FALSE;
-#ifndef WINCE
- CoInitialize(NULL);
- // Get a pointer to the IShellLink interface.
- hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
- if (SUCCEEDED(hres))
- {
- IPersistFile* ppf;
-
- // Get a pointer to the IPersistFile interface.
- hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
-
- if (SUCCEEDED(hres))
- {
- WCHAR wsz[MAX_PATH];
- // Ensure that the string is Unicode.
- MultiByteToWideChar(CP_ACP, 0, mPath, -1, wsz, MAX_PATH);
-
- // Load the shortcut.
- hres = ppf->Load(wsz, STGM_READ);
- if (SUCCEEDED(hres))
- {
- isSymlink = PR_TRUE;
- }
-
- // Release the pointer to the IPersistFile interface.
- ppf->Release();
- }
-
- // Release the pointer to the IShellLink interface.
- psl->Release();
- }
-
- CoUninitialize();
-#endif
- return isSymlink;
-}
-
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::ResolveSymlink(PRBool& wasSymlink)
-//----------------------------------------------------------------------------------------
-{
- wasSymlink = PR_FALSE; // assume failure
-#ifndef WINCE
- if (Exists())
- return NS_OK;
-
-
- HRESULT hres;
- IShellLink* psl;
-
- CoInitialize(NULL);
-
- // Get a pointer to the IShellLink interface.
- hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void**)&psl);
- if (SUCCEEDED(hres))
- {
- IPersistFile* ppf;
-
- // Get a pointer to the IPersistFile interface.
- hres = psl->QueryInterface(IID_IPersistFile, (void**)&ppf);
-
- if (SUCCEEDED(hres))
- {
- WCHAR wsz[MAX_PATH];
- // Ensure that the string is Unicode.
- MultiByteToWideChar(CP_ACP, 0, mPath, -1, wsz, MAX_PATH);
-
- // Load the shortcut.
- hres = ppf->Load(wsz, STGM_READ);
- if (SUCCEEDED(hres))
- {
- wasSymlink = PR_TRUE;
-
- // Resolve the link.
- hres = psl->Resolve(nsnull, SLR_NO_UI );
- if (SUCCEEDED(hres))
- {
- char szGotPath[MAX_PATH];
- WIN32_FIND_DATA wfd;
-
- // Get the path to the link target.
- hres = psl->GetPath( szGotPath, MAX_PATH, &wfd, SLGP_UNCPRIORITY );
-
- if (SUCCEEDED(hres))
- {
- // Here we modify the nsFileSpec;
- mPath = szGotPath;
- mError = NS_OK;
- }
- }
- }
- else {
- // It wasn't a shortcut. Oh well. Leave it like it was.
- hres = 0;
- }
-
- // Release the pointer to the IPersistFile interface.
- ppf->Release();
- }
- // Release the pointer to the IShellLink interface.
- psl->Release();
- }
-
- CoUninitialize();
-
- if (SUCCEEDED(hres))
- return NS_OK;
-
- return NS_FILE_FAILURE;
-#else
- return NS_OK;
-#endif //WINCE
-}
-
-
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::GetParent(nsFileSpec& outSpec) const
-//----------------------------------------------------------------------------------------
-{
- outSpec.mPath = mPath;
- char* chars = (char*)outSpec.mPath;
- chars[outSpec.mPath.Length() - 1] = '\0'; // avoid trailing separator, if any
- unsigned char* cp = _mbsrchr((unsigned char*)chars, '\\');
- if (cp++)
- outSpec.mPath.SetLength(cp - (unsigned char*)chars); // truncate.
-} // nsFileSpec::GetParent
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::operator += (const char* inRelativePath)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inRelativePath, "Attempt to do += with a null string");
-
- if (!inRelativePath || mPath.IsEmpty())
- return;
-
- if (mPath[mPath.Length() - 1] == '\\')
- mPath += "x";
- else
- mPath += "\\x";
-
- // If it's a (unix) relative path, make it native
- nsSimpleCharString dosPath = inRelativePath;
- nsFileSpecHelpers::UnixToNative(dosPath);
- SetLeafName(dosPath);
-} // nsFileSpec::operator +=
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::CreateDirectory(int /*mode*/)
-//----------------------------------------------------------------------------------------
-{
- // Note that mPath is canonical!
- if (!mPath.IsEmpty())
- mkdir(nsNSPRPath(*this));
-} // nsFileSpec::CreateDirectory
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::Delete(PRBool inRecursive) const
-//----------------------------------------------------------------------------------------
-{
- if (IsDirectory())
- {
- if (inRecursive)
- {
- for (nsDirectoryIterator i(*this, PR_FALSE); i.Exists(); i++)
- {
- nsFileSpec& child = (nsFileSpec&)i;
- child.Delete(inRecursive);
- }
- }
- rmdir(nsNSPRPath(*this));
- }
- else if (!mPath.IsEmpty())
- {
- remove(nsNSPRPath(*this));
- }
-} // nsFileSpec::Delete
-
-
-//----------------------------------------------------------------------------------------
-void nsFileSpec::RecursiveCopy(nsFileSpec newDir) const
-//----------------------------------------------------------------------------------------
-{
- if (IsDirectory())
- {
- if (!(newDir.Exists()))
- {
- newDir.CreateDirectory();
- }
-
- for (nsDirectoryIterator i(*this, PR_FALSE); i.Exists(); i++)
- {
- nsFileSpec& child = (nsFileSpec&)i;
-
- if (child.IsDirectory())
- {
- nsFileSpec tmpDirSpec(newDir);
-
- char *leafname = child.GetLeafName();
- tmpDirSpec += leafname;
- nsCRT::free(leafname);
-
- child.RecursiveCopy(tmpDirSpec);
- }
- else
- {
- child.RecursiveCopy(newDir);
- }
- }
- }
- else if (!mPath.IsEmpty())
- {
- nsFileSpec& filePath = (nsFileSpec&) *this;
-
- if (!(newDir.Exists()))
- {
- newDir.CreateDirectory();
- }
-
- filePath.CopyToDir(newDir);
- }
-} // nsFileSpec::RecursiveCopy
-
-//----------------------------------------------------------------------------------------
-nsresult
-nsFileSpec::Truncate(PRInt32 aNewFileLength) const
-//----------------------------------------------------------------------------------------
-{
- DWORD status;
- HANDLE hFile;
-
- // Leave it to Microsoft to open an existing file with a function
- // named "CreateFile".
- hFile = CreateFile(mPath,
- GENERIC_WRITE,
- FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL,
- NULL);
- if (hFile == INVALID_HANDLE_VALUE)
- return NS_FILE_FAILURE;
-
- // Seek to new, desired end of file
- status = SetFilePointer(hFile, aNewFileLength, NULL, FILE_BEGIN);
- if (status == 0xffffffff)
- goto error;
-
- // Truncate file at current cursor position
- if (!SetEndOfFile(hFile))
- goto error;
-
- if (!CloseHandle(hFile))
- return NS_FILE_FAILURE;
-
- return NS_OK;
-
- error:
- CloseHandle(hFile);
- return NS_FILE_FAILURE;
-
-} // nsFileSpec::Truncate
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Rename(const char* inNewName)
-//----------------------------------------------------------------------------------------
-{
- NS_ASSERTION(inNewName, "Attempt to Rename with a null string");
-
- // This function should not be used to move a file on disk.
- if (strchr(inNewName, '/'))
- return NS_FILE_FAILURE;
-
- char* oldPath = nsCRT::strdup(mPath);
-
- SetLeafName(inNewName);
-
- if (PR_Rename(oldPath, mPath) != NS_OK)
- {
- // Could not rename, set back to the original.
- mPath = oldPath;
- return NS_FILE_FAILURE;
- }
-
- nsCRT::free(oldPath);
-
- return NS_OK;
-} // nsFileSpec::Rename
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::CopyToDir(const nsFileSpec& inParentDirectory) const
-//----------------------------------------------------------------------------------------
-{
- // We can only copy into a directory, and (for now) can not copy entire directories
- if (inParentDirectory.IsDirectory() && (! IsDirectory() ) )
- {
- char *leafname = GetLeafName();
- nsSimpleCharString destPath(inParentDirectory.GetCString());
- destPath += "\\";
- destPath += leafname;
- nsCRT::free(leafname);
-
- // CopyFile returns non-zero if succeeds
- int copyOK = CopyFile(GetCString(), destPath, PR_TRUE);
- if (copyOK)
- return NS_OK;
- }
- return NS_FILE_FAILURE;
-} // nsFileSpec::CopyToDir
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::MoveToDir(const nsFileSpec& inNewParentDirectory)
-//----------------------------------------------------------------------------------------
-{
- // We can only copy into a directory, and (for now) can not copy entire directories
- if (inNewParentDirectory.IsDirectory() && (! IsDirectory() ) )
- {
- char *leafname = GetLeafName();
- nsSimpleCharString destPath(inNewParentDirectory.GetCString());
- destPath += "\\";
- destPath += leafname;
- nsCRT::free(leafname);
-
- // MoveFile returns non-zero if succeeds
- int copyOK = MoveFile(GetCString(), destPath);
-
- if (copyOK)
- {
- *this = inNewParentDirectory + GetLeafName();
- return NS_OK;
- }
-
- }
- return NS_FILE_FAILURE;
-} // nsFileSpec::MoveToDir
-
-//----------------------------------------------------------------------------------------
-nsresult nsFileSpec::Execute(const char* inArgs ) const
-//----------------------------------------------------------------------------------------
-{
-#ifndef WINCE
- if (!IsDirectory())
- {
- nsSimpleCharString fileNameWithArgs = "\"";
- fileNameWithArgs += mPath + "\" " + inArgs;
- int execResult = WinExec( fileNameWithArgs, SW_NORMAL );
- if (execResult > 31)
- return NS_OK;
- }
-#endif
- return NS_FILE_FAILURE;
-} // nsFileSpec::Execute
-
-
-//----------------------------------------------------------------------------------------
-PRInt64 nsFileSpec::GetDiskSpaceAvailable() const
-//----------------------------------------------------------------------------------------
-{
-#ifndef WINCE
- PRInt64 int64;
-
- LL_I2L(int64 , LONG_MAX);
-
- char aDrive[_MAX_DRIVE + 2];
- _splitpath( (const char*)mPath, aDrive, NULL, NULL, NULL);
-
- if (aDrive[0] == '\0')
- {
- // The back end is always trying to pass us paths that look
- // like /c|/netscape/mail. See if we've got one of them
- if (mPath.Length() > 2 && mPath[0] == '/' && mPath[2] == '|')
- {
- aDrive[0] = mPath[1];
- aDrive[1] = ':';
- aDrive[2] = '\0';
- }
- else
- {
- // Return bogus large number and hope for the best
- return int64;
- }
- }
-
- strcat(aDrive, "\\");
-
- // Check disk space
- DWORD dwSecPerClus, dwBytesPerSec, dwFreeClus, dwTotalClus;
- ULARGE_INTEGER liFreeBytesAvailableToCaller, liTotalNumberOfBytes, liTotalNumberOfFreeBytes;
- double nBytes = 0;
-
- BOOL (WINAPI* getDiskFreeSpaceExA)(LPCTSTR lpDirectoryName,
- PULARGE_INTEGER lpFreeBytesAvailableToCaller,
- PULARGE_INTEGER lpTotalNumberOfBytes,
- PULARGE_INTEGER lpTotalNumberOfFreeBytes) = NULL;
-
- HINSTANCE hInst = LoadLibrary("KERNEL32.DLL");
- NS_ASSERTION(hInst != NULL, "COULD NOT LOAD KERNEL32.DLL");
- if (hInst != NULL)
- {
- getDiskFreeSpaceExA = (BOOL (WINAPI*)(LPCTSTR lpDirectoryName,
- PULARGE_INTEGER lpFreeBytesAvailableToCaller,
- PULARGE_INTEGER lpTotalNumberOfBytes,
- PULARGE_INTEGER lpTotalNumberOfFreeBytes))
- GetProcAddress(hInst, "GetDiskFreeSpaceExA");
- FreeLibrary(hInst);
- }
-
- if (getDiskFreeSpaceExA && (*getDiskFreeSpaceExA)(aDrive,
- &liFreeBytesAvailableToCaller,
- &liTotalNumberOfBytes,
- &liTotalNumberOfFreeBytes))
- {
- nBytes = (double)(signed __int64)liFreeBytesAvailableToCaller.QuadPart;
- }
- else if ( GetDiskFreeSpace(aDrive, &dwSecPerClus, &dwBytesPerSec, &dwFreeClus, &dwTotalClus))
- {
- nBytes = (double)dwFreeClus*(double)dwSecPerClus*(double) dwBytesPerSec;
- }
- return (PRInt64)nBytes;
-#else
- return (PRInt64)0;
-#endif
-}
-
-
-
-//========================================================================================
-// nsDirectoryIterator
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator::nsDirectoryIterator(const nsFileSpec& inDirectory, PRBool resolveSymlink)
-//----------------------------------------------------------------------------------------
- : mCurrent(inDirectory)
- , mDir(nsnull)
- , mStarting(inDirectory)
- , mExists(PR_FALSE)
- , mResoveSymLinks(resolveSymlink)
-{
- mDir = PR_OpenDir(inDirectory);
- mCurrent += "dummy";
- mStarting += "dummy";
- ++(*this);
-} // nsDirectoryIterator::nsDirectoryIterator
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator::~nsDirectoryIterator()
-//----------------------------------------------------------------------------------------
-{
- if (mDir)
- PR_CloseDir(mDir);
-} // nsDirectoryIterator::nsDirectoryIterator
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator& nsDirectoryIterator::operator ++ ()
-//----------------------------------------------------------------------------------------
-{
- mExists = PR_FALSE;
- if (!mDir)
- return *this;
- PRDirEntry* entry = PR_ReadDir(mDir, PR_SKIP_BOTH); // Ignore '.' && '..'
- if (entry)
- {
- mExists = PR_TRUE;
- mCurrent = mStarting;
- mCurrent.SetLeafName(entry->name);
- if (mResoveSymLinks)
- {
- PRBool ignore;
- mCurrent.ResolveSymlink(ignore);
- }
- }
- return *this;
-} // nsDirectoryIterator::operator ++
-
-//----------------------------------------------------------------------------------------
-nsDirectoryIterator& nsDirectoryIterator::operator -- ()
-//----------------------------------------------------------------------------------------
-{
- return ++(*this); // can't do it backwards.
-} // nsDirectoryIterator::operator --
-
deleted file mode 100644
--- a/xpcom/obsolete/nsFileStream.cpp
+++ /dev/null
@@ -1,367 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** 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
- * http://www.mozilla.org/MPL/
- *
- * 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 mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * 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 ***** */
-
-// First checked in on 98/12/08 by John R. McMullen.
-// Since nsFileStream.h is entirely templates, common code (such as open())
-// which does not actually depend on the charT, can be placed here.
-
-#include "nsFileStream.h"
-#include "nsFileSpec.h"
-#include "nsIFileSpec.h"
-#include "nsIStringStream.h"
-#include "nsInt64.h"
-#include <string.h>
-#include <stdio.h>
-
-
-//========================================================================================
-// nsInputStream
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsInputStream::~nsInputStream()
-//----------------------------------------------------------------------------------------
-{
-}
-
-//----------------------------------------------------------------------------------------
-char nsInputStream::get()
-//----------------------------------------------------------------------------------------
-{
- char c;
- if (read(&c, sizeof(c)) == sizeof(c))
- return c;
- return 0;
-}
-
-//----------------------------------------------------------------------------------------
-PRInt32 nsInputStream::read(void* s, PRInt32 n)
-//----------------------------------------------------------------------------------------
-{
- if (!mInputStream)
- return 0;
- PRInt32 result = 0;
- PRInt32 status = mInputStream->Read((char*)s, n, (PRUint32*)&result);
- if (result == 0)
- set_at_eof(PR_TRUE);
- if (status < 0)
- return (status);
- return result;
-} // nsInputStream::read
-
-//----------------------------------------------------------------------------------------
-static void TidyEndOfLine(char*& cp)
-// Assumes that cp is pointing at \n or \r. Nulls out the character, checks for
-// a second terminator (of the opposite persuasion), and returns cp pointing past the
-// entire eol construct (one or two characters).
-//----------------------------------------------------------------------------------------
-{
- char ch = *cp;
- *cp++ = '\0'; // terminate at the newline, then skip past it
- if ((ch == '\n' && *cp == '\r') || (ch == '\r' && *cp == '\n'))
- cp++; // possibly a pair.
-}
-
-//----------------------------------------------------------------------------------------
-nsInputStream& nsInputStream::operator >> (char& c)
-//----------------------------------------------------------------------------------------
-{
- c = get();
- return *this;
-}
-
-//========================================================================================
-// nsOutputStream
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsOutputStream::~nsOutputStream()
-//----------------------------------------------------------------------------------------
-{
-}
-
-//----------------------------------------------------------------------------------------
-void nsOutputStream::put(char c)
-//----------------------------------------------------------------------------------------
-{
- write(&c, sizeof(c));
-}
-
-//----------------------------------------------------------------------------------------
-PRInt32 nsOutputStream::write(const void* s, PRInt32 n)
-//----------------------------------------------------------------------------------------
-{
- if (!mOutputStream)
- return 0;
- PRInt32 result = 0;
- mWriteStatus = mOutputStream->Write((char*)s, n, (PRUint32*)&result);
- return result;
-} // nsOutputStream::write
-
-//----------------------------------------------------------------------------------------
-nsresult nsOutputStream::flush()
-//----------------------------------------------------------------------------------------
-{
- return NS_OK;
-}
-
-//----------------------------------------------------------------------------------------
-nsresult nsOutputStream::lastWriteStatus()
-//----------------------------------------------------------------------------------------
-{
- return mWriteStatus;
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputStream& nsOutputStream::operator << (char c)
-//----------------------------------------------------------------------------------------
-{
- put(c);
- return *this;
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputStream& nsOutputStream::operator << (const char* s)
-//----------------------------------------------------------------------------------------
-{
- if (s)
- write(s, strlen(s));
- return *this;
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputStream& nsOutputStream::operator << (short val)
-//----------------------------------------------------------------------------------------
-{
- char buf[30];
- sprintf(buf, "%hd", val);
- return (*this << buf);
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputStream& nsOutputStream::operator << (unsigned short val)
-//----------------------------------------------------------------------------------------
-{
- char buf[30];
- sprintf(buf, "%hu", val);
- return (*this << buf);
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputStream& nsOutputStream::operator << (long val)
-//----------------------------------------------------------------------------------------
-{
- char buf[30];
- sprintf(buf, "%ld", val);
- return (*this << buf);
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputStream& nsOutputStream::operator << (unsigned long val)
-//----------------------------------------------------------------------------------------
-{
- char buf[30];
- sprintf(buf, "%lu", val);
- return (*this << buf);
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputStream& nsOutputStream::operator << (int val)
-//----------------------------------------------------------------------------------------
-{
- char buf[30];
- sprintf(buf, "%d", val);
- return (*this << buf);
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputStream& nsOutputStream::operator << (unsigned int val)
-//----------------------------------------------------------------------------------------
-{
- char buf[30];
- sprintf(buf, "%u", val);
- return (*this << buf);
-}
-
-//========================================================================================
-// nsRandomAccessInputStream
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-PRBool nsRandomAccessInputStream::readline(char* s, PRInt32 n)
-// This will truncate if the buffer is too small. Result will always be null-terminated.
-//----------------------------------------------------------------------------------------
-{
- PRBool bufferLargeEnough = PR_TRUE; // result
- if (!s || !n)
- return PR_TRUE;
-
- nsInt64 position = tell();
- const nsInt64 zero(0);
- if (position < zero)
- return PR_FALSE;
- PRInt32 bytesRead = read(s, n - 1);
- if (failed() || bytesRead < 0)
- return PR_FALSE;
- s[bytesRead] = '\0'; // always terminate at the end of the buffer
- char* tp = strpbrk(s, "\n\r");
- if (tp)
- {
- TidyEndOfLine(tp);
- bytesRead = (tp - s);
- }
- else if (!eof() && n-1 == bytesRead)
- bufferLargeEnough = PR_FALSE;
- position += bytesRead;
- seek(position);
- return bufferLargeEnough;
-} // nsRandomAccessInputStream::readline
-
-//========================================================================================
-// nsInputFileStream
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsInputFileStream::nsInputFileStream(
- const nsFileSpec& inFile,
- int nsprMode,
- PRIntn accessMode)
-//----------------------------------------------------------------------------------------
-{
- nsISupports* stream;
- if (NS_FAILED(NS_NewIOFileStream(&stream, inFile, nsprMode, accessMode)))
- return;
- AssignFrom(stream);
- NS_RELEASE(stream);
-} // nsInputFileStream::nsInputFileStream
-
-//----------------------------------------------------------------------------------------
-nsInputFileStream::nsInputFileStream(nsIFileSpec* inSpec)
-//----------------------------------------------------------------------------------------
-{
- nsIInputStream* stream;
- if (NS_FAILED(inSpec->GetInputStream(&stream)))
- return;
- AssignFrom(stream);
- NS_RELEASE(stream);
-} // nsInputFileStream::nsInputFileStream
-
-//----------------------------------------------------------------------------------------
-nsInputFileStream::~nsInputFileStream()
-//----------------------------------------------------------------------------------------
-{
-// if (is_open())
-// close();
-}
-
-//----------------------------------------------------------------------------------------
-void nsInputFileStream::AssignFrom(nsISupports* stream)
-//----------------------------------------------------------------------------------------
-{
- mFile = do_QueryInterface(stream);
- mInputStream = do_QueryInterface(stream);
- mStore = do_QueryInterface(stream);
- mFileInputStream = do_QueryInterface(stream);
-}
-
-//========================================================================================
-// nsOutputFileStream
-//========================================================================================
-
-//----------------------------------------------------------------------------------------
-nsOutputFileStream::nsOutputFileStream(nsIFileSpec* inSpec)
-//----------------------------------------------------------------------------------------
-{
- if (!inSpec)
- return;
- nsIOutputStream* stream;
- if (NS_FAILED(inSpec->GetOutputStream(&stream)))
- return;
- AssignFrom(stream);
- NS_RELEASE(stream);
-}
-
-//----------------------------------------------------------------------------------------
-nsOutputFileStream::~nsOutputFileStream()
-//----------------------------------------------------------------------------------------
-{
-// if (is_open())
-// close();
-}
-//----------------------------------------------------------------------------------------
-void nsOutputFileStream::AssignFrom(nsISupports* stream)
-//----------------------------------------------------------------------------------------
-{
- mFile = do_QueryInterface(stream);
- mOutputStream = do_QueryInterface(stream);
- mStore = do_QueryInterface(stream);
- mFileOutputStream = do_QueryInterface(stream);
-}
-
-//----------------------------------------------------------------------------------------
-nsresult nsOutputFileStream::flush()
-//----------------------------------------------------------------------------------------
-{
- if (mFileOutputStream)
- mFileOutputStream->Flush();
- return error();
-}
-
-//----------------------------------------------------------------------------------------
-void nsOutputFileStream::abort()
-//----------------------------------------------------------------------------------------
-{
- mResult = NS_FILE_FAILURE;
- close();
-}
-