DEADSOFTWARE

0a7fcbcd6ce4a20958b2d915e730c2ee9fb89a81
[flatwaifu.git] / src / my.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
23 #include <SDL.h>
24 #include "glob.h"
25 #include "error.h"
26 #include <stdio.h>
28 void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext)
29 {
30 const char* end; /* end of processed string */
31 const char* p; /* search pointer */
32 const char* s; /* copy pointer */
34 /* extract drive name */
35 if (path[0] && path[1]==':') {
36 if (drv) {
37 *drv++ = *path++;
38 *drv++ = *path++;
39 *drv = '\0';
40 }
41 } else if (drv)
42 *drv = '\0';
44 /* search for end of string or stream separator */
45 for(end=path; *end && *end!=':'; )
46 end++;
48 /* search for begin of file extension */
49 for(p=end; p>path && *--p!='\\' && *p!='/'; )
50 if (*p == '.') {
51 end = p;
52 break;
53 }
55 if (ext)
56 for(s=end; (*ext=*s++); )
57 ext++;
59 /* search for end of directory name */
60 for(p=end; p>path; )
61 if (*--p=='\\' || *p=='/') {
62 p++;
63 break;
64 }
66 if (name) {
67 for(s=p; s<end; )
68 *name++ = *s++;
70 *name = '\0';
71 }
73 if (dir) {
74 for(s=path; s<p; )
75 *dir++ = *s++;
77 *dir = '\0';
78 }
79 }
81 size_t myfreadc(void *ptr, size_t size, size_t n, FILE *f) {
82 return fread(ptr, size, n, f);
83 }
85 void myfread(void *ptr, size_t size, size_t n, FILE *f) {
86 if (myfreadc(ptr, size, n, f) != n) {
87 ERR_fatal("File reading error\n");
88 }
89 }
91 void myfwrite(void *ptr, size_t n, size_t size, FILE *f) {
92 size_t s = fwrite(ptr,n,size,f);
93 }
95 void myrandomize(void)
96 {
97 srand(SDL_GetTicks());
98 }
100 int fexists(char * filename)
102 FILE *f;
103 if ((f = fopen(filename, "r")))
105 fclose(f);
106 return 1;
108 return 0;