Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
afb60034
Commit
afb60034
authored
Oct 14, 2002
by
Jeff Dike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some code to arch/um/kernel/tempfile.c.
parent
facb7381
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
0 deletions
+79
-0
arch/um/kernel/tempfile.c
arch/um/kernel/tempfile.c
+79
-0
No files found.
arch/um/kernel/tempfile.c
View file @
afb60034
/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/param.h>
#include "init.h"
char
*
tempdir
=
NULL
;
static
void
__init
find_tempdir
(
void
)
{
char
*
dirs
[]
=
{
"TMP"
,
"TEMP"
,
"TMPDIR"
,
NULL
};
int
i
;
char
*
dir
=
NULL
;
if
(
tempdir
!=
NULL
)
return
;
/* We've already been called */
for
(
i
=
0
;
dirs
[
i
];
i
++
){
dir
=
getenv
(
dirs
[
i
]);
if
(
dir
!=
NULL
)
break
;
}
if
(
dir
==
NULL
)
dir
=
"/tmp"
;
else
if
(
*
dir
==
'\0'
)
dir
=
NULL
;
if
(
dir
!=
NULL
)
{
tempdir
=
malloc
(
strlen
(
dir
)
+
2
);
if
(
tempdir
==
NULL
){
fprintf
(
stderr
,
"Failed to malloc tempdir, "
"errno = %d
\n
"
,
errno
);
return
;
}
strcpy
(
tempdir
,
dir
);
strcat
(
tempdir
,
"/"
);
}
}
int
make_tempfile
(
const
char
*
template
,
char
**
out_tempname
,
int
do_unlink
)
{
char
tempname
[
MAXPATHLEN
];
int
fd
;
find_tempdir
();
if
(
*
template
!=
'/'
)
strcpy
(
tempname
,
tempdir
);
else
*
tempname
=
0
;
strcat
(
tempname
,
template
);
if
((
fd
=
mkstemp
(
tempname
))
<
0
){
fprintf
(
stderr
,
"open - cannot create %s: %s
\n
"
,
tempname
,
strerror
(
errno
));
return
-
1
;
}
if
(
do_unlink
&&
(
unlink
(
tempname
)
<
0
)){
perror
(
"unlink"
);
return
-
1
;
}
if
(
out_tempname
){
if
((
*
out_tempname
=
strdup
(
tempname
))
==
NULL
){
perror
(
"strdup"
);
return
-
1
;
}
}
return
(
fd
);
}
/*
* Overrides for Emacs so that we follow Linus's tabbing style.
* Emacs will notice this stuff at the end of the file and automatically
* adjust the settings for this buffer only. This must remain at the end
* of the file.
* ---------------------------------------------------------------------------
* Local variables:
* c-file-style: "linux"
* End:
*/
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment