lib/tdl-util.c
/**
 * Moves the cursor to the first data point entry.
 * This MUST be called before any calls to tdl_read.
 * Additionally, this will store the name of the tracked
 * object that the file contatins to the given pointer.
 *
 * @param f A file descripter pointing to the file.
 * @param name A pointer to the char* where the name should be stored.
 * if this is null, the name will be ignored.
 */
Moves the cursor to the first data point entry.
This MUST be called before any calls to tdl_read.
Additionally, this will store the name of the tracked
object that the file contatins to the given pointer.

@param f A file descripter pointing to the file.
@param name A pointer to the char* where the name should be stored.
if this is null, the name will be ignored.
Moves the cursor to the first data point entry . This MUST be called before any calls to tdl_read . Additionally this will store the name of the tracked object that the file contatins to the given pointer . @param f A file descripter pointing to the file . @param name A pointer to the char * where the name should be stored . if this is null the name will be ignored .
int tdl_prepare(FILE *f, char** name)
{
#ifdef _WIN32
	msg(MSG_ERROR, "This function is not defined on Windows.");
	return -1;
#else
	rewind(f);
	if(tdl_validate(f))
	{
		char c = 0;
		char* tmpName = (char*)malloc(sizeof(char) * 33);
		int i = 0, bRead = 0;
		while((bRead = fread(&c, 1, 1, f)) == 1)
		{
			if(i < 33)
			{
				tmpName[i++] = c;
			}
			if(c == 0) break;
		}
		if(bRead < 1)
		{
			perror("Reading object name failed");
		}
		if(name != NULL)
		{
			name[0] = tmpName;
		}	
	}
	else
	{
		return -1;
	}
	return 1;
#endif
}
int tdl_prepare ( FILE * f , char * * name ) { #ifdef _WIN32 msg ( MSG_ERROR , " " ) ; return -1 ; #else rewind ( f ) ; if ( tdl_validate ( f ) ) { char c = 0 ; char * tmpName = ( char * ) malloc ( sizeof ( char ) * 33 ) ; int i = 0 , bRead = 0 ; while ( ( bRead = fread ( & c , 1 , 1 , f ) ) == 1 ) { if ( i < 33 ) { tmpName [ i ++ ] = c ; } if ( c == 0 ) break ; } if ( bRead < 1 ) { perror ( " " ) ; } if ( name != NULL ) { name [ 0 ] = tmpName ; } } else { return -1 ; } return 1 ; #endif }
Moves the cursor to the first data point entry.
Moves the cursor to the first data point entry .
//Seek to the begining of the file. /*
		  Read until we find a NULL char that indicates the end of the name
		  even if we reach the char limit, we still need to keep reading just
		  in case a name longer than 32 chars was written to the file some how.
		  The extra chars should be ignored, this is simple to set the cursor
		  for further reads.
		*/ //error check for the read. //If the specified pointer isn't null, store to it. //return -1 if the file is invalid. //Everthing went fine, so return 1.