DEADSOFTWARE

menu: remove data field from menu_t
[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 "glob.h"
24 #include "error.h"
25 #include "misc.h"
26 #include <stdio.h>
27 #include <stdint.h>
28 #include <assert.h>
30 void mysplitpath(const char* path, char* drv, char* dir, char* name, char* ext) {
31 const char* end; /* end of processed string */
32 const char* p; /* search pointer */
33 const char* s; /* copy pointer */
35 /* extract drive name */
36 if (path[0] && path[1]==':') {
37 if (drv) {
38 *drv++ = *path++;
39 *drv++ = *path++;
40 *drv = '\0';
41 }
42 } else if (drv)
43 *drv = '\0';
45 /* search for end of string or stream separator */
46 for(end=path; *end && *end!=':'; )
47 end++;
49 /* search for begin of file extension */
50 for(p=end; p>path && *--p!='\\' && *p!='/'; )
51 if (*p == '.') {
52 end = p;
53 break;
54 }
56 if (ext)
57 for(s=end; (*ext=*s++); )
58 ext++;
60 /* search for end of directory name */
61 for(p=end; p>path; )
62 if (*--p=='\\' || *p=='/') {
63 p++;
64 break;
65 }
67 if (name) {
68 for(s=p; s<end; )
69 *name++ = *s++;
71 *name = '\0';
72 }
74 if (dir) {
75 for(s=path; s<p; )
76 *dir++ = *s++;
78 *dir = '\0';
79 }
80 }
82 size_t myfreadc (void *ptr, size_t size, size_t n, FILE *f) {
83 return fread(ptr, size, n, f);
84 }
86 void myfread (void *ptr, size_t size, size_t n, FILE *f) {
87 if (myfreadc(ptr, size, n, f) != n) {
88 ERR_fatal("File reading error\n");
89 }
90 }
92 int8_t myfread8 (FILE *f) {
93 int8_t x;
94 myfread(&x, 1, 1, f);
95 return x;
96 }
98 int16_t myfread16 (FILE *f) {
99 int16_t x;
100 myfread(&x, 2, 1, f);
101 return short2host(x);
104 int32_t myfread32 (FILE *f) {
105 int32_t x;
106 myfread(&x, 4, 1, f);
107 return int2host(x);
110 void myfwrite (void *ptr, size_t size, size_t n, FILE *f) {
111 assert(fwrite(ptr, size, n, f) == n);
114 void myfwrite8 (int8_t x, FILE *f) {
115 myfwrite(&x, 1, 1, f);
118 void myfwrite16 (int16_t x, FILE *f) {
119 x = short2host(x);
120 myfwrite(&x, 2, 1, f);
123 void myfwrite32 (int32_t x, FILE *f) {
124 x = int2host(x);
125 myfwrite(&x, 4, 1, f);
128 int fexists (char *filename) {
129 FILE *f;
130 if ((f = fopen(filename, "r")))
132 fclose(f);
133 return 1;
135 return 0;