예제 #1
0
파일: lock.cpp 프로젝트: Cloudxtreme/tmwa
// Delete the old file and rename the new file
void lock_fclose (FILE * fp, const char *filename, int *info)
{
    char newfile[512];
    if (fp)
    {
        fclose_ (fp);
        sprintf (newfile, "%s_%d.tmp", filename, *info);
        rename (newfile, filename);
    }
}
예제 #2
0
파일: lock.cpp 프로젝트: Cloudxtreme/tmwa
// Start writing a tmpfile
FILE *lock_fopen (const char *filename, int *info)
{
    char newfile[512];
    FILE *fp;
    int  no = getpid ();

    // Get a filename that doesn't already exist
    do
    {
        sprintf (newfile, "%s_%d.tmp", filename, no++);
    }
    while ((fp = fopen_ (newfile, "r")) && (fclose_ (fp), 1));
    *info = --no;
    return fopen_ (newfile, "w");
}
예제 #3
0
파일: gpx.c 프로젝트: zakwiggy/FollowMe
uint8_t GPX_DocumentClose(GPX_Document_t *doc)
{

	uint8_t retvalue = 1;
	uint16_t i;
	int8_t c;
	const prog_char *str;

	if(doc == NULL) return(0);

	while(doc->state != GPX_DOC_CLOSED)								// close linestring, placemark and document before closing the file on the memorycard
	{
		switch(doc->state)
		{
			case GPX_DOC_TRACKSEGMENT_OPENED:
				GPX_TrackSegmentEnd(doc);						// write terminating tag to end tracksegment.
				break;

			case GPX_DOC_TRACK_OPENED:								// write terminating tag to close track.
				GPX_TrackEnd(doc);
				break;

			case GPX_DOC_OPENED:									// close the file on the memorycard
				if(doc->file != NULL)
				{
					str = GPX_DOCUMENT_FOOTER;						// write the gpx-footer to the document.
					for(i= 0; i < sizeof(GPX_DOCUMENT_FOOTER)-1; i++)
					{
						c = (int8_t)pgm_read_byte(str++); // get byte from flash
						fputc_(c, doc->file); // and write that to sd-card
					}
					fclose_(doc->file);
					retvalue = 1;
				}
				doc->state = GPX_DOC_CLOSED;
				break;

			default:
				doc->state = GPX_DOC_CLOSED;
				break;
		}
	}
	return(retvalue);
}
예제 #4
0
파일: kml.c 프로젝트: Paulxia/navictrl
u8 KML_DocumentClose(KML_Document_t *doc)
{

	u8 retvalue = 1;

	if(doc == NULL) return(0);

	while(doc->state != KML_DOC_CLOSED)								// close linestring, placemark and document before closing the file on the memorycard
	{
		switch(doc->state)
		{
			case KML_DOC_LINESTRING_OPENED:
				KML_LineStringEnd(doc);							// write terminating tag to end linestring.
				break;

	 		case KML_DOC_PLACEMARK_OPENED:							// write terminating tag to close placemark.
				KML_PlaceMarkClose(doc);
				break;

			case KML_DOC_OPENED:									// close the file on the memorycard
				if(doc->file != NULL)
				{
					fwrite_((void*)KML_DOCUMENT_FOOTER, sizeof(KML_DOCUMENT_FOOTER)-1,1,doc->file);	// write the KML- footer to the document.
					fclose_(doc->file);
					retvalue = 1;
				}
				doc->state = KML_DOC_CLOSED;
				break;

			default:
				doc->state = KML_DOC_CLOSED;
				break;

		}
	}
	return(retvalue);
}
예제 #5
0
파일: gpx.c 프로젝트: Paulxia/navictrl
u8 GPX_DocumentClose(GPX_Document_t *doc)
{

	u8 retvalue = 1;

	if(doc == NULL) return(0);

	while(doc->state != GPX_DOC_CLOSED)								// close linestring, placemark and document before closing the file on the memorycard
	{
		switch(doc->state)
		{
			case GPX_DOC_TRACKSEGMENT_OPENED:
				GPX_TrackSegmentEnd(doc);						// write terminating tag to end tracksegment.
				break;

			case GPX_DOC_TRACK_OPENED:								// write terminating tag to close track.
				GPX_TrackEnd(doc);
				break;

			case GPX_DOC_OPENED:									// close the file on the memorycard
				if(doc->file != NULL)
				{
					fwrite_((void*)GPX_DOCUMENT_FOOTER, sizeof(GPX_DOCUMENT_FOOTER)-1,1,doc->file);	// write the gpx-footer to the document.
					fclose_(doc->file);
					retvalue = 1;
				}
				doc->state = GPX_DOC_CLOSED;
				break;

			default:
				doc->state = GPX_DOC_CLOSED;
				break;
		}
	}
	return(retvalue);
}