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 $";
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
);
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
)
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
)
65 fwrite(src
, 4, n
, fp
);
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");
88 sprintf(fname
, "%s/%s", FILE_BASE_PATH
, file
);