int main(int argc, char *argv[]) { int i; FILE *fp, *fpt, *fparch; char header[MAXLINE]; if ((fpt = fopen(tempfile, "w+")) == NULL) { perror("fopen():"); exit(EXIT_FAILURE); } // remove() immediately after open(), in case of program crushes. File will be unlinked when file closed or program terminates if (remove(tempfile) < 0) { perror("remove():"); } for (i = 2; i < argc; i++) { if ((fp = fopen(argv[i], "r")) == NULL) { perror("fopen():"); continue; } makehdr(argv[i], header); fputs(header, fpt); fcopy(fp, fpt); } if ((fparch = fopen(argv[1], "w")) == NULL) { perror("fopen():"); exit(EXIT_FAILURE); } rewind(fpt); // equals to: fseek(fpt, 0, SEEK_SET); fcopy(fpt, fparch); return 0; }
/* write from start of file to end of header comments */ void writeheader(int p) { fseek(infile, 0L, SEEK_SET); if (pagescmt) { if (!fcopy(pagescmt) || fgets(buffer, BUFSIZ, infile) == NULL) message(FATAL, "I/O error in header\n"); sprintf(buffer, "%%%%Pages: %d 0\n", p); writestring(buffer); } if (!fcopy(headerpos)) message(FATAL, "I/O error in header\n"); }
int pce_swap (st_ucon64_nfo_t *rominfo) { char src_name[FILENAME_MAX], dest_name[FILENAME_MAX]; unsigned char *rom_buffer; int size = ucon64.file_size - rominfo->backup_header_len; if ((rom_buffer = (unsigned char *) malloc (size)) == NULL) { fprintf (stderr, ucon64_msg[ROM_BUFFER_ERROR], size); return -1; } strcpy (src_name, ucon64.fname); strcpy (dest_name, ucon64.fname); ucon64_file_handler (dest_name, src_name, 0); if (rominfo->backup_header_len) // copy header (if present) fcopy (src_name, 0, rominfo->backup_header_len, dest_name, "wb"); ucon64_fread (rom_buffer, rominfo->backup_header_len, size, src_name); swapbits (rom_buffer, size); ucon64_fwrite (rom_buffer, rominfo->backup_header_len, size, dest_name, rominfo->backup_header_len ? "ab" : "wb"); free (rom_buffer); printf (ucon64_msg[WROTE], dest_name); remove_temp_file (); return 0; }
void funion (register FSET s1, register FSET s2, register FSET s3) { register unsigned short *x, *y, *z; FSET tmp; z = (unsigned short *) tmp; for (x = (unsigned short *) s1; *x; x++) { for (y = (unsigned short *) s2; *y; y++) if (*x == *y) break; if (*y) *z++ = *x; } for (y = (unsigned short *) s2; *y; y++) { if (z == (unsigned short *) &tmp[LENGTH-1]) { fprintf (stderr, "error: overflow in funion\n"); fprintf (stderr, " recompile fset library with a higher LENGHT\n"); exit (-1); } *z++ = *x; } while (z < (unsigned short *) &tmp[LENGTH]) *z++ = 0; fcopy(s3, tmp); }
int ppf_set_fid (const char *ppf, const char *fidname) { int fidsize, ppfsize, pos; char ppfname[FILENAME_MAX], fidbuf[MAX_ID_SIZE + 34 + 1] = "@BEGIN_FILE_ID.DIZ"; // +1 for string terminator strcpy (ppfname, ppf); ucon64_file_handler (ppfname, NULL, 0); fcopy (ppf, 0, fsizeof (ppf), ppfname, "wb"); // no copy if one file printf ("Adding FILE_ID.DIZ (%s)...\n", fidname); fidsize = ucon64_fread (fidbuf + 18, 0, MAX_ID_SIZE, fidname); memcpy (fidbuf + 18 + fidsize, "@END_FILE_ID.DIZ", 16); ppfsize = fsizeof (ppfname); pos = ucon64_find (ppfname, 0, ppfsize, "@BEGIN_FILE_ID.DIZ", 18, MEMCMP2_CASE | UCON64_FIND_QUIET); if (pos == -1) pos = ppfsize; truncate (ppfname, pos); ucon64_fwrite (fidbuf, pos, fidsize + 18 + 16, ppfname, "r+b"); pos += fidsize + 18 + 16; #ifdef WORDS_BIGENDIAN fidsize = bswap_32 (fidsize); // Write file size in little-endian format #endif ucon64_fwrite (&fidsize, pos, 4, ppfname, "r+b"); printf (ucon64_msg[WROTE], ppfname); return 0; }
int pce_f (st_ucon64_nfo_t *rominfo) /* Region protection codes are found in (American) TurboGrafx-16 games. It prevents those games from running on a PC-Engine. One search pattern seems sufficient to fix/crack all TG-16 games. In addition to that, the protection code appears to be always somewhere in the first 32 kB. */ { char src_name[FILENAME_MAX], dest_name[FILENAME_MAX], buffer[32 * 1024]; int bytesread, n; puts ("Attempting to fix region protection code..."); strcpy (src_name, ucon64.fname); strcpy (dest_name, ucon64.fname); ucon64_file_handler (dest_name, src_name, 0); fcopy (src_name, 0, ucon64.file_size, dest_name, "wb"); // no copy if one file if ((bytesread = ucon64_fread (buffer, rominfo->backup_header_len, 32 * 1024, src_name)) <= 0) return -1; // '!' == ASCII 33 (\x21), '*' == 42 (\x2a) if (rominfo->interleaved) n = change_mem (buffer, bytesread, "\x94\x02\x0f", 3, '*', '!', "\x01", 1, 0); else n = change_mem (buffer, bytesread, "\x29\x40\xf0", 3, '*', '!', "\x80", 1, 0); ucon64_fwrite (buffer, rominfo->backup_header_len, 32 * 1024, dest_name, "r+b"); printf ("Found %d pattern%s\n", n, n != 1 ? "s" : ""); printf (ucon64_msg[WROTE], dest_name); remove_temp_file (); return n; }
/* copy input file from current position upto new position to output file, * ignoring the lines starting at something ignorelist points to */ static int fcopy(off_t upto, off_t *ignorelist) { off_t here = ftello(infile); off_t bytes_left; if (ignorelist != NULL) { while (*ignorelist > 0 && *ignorelist < here) ignorelist++; while (*ignorelist > 0 && *ignorelist < upto) { int r = fcopy(*ignorelist, NULL); if (!r || fgets(buffer, BUFSIZ, infile) == NULL) return 0; ignorelist++; here = ftello(infile); while (*ignorelist > 0 && *ignorelist < here) ignorelist++; } } bytes_left = upto - here; while (bytes_left > 0) { size_t rw_result; const size_t numtocopy = (bytes_left > BUFSIZ) ? BUFSIZ : bytes_left; rw_result = fread(buffer, 1, numtocopy, infile); if (rw_result < numtocopy) return (0); rw_result = fwrite(buffer, 1, numtocopy, outfile); if (rw_result < numtocopy) return (0); bytes_left -= numtocopy; bytes += numtocopy; } return (1); }
int lynx_n (st_rominfo_t *rominfo, const char *name) { st_lnx_header_t header; char dest_name[FILENAME_MAX]; if (!rominfo->buheader_len) { fprintf (stderr, "ERROR: This is no LNX file\n\n"); return -1; } ucon64_fread (&header, 0, sizeof (st_lnx_header_t), ucon64.rom); memset (header.cartname, 0, sizeof (header.cartname)); strncpy (header.cartname, name, sizeof (header.cartname)); strcpy (dest_name, ucon64.rom); ucon64_file_handler (dest_name, NULL, 0); fcopy (ucon64.rom, 0, ucon64.file_size, dest_name, "wb"); ucon64_fwrite (&header, 0, sizeof (st_lnx_header_t), dest_name, "r+b"); printf (ucon64_msg[WROTE], dest_name); return 0; }
int ca_cert_install(struct ca *ca, char *keyname, char *dir) { char src[PATH_MAX]; char dst[PATH_MAX]; int r; char *p = NULL; if (dir == NULL) p = dir = strdup(KEYBASE); ca_hier(dir); if ((r = ca_key_install(ca, keyname, dir)) != 0) { free(dir); return (r); } snprintf(src, sizeof(src), "%s/%s.crt", ca->sslpath, keyname); snprintf(dst, sizeof(dst), "%s/certs/%s.crt", dir, keyname); fcopy(src, dst, 0644); free(p); return (0); }
int ca_key_install(struct ca *ca, char *keyname, char *dir) { struct stat st; char cmd[PATH_MAX * 2]; char src[PATH_MAX]; char dst[PATH_MAX]; char *p = NULL; snprintf(src, sizeof(src), "%s/private/%s.key", ca->sslpath, keyname); if (stat(src, &st) == -1) { if (errno == ENOENT) printf("key for '%s' does not exist\n", ca->caname); else warn("could not access key"); return (1); } if (dir == NULL) p = dir = strdup(KEYBASE); ca_hier(dir); snprintf(dst, sizeof(dst), "%s/private/local.key", dir); fcopy(src, dst, 0600); snprintf(cmd, sizeof(cmd), "%s rsa -out %s/local.pub" " -in %s/private/local.key -pubout", PATH_OPENSSL, dir, dir); system(cmd); free(p); return (0); }
static int lynx_b (st_rominfo_t *rominfo, int bank, const char *value) { st_lnx_header_t header; short int *bankvar; char dest_name[FILENAME_MAX]; if (!rominfo->buheader_len) { fprintf (stderr, "ERROR: This is no LNX file\n\n"); return -1; } ucon64_fread (&header, 0, sizeof (st_lnx_header_t), ucon64.rom); bankvar = (bank == 0 ? &header.page_size_bank0 : &header.page_size_bank1); if ((atol (value) % 64) != 0 || (atol (value) > 512)) *bankvar = 0; else #ifdef WORDS_BIGENDIAN *bankvar = bswap_16 (atol (value) * 4); #else *bankvar = atol (value) * 4; #endif strcpy (dest_name, ucon64.rom); ucon64_file_handler (dest_name, NULL, 0); fcopy (ucon64.rom, 0, ucon64.file_size, dest_name, "wb"); ucon64_fwrite (&header, 0, sizeof (st_lnx_header_t), dest_name, "r+b"); printf (ucon64_msg[WROTE], dest_name); return 0; }
// Simultaneous modular inversion; See Section 2.25 of Guide to Elliptic Curve Cryptography (2004) void batch_inverse(felem *a, int n) { felem c[BATCH_SIZE]; fcopy(c[0], a[0]); for ( int i = 1; i < n; i ++ ) { fmul(c[i], c[i-1], a[i]); } felem u; crecip(u, c[n - 1]); for ( int i = n - 1; i > 0; i-- ) { felem t1, t2; fmul(t1, u, c[i-1]); fmul(t2, u, a[i]); fcopy(a[i], t1); fcopy(u, t2); } fcopy(a[0], u); }
/* write prologue to end of setup section excluding PStoPS procset */ int writepartprolog(void) { if (beginprocset && !fcopy(beginprocset, NULL)) message(FATAL, "I/O error in prologue\n"); if (endprocset) fseeko(infile, endprocset, SEEK_SET); writeprolog(); return !beginprocset; }
void writeheadermedia(int p, off_t *ignore, double width, double height) { fseeko(infile, (off_t) 0, SEEK_SET); if (pagescmt) { if (!fcopy(pagescmt, ignore) || fgets(buffer, BUFSIZ, infile) == NULL) message(FATAL, "I/O error in header\n"); if (width > -1 && height > -1) { sprintf(buffer, "%%%%DocumentMedia: plain %d %d 0 () ()\n", (int) width, (int) height); writestring(buffer); sprintf(buffer, "%%%%BoundingBox: 0 0 %d %d\n", (int) width, (int) height); writestring(buffer); } sprintf(buffer, "%%%%Pages: %d 0\n", p); writestring(buffer); } if (!fcopy(headerpos, ignore)) message(FATAL, "I/O error in header\n"); }
char * mkbak (const char *filename, backup_t type) { static char buf[FILENAME_MAX]; if (access (filename, R_OK) != 0) return (char *) filename; strcpy (buf, filename); set_suffix (buf, ".bak"); if (strcmp (filename, buf) != 0) { remove (buf); // *try* to remove or rename() will fail if (rename (filename, buf)) // keep file attributes like date, etc. { fprintf (stderr, "ERROR: Can't rename \"%s\" to \"%s\"\n", filename, buf); exit (1); } } else // handle the case where filename has the suffix ".bak". { char buf2[FILENAME_MAX]; if (!dirname2 (filename, buf)) { fprintf (stderr, "INTERNAL ERROR: dirname2() returned NULL\n"); exit (1); } if (buf[0] != 0) if (buf[strlen (buf) - 1] != FILE_SEPARATOR) strcat (buf, FILE_SEPARATOR_S); strcat (buf, basename2 (tmpnam2 (buf2))); if (rename (filename, buf)) { fprintf (stderr, "ERROR: Can't rename \"%s\" to \"%s\"\n", filename, buf); exit (1); } } switch (type) { case BAK_MOVE: return buf; case BAK_DUPE: default: if (fcopy (buf, 0, fsizeof (buf), filename, "wb")) { fprintf (stderr, "ERROR: Can't open \"%s\" for writing\n", filename); exit (1); } sync (); return buf; } }
int gzpack (char *input_dir, char *output_file) { struct dirent **namelist; int dirent_count = scandir (input_dir, &namelist, 0, versionsort); if (dirent_count < 0) { perror (input_dir); return Z_ERRNO; } char pathname[PATH_MAX]; FILE *inf; FILE *outf = fopen (output_file, "a"); struct stat s; int symm; int i; for (i = 0; i < dirent_count; i++) { sprintf (pathname, "%s/%s", input_dir, namelist[i]->d_name); /* Skip current directory, parent directory, and any subdirectories. */ if (!stat (pathname, &s)) { perror (pathname); return Z_ERRNO; } if (!strcmp (namelist[i]->d_name, ".") || !strcmp (namelist[i]->d_name, "..") || S_ISDIR (s.st_mode)) { continue; } inf = fopen (pathname, "r"); fcopy (inf, outf, -1, &symm); if (!symm) { return Z_ERRNO; } fclose (inf); free (namelist[i]); } fclose (outf); free (namelist); return Z_OK; }
void prepareImage(STS sts, char *inpath, char *outpath) { for (int i = 0; sts[i] != NULL; i++) { // Tao duong dan noi luu file char *smallin = new char[strlen(inpath)+strlen(sts[i]->smallImg)+9]; sprintf(smallin, "%s/images/%s", inpath, sts[i]->smallImg); char *bigin = new char[strlen(inpath)+strlen(sts[i]->bigImg)+9]; sprintf(bigin, "%s/images/%s", inpath, sts[i]->bigImg); // Tao duong dan noi chua file char *smallout = new char[strlen(outpath)+strlen(sts[i]->MSSV)+17]; sprintf(smallout, "%s/images/%s_t.jpg", outpath, sts[i]->MSSV); char *bigout = new char[strlen(outpath)+strlen(sts[i]->MSSV)+15]; sprintf(bigout, "%s/images/%s.jpg", outpath, sts[i]->MSSV); // Copy file fcopy(smallin, smallout); fcopy(bigin, bigout); } }
int main(int argc, char *argv[]) { printf("# killingCopy v.1.0.1 - 2012 (c) Artur Trzop\n"); if(argv[1] == NULL) { printf("Nie podano pierwszego argumentu.\n"); } else if(argv[2] == NULL) { printf("Nie podano drugiego argumentu.\n"); } else { printf("Poprawnie podano oba argumenty dla nazw plików...\n"); /* Utwórz bufor buf o długości 512 bajtów Otwórz plik file2 Utwórz plik file2 Czytaj 512 bajtów z file1 do bufora buf Zapisz liczbę rzeczywiście odczytanych bajtów z bufora buf do pliku file2 Jeśli liczba przeczytanych bajtów jest równa 512 to wróć do punktu 4 ... w przeciwnym wypadku zamknij pliki i zakończ program. */ FILE *fp1; FILE *fp2; int rozmiar = 0; int flag = 1; if((fp1 = fopen(argv[1], "rb")) == 0) { printf("Nie mozna otworzyc: %s\n", argv[1]); flag = 0; } if ((fp2 = fopen(argv[2], "wb")) == 0) { printf("Nie mozna otworzyc: %s\n", argv[2]); flag = 0; } if(flag == 1) { fcopy(fp1, fp2, &rozmiar); printf("Rozmar pliku, który skopiowalismy: %i\n", rozmiar); } } printf("\n"); return EXIT_SUCCESS; }
int main( int argc, char *argv[] ) { // Here we parse command line args and configfile ******************************************************************* GtkWidget *dockapp; static char *defaultcf; static char *configfile; static char *homecf; static char *homedir; homecf = malloc(MEDIUM_STRING); configfile = malloc(MEDIUM_STRING); defaultcf = malloc(MEDIUM_STRING); strncpy(defaultcf, __CONFPATH, MEDIUM_STRING); strcat(defaultcf, "/"); strcat(defaultcf, __CONFFILE); homedir = malloc(SHORT_STRING); homedir = getenv("HOME"); strncpy(homecf, homedir, SHORT_STRING); strcat(homecf, "/"); strcat(homecf, ".wmtrash.cf"); int test1, test2; if ((test1 = access(homecf, F_OK)) == -1){ if ((test2 = fcopy(defaultcf, homecf)) == EXIT_FAILURE){ fprintf (stderr,"Error creating config file %s !\n",homecf); } } int i; if (argc < 2){ configfile = homecf; }else{ while ((i = getopt(argc, argv, "hc:")) != EOF){ switch (i){ case 'c': /* config file */ strncpy(configfile, optarg, MEDIUM_STRING); break; case 'h': usage(homecf, defaultcf); exit (EXIT_SUCCESS); } } } gtk_init(&argc, &argv); dockapp = (GtkWidget *) build_dockapp(configfile); gtk_widget_show_all (dockapp); gtk_main (); return(0); } // end main
// Point doubling; See http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-mdbl-1987-m void xz_ge_double(felem xout, felem zout, const felem xin) { static const felem fone = {1}; felem xx1, t0, t1, t2; fsquare_times(xx1, xin, 1); fcopy(t0, fone); fdifference_backwards(t0, xx1); fsquare_times(xout, t0, 1); fscalar_product(t1, xin, 486662); fsum(t1, xx1); fsum(t1, fone); fmul(t2, xin, t1); fscalar_product(zout, t2, 4); }
static void cb_ad_content(FILE *const out,void *data) { struct callback_data *cbd = data; assert(out != NULL); assert(data != NULL); /*------------------------------------------ ; we might also do a generic_cb() here, but ; I would need one that takes a FILE * ; object ... just an idea ... ;-------------------------------------------*/ fcopy(out,cbd->ad); }
int ppf_set_desc (const char *ppf, const char *description) { char desc[50], ppfname[FILENAME_MAX]; strcpy (ppfname, ppf); memset (desc, ' ', 50); strncpy (desc, description, strlen (description)); ucon64_file_handler (ppfname, NULL, 0); fcopy (ppf, 0, fsizeof (ppf), ppfname, "wb"); // no copy if one file ucon64_fwrite (desc, 6, 50, ppfname, "r+b"); printf (ucon64_msg[WROTE], ppfname); return 0; }
bool CreateDefaultFolders(void) { //create data directory if not exists bool result = true; result &= CreateDirectory(systemData.dataDirectory); result &= CreateDirectory(systemData.dataDirectory + "images"); result &= CreateDirectory(systemData.dataDirectory + "keyframes"); result &= CreateDirectory(systemData.dataDirectory + "paths"); result &= CreateDirectory(systemData.dataDirectory + "undo"); result &= CreateDirectory(systemData.dataDirectory + "paths"); result &= CreateDirectory(systemData.dataDirectory + "thumbnails"); result &= CreateDirectory(systemData.dataDirectory + "toolbar"); // if(!QFileInfo(systemData.dataDirectory + "toolbar/default.fract").exists()) if(QDir(systemData.dataDirectory + "toolbar").entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count() == 0) { // first run of program (or all toolbar items deleted) -> copy toolbar presets to working folder QDirIterator toolbarFiles(systemData.sharedDir + "toolbar"); while (toolbarFiles.hasNext()) { toolbarFiles.next(); if(toolbarFiles.fileName() == "." || toolbarFiles.fileName() == "..") continue; fcopy(toolbarFiles.filePath(), systemData.dataDirectory + "toolbar/" + toolbarFiles.fileName()); } } #ifdef CLSUPPORT string oclDir = systemData.dataDirectory + "/custom_ocl_formulas"; QString qoclDir = QString::fromStdString(oclDir); if(!QDir(qoclDir).exists()) { result &= CreateDirectory(oclDir); if(result) { fcopy(systemData.sharedDir + "/exampleOCLformulas/cl_example1.c", oclDir + "/cl_example1.c"); fcopy(systemData.sharedDir + "/exampleOCLformulas/cl_example2.c", oclDir + "/cl_example2.c"); fcopy(systemData.sharedDir + "/exampleOCLformulas/cl_example3.c", oclDir + +"/cl_example3.c"); fcopy(systemData.sharedDir + "/exampleOCLformulas/cl_example1Init.c", oclDir + "/cl_example1Init.c"); fcopy(systemData.sharedDir + "/exampleOCLformulas/cl_example2Init.c", oclDir + "/cl_example2Init.c"); fcopy(systemData.sharedDir + "/exampleOCLformulas/cl_example3Init.c", oclDir + "/cl_example3Init.c"); } } #endif actualFileNames.actualFilenameSettings = QString("settings") + QDir::separator() + "default.fract"; actualFileNames.actualFilenameImage = QString("images") + QDir::separator() + "image.jpg"; actualFileNames.actualFilenamePalette = systemData.sharedDir + "textures" + QDir::separator() + "colour palette.jpg"; return result; }
void fdel (register unsigned short e, register FSET s1, register FSET s2) { register unsigned short *x, *y; FSET tmp; y = (unsigned short *) tmp; for (x = (unsigned short *) s1; *x; x++) if (*x != e) *y++ = *x; while (y < (unsigned short *) &tmp[LENGTH]) *y++ = 0; fcopy(s2, tmp); }
int ca_install(struct ca *ca, char *dir) { struct stat st; char src[PATH_MAX]; char dst[PATH_MAX]; char *p = NULL; snprintf(src, sizeof(src), "%s/ca.crt", ca->sslpath); if (stat(src, &st) == -1) { printf("CA '%s' does not exist\n", ca->caname); return (1); } if (dir == NULL) p = dir = strdup(KEYBASE); ca_hier(dir); snprintf(dst, sizeof(dst), "%s/ca/ca.crt", dir); if (fcopy(src, dst, 0644) == 0) printf("certificate for CA '%s' installed into %s\n", ca->caname, dst); snprintf(src, sizeof(src), "%s/ca.crl", ca->sslpath); if (stat(src, &st) == 0) { snprintf(dst, sizeof(dst), "%s/crls/ca.crl", dir); if (fcopy(src, dst, 0644) == 0) printf("CRL for CA '%s' installed to %s\n", ca->caname, dst); } free(p); return (0); }
int LuaArgs::getF(int idx, const char *key) { if (tbl > 0 && lua_checkstack(L, 1)) { lua_getfield(L, tbl, key); if (!lua_isfunction(L, -1) && idx > 0) { lua_pop(L, 1); lua_pushinteger(L, idx); lua_gettable(L, tbl); } int ret = fcopy(-1); lua_pop(L, 1); return ret; } else { return getF(idx); } }
int ca_key_import(struct ca *ca, char *keyname, char *import) { struct stat st; char dst[PATH_MAX]; if (stat(import, &st) != 0) { warn("could not access keyfile %s", import); return (1); } snprintf(dst, sizeof(dst), "%s/private/%s.key", ca->sslpath, keyname); fcopy(import, dst, 0600); return (0); }
/* DoExit - leave the compose mode in 1 of three ways, send message, abort or * save prior to exit. * * usage: * abort - aborts compose mode * send - sends current compose message * save <file name> - save current compose message to <file name> * * arguments: * hWnd window for commands * p character pointer to beginning of arguments * operation COMPABORT aborts the current message then exits * COMPMAIL mails the current message then exits * COMPSAVE saves the current message then exits * * return value: * none. * * IMPORTANT: * DoExit will only kill the compose mode on a send or save command if * they are successful, otherwise DoExit returns to the compose mode */ VOID PASCAL INTERNAL DoExit ( HW hWnd, PSTR p, INT operation ) { CHAR buf [ 2 ]; PSTR pErrMsg = NULL; switch ( operation ) { case COMPSAVE : p = whiteskip ( p ); pErrMsg = fcopy ( pCompFile, p ); if ( pErrMsg != NULL ) { SendMessage ( hWnd, DISPLAY, pErrMsg ); return; } else SendMessage ( hWnd, DISPLAY, "Message saved." ); break; case COMPMAIL : if (!fMailAllowed) { SendMessage (hWnd, DISPLAY, "Cannot send mail"); return; } SendMessage ( hCompose, CLOSEFILE, 0 ); if ( MailFile ( pCompFile, TRUE ) ) { SendMessage ( hWnd, DISPLAY, "Error during send, send was aborted." ); SendMessage ( hCompose, REOPNFILE, 1 ); return; } else { SendMessage ( hWnd, DISPLAY, "Message sent successfully." ); if ( (fNewmailOnSend) && (fCurFldIsDefFld) ) DoNewMail(hWnd, p, TRUE); } break; default : if ( fConfirmComposeAbort ) { SendMessage ( hWnd, DISPLAYSTR, "Type y to confirm abort composed msg "); buf[0] = (CHAR)ReadKey(); buf[1] = '\0'; SendMessage ( hWnd, DISPLAY, buf ); if ( *buf != 'y' ) return; } break; } ExitComposer ( ); }
std::vector< uint8_t > file_t::get_file(const std::string& file) { std::string fcopy(file); std::string path(file_t::to_absolute(trim(fcopy))); std::ifstream stream(path, std::ios_base::in); std::vector< uint8_t > retval; if (! stream.is_open() || ! stream.good()) throw std::runtime_error("Error opening file"); retval.resize(file_t::get_file_size(stream)); stream.read(reinterpret_cast< char* >(retval.data()), retval.size()); stream.close(); return retval; }
int lynx_lnx (st_rominfo_t *rominfo) { st_lnx_header_t header; char dest_name[FILENAME_MAX]; int size = ucon64.file_size; if (rominfo->buheader_len != 0) { fprintf (stderr, "ERROR: This seems to already be an LNX file\n\n"); return -1; } header.page_size_bank0 = size > 4 * MBIT ? 4 * MBIT / 256 : size / 256; header.page_size_bank1 = size > 4 * MBIT ? (size - (4 * MBIT)) / 256 : 0; #ifdef WORDS_BIGENDIAN header.page_size_bank0 = bswap_16 (header.page_size_bank0); header.page_size_bank1 = bswap_16 (header.page_size_bank1); #endif memset (header.cartname, 0, sizeof (header.cartname)); memset (header.manufname, 0, sizeof (header.manufname)); memset (header.spare, 0, sizeof (header.spare)); #ifdef WORDS_BIGENDIAN header.version = bswap_16 (1); #else header.version = 1; #endif memcpy (header.magic, "LYNX", 4); header.rotation = 0; strncpy (header.cartname, ucon64.rom, sizeof (header.cartname)); strcpy (header.manufname, "Atari"); strcpy (dest_name, ucon64.rom); set_suffix (dest_name, ".lnx"); ucon64_file_handler (dest_name, NULL, 0); ucon64_fwrite (&header, 0, sizeof (st_lnx_header_t), dest_name, "wb"); fcopy (ucon64.rom, 0, ucon64.file_size, dest_name, "ab"); printf (ucon64_msg[WROTE], dest_name); return 0; }