projects
/
deliverable
/
binutils-gdb.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix possible bug when no args have been provided to the executable
[deliverable/binutils-gdb.git]
/
libiberty
/
mkstemps.c
diff --git
a/libiberty/mkstemps.c
b/libiberty/mkstemps.c
index 56b0baea77e13a6806e6185017186976cd27f736..8a0effdd5bf1c152f02c5f4df38b4b755d6f46d3 100644
(file)
--- a/
libiberty/mkstemps.c
+++ b/
libiberty/mkstemps.c
@@
-1,4
+1,4
@@
-/* Copyright (C) 1991
, 1992, 1996, 1998
Free Software Foundation, Inc.
+/* Copyright (C) 1991
-2017
Free Software Foundation, Inc.
This file is derived from mkstemp.c from the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
This file is derived from mkstemp.c from the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@
-13,8
+13,8
@@
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 5
9 Temple Place - Suite 330
,
- Boston, MA 0211
1-1307
, USA. */
+ write to the Free Software Foundation, Inc., 5
1 Franklin Street - Fifth Floor
,
+ Boston, MA 0211
0-1301
, USA. */
#ifdef HAVE_CONFIG_H
#include "config.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
@@
-35,6
+35,8
@@
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
+#elif HAVE_TIME_H
+#include <time.h>
#endif
#include "ansidecl.h"
#endif
#include "ansidecl.h"
@@
-49,20
+51,24
@@
typedef unsigned long gcc_uint64_t;
#define TMP_MAX 16384
#endif
#define TMP_MAX 16384
#endif
+#ifndef O_BINARY
+# define O_BINARY 0
+#endif
+
/*
/*
-@deftypefn Replacement int mkstemps (char *@var{
template
}, int @var{suffix_len})
+@deftypefn Replacement int mkstemps (char *@var{
pattern
}, int @var{suffix_len})
-Generate a unique temporary file name from @var{
template
}.
-@var{
template
} has the form:
+Generate a unique temporary file name from @var{
pattern
}.
+@var{
pattern
} has the form:
@example
@example
- <path>/ccXXXXXX<suffix>
+ @var{path}/ccXXXXXX@var{suffix}
@end example
@end example
-@var{suffix_len} tells us how long
<suffix>
is (it can be zero
-length). The last six characters of @var{
template} before <suffix>
-must be @
code
{XXXXXX}; they are replaced with a string that makes the
+@var{suffix_len} tells us how long
@var{suffix}
is (it can be zero
+length). The last six characters of @var{
pattern} before @var{suffix}
+must be @
samp
{XXXXXX}; they are replaced with a string that makes the
filename unique. Returns a file descriptor open on the file for
reading and writing.
filename unique. Returns a file descriptor open on the file for
reading and writing.
@@
-71,9
+77,7
@@
reading and writing.
*/
int
*/
int
-mkstemps (template, suffix_len)
- char *template;
- int suffix_len;
+mkstemps (char *pattern, int suffix_len)
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
{
static const char letters[]
= "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
@@
-85,15
+89,15
@@
mkstemps (template, suffix_len)
size_t len;
int count;
size_t len;
int count;
- len = strlen (
template
);
+ len = strlen (
pattern
);
if ((int) len < 6 + suffix_len
if ((int) len < 6 + suffix_len
- || strncmp (&
template
[len - 6 - suffix_len], "XXXXXX", 6))
+ || strncmp (&
pattern
[len - 6 - suffix_len], "XXXXXX", 6))
{
return -1;
}
{
return -1;
}
- XXXXXX = &
template
[len - 6 - suffix_len];
+ XXXXXX = &
pattern
[len - 6 - suffix_len];
#ifdef HAVE_GETTIMEOFDAY
/* Get some more or less random data. */
#ifdef HAVE_GETTIMEOFDAY
/* Get some more or less random data. */
@@
-121,10
+125,17
@@
mkstemps (template, suffix_len)
v /= 62;
XXXXXX[5] = letters[v % 62];
v /= 62;
XXXXXX[5] = letters[v % 62];
- fd = open (
template,
O_RDWR|O_CREAT|O_EXCL, 0600);
+ fd = open (
pattern, O_BINARY|
O_RDWR|O_CREAT|O_EXCL, 0600);
if (fd >= 0)
/* The file does not exist. */
return fd;
if (fd >= 0)
/* The file does not exist. */
return fd;
+ if (errno != EEXIST
+#ifdef EISDIR
+ && errno != EISDIR
+#endif
+ )
+ /* Fatal error (EPERM, ENOSPC etc). Doesn't make sense to loop. */
+ break;
/* This is a random value. It is only necessary that the next
TMP_MAX values generated by adding 7777 to VALUE are different
/* This is a random value. It is only necessary that the next
TMP_MAX values generated by adding 7777 to VALUE are different
@@
-133,6
+144,6
@@
mkstemps (template, suffix_len)
}
/* We return the null string if we can't find a unique file name. */
}
/* We return the null string if we can't find a unique file name. */
-
template
[0] = '\0';
+
pattern
[0] = '\0';
return -1;
}
return -1;
}
This page took
0.024452 seconds
and
4
git commands to generate.