int shell_command(struct extensible *ex) { #if HAVE_SYSTEM const char *ofname; char shellline[STRMAX]; FILE *shellout; ofname = make_tempfile(); if (ofname == NULL) { ex->output[0] = 0; ex->result = 127; return ex->result; } snprintf(shellline, sizeof(shellline), "%s > %s", ex->command, ofname); shellline[ sizeof(shellline)-1 ] = 0; ex->result = system(shellline); ex->result = WEXITSTATUS(ex->result); shellout = fopen(ofname, "r"); if (shellout != NULL) { if (fgets(ex->output, sizeof(ex->output), shellout) == NULL) { ex->output[0] = 0; } fclose(shellout); } unlink(ofname); #else ex->output[0] = 0; ex->result = 0; #endif return (ex->result); }
static int load_svg( producer_qimage self, mlt_properties properties, const char *filename ) { int result = 0; // Read xml string if ( strstr( filename, "<svg" ) ) { make_tempfile( self, filename ); result = 1; } return result; }
static int init_temp_file(char tmpname[], FILE **temp_fd, int target_gen) { int status = U1DB_OK; *temp_fd = make_tempfile(tmpname); if (*temp_fd == NULL) { status = errno; if (status == 0) { status = U1DB_INTERNAL_ERROR; } goto finish; } // Spool all of the documents to a temporary file, so that it we can // determine Content-Length before we start uploading the data. fprintf(*temp_fd, "[\r\n{\"last_known_generation\": %d}", target_gen); finish: return status; }
static int get_default_values() { char tool_path[FN_REFLEN]; char defaults_cmd[FN_REFLEN]; char defaults_file[FN_REFLEN]; char line[FN_REFLEN]; int error= 0; int ret= 0; FILE *file= 0; memset(tool_path, 0, FN_REFLEN); if ((error= find_tool("my_print_defaults" FN_EXEEXT, tool_path))) goto exit; else { if ((error= make_tempfile(defaults_file, "txt"))) goto exit; #ifdef __WIN__ { char *format_str= 0; if (has_spaces(tool_path) || has_spaces(defaults_file)) format_str = "\"%s mysqld > %s\""; else format_str = "%s mysqld > %s"; snprintf(defaults_cmd, sizeof(defaults_cmd), format_str, add_quotes(tool_path), add_quotes(defaults_file)); if (opt_verbose) { printf("# my_print_defaults found: %s\n", tool_path); } } #else snprintf(defaults_cmd, sizeof(defaults_cmd), "%s mysqld > %s", tool_path, defaults_file); #endif /* Execute the command */ if (opt_verbose) { printf("# Command: %s\n", defaults_cmd); } error= run_command(defaults_cmd, "r"); if (error) { fprintf(stderr, "ERROR: my_print_defaults failed. Error code: %d.\n", ret); goto exit; } /* Now open the file and read the defaults we want. */ file= fopen(defaults_file, "r"); while (fgets(line, FN_REFLEN, file) != NULL) { char *value= 0; if ((opt_datadir == 0) && ((value= get_value(line, "--datadir")))) { opt_datadir= my_strdup(value, MYF(MY_FAE)); } if ((opt_basedir == 0) && ((value= get_value(line, "--basedir")))) { opt_basedir= my_strdup(value, MYF(MY_FAE)); } if ((opt_plugin_dir == 0) && ((value= get_value(line, "--plugin_dir")))) { opt_plugin_dir= my_strdup(value, MYF(MY_FAE)); } if ((opt_plugin_ini == 0) && ((value= get_value(line, "--plugin_ini")))) { opt_plugin_ini= my_strdup(value, MYF(MY_FAE)); } } } exit: if (file) { fclose(file); /* Remove file */ my_delete(defaults_file, MYF(0)); } return error; }
/* * Note: openinfo is a function for reading info files, and putting * uncompressed content into a temporary filename. For a flexibility, there * are two temporary files supported, i.e. one for keeping opened info file, * and second for i.e. regexp search across info nodes, which are in other * info-subfiles. The temporary file 1 is refrenced by number=0, and file 2 by * number=1 Openinfo by default first tries the path stored in char * *filenameprefix and then in the rest of userdefined paths. */ FILE * openinfo(char *filename, int number) { FILE *id = NULL; #define BUF_LEN 1024 char *buf = xmalloc(BUF_LEN); /* holds local copy of filename */ char *bufend; /* points at the trailing 0 of initial name */ char command[1128]; /* holds command to evaluate for decompression of file */ int i, j; char *tmpfilename; if ((strncmp(filename, "dir", 3)==0) && !isalnum(filename[3])) { xfree(buf); return opendirfile(number); } if (number == 0) /* initialize tmp filename for file 1 */ { if (tmpfilename1) { unlink(tmpfilename1); /* erase old tmpfile */ free(tmpfilename1); } tmpfilename1 = make_tempfile(); tmpfilename = tmpfilename1; /* later we will refere only to tmp1 */ } else /* initialize tmp filename for file 2 */ { if (tmpfilename2) { unlink(tmpfilename2); /* erase old tmpfile */ free(tmpfilename2); } tmpfilename2 = make_tempfile(); tmpfilename = tmpfilename2; /* later we will refere only to tmp2 */ } for (i = -2; i < infopathcount; i++) /* go through all paths */ { if (i < 0) { /* * no filenameprefix, we don't navigate around any specific * infopage set, so simply scan all directories for a hit */ if (!filenameprefix) continue; /* build a filename: First (i == -2) try filenameprefix/filename, * then try with a .info appended */ if (i == -2) snprintf(buf, BUF_LEN, "%s/%s", filenameprefix, basename(filename)); else snprintf(buf, BUF_LEN, "%s/%s.info", filenameprefix, basename(filename)); } else { /* build a filename */ strcpy(buf, infopaths[i]); /* no match found in this directory */ if (! matchfile(&buf, filename)) continue; } bufend = buf; /* remember the bufend to make it possible later to glue compression * suffixes. */ bufend += strlen(buf); for (j = 0; j < SuffixesNumber; j++) /* go through all suffixes */ { strcat(buf, suffixes[j].suffix); if ((id = fopen(buf, "r")) != NULL) { fclose(id); clearfilenameprefix(); filenameprefix = strdup(buf); { /* small scope for removal of filename */ int prefixi, prefixlen = strlen(filenameprefix); for (prefixi = prefixlen; prefixi > 0; prefixi--) if (filenameprefix[prefixi] == '/') { filenameprefix[prefixi] = 0; break; } } buildcommand(command, suffixes[j].command, buf, tmpfilename); xsystem(command); id = fopen(tmpfilename, "r"); if (id) { xfree(buf); return id; } } (*bufend) = 0; } /* if we have a nonzero filename prefix, that is we view a set of * infopages, we don't want to search for a page in all * directories, but only in the prefix directory. Therefore break * here. */ if ((i == -1) &&(filenameprefix)) break; } xfree(buf); return 0; #undef BUF_LEN }
FILE * opendirfile(int number) { FILE *id = NULL; char buf[1024]; /* holds local copy of filename */ char *bufend; /* points at the trailing 0 of initial name */ char command[1128]; /* holds command to evaluate for decompression of file */ int i, j; char *tmpfilename = NULL; size_t *fileendentries = xmalloc(infopathcount * sizeof(*fileendentries)); /* should really be off_t, but a signed type really doesn't make sense here */ int dir_found = 0; int dircount = 0; int lang_found; struct stat status; if (number == 0) /* initialize tmp filename for file 1 */ { /* close and delete old tmp file */ if (tmpfilename1) { unlink(tmpfilename1); /* erase old tmpfile */ free(tmpfilename1); } tmpfilename1 = make_tempfile(); tmpfilename = tmpfilename1; /* later we will refere only to tmp1 */ } for (i = 0; i < infopathcount; i++) /* go through all paths */ { lang_found = 0; strcpy(buf, infopaths[i]); /* build a filename */ strcat(buf, "/"); if (getenv("LANG") != NULL) strcat(buf, getenv("LANG")); strcat(buf, "/dir"); /* * remember the bufend to make it * possible later to glue compression suffixes. */ bufend = buf; bufend += strlen(buf); for (j = 0; j < SuffixesNumber; j++) /* go through all suffixes */ { strcat(buf, suffixes[j].suffix); if ((id = fopen(buf, "r")) != NULL) { fclose(id); builddircommand(command, suffixes[j].command, buf, tmpfilename); xsystem(command); lstat(tmpfilename, &status); fileendentries[dircount] = status.st_size; dircount++; dir_found = 1; lang_found = 1; } (*bufend) = 0; } /* same as above, but without $LANG support */ if (!lang_found) { strcpy(buf, infopaths[i]); /* build a filename */ strcat(buf, "/"); strcat(buf, "dir"); /* * remember the bufend to make it possible later to glue * compression suffixes. */ bufend = buf; bufend += strlen(buf); for (j = 0; j < SuffixesNumber; j++) /* go through all suffixes */ { strcat(buf, suffixes[j].suffix); if ((id = fopen(buf, "r")) != NULL) { fclose(id); builddircommand(command, suffixes[j].command, buf, tmpfilename); xsystem(command); lstat(tmpfilename, &status); fileendentries[dircount] = status.st_size; dircount++; dir_found = 1; } (*bufend) = 0; } } } if (dir_found) id = fopen(tmpfilename, "r"); /* * Filter the concatenated dir pages to exclude hidden parts of info * entries */ if (id) { char *tmp; size_t filelen, l; int aswitch = 0; int firstswitch = 0; dircount = 0; fseek(id, 0, SEEK_END); filelen = ftell(id); tmp = xmalloc(filelen); fseek(id, 0, SEEK_SET); if (fread(tmp, 1, filelen, id)!=filelen) { printf(_("Error while reading file '%s'"), tmp); closeprogram(); exit(1); } fclose(id); id = fopen(tmpfilename, "w"); for (l = 0; l < filelen; l++) { if (tmp[l] == INFO_TAG) { aswitch ^= 1; if (!firstswitch) fputc(tmp[l], id); firstswitch = 1; } else if ((aswitch) ||(!firstswitch)) fputc(tmp[l], id); if (l + 1 == fileendentries[dircount]) { if (aswitch != 0) aswitch = 0; dircount++; /* the last dircount should fit to the end of filelen */ } } fputc(INFO_TAG, id); fputc('\n', id); xfree(fileendentries); fclose(id); id = fopen(tmpfilename, "r"); xfree(tmp); return id; } return NULL; }
/* Rebuild the checked out administrative files in directory DIR. */ int mkmodules (char *dir) { struct saved_cwd cwd; char *temp; char *cp, *last, *fname; #ifdef MY_NDBM DBM *db; #endif FILE *fp; char *line = NULL; size_t line_allocated = 0; const struct admin_file *fileptr; mode_t mode; if (noexec) return 0; if (save_cwd (&cwd)) error_exit (); if ( CVS_CHDIR (dir) < 0) error (1, errno, "cannot chdir to %s", dir); /* * First, do the work necessary to update the "modules" database. */ temp = make_tempfile (); switch (checkout_file (CVSROOTADM_MODULES, dir, temp, NULL)) { case 0: /* everything ok */ #ifdef MY_NDBM /* open it, to generate any duplicate errors */ if ((db = dbm_open (temp, O_RDONLY, 0666)) != NULL) dbm_close (db); #else write_dbmfile (temp); rename_dbmfile (temp); #endif rename_rcsfile (temp, CVSROOTADM_MODULES); break; default: error (0, 0, "'cvs checkout' is less functional without a %s file", CVSROOTADM_MODULES); break; } /* switch on checkout_file() */ if (unlink_file (temp) < 0 && !existence_error (errno)) error (0, errno, "cannot remove %s", temp); xfree (temp); /* Checkout the files that need it in CVSROOT dir */ for (fileptr = filelist; fileptr && fileptr->filename; fileptr++) { if (fileptr->errormsg == NULL) continue; temp = make_tempfile (); if (checkout_file (fileptr->filename, dir, temp, NULL) == 0) rename_rcsfile (temp, fileptr->filename); if (unlink_file (temp) < 0 && !existence_error (errno)) error (0, errno, "cannot remove %s", temp); xfree (temp); } fp = CVS_FOPEN (CVSROOTADM_CHECKOUTLIST, "r"); if (fp) { /* * File format: * [<whitespace>]<filename><whitespace><error message><end-of-line> * * comment lines begin with '#' */ while (getline (&line, &line_allocated, fp) >= 0) { /* skip lines starting with # */ if (line[0] == '#') continue; if ((last = strrchr (line, '\n')) != NULL) *last = '\0'; /* strip the newline */ /* Skip leading white space. */ for (fname = line; *fname && isspace ((unsigned char) *fname); fname++) ; /* Find end of filename. */ for (cp = fname; *cp && !isspace ((unsigned char) *cp); cp++) ; *cp = '\0'; if(isabsolute(fname) || pathname_levels(fname)>0 || !fncmp(fname,"checkoutlist")) { error(0,0,"Invalid filename '%s' in checkoutlist", fname); continue; } temp = make_tempfile (); if (checkout_file (fname, dir, temp, &mode) == 0) { chmod(temp,mode); rename_rcsfile (temp, fname); } else { for (cp++; cp < last && *last && isspace ((unsigned char) *last); cp++) ; if (cp < last && *cp) error (0, 0, cp, fname); } if (unlink_file (temp) < 0 && !existence_error (errno)) error (0, errno, "cannot remove %s", temp); xfree (temp); } if (line) xfree (line); if (ferror (fp)) error (0, errno, "cannot read %s", CVSROOTADM_CHECKOUTLIST); if (fclose (fp) < 0) error (0, errno, "cannot close %s", CVSROOTADM_CHECKOUTLIST); } else { /* Error from CVS_FOPEN. */ if (!existence_error (errno)) error (0, errno, "cannot open %s", CVSROOTADM_CHECKOUTLIST); } if (restore_cwd (&cwd, NULL)) error_exit (); free_cwd (&cwd); return (0); }