gboolean website_update_games_database(HttpHelper* hh, const gchar* localfile, const gchar* fileurl, MudError** error) { gchar* tmpfile_templ = "mmXXXXXX"; gchar* tmpfile_name = NULL; int tmpfile = 0; int gmfile = 0; int ret = TRUE; GError* gerror = NULL; tmpfile = g_file_open_tmp (tmpfile_templ, &tmpfile_name, &gerror); if (tmpfile == -1) { g_free (tmpfile_name); *error = mud_cnv (gerror); return FALSE; } mdebug (DBG_GAMELIST, 0, "Using temp file: %s\n", tmpfile_name); ret = http_download (fileurl, tmpfile, hh); if( ret != CONNECT_OK ) { *error = mud_error_new (MUD_NETWORK_ERROR, ret, network_errmsg (ret)); ret = FALSE; } else { gmfile = open (localfile, O_WRONLY | O_CREAT | O_TRUNC, MUD_NEW_FILE_MODE); if (gmfile == -1) { *error = mud_error_new (MUD_NETWORK_ERROR, errno, strerror (errno)); close (tmpfile); ret = FALSE; } else { lseek (tmpfile, (off_t) 0, SEEK_SET); mdebug (DBG_GAMELIST, 0, "Uncompressing to %s...\n", localfile); ret = uncompress_file (tmpfile, gmfile, error); } } g_remove (tmpfile_name); // close (tmpfile); // closed in uncompress_file close (gmfile); g_free (tmpfile_name); return ret; }
int queue_message_fd_r(uint32_t msgid) { int fdin = -1, fdout = -1, fd = -1; FILE *ifp = NULL; FILE *ofp = NULL; if ((fdin = env->sc_queue->message(QOP_FD_R, &msgid)) == -1) return (-1); if (env->sc_queue_flags & QUEUE_COMPRESS) { if ((fdout = mktmpfile()) == -1) goto err; if ((fd = dup(fdout)) == -1) goto err; if ((ifp = fdopen(fdin, "r")) == NULL) goto err; fdin = fd; fd = -1; if ((ofp = fdopen(fdout, "w+")) == NULL) goto err; if (! uncompress_file(ifp, ofp)) goto err; fclose(ifp); fclose(ofp); lseek(fdin, SEEK_SET, 0); } return (fdin); err: if (fd != -1) close(fd); if (fdin != -1) close(fdin); if (fdout != -1) close(fdout); if (ifp) fclose(ifp); if (ofp) fclose(ofp); return -1; }
static int uff_uncomp(int idx, char *filename) { debug1("Uncompressing user file from %s.", dcc[idx].nick); return uncompress_file(filename); }
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { int dims[2] = {1, 1 }; int i, buflen, status; char *filename; DYN_GROUP *dg; FILE *fp; int newentry; char *newname = NULL, *suffix; char tempname[128]; char message[256]; char **field_names; mxArray *field_value; /* Check for proper number of input and output arguments */ if (nrhs !=1) { mexErrMsgTxt("usage: dgz_read filename"); } if(nlhs > 1){ mexErrMsgTxt("Too many output arguments."); } buflen = (mxGetM(FILE_IN) * mxGetN(FILE_IN)) + 1; filename = mxCalloc(buflen, sizeof(char)); status = mxGetString(FILE_IN, filename, buflen); /* No need to uncompress a .dg file */ if ((suffix = strrchr(filename, '.')) && strstr(suffix, "dg") && !strstr(suffix, "dgz")) { fp = fopen(filename, "rb"); if (!fp) { sprintf(message, "Error opening data file \"%s\".", filename); mexErrMsgTxt(message); tempname[0] = 0; } } else if ((fp = uncompress_file(filename, tempname)) == NULL) { char fullname[128]; sprintf(fullname,"%s.dg", filename); mexPrintf(message); if ((fp = uncompress_file(fullname, tempname)) == NULL) { sprintf(fullname,"%s.dgz", filename); if ((fp = uncompress_file(fullname, tempname)) == NULL) { sprintf(message, "dg_read: file %s not found", filename); mexErrMsgTxt(message); } } } if (!(dg = dfuCreateDynGroup(4))) { mexErrMsgTxt("Error creating dyn group."); } if (!dguFileToStruct(fp, dg)) { /* THE PROBLEM */ sprintf(message, "dg_read: file %s not recognized as dg format", filename); fclose(fp); if (tempname[0]) unlink(tempname); mexErrMsgTxt(message); } fclose(fp); if (tempname[0]) unlink(tempname); dims[1] = 1; /* 10-August-2000 // Yusuke MURAYAMA modified below to add dgzfilename */ #ifdef YM_MODIFY field_names = mxCalloc(DYN_GROUP_NLISTS(dg)+1, sizeof (char *)); for (i = 0; i < DYN_GROUP_NLISTS(dg); i++) { field_names[i] = DYN_LIST_NAME(DYN_GROUP_LIST(dg,i)); } field_names[i] = "filename"; plhs[0] = mxCreateStructArray(2, (const mwSize*)dims, DYN_GROUP_NLISTS(dg)+1, (const char**)field_names); for (i = 0; i < DYN_GROUP_NLISTS(dg); i++) { field_value = dynListToCellArray(DYN_GROUP_LIST(dg, i)); if (!field_value) { sprintf(message, "dg_read: error reading data file \"%s\"", filename); dfuFreeDynGroup(dg); mexErrMsgTxt(message); } mxSetFieldByNumber(plhs[0], 0, i, field_value); } mxSetFieldByNumber(plhs[0], 0, i, mxCreateString(filename)); #else field_names = mxCalloc(DYN_GROUP_NLISTS(dg), sizeof (char *)); for (i = 0; i < DYN_GROUP_NLISTS(dg); i++) { field_names[i] = DYN_LIST_NAME(DYN_GROUP_LIST(dg,i)); } plhs[0] = mxCreateStructArray(2, dims, DYN_GROUP_NLISTS(dg), field_names); for (i = 0; i < DYN_GROUP_NLISTS(dg); i++) { field_value = dynListToCellArray(DYN_GROUP_LIST(dg, i)); if (!field_value) { sprintf(message, "dg_read: error reading data file \"%s\"", filename); dfuFreeDynGroup(dg); mexErrMsgTxt(message); } mxSetFieldByNumber(plhs[0], 0, i, field_value); } #endif dfuFreeDynGroup(dg); }
/* * main * * Main procedure. Sets default values, parses arguments from command line, * and calls uncompress or compress depending on the file linktype * */ int main (int argc, char **argv) { FILE *fin; lFILE *lfout; struct pcap_file_header filehdr; int swapped; co_t co; char filter[PROT_MAX_INDIVIDUAL_FILTER]; /* get the file names */ finname[0] = '\0'; foutname[0] = '\0'; parse_args (argc, argv); /* open input file */ if ((finname[0] == '-' && finname[1] == '\0') || (finname[0] == '\0')) { fin = stdin; } else { fin = fopen (finname, "r"); if (fin == NULL) { fprintf (stderr, "Error: cannot open file %s\n", finname); exit (1); } } /* read the input header to know whether it's compressed or not */ if (pktd_fread_header (fin, &filehdr, &swapped, &co, filter) < 0) { fprintf (stderr, "Error: file %s has wrong format\n", finname); exit (1); } if (filehdr.version_minor == 5) { /* pcap extended header */ printf ("Extended IP header contains mask: 0x%02x\n", co.ip_mask); /* XXX */ printf ("Extended TCP header contains mask: 0x%04x\n", co.tcp_mask); /* XXX */ printf ("Extended UDP header contains mask: 0x%02x\n", co.udp_mask); /* XXX */ printf ("Extended header contains offset: %i\n", co.rm_offset); /* XXX */ printf ("Extended header contains filter: %s\n", filter); /* XXX */ } /* open output file */ if ((foutname[0] == '-' && foutname[1] == '\0') || (foutname[0] == '\0')) { lfout = lfdopen (STDOUT_FILENO, 8192); } else { lfout = lfopen (foutname, 8192); if (lfout == NULL) { fprintf (stderr, "Error: cannot open file %s\n", foutname); fclose (fin); exit (1); } } /* check if the file is compressed or not */ if (filehdr.linktype == DLT_COMPRESSED) { uncompress_file (fin, lfout, &co); } else { compress_file (fin, lfout, &filehdr, swapped); } fclose (fin); lfclose (lfout); exit (0); }
int queue_message_fd_r(uint32_t msgid) { int fdin, fdout = -1, fd = -1; FILE *ifp = NULL; FILE *ofp = NULL; profile_enter("queue_message_fd_r"); fdin = handler_message_fd_r(msgid); profile_leave(); log_trace(TRACE_QUEUE, "queue-backend: queue_message_fd_r(%08"PRIx32") -> %d", msgid, fdin); if (fdin == -1) return (-1); if (env->sc_queue_flags & QUEUE_ENCRYPTION) { if ((fdout = mktmpfile()) == -1) goto err; if ((fd = dup(fdout)) == -1) goto err; if ((ifp = fdopen(fdin, "r")) == NULL) goto err; fdin = fd; fd = -1; if ((ofp = fdopen(fdout, "w+")) == NULL) goto err; if (! crypto_decrypt_file(ifp, ofp)) goto err; fclose(ifp); ifp = NULL; fclose(ofp); ofp = NULL; lseek(fdin, SEEK_SET, 0); } if (env->sc_queue_flags & QUEUE_COMPRESSION) { if ((fdout = mktmpfile()) == -1) goto err; if ((fd = dup(fdout)) == -1) goto err; if ((ifp = fdopen(fdin, "r")) == NULL) goto err; fdin = fd; fd = -1; if ((ofp = fdopen(fdout, "w+")) == NULL) goto err; if (! uncompress_file(ifp, ofp)) goto err; fclose(ifp); ifp = NULL; fclose(ofp); ofp = NULL; lseek(fdin, SEEK_SET, 0); } return (fdin); err: if (fd != -1) close(fd); if (fdin != -1) close(fdin); if (fdout != -1) close(fdout); if (ifp) fclose(ifp); if (ofp) fclose(ofp); return -1; }
static int uff_uncomp(int idx, char *filename) { putlog(LOG_BOTS, "*", "Uncompressing user file from %s.", dcc[idx].nick); return uncompress_file(filename); }