2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
11 #include <sys/param.h>
14 /* Modified from create_mem_file and start_debugger */
15 static char *tempdir = NULL;
17 static void __init find_tempdir(void)
19 char *dirs[] = { "TMP", "TEMP", "TMPDIR", NULL };
23 if(tempdir != NULL) return; /* We've already been called */
24 for(i = 0; dirs[i]; i++){
25 dir = getenv(dirs[i]);
26 if((dir != NULL) && (*dir != '\0'))
29 if((dir == NULL) || (*dir == '\0'))
31 tempdir = malloc(strlen(dir) + 2);
33 fprintf(stderr, "Failed to malloc tempdir, "
34 "errno = %d\n", errno);
41 int make_tempfile(const char *template, char **out_tempname, int do_unlink)
43 char tempname[MAXPATHLEN];
48 strcpy(tempname, tempdir);
51 strcat(tempname, template);
52 if((fd = mkstemp(tempname)) < 0){
53 fprintf(stderr, "open - cannot create %s: %s\n", tempname,
57 if(do_unlink && (unlink(tempname) < 0)){
62 if((*out_tempname = strdup(tempname)) == NULL){
71 * Overrides for Emacs so that we follow Linus's tabbing style.
72 * Emacs will notice this stuff at the end of the file and automatically
73 * adjust the settings for this buffer only. This must remain at the end
75 * ---------------------------------------------------------------------------
77 * c-file-style: "linux"