Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ISC Open Source Projects
BIND
Commits
febf5f8b
Commit
febf5f8b
authored
Jul 27, 2000
by
David Lawrence
Browse files
355. [func] Added isc_dir_createunique(), similar to mkdtemp().
parent
c34bdef6
Changes
3
Hide whitespace changes
Inline
Side-by-side
CHANGES
View file @
febf5f8b
355. [func] Added isc_dir_createunique(), similar to mkdtemp().
354. [doc] Man pages for the dnssec tools are now included in
the distribution, in doc/man/dnssec.
...
...
lib/isc/unix/dir.c
View file @
febf5f8b
...
...
@@ -15,12 +15,16 @@
* SOFTWARE.
*/
/* $Id: dir.c,v 1.1
0
2000/0
5/11 15:09:27
tale Exp $ */
/* $Id: dir.c,v 1.1
1
2000/0
7/27 02:04:34
tale Exp $ */
/* Principal Authors: DCL */
#include <config.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
...
...
@@ -126,10 +130,6 @@ isc_dir_reset(isc_dir_t *dir) {
return
(
ISC_R_SUCCESS
);
}
/*
* XXX Is there a better place for this?
*/
isc_result_t
isc_dir_chdir
(
const
char
*
dirname
)
{
/*
...
...
@@ -143,3 +143,72 @@ isc_dir_chdir(const char *dirname) {
return
(
ISC_R_SUCCESS
);
}
isc_result_t
isc_dir_createunique
(
char
*
templet
)
{
isc_result_t
result
;
char
*
x
;
char
*
p
;
int
i
;
int
pid
;
REQUIRE
(
templet
!=
NULL
);
/*
* mkdtemp is not portable, so this emulates it.
*/
pid
=
getpid
();
/*
* Replace trailing Xs with the process-id, zero-filled.
*/
for
(
x
=
templet
+
strlen
(
templet
)
-
1
;
*
x
==
'X'
&&
x
>=
templet
;
x
--
,
pid
/=
10
)
*
x
=
pid
%
10
+
'0'
;
x
++
;
/* Set x to start of ex-Xs. */
do
{
i
=
mkdir
(
templet
,
0700
);
if
(
i
==
0
||
errno
!=
EEXIST
)
break
;
/*
* The BSD algorithm.
*/
p
=
x
;
while
(
*
p
!=
'\0'
)
{
if
(
isdigit
(
*
p
))
*
p
=
'a'
;
else
if
(
*
p
!=
'z'
)
++*
p
;
else
{
/*
* Reset character and move to next.
*/
*
p
++
=
'a'
;
continue
;
}
break
;
}
if
(
*
p
==
'\0'
)
{
/*
* Tried all combinations. errno should already
* be EEXIST, but ensure it is anyway for
* isc__errno2result().
*/
errno
=
EEXIST
;
break
;
}
}
while
(
1
);
if
(
i
==
-
1
)
result
=
isc__errno2result
(
errno
);
else
result
=
ISC_R_SUCCESS
;
return
(
result
);
}
lib/isc/unix/include/isc/dir.h
View file @
febf5f8b
...
...
@@ -15,7 +15,7 @@
* SOFTWARE.
*/
/* $Id: dir.h,v 1.
8
2000/0
6
/2
3
0
3
:0
8:18
tale Exp $ */
/* $Id: dir.h,v 1.
9
2000/0
7
/2
7
0
2
:0
4:36
tale Exp $ */
/* Principal Authors: DCL */
...
...
@@ -73,6 +73,15 @@ isc_dir_close(isc_dir_t *dir);
isc_result_t
isc_dir_chdir
(
const
char
*
dirname
);
isc_result_t
isc_dir_createunique
(
char
*
templet
);
/*
* Use a templet (such as from isc_file_mktemplate()) to create a uniquely
* named, empty directory. The templet string is modified in place.
* If result == ISC_R_SUCCESS, it is the name of the directory that was
* created.
*/
ISC_LANG_ENDDECLS
#endif
/* ISC_DIR_H */
Write
Preview
Supports
Markdown
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