|
|
BOOL trun_syms; /* truncate symbols to 8 characters */ | BOOL trun_syms; /* truncate symbols to 8 characters */ |
char tempstring[8192]; /* use this as a buffer, instead of 'yytext', | char tempstring[8192]; /* use this as a buffer, instead of 'yytext', |
* which had better be left alone */ | * which had better be left alone */ |
char *tmpdir; /* temporary directory */ |
char tmpdir[2048]; /* temporary directory */ |
| |
static BOOL onesearch; /* one search only in line mode */ | static BOOL onesearch; /* one search only in line mode */ |
static char *reflines; /* symbol reference lines file */ | static char *reflines; /* symbol reference lines file */ |
|
|
shell = mygetenv("SHELL", SHELL); | shell = mygetenv("SHELL", SHELL); |
lineflag = mygetenv("CSCOPE_LINEFLAG", LINEFLAG); | lineflag = mygetenv("CSCOPE_LINEFLAG", LINEFLAG); |
lineflagafterfile = getenv("CSCOPE_LINEFLAG_AFTER_FILE")?1:0; | lineflagafterfile = getenv("CSCOPE_LINEFLAG_AFTER_FILE")?1:0; |
tmpdir = mygetenv("TMPDIR", TMPDIR); |
|
| |
|
char template[] = "cscope.XXXXXX"; |
|
snprintf(tmpdir, sizeof(tmpdir), "%s/%s", mygetenv("TMPDIR", TMPDIR), template); |
|
tmpdir[sizeof(tmpdir)-1] = '\0'; |
|
char *ret; |
|
ret = mkdtemp(tmpdir); |
|
if (ret == NULL)s |
|
{ |
|
fprintf (stderr, "cscope: Temporary directory %s cannot be created.\n", tmpdir); |
|
myexit(1); |
|
} |
|
|
/* XXX remove if/when clearerr() in dir.c does the right thing. */ | /* XXX remove if/when clearerr() in dir.c does the right thing. */ |
if (namefile && strcmp(namefile, "-") == 0 && !buildonly) | if (namefile && strcmp(namefile, "-") == 0 && !buildonly) |
{ | { |
|
|
| |
/* create the temporary file names */ | /* create the temporary file names */ |
pid = getpid(); | pid = getpid(); |
(void) sprintf(temp1, "%s/cscope%d.1", tmpdir, pid); |
(void) snprintf(temp1, sizeof(temp1), "%s/cscope%d.1", tmpdir, pid); |
(void) sprintf(temp2, "%s/cscope%d.2", tmpdir, pid); |
temp1[sizeof(temp1)-1] = '\0'; |
|
(void) snprintf(temp2, sizeof(temp1), "%s/cscope%d.2", tmpdir, pid); |
|
temp2[sizeof(temp2)-1] = '\0'; |
| |
/* if running in the foreground */ | /* if running in the foreground */ |
if (signal(SIGINT, SIG_IGN) != SIG_IGN) { | if (signal(SIGINT, SIG_IGN) != SIG_IGN) { |
|
|
void | void |
myexit(int sig) | myexit(int sig) |
{ | { |
|
int retval; |
/* HBB 20010313; close file before unlinking it. Unix may not care | /* HBB 20010313; close file before unlinking it. Unix may not care |
* about that, but DOS absolutely needs it */ | * about that, but DOS absolutely needs it */ |
if (refsfound != NULL) | if (refsfound != NULL) |
|
|
if (temp1[0] != '\0') { | if (temp1[0] != '\0') { |
(void) unlink(temp1); | (void) unlink(temp1); |
(void) unlink(temp2); | (void) unlink(temp2); |
|
if (retval = rmdir(tmpdir) != 0) |
|
{ |
|
fprintf(stderr, "error deleting %s\n", tmpdir); |
|
} |
} | } |
/* restore the terminal to its original mode */ | /* restore the terminal to its original mode */ |
if (incurses == YES) { | if (incurses == YES) { |