fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

sysdep: Add function pce_file_exist()

Hampa Hug a63a69cc 09453d2e

+41 -67
+3 -1
Makefile.dep
··· 2415 2415 src/drivers/pti/pti.h \ 2416 2416 src/lib/console.h \ 2417 2417 src/lib/msg.h \ 2418 - src/lib/string.h 2418 + src/lib/string.h \ 2419 + src/lib/sysdep.h 2419 2420 2420 2421 src/devices/clock/ds1743.o: src/devices/clock/ds1743.c \ 2421 2422 src/chipset/clock/ds1743.h \ ··· 3130 3131 src/lib/inidsk.h \ 3131 3132 src/lib/log.h \ 3132 3133 src/lib/path.h \ 3134 + src/lib/sysdep.h \ 3133 3135 src/libini/libini.h 3134 3136 3135 3137 src/lib/iniram.o: src/lib/iniram.c \
+1 -15
src/arch/spectrum/spectrum.c
··· 465 465 } 466 466 467 467 static 468 - int file_exists (const char *fname) 469 - { 470 - FILE *fp; 471 - 472 - if ((fp = fopen (fname, "rb")) == NULL) { 473 - return (0); 474 - } 475 - 476 - fclose (fp); 477 - 478 - return (1); 479 - } 480 - 481 - static 482 468 void spec_setup_snap (spectrum_t *sim, ini_sct_t *ini) 483 469 { 484 470 const char *snap; ··· 496 482 snap = par_snapshot; 497 483 } 498 484 499 - if (file_exists (snap) == 0) { 485 + if (pce_file_exists (snap) == 0) { 500 486 return; 501 487 } 502 488
+4 -17
src/devices/cassette.c
··· 5 5 /***************************************************************************** 6 6 * File name: src/devices/cassette.c * 7 7 * Created: 2020-04-30 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2020-2021 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2020-2025 Hampa Hug <hampa@hampa.ch> * 9 9 *****************************************************************************/ 10 10 11 11 /***************************************************************************** ··· 15 15 * * 16 16 * This program is distributed in the hope that it will be useful, but * 17 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 19 * Public License for more details. * 20 20 *****************************************************************************/ 21 21 ··· 33 33 #include <lib/console.h> 34 34 #include <lib/msg.h> 35 35 #include <lib/string.h> 36 + #include <lib/sysdep.h> 36 37 37 38 38 39 typedef struct { ··· 404 405 return (NULL); 405 406 } 406 407 407 - static 408 - int cas_file_exists (const char *name) 409 - { 410 - FILE *fp; 411 - 412 - if ((fp = fopen (name, "rb")) == NULL) { 413 - return (0); 414 - } 415 - 416 - fclose (fp); 417 - 418 - return (1); 419 - } 420 - 421 408 int cas_set_read_name (cassette_t *cas, const char *fname) 422 409 { 423 410 cas_set_record (cas, 0); ··· 477 464 } 478 465 479 466 if (create) { 480 - if (cas_file_exists (fname) == 0) { 467 + if (pce_file_exists (fname) == 0) { 481 468 if ((cas->write_img = pti_img_new()) == NULL) { 482 469 return (1); 483 470 }
+4 -17
src/lib/inidsk.c
··· 5 5 /***************************************************************************** 6 6 * File name: src/lib/inidsk.c * 7 7 * Created: 2004-12-13 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2004-2019 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2004-2025 Hampa Hug <hampa@hampa.ch> * 9 9 *****************************************************************************/ 10 10 11 11 /***************************************************************************** ··· 15 15 * * 16 16 * This program is distributed in the hope that it will be useful, but * 17 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 19 * Public License for more details. * 20 20 *****************************************************************************/ 21 21 ··· 28 28 #include <lib/inidsk.h> 29 29 #include <lib/log.h> 30 30 #include <lib/path.h> 31 + #include <lib/sysdep.h> 31 32 32 33 #include <drivers/block/blkchd.h> 33 34 #include <drivers/block/blkcow.h> ··· 101 102 return (0); 102 103 } 103 104 104 - static 105 - int file_exists (const char *name) 106 - { 107 - FILE *fp; 108 - 109 - if ((fp = fopen (name, "rb")) == NULL) { 110 - return (0); 111 - } 112 - 113 - fclose (fp); 114 - 115 - return (1); 116 - } 117 - 118 105 disk_t *ini_get_cow (ini_sct_t *sct, disk_t *dsk) 119 106 { 120 107 disk_t *cow; ··· 129 116 return (NULL); 130 117 } 131 118 132 - if (file_exists (cname) == 0) { 119 + if (pce_file_exists (cname) == 0) { 133 120 cow = dsk_create_cow (dsk, cname, 16384); 134 121 } 135 122 else {
+26 -2
src/lib/sysdep.c
··· 5 5 /***************************************************************************** 6 6 * File name: src/lib/sysdep.c * 7 7 * Created: 2006-06-19 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2006-2015 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2006-2025 Hampa Hug <hampa@hampa.ch> * 9 9 *****************************************************************************/ 10 10 11 11 /***************************************************************************** ··· 15 15 * * 16 16 * This program is distributed in the hope that it will be useful, but * 17 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 19 * Public License for more details. * 20 20 *****************************************************************************/ 21 21 ··· 37 37 38 38 #ifdef HAVE_SYS_POLL_H 39 39 #include <sys/poll.h> 40 + #endif 41 + 42 + #ifdef HAVE_SYS_STAT_H 43 + #include <sys/stat.h> 40 44 #endif 41 45 42 46 #ifdef HAVE_TERMIOS_H ··· 184 188 tcsetattr (fd, TCSANOW, &tios); 185 189 } 186 190 #endif 191 + } 192 + 193 + int pce_file_exists (const char *name) 194 + { 195 + #ifdef HAVE_SYS_STAT_H 196 + struct stat st; 197 + 198 + if (stat (name, &st) != 0) { 199 + return (0); 200 + } 201 + #else 202 + FILE *fp; 203 + 204 + if ((fp = fopen (name, "rb")) == NULL) { 205 + return (0); 206 + } 207 + 208 + fclose (fp); 209 + #endif 210 + return (1); 187 211 } 188 212 189 213 void pce_start (unsigned *brk)
+3 -2
src/lib/sysdep.h
··· 5 5 /***************************************************************************** 6 6 * File name: src/lib/sysdep.h * 7 7 * Created: 2006-06-19 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2006-2015 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2006-2025 Hampa Hug <hampa@hampa.ch> * 9 9 *****************************************************************************/ 10 10 11 11 /***************************************************************************** ··· 15 15 * * 16 16 * This program is distributed in the hope that it will be useful, but * 17 17 * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 19 * Public License for more details. * 20 20 *****************************************************************************/ 21 21 ··· 56 56 *****************************************************************************/ 57 57 int pce_fd_writeable (int fd, int t); 58 58 59 + int pce_file_exists (const char *name); 59 60 60 61 void pce_start (unsigned *brk); 61 62
-13
src/utils/pce-img/pce-img.c
··· 493 493 return (1); 494 494 } 495 495 496 - int pce_file_exists (const char *name) 497 - { 498 - FILE *fp; 499 - 500 - if ((fp = fopen (name, "rb")) == NULL) { 501 - return (0); 502 - } 503 - 504 - fclose (fp); 505 - 506 - return (1); 507 - } 508 - 509 496 void pce_set_disk_parameters (disk_t *dsk) 510 497 { 511 498 if (dsk == NULL) {