/*--------------------------------------------------------------------------
 *
 * 	You may freely copy, distribute, and reuse the code in this example.
 * 	SHL Systemhouse disclaims any warranty of any kind, expressed or
 *	implied, as to its fitness for any particular use.
 *
 *
 *	FoundationExtensions
 *
 *	Category Of:		NSArry, NSString
 *
 *	Conforms To:		None
 *
 *	Declared In:		FoundationExtensions.h
 *
 *
 *------------------------------------------------------------------------*/

#import "FoundationExtensions.h"



@implementation NSObject (WriteToFileExtensions)

- (BOOL) writeToFile: (NSString *) path
	atomically: (BOOL) useAuxiliaryFile
{
	BOOL
		returnValue = YES;
	NXStream
		*myStream = NXOpenMemory (NULL, 0, NX_WRITEONLY);

	NXPrintf (myStream, "%s", [[(NSObject *)self description] cString]);

	if (useAuxiliaryFile)
		{
		NSString
			*myPathname = [NSString stringWithFormat:@"%@~", path];
		
		if (NXSaveToFile (myStream, [myPathname cString]) == -1)
			{
			returnValue = NO;
			}
		}

	if (returnValue)
		{
		if (NXSaveToFile (myStream, [path cString]) == -1)
			{
			returnValue = NO;
			}
		}
	
	NXClose (myStream);
	
	return returnValue;
}

@end
