2 * © 2007-2009 phil_fry, sECuRE, sur5r
3 * See LICENSE for license information
16 /* NOTE: undocumented function which scratches files
17 We need to use this function because linking unistd.h
18 makes our program break at runtime.
20 unsigned char __fastcall__ _sysremove(const char *name);
22 void print_the_buffer() {
25 c = cbm_open((BYTE)4, (BYTE)4, (BYTE)0, NULL);
27 c128_perror(c, "cbm_open(printer)");
28 if (retry_or_quit() == 'q')
33 c = cbm_write((BYTE)4, print_buffer, strlen(print_buffer));
34 if (c != strlen(print_buffer)) {
35 c128_perror(c, "write(printer)");
36 if (retry_or_quit() == 'q')
41 log_file(print_buffer);
44 void log_file(const char *s) {
45 /* A log-entry has usually 50 bytes, so we take 64 bytes.
46 Because files are wrapped (log.0, log.1, ...) every 100
47 lines, we don't need more than 100 * 64 bytes. */
48 char *buffer = malloc(sizeof(char) * 64 * 100);
54 cprintf("No memory available\n");
59 if (((++log_lines_written) % 100) == 0)
61 sprintf(filename, "log-%d", log_num);
62 /* Don't read log if there were no lines written before */
63 if (log_lines_written != 1) {
64 if ((c = cbm_open((BYTE)8, (BYTE)8, (BYTE)0, filename)) != 0) {
65 c128_perror(c, "cbm_open(log)");
68 read = cbm_read((BYTE)8, buffer, sizeof(char) * 64 * 100);
72 if ((c = cbm_open((BYTE)8, (BYTE)8, (BYTE)1, filename)) != 0) {
73 c128_perror(c, "cbm_open(log)");
77 cprintf("Could not read existing logfile (read returned %d)\n", read);
80 strcpy(buffer+read, s);
81 c = cbm_write((BYTE)8, buffer, read+strlen(s));
82 if (c != (read+strlen(s))) {
83 cprintf("Could not save logfile (wrote %d bytes, wanted %d bytes), please make sure the floppy is not full!\n", c, (read+strlen(s)));