nsCRT::memcpy(&reply.sfFile.name, p_ap_decode_obj->mSpec->name , 63 ); }  nsCRT::memcpy(p_ap_decode_obj->fname,
memcpy(&reply.sfFile.name, p_ap_decode_obj->mSpec->name , 63 ); }  memcpy(p_ap_decode_obj->fname,
int ap_decode_file_infor(appledouble_decode_object *p_ap_decode_obj){	ap_header 	head;	ap_entry 	entries[NUM_ENTRIES + 1];	int 		i, j;	int			st_pt;	PRInt32		in_count;	int			status;	char		name[256];	PRBool		positionedAtRFork = FALSE;		st_pt = p_ap_decode_obj->pos_inbuff;		/*	** 	Read & verify header 	*/	status = from_decoder(					p_ap_decode_obj, 					(char *) &head, 					26, 		/* sizeof (head), 	*/					&in_count);	if (status != NOERR)		return status;		if (p_ap_decode_obj->is_apple_single)	{		if (ntohl(head.magic) != APPLESINGLE_MAGIC)			return errVersion;	}	else	{		if(ntohl(head.magic) != APPLEDOUBLE_MAGIC) 			return errVersion;	}			if (ntohl(head.version) != VERSION) 	{		return errVersion;	}		/* read entries */	head.entries = ntohs(head.entries);	for (i = j = 0; i < head.entries; ++i) 	{		status = from_decoder(					p_ap_decode_obj,					(char *) (entries + j), 					sizeof (ap_entry), 					&in_count);		if (status != NOERR)			return errDecoding;				/*		**	correct the byte order now.		*/		entries[j].id 	  = ntohl(entries[j].id);		entries[j].offset = ntohl(entries[j].offset);		entries[j].length = ntohl(entries[j].length);		/*		**	only care about these entries...		*/		if (j < NUM_ENTRIES) 		switch (entries[j].id) 		{			case ENT_NAME:			case ENT_FINFO:			case ENT_DATES:			case ENT_COMMENT:			case ENT_RFORK:			case ENT_DFORK:				++j;				break;		}	}		in_count = nsCRT::strlen(p_ap_decode_obj->fname);		/* if the user has not provided the output file name, read it		 * from the ENT_NAME entry		 */	if (in_count == 0) 	{		/* read name */		for (i = 0; i < j && entries[i].id != ENT_NAME; ++i)			;		if (i == j) 			return errDecoding;					status = decoder_seek(						p_ap_decode_obj, 						entries[i].offset,						st_pt);			if (status != NOERR)			return status;					if (entries[i].length > 63) 			entries[i].length = 63;					status = from_decoder(						p_ap_decode_obj, 						p_ap_decode_obj->fname, 						entries[i].length,						&in_count);		if (status != NOERR)			return status;		p_ap_decode_obj->fname[in_count] = '\0';	}	/* P_String version of the file name. */  PL_strcpy((char *)name+1, p_ap_decode_obj->fname);	name[0] = (char) in_count;		if (p_ap_decode_obj->write_as_binhex)	{		/*		**	fill out the simple the binhex head.		*/		binhex_header head;		myFInfo		  myFInfo;		status = (*p_ap_decode_obj->binhex_stream->put_block)					(p_ap_decode_obj->binhex_stream->data_object,					name, 					name[0] + 2);		if (status != NOERR)			return status;				/* get finder info */		for (i = 0; i < j && entries[i].id != ENT_FINFO; ++i)			;		if (i < j) 		{			status = decoder_seek(p_ap_decode_obj, 						entries[i].offset, 						st_pt);			if (status != NOERR)				return status;							status = from_decoder(p_ap_decode_obj, 						(char *) &myFInfo, 						sizeof (myFInfo), 						&in_count);			if (status != NOERR)				return status;						}				head.type 		= myFInfo.fdType;		head.creator 	= myFInfo.fdCreator;		head.flags 		= myFInfo.fdFlags;		for (i = 0; i < j && entries[i].id != ENT_DFORK; ++i)			;		if (i < j && entries[i].length != 0)		{			head.dlen = entries[i].length;	/* set the data fork length 	*/		}			else		{			head.dlen = 0;		}			for (i = 0; i < j && entries[i].id != ENT_RFORK; ++i)			;		if (i < j && entries[i].length != 0)		{			head.rlen = entries[i].length;	/* set the resource fork length */		}		else		{			head.rlen = 0;		}		/*		**	and the dlen, rlen is in the host byte order, correct it if needed ...		*/		head.dlen = htonl(head.dlen);		head.rlen = htonl(head.rlen);		/*		**	then encode them in binhex.		*/		status = (*p_ap_decode_obj->binhex_stream->put_block)					(p_ap_decode_obj->binhex_stream->data_object,					(char*)&head,					sizeof(binhex_header));		if (status != NOERR)			return status;				/*		**	after we have done with the header, end the binhex header part.		*/		status = (*p_ap_decode_obj->binhex_stream->put_block)					(p_ap_decode_obj->binhex_stream->data_object,					NULL,					0);	}	else	{	#ifdef	XP_MAC		ap_dates 	dates;		HFileInfo 	*fpb;		CInfoPBRec 	cipbr;		IOParam 	vinfo;		GetVolParmsInfoBuffer vp;		DTPBRec 	dtp;		char 		comment[256];		unsigned char filename[256]; /* this is a pascal string - should be unsigned char. */		StandardFileReply reply;		/* convert char* p_ap_decode_obj->fname to a pascal string */		PL_strcpy((char*)filename + 1, p_ap_decode_obj->fname);		filename[0] = nsCRT::strlen(p_ap_decode_obj->fname);																if( !p_ap_decode_obj->mSpec )		{			StandardPutFile("\pSave decoded file as:", 						(const unsigned char*)filename, 						&reply);									if (!reply.sfGood) 			{				return errUsrCancel;			}		}		else		{			reply.sfFile.vRefNum = p_ap_decode_obj->mSpec->vRefNum;			reply.sfFile.parID = p_ap_decode_obj->mSpec->parID;      nsCRT::memcpy(&reply.sfFile.name, p_ap_decode_obj->mSpec->name , 63 );				}				nsCRT::memcpy(p_ap_decode_obj->fname, 					reply.sfFile.name+1, 					*(reply.sfFile.name)+1);		p_ap_decode_obj->fname[*(reply.sfFile.name)] = '\0';					p_ap_decode_obj->vRefNum = reply.sfFile.vRefNum;		p_ap_decode_obj->dirId   = reply.sfFile.parID;			/* create & get info for file */		HDelete(reply.sfFile.vRefNum, 					reply.sfFile.parID, 					reply.sfFile.name);#define DONT_CARE_TYPE	0x3f3f3f3f			if (HCreate(reply.sfFile.vRefNum,					reply.sfFile.parID, 					reply.sfFile.name, 					DONT_CARE_TYPE, 					DONT_CARE_TYPE) != NOERR) 		{			return errFileOpen;		}				fpb = (HFileInfo *) &cipbr;		fpb->ioVRefNum = reply.sfFile.vRefNum;		fpb->ioDirID   = reply.sfFile.parID;		fpb->ioNamePtr = reply.sfFile.name;		fpb->ioFDirIndex = 0;		PBGetCatInfoSync(&cipbr);			/* get finder info */		for (i = 0; i < j && entries[i].id != ENT_FINFO; ++i)			;		if (i < j) 		{			status = decoder_seek(p_ap_decode_obj, 							entries[i].offset, 							st_pt);			if (status != NOERR)				return status;							status = from_decoder(p_ap_decode_obj, 							(char *) &fpb->ioFlFndrInfo, 							sizeof (FInfo), 							&in_count);			if (status != NOERR)				return status;							status = from_decoder(p_ap_decode_obj,							(char *) &fpb->ioFlXFndrInfo, 							sizeof (FXInfo),							&in_count);					if (status != NOERR && status != errEOP )				return status;							fpb->ioFlFndrInfo.fdFlags &= 0xfc00; /* clear flags maintained by finder */		}			/*		** 	get file date info 		*/		for (i = 0; i < j && entries[i].id != ENT_DATES; ++i)			;		if (i < j) 		{			status = decoder_seek(p_ap_decode_obj, 							entries[i].offset, 							st_pt);			if (status != NOERR && status != errEOP )				return status;							status = from_decoder(p_ap_decode_obj,							(char *) &dates, 							sizeof (dates), 							&in_count);			if (status != NOERR)				return status;							fpb->ioFlCrDat = dates.create - CONVERT_TIME;			fpb->ioFlMdDat = dates.modify - CONVERT_TIME;			fpb->ioFlBkDat = dates.backup - CONVERT_TIME;		}				/*		** 	update info 		*/		fpb->ioDirID = fpb->ioFlParID;		PBSetCatInfoSync(&cipbr);				/*		** 	get comment & save it 		*/		for (i = 0; i < j && entries[i].id != ENT_COMMENT; ++i)			;		if (i < j && entries[i].length != 0) 		{			memset((void *) &vinfo, '\0', sizeof (vinfo));			vinfo.ioVRefNum = fpb->ioVRefNum;			vinfo.ioBuffer  = (Ptr) &vp;			vinfo.ioReqCount = sizeof (vp);			if (PBHGetVolParmsSync((HParmBlkPtr) &vinfo) == NOERR &&				((vp.vMAttrib >> bHasDesktopMgr) & 1)) 			{				memset((void *) &dtp, '\0', sizeof (dtp));				dtp.ioVRefNum = fpb->ioVRefNum;				if (PBDTGetPath(&dtp) == NOERR) 				{					if (entries[i].length > 255) 						entries[i].length = 255;											status = decoder_seek(p_ap_decode_obj, 								entries[i].offset, 								st_pt);					if (status != NOERR)						return status;											status = from_decoder(p_ap_decode_obj, 								comment, 								entries[i].length, 								&in_count);					if (status != NOERR)						return status;											dtp.ioDTBuffer = (Ptr) comment;					dtp.ioNamePtr  = fpb->ioNamePtr;					dtp.ioDirID    = fpb->ioDirID;					dtp.ioDTReqCount = entries[i].length;					if (PBDTSetCommentSync(&dtp) == NOERR) 					{						PBDTFlushSync(&dtp);					}				}			}		}		#else		/*		**	in non-mac system, creating a data fork file will be it.		*/#endif	}		/* 	** Get the size of the resource fork, and (maybe) position to the beginning of it. 	*/	for (i = 0; i < j && entries[i].id != ENT_RFORK; ++i)		;	if (i < j && entries[i].length != 0)	{#ifdef XP_MAC		/* Seek to the start of the resource fork only if we're on a Mac */		status = decoder_seek(p_ap_decode_obj, 								entries[i].offset, 								st_pt);		positionedAtRFork = TRUE;#endif		p_ap_decode_obj->rksize = entries[i].length;	}	else		p_ap_decode_obj->rksize = 0;		/*	** Get the size of the data fork, and (maybe) position to the beginning of it.	*/	for (i = 0; i < j && entries[i].id != ENT_DFORK; ++i)		;	if (i < j && entries[i].length != 0)	{		if (p_ap_decode_obj->is_apple_single && !positionedAtRFork)			status = decoder_seek(p_ap_decode_obj, 									entries[i].offset, 									st_pt);		p_ap_decode_obj->dksize = entries[i].length;	}		else		p_ap_decode_obj->dksize = 0;	/*	**	Prepare a tempfile to hold the resource fork decoded by the decoder,	**		because in binhex, resource fork appears after the data fork!!!	*/	if (p_ap_decode_obj->write_as_binhex)	{		if (p_ap_decode_obj->rksize != 0)		{			/* we need a temp file to hold all the resource data, because the */						p_ap_decode_obj->tmpFileSpec = nsMsgCreateTempFileSpec("apmail");      if (!p_ap_decode_obj->tmpFileSpec)        return errFileOpen;      p_ap_decode_obj->tmpFileStream = new nsIOFileStream(*(p_ap_decode_obj->tmpFileSpec));      if ( (!p_ap_decode_obj->tmpFileStream) ||           (p_ap_decode_obj->tmpFileStream->is_open()) )      {        delete p_ap_decode_obj->tmpFileSpec;        return errFileOpen;      }		}	}	return NOERR;}