1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 * Copyright (C) 2011 Rambo
3 * Copyright (C) 2020 SovietPony
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 void mysplitpath(const char* path
, char* drv
, char* dir
, char* name
, char* ext
) {
27 const char* end
; /* end of processed string */
28 const char* p
; /* search pointer */
29 const char* s
; /* copy pointer */
31 /* extract drive name */
32 if (path
[0] && path
[1]==':') {
41 /* search for end of string or stream separator */
42 for(end
=path
; *end
&& *end
!=':'; )
45 /* search for begin of file extension */
46 for(p
=end
; p
>path
&& *--p
!='\\' && *p
!='/'; )
53 for(s
=end
; (*ext
=*s
++); )
56 /* search for end of directory name */
58 if (*--p
=='\\' || *p
=='/') {
78 size_t myfreadc (void *ptr
, size_t size
, size_t n
, FILE *f
) {
79 return fread(ptr
, size
, n
, f
);
82 void myfread (void *ptr
, size_t size
, size_t n
, FILE *f
) {
83 if (myfreadc(ptr
, size
, n
, f
) != n
) {
84 ERR_fatal("File reading error\n");
88 int8_t myfread8 (FILE *f
) {
94 int16_t myfread16 (FILE *f
) {
100 int32_t myfread32 (FILE *f
) {
102 myfread(&x
, 4, 1, f
);
106 void myfwrite (void *ptr
, size_t size
, size_t n
, FILE *f
) {
107 assert(fwrite(ptr
, size
, n
, f
) == n
);
110 void myfwrite8 (int8_t x
, FILE *f
) {
111 myfwrite(&x
, 1, 1, f
);
114 void myfwrite16 (int16_t x
, FILE *f
) {
116 myfwrite(&x
, 2, 1, f
);
119 void myfwrite32 (int32_t x
, FILE *f
) {
121 myfwrite(&x
, 4, 1, f
);
124 int fexists (char *filename
) {
126 if ((f
= fopen(filename
, "r")))