console: Format tabs semi-intelligently
[attac-man.git] / file.c
blob2bd6cac468f04c46a630f7f9e59b47333ae969e9
1 /*
2 Pacman Arena
3 Copyright (C) 2003 Nuno Subtil
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 static const char cvsid[] =
21 "$Id: file.c,v 1.5 2003/11/23 00:06:39 nsubtil Exp $";
23 #include <SDL.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
28 #include "include/file.h"
30 FILE *file_open(char *file)
32 char fname[FILE_NAME_LEN];
34 if(strlen(file) + strlen(FILE_BASE_PATH) + 2 > FILE_NAME_LEN)
36 printf("file_open: %s: that's too much for me\n", file);
37 exit(1);
40 sprintf(fname, "%s/%s", FILE_BASE_PATH, file);
41 return fopen(fname, "rb");
45 all data on files is in little-endian format
47 void file_read_values32(void *ret, int n, FILE *fp)
49 #ifdef SDL_LIL_ENDIAN
50 fread(ret, 4, n, fp);
51 #else
52 int c, *i;
54 fread(ret, 4, n, fp);
55 i = (int *)ret;
57 for(c = 0; c < n; c++)
58 i[c] = SDL_Swap32(i[c]);
59 #endif /* SDL_LIL_ENDIAN */
62 void file_write_values32(void *src, int n, FILE *fp)
64 #ifdef SDL_LIL_ENDIAN
65 fwrite(src, 4, n, fp);
66 #else
67 int c, tmp, *i;
69 i = (int *)src;
70 for(c = 0; c < n; c++)
72 tmp = SDL_Swap32(i[c]);
73 fwrite(&tmp, 4, 1, fp);
75 #endif /* SDL_LIL_ENDIAN */
78 char *file_make_fname(char *file)
80 static char fname[FILE_NAME_LEN];
82 if(strlen(FILE_BASE_PATH) + strlen(file) + 2 > FILE_NAME_LEN)
84 printf("file_make_fname: too much!\n");
85 exit(1);
88 sprintf(fname, "%s/%s", FILE_BASE_PATH, file);
89 return fname;