}
-FILE *open_scc_temp_file (char *name, size_t name_size) {
+FILE *scc_tmpfile (void) {
char *temp_path, *template;
int fd;
template = xmalloc (strlen (temp_path) + 1 + 10 + 1);
sprintf (template, "%s/sccXXXXXX", temp_path);
- if (!(fd = mkstemp (template))) {
+ if ((fd = mkstemp (template)) < 0) {
return 0;
}
- (void) name;
- (void) name_size;
-
return fdopen (fd, "w+b");
}
-FILE *scc_tmpfile (void) {
-
- char name[64];
- return open_scc_temp_file (name, sizeof (name));
-
+int scc_close (FILE *fp) {
+ return fclose (fp);
}
+
#elif defined (_WIN32)
# include <windows.h>
+# ifndef MAX_PATH
+# define MAX_PATH 206
+# endif
+
+# include "hashtab.h"
+
struct pragma_entry {
DWORD dwVolumeSerialNumber;
}
-FILE *open_scc_temp_file (char *name, size_t name_size) {
+struct temp_file {
+
+ char *name, *path;
+ FILE *fp;
+
+};
+
+static struct hashtab hashtab_tmpfiles = { 0 };
+
+FILE *scc_tmpfile (void) {
char temp_path[MAX_PATH + 1] = { 0 };
char full_path[MAX_PATH + 1] = { 0 };
+ struct hashtab_name *key;
+ struct temp_file *tmp;
+
+ char *name;
+ FILE *fp;
+
if (!GetTempPath (MAX_PATH + 1, temp_path)) {
return 0;
}
return 0;
}
- (void) name;
- (void) name_size;
+ if ((name = strrchr (full_path, '\\'))) {
+ name++;
+ } else {
+ name = full_path;
+ }
- return fopen (full_path, "w+b");
+ if ((fp = fopen (full_path, "w+b"))) {
+
+ if (!(key = hashtab_get_key (&hashtab_tmpfiles, name))) {
+
+ if (!((key = hashtab_alloc_name (xstrdup (name))))) {
+
+ remove (full_path);
+ fclose (fp);
+
+ return 0;
+
+ }
+
+ }
+
+ tmp = xmalloc (sizeof (*tmp));
+ tmp->fp = fp;
+
+ tmp->path = xstrdup (full_path);
+ tmp->name = xstrdup (name);
+
+ hashtab_put (&hashtab_tmpfiles, key, tmp);
+ return fp;
+
+ }
+
+ return 0;
}
-FILE *scc_tmpfile (void) {
+int scc_close (FILE *fp) {
- char name[64];
- return open_scc_temp_file (name, sizeof (name));
+ struct hashtab_entry *entry;
+ struct temp_file *tmp;
+
+ int ret, i;
+
+ for (i = 0; i < hashtab_tmpfiles.capacity; i++) {
+
+ if (!(entry = &hashtab_tmpfiles.entries[i])) {
+ continue;
+ }
+
+ if (!entry->key || !entry->value) {
+ continue;
+ }
+
+ tmp = (struct temp_file *) entry->value;
+
+ if (tmp->fp == fp) {
+
+ if ((ret = fclose (fp))) {
+ return ret;
+ }
+
+ remove (tmp->path);
+
+ hashtab_remove (&hashtab_tmpfiles, hashtab_get_key (&hashtab_tmpfiles, tmp->name));
+ return 0;
+
+ }
+
+ }
+
+ return 0;
}
#else
+# include "hashtab.h"
+
+struct temp_file {
+
+ FILE *fp;
+ char name[1];
+
+};
+
+static struct hashtab hashtab_tmpfiles = { 0 };
+
char *get_current_directory (void) {
return xstrdup ("");
}
}
-FILE *open_scc_temp_file (char *name, size_t name_size) {
+FILE *scc_tmpfile (void) {
static unsigned long temp_id = 1;
+
+ char name[64];
unsigned long i;
- FILE *fp;
+ struct hashtab_name *key;
+ struct temp_file *tmp;
- if (!name || name_size == 0) {
- return 0;
- }
+ FILE *fp;
for (i = 0; i < 1000; i++) {
}
- fp = fopen (name, "w+b");
+ if ((fp = fopen (name, "w+b"))) {
+
+ if (!(key = hashtab_get_key (&hashtab_tmpfiles, name))) {
+
+ if (!((key = hashtab_alloc_name (xstrdup (name))))) {
+
+ remove (name);
+ fclose (fp);
+
+ continue;
+
+ }
+
+ }
+
+ tmp = xmalloc (sizeof (*tmp) + strlen (name) + 1);
+ sprintf (tmp->name, "%s", name);
+
+ tmp->fp = fp;
- if (fp) {
+ hashtab_put (&hashtab_tmpfiles, key, tmp);
return fp;
+
}
}
- name[0] = 0;
return 0;
}
-FILE *scc_tmpfile (void) {
+int scc_close (FILE *fp) {
- char name[64];
- FILE *fp;
-
- fp = open_scc_temp_file (name, sizeof (name));
-
- if (fp && name[0]) {
- remove (name);
+ struct hashtab_entry *entry;
+ struct temp_file *tmp;
+
+ int ret, i;
+
+ for (i = 0; i < hashtab_tmpfiles.capacity; i++) {
+
+ if (!(entry = &hashtab_tmpfiles.entries[i])) {
+ continue;
+ }
+
+ if (!entry->key || !entry->value) {
+ continue;
+ }
+
+ tmp = (struct temp_file *) entry->value;
+
+ if (tmp->fp == fp) {
+
+ if ((ret = fclose (fp))) {
+ return ret;
+ }
+
+ remove (tmp->name);
+
+ hashtab_remove (&hashtab_tmpfiles, hashtab_get_key (&hashtab_tmpfiles, tmp->name));
+ return 0;
+
+ }
+
}
-
- return fp;
+
+ return 0;
}
#endif
for (i = state->vec_hist.length - 1; i >= 0; i--) {
- entry = state->vec_hist.data[i];
+ entry = (struct hist_entry *) state->vec_hist.data[i];
printf ("from %s:%lu", entry->filename, entry->line_number);
if (i > 0) {
}
- fclose (*tmp);
+ scc_close (*tmp);
*tmp = 0;
*saved = 0;
if (arg_tmp_ofp) {
- fclose (arg_tmp_ofp);
+ scc_close (arg_tmp_ofp);
arg_tmp_ofp = 0;
}
fputc (ch, state->ofp);
}
- fclose (arg_tmp_ofps[i]);
+ scc_close (arg_tmp_ofps[i]);
arg_tmp_ofps[i] = 0;
}
for (i = 0; i < argc; i++) {
if (arg_tmp_ofps[i]) {
- fclose (arg_tmp_ofps[i]);
+ scc_close (arg_tmp_ofps[i]);
}
}
if (arg_tmp_ofp) {
- fclose (arg_tmp_ofp);
+ scc_close (arg_tmp_ofp);
arg_tmp_ofp = 0;
}
for (i = 0; i < argc; i++) {
if (arg_tmp_ofps[i]) {
- fclose (arg_tmp_ofps[i]);
+ scc_close (arg_tmp_ofps[i]);
}
}
fputc (ch, state->ofp);
}
- fclose (arg_tmp_ofps[i]);
+ scc_close (arg_tmp_ofps[i]);
arg_tmp_ofps[i] = 0;
}
for (i = 0; i < argc; i++) {
if (arg_tmp_ofps[i]) {
- fclose (arg_tmp_ofps[i]);
+ scc_close (arg_tmp_ofps[i]);
}
}
body_text = read_tmp_file_text (body_tmp);
- fclose (body_tmp);
+ scc_close (body_tmp);
body_tmp = 0;
state->ofp = saved_ofp;
}
if (arg_tmp_ofp) {
- fclose (arg_tmp_ofp);
+ scc_close (arg_tmp_ofp);
}
argc++;
fputc (ch, state->ofp);
}
- fclose (arg_tmp_ofps[i]);
+ scc_close (arg_tmp_ofps[i]);
arg_tmp_ofps[i] = 0;
}
if (step_tmp) {
replay_tmp_file_to_output (step_tmp, state->ofp);
- fclose (step_tmp);
+ scc_close (step_tmp);
step_tmp = 0;
}
if (step_tmp) {
- fclose (step_tmp);
+ scc_close (step_tmp);
}
emit_statement_label (break_label);
char *inline_asm_text = 0;
char *function_asm_text = 0;
- char function_tmp_name[64];
int capture_inline_body = 0;
int capture_function_body = 0;
int old_function_has_return_statement;
char *function_filename_copy = 0;
- function_tmp_name[0] = 0;
/**
* Inline definitions are compiled into a temporary assembler buffer so
if (capture_function_body) {
- function_tmp = open_scc_temp_file (function_tmp_name, sizeof (function_tmp_name));
+ function_tmp = scc_tmpfile ();
if (!function_tmp) {
capture_function_body = 0;
}
- fclose (function_tmp);
+ scc_close (function_tmp);
function_tmp = 0;
-
- if (function_tmp_name[0]) {
-
- remove (function_tmp_name);
- function_tmp_name[0] = 0;
-
- }
}