#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <SDL.h>
#include <SDL_byteorder.h>
put_float(fout, v + i);
}
+void put_string(FILE *fp, char * str)
+{
+ int len = strlen(str) + 1;
+ fwrite(str, 1, len, fp);
+}
+
+
/*---------------------------------------------------------------------------*/
void get_float(FILE *fin, float *f)
get_float(fin, v + i);
}
-/*needed for old-style replay compatability*/
-void get_short(FILE *fin, short *s)
+void get_string(FILE *fp, char * str, int len)
+ /* len include the room for the \0 */
+ /* if len is too small, the string is truncated. */
{
- unsigned char *p = (unsigned char *) s;
-
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- p[1] = (unsigned char) fgetc(fin);
- p[0] = (unsigned char) fgetc(fin);
-#else
- p[0] = (unsigned char) fgetc(fin);
- p[1] = (unsigned char) fgetc(fin);
-#endif
+ char b;
+ while (1)
+ {
+ fread(&b, 1, 1, fp);
+ if (len > 0)
+ {
+ *(str++) = (len > 1 ? b : '\0');
+ len--;
+ }
+ if (b == '\0')
+ return;
+ }
}